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

Commit 049ab69

Browse files
rfrankeOpenModelica-Hudson
authored andcommitted
Support array equation with der(v) on left hand side
See e.g. import of FMU in testsuite/openmodelica/cppruntime/fmu/modelExchange/2.0/DIC_FMU2_CPP.mos: der(fmi_x) = DIC_me_FMU.fmi2Functions.fmi2GetDerivatives(fmi2me, 2, flowStatesInputs) Belonging to [master]: - #2658
1 parent 18752c9 commit 049ab69

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

Compiler/BackEnd/BackendDAETransform.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ algorithm
865865
(exp1::exps) := Expression.flattenArrayExpToList(e);
866866
(cr1, call1) := match exp1
867867
case DAE.CREF(componentRef=cr1) then (cr1, "");
868-
case DAE.CALL(path=Absyn.IDENT(name="previous"), expLst={DAE.CREF(componentRef=cr1)}) then (cr1, "previous");
868+
case DAE.CALL(path=Absyn.IDENT(name=call1), expLst={DAE.CREF(componentRef=cr1)}) then (cr1, call1);
869869
else fail();
870870
end match;
871871
if call1 <> "" and Config.simCodeTarget() <> "Cpp" or call1 == "pre" then
@@ -886,7 +886,7 @@ algorithm
886886
//DAE.CREF(componentRef=cr2) := exp;
887887
(cr2, call2) := match exp
888888
case DAE.CREF(componentRef=cr2) then (cr2, "");
889-
case DAE.CALL(path=Absyn.IDENT(name="previous"), expLst={DAE.CREF(componentRef=cr2)}) then (cr2, "previous");
889+
case DAE.CALL(path=Absyn.IDENT(name=call2), expLst={DAE.CREF(componentRef=cr2)}) then (cr2, call2);
890890
else fail();
891891
end match;
892892
true := ndim==listLength(ComponentReference.crefLastSubs(cr2));

Compiler/SimCode/SimCodeUtil.mo

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5444,11 +5444,21 @@ protected function createSingleArrayEqnCode
54445444
output list<SimCode.SimEqSystem> noDiscequations;
54455445
output Integer ouniqueEqIndex;
54465446
output list<SimCodeVar.SimVar> otempvars;
5447+
protected
5448+
BackendDAE.Equation inEquation;
54475449
algorithm
5448-
(equations_, noDiscequations, ouniqueEqIndex, otempvars) := matchcontinue(genDiscrete, inEquations, inVars, iuniqueEqIndex, itempvars, iextra)
5450+
// first replace der() to match them as cref $DER. below
5451+
inEquation := match listHead(inEquations)
5452+
case inEquation as BackendDAE.ARRAY_EQUATION(_)
5453+
algorithm
5454+
inEquation.left := Expression.replaceDerOpInExp(inEquation.left);
5455+
inEquation.right := Expression.replaceDerOpInExp(inEquation.right);
5456+
then inEquation;
5457+
end match;
5458+
(equations_, noDiscequations, ouniqueEqIndex, otempvars) := matchcontinue(genDiscrete, inEquation, inVars, iuniqueEqIndex, itempvars, iextra)
54495459
local
54505460
list<Integer> ds;
5451-
DAE.Exp e1, e2, e1_1, e2_1, lhse, rhse;
5461+
DAE.Exp e1, e2, lhse, rhse;
54525462
list<DAE.Exp> ea1, ea2, expLst, expLstTmp;
54535463
list<BackendDAE.Equation> re;
54545464
list<BackendDAE.Var> vars;
@@ -5482,14 +5492,11 @@ algorithm
54825492
// {z1,z2,..} = rhsexp -> solved for {z1,z2,..}
54835493
// => tmp = rhsexp;
54845494
// z1 = tmp[1]; z2 = tmp[2] ....
5485-
case (_, (BackendDAE.ARRAY_EQUATION(dimSize=ds, left=e1, right=e2, source=source, attr=eqAttr))::{}, _, _, _, _)
5495+
case (_, (BackendDAE.ARRAY_EQUATION(dimSize=ds, left=e1, right=e2, source=source, attr=eqAttr)), _, _, _, _)
54865496
guard Expression.isMatrix(e1) or Expression.isArray(e1)
54875497
equation
54885498
// Flattne multi-dimensional ARRAY{ARRAY} expressions
54895499
expLst = Expression.flattenArrayExpToList(e1);
5490-
// Replace the der() operators
5491-
expLst = List.map(expLst, Expression.replaceDerOpInExp);
5492-
e2_1 = Expression.replaceDerOpInExp(e2);
54935500
// create the lhs tmp var
54945501
ty = Expression.typeof(e1);
54955502
(basety,dims) = Types.flattenArrayType(ty);
@@ -5506,16 +5513,14 @@ algorithm
55065513
exptl = List.threadTuple(expLst, expLstTmp);
55075514
(eqSystlst, uniqueEqIndex) = List.map2Fold(exptl, makeSES_SIMPLE_ASSIGN, source, eqAttr, iuniqueEqIndex);
55085515
// Create the array equation with the tmp var as lhs
5509-
eqSystlst = SimCode.SES_ARRAY_CALL_ASSIGN(uniqueEqIndex, lhse, e2_1, source, eqAttr)::eqSystlst;
5516+
eqSystlst = SimCode.SES_ARRAY_CALL_ASSIGN(uniqueEqIndex, lhse, e2, source, eqAttr)::eqSystlst;
55105517
then (eqSystlst, eqSystlst, uniqueEqIndex+1, tempvars);
55115518

