Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 47aad95

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Add differentiation of DAE.RSUB
Belonging to [master]: - #2076 - OpenModelica/OpenModelica-testsuite#810
1 parent 059c8c0 commit 47aad95

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

Compiler/BackEnd/Differentiate.mo

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -685,21 +685,30 @@ algorithm
685685
then (res, functionTree);
686686

687687
// differentiate tsub
688-
case DAE.TSUB(exp=e1, ix=i, ty=tp) equation
689-
//se1 = ExpressionDump.printExpStr(inExp);
690-
//print("\nExp-TSUB\nDifferentiate exp: " + se1);
688+
case DAE.TSUB(exp=e1, ix=i, ty=tp)
689+
algorithm
690+
(res1, functionTree) := differentiateExp(e1, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1);
691691

692-
(res1, functionTree) = differentiateExp(e1, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1);
692+
if not referenceEq(e1, res1) then
693+
res := DAE.TSUB(res1, i, tp);
694+
(res,_) := ExpressionSimplify.simplify1(res);
695+
else
696+
res := inExp;
697+
end if;
698+
then (res, functionTree);
693699

694-
res = DAE.TSUB(res1, i, tp);
695-
(res,_) = ExpressionSimplify.simplify1(res);
696-
//(res,_) = ExpressionSimplify.simplify(res);
697700

698-
//se1 = ExpressionDump.printExpStr(res);
699-
//print("\nresults to exp: " + se1);
700-
then (res, functionTree);
701+
// differentiate tsub
702+
case e1 as DAE.RSUB()
703+
algorithm
704+
(res1, functionTree) := differentiateExp(e1.exp, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter-1);
705+
if not referenceEq(e1.exp, res1) then
706+
e1.exp := res1;
707+
(e1,_) := ExpressionSimplify.simplify1(e1);
708+
end if;
709+
then (e1, functionTree);
701710

702-
// differentiate tuple
711+
// differentiate tuple
703712
case DAE.TUPLE(PR=expl) equation
704713
//se1 = ExpressionDump.printExpStr(inExp);
705714
//print("\nExp-TUPLE\nDifferentiate exp: " + se1);

0 commit comments

Comments
 (0)