Skip to content

Commit

Permalink
[NB] add entwined equation elements to allSim and initial blocks (Ope…
Browse files Browse the repository at this point in the history
…nModelica#12560)

- collect the entwined equation sub equations for sim code
 - update collecting of literals for simcode to correctly map expressions
  • Loading branch information
kabdelhak committed Jun 12, 2024
1 parent 7055b41 commit aac2b10
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
11 changes: 2 additions & 9 deletions OMCompiler/Compiler/NFFrontEnd/NFExpression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4477,15 +4477,8 @@ public
b := match exp
case STRING() then true;
case BOX(STRING()) then true;
case BOX(REAL()) then true;
case BOX() then false;
case INTEGER() then false;
case BOOLEAN() then false;
case REAL() then false;
case ENUM_LITERAL() then false;
case SHARED_LITERAL() then false;
case ARRAY() guard(arrayEmpty(exp.elements)) then false;
case RECORD() then List.all(exp.elements, isLiteralReplace);
case ARRAY() then exp.literal or Array.all(exp.elements, isLiteral);
//case RECORD() then List.all(exp.elements, isLiteralReplace);
else false;
end match;
end isLiteralReplace;
Expand Down
15 changes: 12 additions & 3 deletions OMCompiler/Compiler/NSimCode/NSimCode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ public
input String fileNamePrefix;
input Option<OldSimCode.SimulationSettings> simSettingsOpt;
output SimCode simCode;
protected
partial function mapExp
input output Expression exp;
end mapExp;
algorithm
simCode := match bdae
local
Expand Down Expand Up @@ -302,16 +306,17 @@ public
Option<DaeModeData> daeModeData;
SimJacobian jacA, jacB, jacC, jacD, jacF, jacH;
list<SimStrongComponent.Block> inlineEquations; // ToDo: what exactly is this?

mapExp collect_literals;
case BackendDAE.MAIN(varData = varData as BVariable.VAR_DATA_SIM(), eqData = eqData as BEquation.EQ_DATA_SIM())
algorithm
// somehow this cannot be set at definition (metamodelica bug?)
simCodeIndices := EMPTY_SIM_CODE_INDICES();
funcTree := BackendDAE.getFunctionTree(bdae);

// get and replace all literals
_ := EqData.mapExp(eqData, function Expression.replaceLiteral(map = literals_map, idx_ptr = literals_idx));
funcTree := FunctionTreeImpl.mapExp(funcTree, function Expression.replaceLiteral(map = literals_map, idx_ptr = literals_idx));
collect_literals := function Expression.map(func = function Expression.replaceLiteral(map = literals_map, idx_ptr = literals_idx));
_ := EqData.mapExp(eqData, collect_literals);
funcTree := FunctionTreeImpl.mapExp(funcTree, collect_literals);
literals := UnorderedMap.keyList(literals_map);

// create sim vars before everything else
Expand Down Expand Up @@ -370,6 +375,10 @@ public
end if;
end if;

// add all entwined equations to all sim
allSim := listAppend(List.flatten(list(SimStrongComponent.Block.collectEntwinedEquations(blck) for blck in allSim)), allSim);
init := listAppend(List.flatten(list(SimStrongComponent.Block.collectEntwinedEquations(blck) for blck in init)), init);

// ToDo add event system
inlineEquations := {};

Expand Down
10 changes: 10 additions & 0 deletions OMCompiler/Compiler/NSimCode/NSimStrongComponent.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,16 @@ public
end match;
end fixIndex;

function collectEntwinedEquations
"collects entwined equations from initial blocks"
input Block blck;
output list<Block> lst;
algorithm
lst := match blck
case ENTWINED_ASSIGN() then blck.single_calls;
else {};
end match;
end collectEntwinedEquations;
protected
function whenString
input list<ComponentRef> conditions;
Expand Down

0 comments on commit aac2b10

Please sign in to comment.