@@ -389,12 +389,12 @@ algorithm
389389 algebraicEquations := List.filterOnFalse(algebraicEquations, listEmpty);
390390
391391 if Flags.isSet(Flags.EXEC_HASH) then
392- print("*** SimCode -> generate cref2simVar hastable : " + realString(clock()) + "\n");
392+ print("*** SimCode -> generate cref2simVar hashtable : " + realString(clock()) + "\n");
393393 end if;
394394 (crefToSimVarHT, mixedArrayVars) := createCrefToSimVarHT(modelInfo);
395395 modelInfo := setMixedArrayVars(mixedArrayVars, modelInfo);
396396 if Flags.isSet(Flags.EXEC_HASH) then
397- print("*** SimCode -> generate cref2simVar hastable done!: " + realString(clock()) + "\n");
397+ print("*** SimCode -> generate cref2simVar hashtable done!: " + realString(clock()) + "\n");
398398 end if;
399399
400400 backendMapping := setBackendVarMapping(inBackendDAE, crefToSimVarHT, modelInfo, backendMapping);
@@ -10623,7 +10623,8 @@ algorithm
1062310623 end matchcontinue;
1062410624end setUpSystMapping;
1062510625
10626- protected function setBackendVarMapping"sets the varmapping in the backendmapping.
10626+ protected function setBackendVarMapping
10627+ "sets the varmapping in the backendmapping.
1062710628author:Waurich TUD 2014-04"
1062810629 input BackendDAE.BackendDAE dae;
1062910630 input SimCode.HashTableCrefToSimVar ht;
@@ -10647,16 +10648,26 @@ algorithm
1064710648 BackendDAE.IncidenceMatrix m;
1064810649 BackendDAE.IncidenceMatrixT mt;
1064910650 array<list<SimCodeVar.SimVar>> simVarMapping;
10651+ SimCode.HashTableCrefToSimVar htStates;
10652+ Integer size;
1065010653 case(_,_,_,_)
1065110654 equation
1065210655 SimCode.BACKENDMAPPING(m=m,mT=mt,eqMapping=eqMapping,varMapping=varMapping,eqMatch=eqMatch,varMatch=varMatch,eqTree=tree,simVarMapping=simVarMapping) = bmapIn;
10653- SimCode.MODELINFO(varInfo=varInfo,vars=allVars) = modelInfo;
1065410656 BackendDAE.DAE(eqs=eqs) = dae;
10657+
10658+ //get Backend vars and index
1065510659 vars = BackendVariable.equationSystemsVarsLst(eqs,{});
1065610660 crefs = List.map(vars,BackendVariable.varCref);
10657- bVarIdcs = List.intRange(listLength(crefs));
10661+ size = listLength(crefs);
10662+ bVarIdcs = List.intRange(size);
1065810663 simVars = List.map1(crefs,SimCodeFunctionUtil.get,ht);
10659- simVarIdcs = List.map2(simVars,getSimVarIndex,varInfo,allVars);
10664+
10665+ // get states and create hash table
10666+ SimCode.MODELINFO(varInfo=varInfo,vars=allVars) = modelInfo;
10667+ htStates = List.fold(allVars.stateVars, addSimVarToHashTable, SimCodeFunctionUtil.emptyHashTableSized(size));
10668+
10669+ // produce mapping
10670+ simVarIdcs = List.map2(simVars,getSimVarIndex,varInfo,htStates);
1066010671 varMapping = makeVarMapTuple(simVarIdcs,bVarIdcs,{});
1066110672 List.fold1(simVars, fillSimVarMapping, simVarMapping, 1);
1066210673 //print(stringDelimitList(List.map(crefs,ComponentReference.printComponentRefStr),"\n")+"\n");
@@ -10679,41 +10690,24 @@ algorithm
1067910690 oVarIdx := iVarIdx + 1;
1068010691end fillSimVarMapping;
1068110692
10682- protected function getSimVarIndex"gets the index from a SimVar and calculates the place in the localData array
10693+ protected function getSimVarIndex
10694+ "gets the index from a SimVar and calculates the place in the localData array
1068310695author:Waurich TUD 2014-04"
1068410696 input SimCodeVar.SimVar var;
1068510697 input SimCode.VarInfo varInfo;
10686- input SimCodeVar.SimVars allVars ;
10698+ input SimCode.HashTableCrefToSimVar htStates ;
1068710699 output Integer idx;
10700+ protected
10701+ Integer offset;
1068810702algorithm
10689- idx := matchcontinue(var,varInfo,allVars)
10690- local
10691- Boolean isState;
10692- Integer i, offset;
10693- list<Boolean> bLst;
10694- list<SimCodeVar.SimVar> states;
10695- case(_,_,_)
10696- equation
10697- // is stateVar
10698- SimCodeVar.SIMVARS(stateVars = states) = allVars;
10699- bLst = List.map1(states,compareSimVarName,var);
10700- isState = List.fold(bLst,boolOr,false);
10701- true = isState;
10702- SimCodeVar.SIMVAR(index=i) = var;
10703- then
10704- i;
10705- case(_,_,_)
10706- equation
10707- // is not a stateVar
10708- SimCodeVar.SIMVARS(stateVars = states) = allVars;
10709- bLst = List.map1(states,compareSimVarName,var);
10710- isState = List.fold(bLst,boolOr,false);
10711- false = isState;
10712- SimCode.VARINFO(numStateVars=offset) = varInfo;
10713- SimCodeVar.SIMVAR(index=i) = var;
10714- then
10715- i+2*offset;
10716- end matchcontinue;
10703+ try
10704+ _ := SimCodeFunctionUtil.get(var.name, htStates);
10705+ idx := var.index;
10706+ else
10707+ offset := varInfo.numStateVars;
10708+ idx := var.index;
10709+ idx := idx+2*offset;
10710+ end try;
1071710711end getSimVarIndex;
1071810712
1071910713protected function makeVarMapTuple"builds a tuple for the varMapping. ((simvarindex,backendvarindex))
0 commit comments