@@ -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;
54475449algorithm
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