Skip to content

Commit

Permalink
[NB] add array compression after simplify to remove DUMMY equations (O…
Browse files Browse the repository at this point in the history
…penModelica#12624)

- dumping updates
  • Loading branch information
kabdelhak committed Jun 21, 2024
1 parent 537f41e commit 8ede334
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 10 additions & 2 deletions OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ public
case ALGORITHM() then str + "[ALGO] " + s + EquationAttributes.toString(eq.attr, " ") + "\n" + Algorithm.toString(eq.alg, str + "[----] ");
case IF_EQUATION() then str + IfEquationBody.toString(eq.body, str + "[----] ", "[-IF-] " + s + EquationAttributes.toString(eq.attr, " "));
case FOR_EQUATION() then str + forEquationToString(eq.iter, eq.body, "", str + "[----] ", "[FOR-] " + s + EquationAttributes.toString(eq.attr, " "));
case WHEN_EQUATION() then str + WhenEquationBody.toString(eq.body, str + "[----] ", "[WHEN] " + s + EquationAttributes.toString(eq.attr, " ") + "\n[----] ");
case WHEN_EQUATION() then str + WhenEquationBody.toString(eq.body, str + "[----] ", "[WHEN] " + s + EquationAttributes.toString(eq.attr, " ") + "\n");
case AUX_EQUATION() then str + "[AUX-] " + s + "Auxiliary equation for " + Variable.toString(Pointer.access(eq.auxiliary));
case DUMMY_EQUATION() then str + "[DUMY] (0) Dummy equation.";
else str + "[FAIL] (0) " + getInstanceName() + " failed!";
Expand Down Expand Up @@ -2523,7 +2523,11 @@ public
protected
WhenEquationBody elseWhen;
algorithm
str := elseStr + "when " + Expression.toString(body.condition) + " then \n";
str := elseStr;
if not selfCall then
str := str + indent;
end if;
str := str + "when " + Expression.toString(body.condition) + " then \n";
for stmt in body.when_stmts loop
str := str + WhenStatement.toString(stmt, indent + " ") + "\n";
end for;
Expand Down Expand Up @@ -3687,7 +3691,11 @@ public
if ExpandableArray.occupied(i, equations.eqArr) then
eqn := ExpandableArray.get(i, equations.eqArr);
() := match Pointer.access(eqn)
local
list<Equation> body;
// todo: add for IF and WHEN
case Equation.DUMMY_EQUATION() then ();
case Equation.FOR_EQUATION(body = body) guard(List.all(body, Equation.isDummy)) then ();
else algorithm
eqns := eqn :: eqns;
then ();
Expand Down
14 changes: 7 additions & 7 deletions OMCompiler/Compiler/NBackEnd/Classes/NBackendDAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,14 @@ public
"ToDo: add simplification for bindings"
input output BackendDAE bdae;
algorithm
// no output needed, all pointers
() := match bdae
bdae := match bdae
local
EquationPointers equations;
case MAIN(eqData = BEquation.EQ_DATA_SIM(equations = equations)) algorithm
_ := EquationPointers.map(equations, function Equation.simplify(name = getInstanceName(), indent = ""));
then ();
else ();
EqData eqData;
case MAIN(eqData = eqData as BEquation.EQ_DATA_SIM()) algorithm
eqData.equations := EquationPointers.map(eqData.equations, function Equation.simplify(name = getInstanceName(), indent = ""));
bdae.eqData := EqData.compress(eqData);
then bdae;
else bdae;
end match;
end simplify;

Expand Down

0 comments on commit 8ede334

Please sign in to comment.