55125519
// An array equation
55135520
// cref = rhsexp
5514-
case (_, (BackendDAE.ARRAY_EQUATION(left=lhse as DAE.CREF(cr_1, _), right=e2, source=source, attr=eqAttr))::_, BackendDAE.VAR(varName=cr)::_, _, _, _)
5521+
case (_, (BackendDAE.ARRAY_EQUATION(left=e1 as DAE.CREF(cr_1, _), right=e2, source=source, attr=eqAttr)), BackendDAE.VAR(varName=cr)::_, _, _, _)
55155522
guard ComponentReference.crefEqual(cr_1, ComponentReference.crefStripLastSubs(cr))
55165523
equation
5517-
e1 = Expression.replaceDerOpInExp(lhse);
5518-
e2 = Expression.replaceDerOpInExp(e2);
55195524
(e1, _) = BackendDAEUtil.collateArrExp(e1, NONE());
55205525
(e2, _) = BackendDAEUtil.collateArrExp(e2, NONE());
55215526
(e1, e2) = solveTrivialArrayEquation(cr_1, e1, e2);
@@ -5525,11 +5530,9 @@ algorithm
55255530

55265531
// An array equation
55275532
// lhsexp = cref
5528-
case (_, (BackendDAE.ARRAY_EQUATION(left=e1, right=rhse as DAE.CREF(cr_1, _), source=source, attr=eqAttr))::_, BackendDAE.VAR(varName=cr)::_, _, _, _)
5533+
case (_, (BackendDAE.ARRAY_EQUATION(left=e1, right=e2 as DAE.CREF(cr_1, _), source=source, attr=eqAttr)), BackendDAE.VAR(varName=cr)::_, _, _, _)
55295534
guard ComponentReference.crefEqual(cr_1, ComponentReference.crefStripLastSubs(cr))
55305535
equation
5531-
e1 = Expression.replaceDerOpInExp(e1);
5532-
e2 = Expression.replaceDerOpInExp(rhse);
55335536
(e1, _) = BackendDAEUtil.collateArrExp(e1, NONE());
55345537
(e2, _) = BackendDAEUtil.collateArrExp(e2, NONE());
55355538
(e2, e1) = solveTrivialArrayEquation(cr_1, e2, e1);

0 commit comments

Comments
 (0)