@@ -79,6 +79,7 @@ import DAEDump;
7979import DAEUtil;
8080import Debug;
8181import Differentiate;
82+ import DoubleEndedList;
8283import Error;
8384import EvaluateFunctions;
8485import Expression;
@@ -11029,41 +11030,6 @@ algorithm
1102911030 b := listMember(bEq,bEq1);
1103011031end findBEqs;
1103111032
11032- /*
11033- This is wrong!
11034- public function getSimVarByIndex
11035- input Integer idx;
11036- input SimCodeVar.SimVars allSimVars;
11037- output SimCodeVar.SimVar simVar;
11038- algorithm
11039- simVar := matchcontinue(idx,allSimVars)
11040- local
11041- Integer size,idx2;
11042- list<SimCodeVar.SimVar> stateVars,algVars;
11043- SimCodeVar.SimVar var;
11044- case(_,SimCodeVar.SIMVARS(stateVars=stateVars,algVars=algVars))
11045- equation
11046- size = listLength(stateVars);
11047- true = idx > size;
11048- //its not a stateVar
11049- idx2 = idx - 2*size + 1;
11050- var = listGet(algVars,idx2);
11051- then var;
11052- case(_,SimCodeVar.SIMVARS(stateVars=stateVars,algVars=algVars))
11053- equation
11054- size = listLength(stateVars);
11055- true = idx <= size;
11056- //its a stateVar
11057- var = listGet(stateVars,idx);
11058- then var;
11059- else
11060- equation
11061- print("SimCodeUtil.getSimVarByIndex failed!\n");
11062- then fail();
11063- end matchcontinue;
11064- end getSimVarByIndex;
11065- */
11066-
1106711033public function getAssignedCrefsOfSimEq"gets the crefs of the vars that are assigned (the lhs) of the simEqSystems
1106811034author:Waurich TUD 2014-05"
1106911035 input Integer idx;
@@ -11079,7 +11045,7 @@ algorithm
1107911045 equation
1108011046 simEqSyst = List.getMemberOnTrue(idx,allEqs,indexIsEqual);
1108111047 crefs = getSimEqSystemCrefsLHS(simEqSyst);
11082- then crefs;
11048+ then crefs;
1108311049 end match;
1108411050end getAssignedCrefsOfSimEq;
1108511051
@@ -11098,17 +11064,15 @@ algorithm
1109811064 case(SimCode.SES_RESIDUAL())
1109911065 equation
1110011066 print("implement SES_RESIDUAL in SimCodeUtil.getSimEqSystemCrefsLHS!\n");
11101- then {};
11067+ then {};
1110211068 case(SimCode.SES_SIMPLE_ASSIGN(cref=cref))
11103- equation
11104- then {cref};
11069+ then {cref};
1110511070 case(SimCode.SES_ARRAY_CALL_ASSIGN(lhs=lhs))
11106- equation
11107- then {Expression.expCref(lhs)};
11071+ then {Expression.expCref(lhs)};
1110811072 case(SimCode.SES_IFEQUATION())
1110911073 equation
1111011074 print("implement SES_IFEQUATION in SimCodeUtil.getSimEqSystemCrefsLHS!\n");
11111- then {};
11075+ then {};
1111211076 case(SimCode.SES_ALGORITHM()) equation
1111311077 print("implement SES_ALGORITHM in SimCodeUtil.getSimEqSystemCrefsLHS!\n");
1111411078 then {};
@@ -11117,20 +11081,15 @@ algorithm
1111711081 then {};
1111811082 case(SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(vars=simVars,residual=residual)))
1111911083 equation
11120- crefs2 = List.flatten(List.map(residual,getSimEqSystemCrefsLHS));
11121- crefs = list(SimCodeFunctionUtil.varName(v) for v in simVars);
11122- crefs = listAppend(crefs,crefs2);
11123- then crefs;
11084+ crefs = List.flatten(List.map(residual,getSimEqSystemCrefsLHS));
11085+ crefs2 = list(SimCodeFunctionUtil.varName(v) for v in simVars);
11086+ then listAppend(crefs2,crefs2);
1112411087 case(SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(crefs=crefs)))
11125- equation
11126- then crefs;
11127- case(SimCode.SES_MIXED(discVars=simVars))
11128- equation
11129- crefs = list(SimCodeFunctionUtil.varName(v) for v in simVars);
1113011088 then crefs;
11089+ case(SimCode.SES_MIXED(discVars=simVars))
11090+ then list(SimCodeFunctionUtil.varName(v) for v in simVars);
1113111091 case(SimCode.SES_WHEN(whenStmtLst={BackendDAE.ASSIGN(left=cref)}))
11132- equation
11133- then {cref};
11092+ then {cref};
1113411093 end match;
1113511094end getSimEqSystemCrefsLHS;
1113611095
@@ -11600,10 +11559,11 @@ protected
1160011559 list<tuple<DAE.ComponentRef, list<DAE.ComponentRef>>> spTA, spTB;
1160111560 list<tuple<Integer, list<Integer>>> sparseInts;
1160211561 list<SimCode.FmiUnknown> derivatives, outputs, discreteStates;
11603- list<SimCodeVar.SimVar> varsA, varsB, clockedStates;
11562+ list<SimCodeVar.SimVar> varsA, varsB, varsC, clockedStates;
1160411563 SimCode.HashTableCrefToSimVar crefSimVarHT;
1160511564 list<DAE.ComponentRef> diffCrefsA, diffedCrefsA, derdiffCrefsA;
1160611565 list<DAE.ComponentRef> diffCrefsB, diffedCrefsB;
11566+ DoubleEndedList<SimCodeVar.SimVar> delst;
1160711567algorithm
1160811568 try
1160911569 //print("Start creating createFMIModelStructure\n");
@@ -11643,13 +11603,12 @@ algorithm
1164311603 spTA := mergeSparsePatter(spTA, spTB, {});
1164411604 //print("-- merged matrixes CD\n");
1164511605
11646- varsB := getSimVars2Crefs(diffedCrefsB, crefSimVarHT);
11647- varsA := getSimVars2Crefs(diffCrefsB, crefSimVarHT);
11648- varsA := listAppend(varsA, varsB);
11649- varsB := getSimVars2Crefs(diffedCrefsA, crefSimVarHT);
11650- varsA := listAppend(varsA, varsB);
11651- varsB := getSimVars2Crefs(diffCrefsA, crefSimVarHT);
11652- varsA := listAppend(varsA, varsB);
11606+ delst := DoubleEndedList.fromList(getSimVars2Crefs(diffedCrefsB, crefSimVarHT));
11607+ DoubleEndedList.push_list_back(delst, getSimVars2Crefs(diffCrefsB, crefSimVarHT));
11608+ DoubleEndedList.push_list_back(delst, getSimVars2Crefs(diffedCrefsA, crefSimVarHT));
11609+ DoubleEndedList.push_list_back(delst, getSimVars2Crefs(diffCrefsA, crefSimVarHT));
11610+ varsA := DoubleEndedList.toListAndClear(delst);
11611+
1165311612 //print("-- created vars for CD\n");
1165411613
1165511614 sparseInts := sortSparsePattern(varsA, spTA, true);
0 commit comments