Skip to content

Commit

Permalink
[NSimCode] have own index for external objects (#11890)
Browse files Browse the repository at this point in the history
  • Loading branch information
kabdelhak committed Jan 26, 2024
1 parent be5a25d commit a2a5435
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion OMCompiler/Compiler/NSimCode/NSimCode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public
Integer residualIndex;
Integer implicitIndex; // this can be removed i think -> moved to solve
Integer genericCallIndex;
Integer extObjIndex;

UnorderedMap<AliasInfo, Integer> alias_map;
UnorderedMap<Identifier, Integer> generic_call_map;
Expand Down Expand Up @@ -152,7 +153,7 @@ public
0,0,0,0,
0,0,0,0,
1,0,0,
0,0,0,0,
0,0,0,0,0,
UnorderedMap.new<Integer>(AliasInfo.hash, AliasInfo.isEqual),
UnorderedMap.new<Integer>(Identifier.hash, Identifier.isEqual)
);
Expand Down
18 changes: 12 additions & 6 deletions OMCompiler/Compiler/NSimCode/NSimVar.mo
Original file line number Diff line number Diff line change
Expand Up @@ -215,25 +215,31 @@ public
case VarType.SIMULATION algorithm
Pointer.update(acc, create(var, simCodeIndices.uniqueIndex, simCodeIndices.realVarIndex) :: Pointer.access(acc));
simCodeIndices.uniqueIndex := simCodeIndices.uniqueIndex + 1;
simCodeIndices.realVarIndex := simCodeIndices.realVarIndex +1;
simCodeIndices.realVarIndex := simCodeIndices.realVarIndex + 1;
then ();

case VarType.PARAMETER algorithm
Pointer.update(acc, create(var, simCodeIndices.uniqueIndex, simCodeIndices.realParamIndex) :: Pointer.access(acc));
simCodeIndices.uniqueIndex := simCodeIndices.uniqueIndex + 1;
simCodeIndices.realParamIndex := simCodeIndices.realParamIndex +1;
simCodeIndices.realParamIndex := simCodeIndices.realParamIndex + 1;
then ();

case VarType.ALIAS algorithm
Pointer.update(acc, create(var, simCodeIndices.uniqueIndex, simCodeIndices.realAliasIndex, Alias.fromBinding(var.binding)) :: Pointer.access(acc));
simCodeIndices.uniqueIndex := simCodeIndices.uniqueIndex + 1;
simCodeIndices.realAliasIndex := simCodeIndices.realAliasIndex +1;
simCodeIndices.realAliasIndex := simCodeIndices.realAliasIndex + 1;
then ();

case VarType.RESIDUAL algorithm
Pointer.update(acc, create(var, simCodeIndices.uniqueIndex, simCodeIndices.residualIndex) :: Pointer.access(acc));
simCodeIndices.uniqueIndex := simCodeIndices.uniqueIndex + 1;
simCodeIndices.residualIndex := simCodeIndices.residualIndex +1;
simCodeIndices.residualIndex := simCodeIndices.residualIndex + 1;
then ();

case VarType.EXTERNAL_OBJECT algorithm
Pointer.update(acc, create(var, simCodeIndices.uniqueIndex, simCodeIndices.extObjIndex) :: Pointer.access(acc));
simCodeIndices.uniqueIndex := simCodeIndices.uniqueIndex + 1;
simCodeIndices.extObjIndex := simCodeIndices.extObjIndex + 1;
then ();

else algorithm
Expand Down Expand Up @@ -1089,7 +1095,7 @@ public
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {});

type SplitType = enumeration(NONE, TYPE);
type VarType = enumeration(SIMULATION, PARAMETER, ALIAS, RESIDUAL); // ToDo: PRE, OLD, RELATIONS...
type VarType = enumeration(SIMULATION, PARAMETER, ALIAS, RESIDUAL, EXTERNAL_OBJECT); // ToDo: PRE, OLD, RELATIONS...

uniontype VarInfo
record VAR_INFO
Expand Down Expand Up @@ -1236,7 +1242,7 @@ public
protected
Pointer<SimCodeIndices> indices_ptr = Pointer.create(simCodeIndices);
Pointer<list<SimVar>> acc = Pointer.create({});
VarType varType = VarType.SIMULATION;
VarType varType = VarType.EXTERNAL_OBJECT;
algorithm
VariablePointers.map(external_objects, function SimVar.traverseCreate(acc = acc, indices_ptr = indices_ptr, varType = varType));
simCodeIndices := Pointer.access(indices_ptr);
Expand Down

0 comments on commit a2a5435

Please sign in to comment.