@@ -4774,6 +4774,8 @@ algorithm
47744774 list< Real > rhsVals,solvedVals;
47754775 BackendDAE . ExternalObjectClasses eoc;
47764776 BackendDAE . AliasVariables ave;
4777+ list< DAE . ElementSource > sources;
4778+ list< DAE . ComponentRef > names;
47774779
47784780 // A single array equation
47794781 case (mixedEvent,genDiscrete,skipDiscInAlgorithm,dae,optJac,jac_tp,block_,helpVarInfo)
@@ -4799,14 +4801,16 @@ algorithm
47994801 eqn_size = BackendDAEUtil . equationSize(eqn);
48004802 ((simVars,_)) = BackendVariable . traverseBackendDAEVars(v,traversingdlowvarToSimvar,({},kv));
48014803 simVars = listReverse(simVars);
4802- ((_,_,_,beqs)) = BackendEquation . traverseBackendDAEEqns(eqn,dlowEqToExp,(v,arrayEqs,{},{}));
4804+ ((_,_,_,beqs,sources )) = BackendEquation . traverseBackendDAEEqns(eqn,dlowEqToExp,(v,arrayEqs,{} ,{},{}));
48034805 beqs = listReverse(beqs);
48044806 rhsVals = ValuesUtil . valueReals(Util . listMap(beqs,Ceval . cevalSimple));
48054807 jacVals = BackendDAEOptimize . evaluateConstantJacobian(listLength(simVars),jac);
48064808 (solvedVals,linInfo) = System . solveLinearSystem(jacVals,rhsVals);
4807- checkLinearSystem(linInfo,simVars,jacVals,rhsVals);
4809+ names = Util . listMap(simVars,varName);
4810+ checkLinearSystem(linInfo,names,jacVals,rhsVals);
48084811 // TODO: Move these to known vars :/ This is done in the wrong phase of the compiler... Also, if done as an optimization module, we can optimize more!
4809- equations_ = Util . listThreadMap(simVars,solvedVals,generateSolvedEquation);
4812+ sources = Util . listMap1(sources, DAEUtil . addSymbolicTransformation, DAE . LINEAR_SOLVED (names,jacVals,solvedVals,rhsVals));
4813+ equations_ = Util . listThread3Map(simVars,solvedVals,sources,generateSolvedEquation);
48104814 then
48114815 equations_;
48124816
@@ -4840,7 +4844,7 @@ algorithm
48404844 equation
48414845 ((simVars,_)) = BackendVariable . traverseBackendDAEVars(v,traversingdlowvarToSimvar,({},kv));
48424846 simVars = listReverse(simVars);
4843- ((_,_,_,beqs)) = BackendEquation . traverseBackendDAEEqns(eqn,dlowEqToExp,(v,arrayEqs,{},{}));
4847+ ((_,_,_,beqs,_ )) = BackendEquation . traverseBackendDAEEqns(eqn,dlowEqToExp,(v,arrayEqs,{} ,{},{}));
48444848 beqs = listReverse(beqs);
48454849 simJac = Util . listMap1(jac, jacToSimjac, v);
48464850 index = Util . listFirst(block_); // use first equation nr as index
@@ -4878,7 +4882,7 @@ end createOdeSystem2;
48784882
48794883protected function checkLinearSystem
48804884 input Integer info;
4881- input list< SimVar > vars;
4885+ input list< DAE . ComponentRef > vars;
48824886 input list< list< Real >> jac;
48834887 input list< Real > rhs;
48844888algorithm
@@ -4889,9 +4893,9 @@ algorithm
48894893 case (info,vars,jac,rhs)
48904894 equation
48914895 true = info > 0 ;
4892- varname = varName (listGet(vars,info));
4896+ varname = ComponentReference . printComponentRefStr (listGet(vars,info));
48934897 infoStr = intString(info);
4894- varnames = Util . stringDelimitList(Util . listMap(vars,varName )," ; \n " );
4898+ varnames = Util . stringDelimitList(Util . listMap(vars,ComponentReference . printComponentRefStr )," ; \n " );
48954899 rhsStr = Util . stringDelimitList(Util . listMap(rhs, realString)," ; \n " );
48964900 jacStr = Util . stringDelimitList(Util . listMap1(Util . listListMap(jac,realString),Util . stringDelimitList," , " )," ; \n " );
48974901 syst = stringAppendList({" \n [ \n " , jacStr, " \n ] \n * \n [ \n " ,varnames," \n ] \n = \n [ \n " ,rhsStr," \n ]" });
@@ -4900,7 +4904,7 @@ algorithm
49004904 case (info,vars,jac,rhs)
49014905 equation
49024906 true = info < 0 ;
4903- varnames = Util . stringDelimitList(Util . listMap(vars,varName )," ; " );
4907+ varnames = Util . stringDelimitList(Util . listMap(vars,ComponentReference . printComponentRefStr )," ; \n " );
49044908 rhsStr = Util . stringDelimitList(Util . listMap(rhs, realString)," ; " );
49054909 jacStr = Util . stringDelimitList(Util . listMap1(Util . listListMap(jac,realString),Util . stringDelimitList," , " )," ; " );
49064910 syst = stringAppendList({"[" , jacStr, "] * [" ,varnames,"] = [" ,rhsStr,"]" });
@@ -4912,12 +4916,13 @@ end checkLinearSystem;
49124916protected function generateSolvedEquation
49134917 input SimVar var ;
49144918 input Real val;
4919+ input DAE . ElementSource source;
49154920 output SimEqSystem eq;
49164921protected
49174922 DAE . ComponentRef name;
49184923algorithm
49194924 SIMVAR (name= name) := var ;
4920- eq := SES_SIMPLE_ASSIGN (name,DAE . RCONST (val),DAE . emptyElementSource );
4925+ eq := SES_SIMPLE_ASSIGN (name,DAE . RCONST (val),source );
49214926end generateSolvedEquation;
49224927
49234928protected function replaceDerOpInEquationList
@@ -5285,7 +5290,7 @@ algorithm
52855290 SOME (jac) = BackendDAEUtil . calculateJacobian(v, eqn, ae, m, mT,false );
52865291 ((simVars,_)) = BackendVariable . traverseBackendDAEVars(v,traversingdlowvarToSimvar,({},kv));
52875292 simVars = listReverse(simVars);
5288- ((_,_,_,beqs)) = BackendEquation . traverseBackendDAEEqns(eqn,dlowEqToExp,(v,ae,{},{}));
5293+ ((_,_,_,beqs,_ )) = BackendEquation . traverseBackendDAEEqns(eqn,dlowEqToExp,(v,ae,{} ,{},{}));
52895294 beqs = listReverse(beqs);
52905295 simJac = Util . listMap1(jac, jacToSimjac, v);
52915296 index = Util . listFirst(block_); // use first equation nr as index
@@ -5317,8 +5322,8 @@ algorithm
53175322end jacToSimjac;
53185323
53195324protected function dlowEqToExp
5320- input tuple< BackendDAE . Equation , tuple< BackendDAE . Variables ,array< BackendDAE . MultiDimEquation > ,list< tuple< Integer ,list< list< DAE . Subscript >>>>,list< DAE . Exp >>> inTpl;
5321- output tuple< BackendDAE . Equation , tuple< BackendDAE . Variables ,array< BackendDAE . MultiDimEquation > ,list< tuple< Integer ,list< list< DAE . Subscript >>>>,list< DAE . Exp >>> outTpl;
5325+ input tuple< BackendDAE . Equation , tuple< BackendDAE . Variables ,array< BackendDAE . MultiDimEquation > ,list< tuple< Integer ,list< list< DAE . Subscript >>>>,list< DAE . Exp > ,list < DAE . ElementSource > >> inTpl;
5326+ output tuple< BackendDAE . Equation , tuple< BackendDAE . Variables ,array< BackendDAE . MultiDimEquation > ,list< tuple< Integer ,list< list< DAE . Subscript >>>>,list< DAE . Exp > ,list < DAE . ElementSource > >> outTpl;
53225327algorithm
53235328 outTpl := matchcontinue inTpl
53245329 local
@@ -5333,22 +5338,24 @@ algorithm
53335338 array< BackendDAE . MultiDimEquation > arrayEqs;
53345339 list< tuple< Integer ,list< list< DAE . Subscript >>>> entrylst,entrylst1;
53355340 list< DAE . Exp > explst;
5341+ list< DAE . ElementSource > sources;
5342+ DAE . ElementSource source;
53365343
5337- case ((eqn as BackendDAE . RESIDUAL_EQUATION (exp= e),(v, arrayEqs,entrylst,explst)))
5344+ case ((eqn as BackendDAE . RESIDUAL_EQUATION (exp= e,source = source ),(v, arrayEqs,entrylst,explst,sources )))
53385345 equation
53395346 rhs_exp = BackendDAEUtil . getEqnsysRhsExp(e, v);
53405347 (rhs_exp_1,_) = ExpressionSimplify . simplify(rhs_exp);
5341- then ((eqn,(v, arrayEqs,entrylst,rhs_exp_1::explst)));
5348+ then ((eqn,(v, arrayEqs,entrylst,rhs_exp_1::explst,source::sources )));
53425349
5343- case ((eqn as BackendDAE . EQUATION (exp= e1, scalar= e2),(v, arrayEqs,entrylst,explst)))
5350+ case ((eqn as BackendDAE . EQUATION (exp= e1, scalar= e2,source = source ),(v, arrayEqs,entrylst,explst,sources )))
53445351 equation
53455352 new_exp = Expression . expSub(e1,e2);
53465353 rhs_exp = BackendDAEUtil . getEqnsysRhsExp(new_exp, v);
53475354 rhs_exp_1 = Expression . negate(rhs_exp);
53485355 (rhs_exp_2,_) = ExpressionSimplify . simplify(rhs_exp_1);
5349- then ((eqn,(v, arrayEqs,entrylst,rhs_exp_2::explst)));
5356+ then ((eqn,(v, arrayEqs,entrylst,rhs_exp_2::explst,source::sources )));
53505357
5351- case ((eqn as BackendDAE . ARRAY_EQUATION (index= index),(v, arrayEqs,entrylst,explst)))
5358+ case ((eqn as BackendDAE . ARRAY_EQUATION (index= index,source = source ),(v, arrayEqs,entrylst,explst,sources )))
53525359 equation
53535360 BackendDAE . MULTIDIM_EQUATION (dimSize= ds,left= e1, right= e2) = arrayEqs[index+ 1 ];
53545361 new_exp = Expression . expSub(e1,e2);
@@ -5358,7 +5365,7 @@ algorithm
53585365 rhs_exp = BackendDAEUtil . getEqnsysRhsExp(new_exp1, v);
53595366 rhs_exp_1 = Expression . negate(rhs_exp);
53605367 (rhs_exp_2,_) = ExpressionSimplify . simplify(rhs_exp_1);
5361- then ((eqn,(v, arrayEqs,entrylst1,rhs_exp_2::explst)));
5368+ then ((eqn,(v, arrayEqs,entrylst1,rhs_exp_2::explst,source::sources )));
53625369
53635370 case ((eqn,_))
53645371 equation
@@ -11414,12 +11421,9 @@ end dumpVarInfo;
1141411421
1141511422protected function varName
1141611423 input SimVar var ;
11417- output String name;
11418- protected
11419- DAE . ComponentRef cr;
11424+ output DAE . ComponentRef name;
1142011425algorithm
11421- SIMVAR (name= cr) := var ;
11422- name := ComponentReference . printComponentRefStr(cr);
11426+ SIMVAR (name= name) := var ;
1142311427end varName;
1142411428
1142511429
0 commit comments