Skip to content

Commit

Permalink
Differentiate homotopy operator with lambda
Browse files Browse the repository at this point in the history
  - Before we only diferentiated the actual expression.
    Now we will differentiate lambda*actual + (1-lambda)*simplified.
  - Added test case
  - Homotopy no longer breaks differentation
  • Loading branch information
AnHeuermann authored and AnHeuermann committed Jan 15, 2021
1 parent 6e46c80 commit f8ceac8
Show file tree
Hide file tree
Showing 5 changed files with 723 additions and 14 deletions.
11 changes: 9 additions & 2 deletions OMCompiler/Compiler/BackEnd/Differentiate.mo
Expand Up @@ -576,7 +576,7 @@ algorithm
Absyn.Path p, p1, p2;
Boolean b;
DAE.CallAttributes attr;
DAE.Exp e1, e2, e3, actual, simplified;
DAE.Exp e1, e2, e3, actual, simplified, lambda;
DAE.Exp res, res1, res2;
DAE.FunctionTree functionTree;
DAE.Operator op;
Expand Down Expand Up @@ -622,8 +622,15 @@ algorithm

// differentiate homotopy
case DAE.CALL(path=p as Absyn.IDENT(name="homotopy"), expLst={actual, simplified}, attr=attr) algorithm
lambda := Expression.crefExp(ComponentReference.makeCrefIdent(BackendDAE.homotopyLambda, DAE.T_REAL_DEFAULT, {}));
(e1, functionTree) := differentiateExp(actual, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter);
then (e1, functionTree);
(e2, functionTree) := differentiateExp(simplified, inDiffwrtCref, inInputData, inDiffType, functionTree, maxIter);
e3 := DAE.BINARY(
DAE.BINARY(lambda, DAE.MUL(DAE.T_REAL_DEFAULT), e1), /* lambda*e1 */
DAE.ADD(DAE.T_REAL_DEFAULT), /* + */
DAE.BINARY(DAE.BINARY(DAE.RCONST(1.0),DAE.SUB(DAE.T_REAL_DEFAULT),lambda), DAE.MUL(DAE.T_REAL_DEFAULT), e2) /* (lambda-1)*e2*/
);
then (e3, functionTree);

/*
do not differentiate semiLinear, if the second or third expression contains the diff cref
Expand Down
1 change: 0 additions & 1 deletion OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo
Expand Up @@ -2982,7 +2982,6 @@ algorithm
Boolean b, insideCall;
DAE.Type ty;
case (DAE.CALL(path=Absyn.IDENT("delay")), (expLst, _, insideCall)) then (inExp, false, (inExp::expLst, false, insideCall));
case (DAE.CALL(path=Absyn.IDENT("homotopy")), (expLst, _, insideCall)) then (inExp, false, (inExp::expLst, false, insideCall));

// For now exclude all not built in calls
case (DAE.CALL(attr=DAE.CALL_ATTR(builtin=false)), (expLst, _, insideCall)) then (inExp, false, (inExp::expLst, false, insideCall));
Expand Down

0 comments on commit f8ceac8

Please sign in to comment.