Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#3305 closed defect (fixed)

Derivative of homotopy

Reported by: Martin Sjölund Owned by: Lennart Ochel
Priority: high Milestone: 1.9.4
Component: Backend Version: trunk
Keywords: Cc: Lennart Ochel, Willi Braun, mbonvini@…

Description

What is the derivative of homotopy? We have the following code commented out:

    // differentiate homotopy
    /* case( e as DAE.CALL(
                path = p as Absyn.IDENT(name="homotopy"),
                expLst = {actual,simplified},
                attr = attr), _, _, _, _)
      equation
        (res, functionTree) = differentiateExp(actual, inDiffwrtCref, inInputData, inDiffType, inFunctionTree);
        // (e2, functionTree) = differentiateExp(simplified, inDiffwrtCref, inInputData, inDiffType, functionTree);
        // res = DAE.CALL(p, {e1, e2}, attr);
      then
        (res, functionTree); */

For Buildings.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples.ACSimpleGrid_N, replacing the expression with the actual expression works well. So does using the --replaceHomotopy=actual flag.

Change History (17)

comment:1 by Lennart Ochel, 10 years ago

This depends on the context. For ordinary simulation it is just the derivative of the actual expression. I am already working on removing homotopy for simulation context.

comment:2 by Lennart Ochel, 9 years ago

Owner: changed from somebody to Lennart Ochel
Status: newaccepted

comment:3 by Lennart Ochel, 9 years ago

I'd expect that just the actual expression need to be differentiated.
I run the entire test suite with that differentiation rule and there is one problem with the symbolic Jacobian for state sets in Modelica.Fluid.Examples.HeatingSystem. Willi, can you explain why it fails?

comment:4 by Willi Braun, 9 years ago

Owner: changed from Lennart Ochel to Willi Braun

For some reason the symbolic jacobian for dynamic state selection has 18 equations and 19 variables. So that's the reason it fails, but that needs some further investigation.

comment:5 by Adrian Pop, 9 years ago

For example some models in Buildings fail with differentiation of homotopy issues:
https://test.openmodelica.org/libraries/Buildings/files/Buildings.Electrical.AC.OnePhase.Conversion.Examples.ACACTransformer.err

Lennart added a case for handling homotopy in the Differentiate module but is commented out due to Jacobian issues.

Willi can you have a quick look?

comment:6 by Willi Braun, 9 years ago

The actual reason for commenting it out was and is somehow the index reduction. In the past we had also issues with this rule in index reduction with avm models.
BTW: Adrian, are they still checked from time to time?
Okay I'll have a other look into it.
However, perhaps we should activated it anyway, even if there are models that fails, but is most likely for other reasons and the rule is correct.

comment:7 by Adrian Pop, 9 years ago

@wbraun. They were checked on each commit but unfortunately we haven't updated them in a while. I disabled the AVM test just yesterday until I get some time to update them.

comment:8 by anonymous, 9 years ago

how about:
if init() then homotopy(diff(),diff()) else diff(actual)

comment:9 by Francesco Casella, 9 years ago

I am not sure I understand what the problem is, also with reference to #3716.

For simulation code generation, the actual expression should be used.

For initialization code generation when lambda = 0, the simplified expression should be used.

For initialization code generation when lambda > 0, lambda*actual + (1-lambda)*simplified should be used.

Any problem with this?

Also the proposal in comment:8 seems just fine to me.

Please close #3716 when this is fixed.

comment:10 by Lennart Ochel, 9 years ago

Owner: changed from Willi Braun to Lennart Ochel
Status: acceptedassigned

I've already implemented proper handling of homotopy for different stages (i.e. simulation and initialization). That means that we always generate just the actual expression for simulation, simplified expression for initialization with lambda=0 and homotopy expression for initialization with lambda <> 0.

The problem is index-reduction which is performed before splitting up initialization/simulation. The equations that are generated during index reduction will later be optimized for simulation/initialization and need therefore to have all the information.

I just reassign this to me.

comment:11 by Lennart Ochel, 9 years ago

I've created PR453 for this.

comment:12 by Francesco Casella, 9 years ago

For the index reduction analysis, you should just use the actual expression. The index is related to the simulation equations, not to the initialization ones.

comment:14 by Lennart Ochel, 9 years ago

Resolution: fixed
Status: assignedclosed

comment:15 by Lennart Ochel, 9 years ago

Milestone: Future1.9.4

comment:16 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.4-1.9.x

Milestone renamed

comment:17 by Martin Sjölund, 9 years ago

Milestone: 1.9.4-1.9.x1.9.4

Milestone renamed

Note: See TracTickets for help on using tickets.