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

Commit 6f93d97

Browse files
WilliOpenModelica-Hudson
authored andcommitted
Scalarize differentiated exp RSUB and TSUB equations
Belonging to [master]: - #2769 - OpenModelica/OpenModelica-testsuite#1083
1 parent 0a46029 commit 6f93d97

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

Compiler/BackEnd/BackendEquation.mo

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,5 +3139,49 @@ algorithm
31393139
end match;
31403140
end getEquationLHS;
31413141

3142+
public function scalarComplexEquations
3143+
"This function splits tuples and record in single equations,
3144+
to avoid non-linear loops.
3145+
e.g.: R(a,b) = R(2*x,3*y) => r.a = 2*x; r.b = 3*y
3146+
(a,b) = (2*g(x)[1],3*g(x)[2]) => a = 2*g(x)[1]; b = 3*g(x)[2]
3147+
Used after some equations have been differentiated.
3148+
"
3149+
input BackendDAE.Equation inEquation;
3150+
input DAE.FunctionTree funcTree;
3151+
output list<BackendDAE.Equation> outEquations;
3152+
algorithm
3153+
3154+
outEquations := match (inEquation)
3155+
local
3156+
DAE.Exp e1, e2;
3157+
DAE.ElementSource source;
3158+
list<DAE.Exp> explst, explst2;
3159+
list<BackendDAE.Equation> eqns;
3160+
BackendDAE.EquationAttributes attr;
3161+
3162+
case (BackendDAE.COMPLEX_EQUATION(left=DAE.TUPLE(explst), right=DAE.TUPLE(explst2), source=source, attr=attr))
3163+
equation
3164+
true = listLength(explst) == listLength(explst2);
3165+
eqns = List.threadMap2(explst, explst2, generateEquation, source, attr);
3166+
then eqns;
3167+
3168+
case (BackendDAE.COMPLEX_EQUATION(left=e1, right=e2, source=source, attr=attr))
3169+
guard ((Expression.isRecordCall(e1, funcTree) or Expression.isRecord(e1)) and
3170+
(Expression.isRecordCall(e2, funcTree) or Expression.isRecord(e2))
3171+
)
3172+
equation
3173+
explst = Expression.splitRecord(e1, Expression.typeof(e1));
3174+
explst2 = Expression.splitRecord(e2, Expression.typeof(e2));
3175+
true = listLength(explst) == listLength(explst2);
3176+
eqns = List.threadMap2(explst, explst2, generateEquation, source, attr);
3177+
then eqns;
3178+
3179+
else
3180+
then {inEquation};
3181+
3182+
end match;
3183+
end scalarComplexEquations;
3184+
3185+
31423186
annotation(__OpenModelica_Interface="backend");
31433187
end BackendEquation;

Compiler/BackEnd/SymbolicJacobian.mo

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2338,6 +2338,7 @@ protected function deriveAll
23382338
protected
23392339
BackendDAE.Variables allVars;
23402340
BackendDAE.Equation currDerivedEquation;
2341+
list<BackendDAE.Equation> tmpEquations;
23412342
list<BackendDAE.Var> solvedvars;
23422343
list<Integer> ass2_1 = ass2, solvedfor;
23432344
Boolean b;
@@ -2352,7 +2353,8 @@ algorithm
23522353
end if;
23532354

23542355
(currDerivedEquation, outFunctions) := Differentiate.differentiateEquation(currEquation, inDiffCref, inDiffData, BackendDAE.GENERIC_GRADIENT(), outFunctions);
2355-
outDerivedEquations := currDerivedEquation::outDerivedEquations;
2356+
tmpEquations := BackendEquation.scalarComplexEquations(currDerivedEquation, outFunctions);
2357+
outDerivedEquations := listAppend(tmpEquations, outDerivedEquations);
23562358

23572359
if Flags.isSet(Flags.JAC_DUMP_EQN) then
23582360
BackendDump.printEquationList(outDerivedEquations);

0 commit comments

Comments
 (0)