Skip to content

Commit

Permalink
Add variable index mappings for C++ to DAE code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke committed Apr 20, 2023
1 parent 0f5882b commit c90b816
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions OMCompiler/Compiler/SimCode/SimCodeMain.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,10 @@ protected
numberofMixedSys, numberOfJacobians, numberofFixedParameters;
Boolean tmpB;

HashTableCrIListArray.HashTable varToArrayIndexMapping "maps each array-variable to a array of positions";
HashTableCrILst.HashTable varToIndexMapping "maps each variable to an array position";
HashTable.HashTable crefToClockIndexHT;

list<DAE.ComponentRef> discreteModelVars;
list<BackendDAE.TimeEvent> timeEvents;
BackendDAE.ZeroCrossingSet zeroCrossingsSet, sampleZCSet;
Expand Down Expand Up @@ -1671,6 +1675,15 @@ algorithm
// The updated variable 'numEquations' (by SimCodeUtil.addNumEqns) is not even used in createCrefToSimVarHT :/
// crefToSimVarHT := SimCodeUtil.createCrefToSimVarHT(modelInfo);

if stringEqual(Config.simCodeTarget(), "Cpp") then
(varToArrayIndexMapping, varToIndexMapping) := SimCodeUtil.createVarToArrayIndexMapping(modelInfo);
(crefToClockIndexHT, _) := List.fold(listReverse(inBackendDAE.eqs), SimCodeUtil.collectClockedVars, (HashTable.emptyHashTable(), 1));
else
varToArrayIndexMapping := HashTableCrIListArray.emptyHashTable();
varToIndexMapping := HashTableCrILst.emptyHashTable();
crefToClockIndexHT := HashTable.emptyHashTable();
end if;

simCode := SimCode.SIMCODE(
modelInfo = modelInfo,
literals = {}, // Set by the traversal below...
Expand Down Expand Up @@ -1712,10 +1725,10 @@ algorithm
fmuTargetName = "",
hpcomData = HpcOmSimCode.emptyHpcomData,
valueReferences = AvlTreeCRToInt.EMPTY(),
varToArrayIndexMapping = HashTableCrIListArray.emptyHashTable(),
varToIndexMapping = HashTableCrILst.emptyHashTable(),
varToArrayIndexMapping = varToArrayIndexMapping,
varToIndexMapping = varToIndexMapping,
crefToSimVarHT = crefToSimVarHT,
crefToClockIndexHT = HashTable.emptyHashTable(),
crefToClockIndexHT = crefToClockIndexHT,
backendMapping = NONE(),
modelStructure = NONE(),
fmiSimulationFlags = NONE(),
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/SimCode/SimCodeUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ algorithm
clockedPartitions := listReverse(clockedPartitions); // in order to keep the correct indexes for the correct clkfire-calls
end createClockedSimPartitions;

protected function collectClockedVars "author: rfranke
public function collectClockedVars "author: rfranke
This function collects clocked variables along with their clockIndex"
input BackendDAE.EqSystem inEqSystem;
input tuple<HashTable.HashTable, Integer> inTpl;
Expand Down

0 comments on commit c90b816

Please sign in to comment.