Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 85e6162

Browse files
Willi BraunOpenModelica-Hudson
authored andcommitted
[DAEMode] Several improvments to the DAEmode
- use sorting information to traverse equations - fixing event update using ida solver - added compilation debug flag: debugDAEmode - better handling of algebraic state variables Belonging to [master]: - #2242
1 parent 6c9726f commit 85e6162

File tree

10 files changed

+319
-171
lines changed

10 files changed

+319
-171
lines changed

Compiler/BackEnd/BackendDAE.mo

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -847,20 +847,15 @@ end CompInfo;
847847
public
848848
uniontype BackendDAEModeData
849849
record BDAE_MODE_DATA
850-
Integer numAuxVars;
851-
list<Var> auxVars;
850+
list<Var> stateVars;
851+
list<Var> algStateVars;
852852

853853
Integer numResVars;
854-
list<Var> resVars;
855854

856-
Integer numAuxEqns;
857-
list<Equation> auxEqns;
858-
859-
Integer numResEqns;
860-
list<Equation> resEqns;
855+
Option<Variables> modelVars;
861856
end BDAE_MODE_DATA;
862857
end BackendDAEModeData;
863-
constant BackendDAEModeData emptyDAEModeData = BDAE_MODE_DATA(0,{},0,{},0,{},0,{});
858+
constant BackendDAEModeData emptyDAEModeData = BDAE_MODE_DATA({},{},0,NONE());
864859

865860
annotation(__OpenModelica_Interface="backend");
866861
end BackendDAE;

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9037,6 +9037,50 @@ algorithm
90379037
comps := Sorting.TarjanTransposed(mT, ass2);
90389038
end causalizeVarBindSystem;
90399039

9040+
public function traverseEqSystemStrongComponents
9041+
"This function goes through the strong components of a EqSystem and pass
9042+
the variables and equation with their indexes to the traversing function.
9043+
It fail if the EqSytem does not have the matching and strong components are
9044+
empty. It does not change the input EqSystem."
9045+
replaceable type Type_a subtypeof Any;
9046+
input BackendDAE.EqSystem syst;
9047+
input FuncExpType func;
9048+
input Type_a inTypeA;
9049+
output Type_a outTypeA = inTypeA;
9050+
partial function FuncExpType
9051+
input list<BackendDAE.Equation> inEqns;
9052+
input list<BackendDAE.Var> inVars;
9053+
input list<Integer> varIdxs;
9054+
input list<Integer> eqnIdxs;
9055+
input Type_a inA;
9056+
output Type_a outA;
9057+
end FuncExpType;
9058+
protected
9059+
BackendDAE.StrongComponents comps;
9060+
BackendDAE.Variables varArr;
9061+
BackendDAE.EquationArray eqnArr;
9062+
list<BackendDAE.Var> vars;
9063+
list<BackendDAE.Equation> eqns;
9064+
list<Integer> varIdxs, eqnIdxs;
9065+
String name;
9066+
algorithm
9067+
try
9068+
BackendDAE.EQSYSTEM(matching = BackendDAE.MATCHING(comps=comps),
9069+
orderedVars = varArr,
9070+
orderedEqs = eqnArr) := syst;
9071+
9072+
for component in comps loop
9073+
(vars, varIdxs, eqns, eqnIdxs) := getStrongComponentVarsAndEquations(component, varArr, eqnArr);
9074+
outTypeA := func(eqns, vars, varIdxs, eqnIdxs, outTypeA);
9075+
end for;
9076+
else
9077+
(_, _, name) := System.dladdr(func);
9078+
Error.addInternalError("BackendDAEUtil.traverseEqSystemStrongComponents failed
9079+
with function:\n" + name + "\n", sourceInfo());
9080+
fail();
9081+
end try;
9082+
end traverseEqSystemStrongComponents;
9083+
90409084
public function getStrongComponentsVarsAndEquations"gets the variables and and the equations from all sccs.
90419085
author: Waurich TUD 09-2015"
90429086
input BackendDAE.StrongComponents comps;

Compiler/BackEnd/BackendDump.mo

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4564,6 +4564,24 @@ algorithm
45644564
str := ComponentReference.printComponentRefStr(Util.tuple21(tpl)) + " -> " + ComponentReference.printComponentRefStr(Util.tuple22(tpl));
45654565
end printStateOrderStr;
45664566

4567+
public function dumpBackendDAEModeData
4568+
input BackendDAE.BackendDAEModeData inDAEmodeData;
4569+
protected
4570+
BackendDAE.Variables modelVars;
4571+
algorithm
4572+
print("\n" + BORDER + "\nDAEMode\n" + UNDERLINE + "\n");
4573+
if isSome(inDAEmodeData.modelVars) then
4574+
SOME(modelVars) := inDAEmodeData.modelVars;
4575+
dumpVariables(modelVars, "ModelVariables");
4576+
else
4577+
print("No ModelVariables\n");
4578+
end if;
4579+
print("DAEmode System:\n " + intString(inDAEmodeData.numResVars) + " residual variables\n " +
4580+
intString(listLength(inDAEmodeData.stateVars)) + " state variables\n " +
4581+
intString(listLength(inDAEmodeData.algStateVars)) + " algebraic state variables\n");
4582+
dumpVarList(inDAEmodeData.stateVars, "State Variables");
4583+
dumpVarList(inDAEmodeData.algStateVars, "Algebraic State Variables");
4584+
end dumpBackendDAEModeData;
45674585

45684586
annotation(__OpenModelica_Interface="backend");
45694587
end BackendDump;

Compiler/BackEnd/CommonSubExpression.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ algorithm
15751575
end match;
15761576
end createVarsForExp;
15771577

1578-
protected function isCSECref
1578+
public function isCSECref
15791579
"Returns true if the cref is prefixed with '$cse'"
15801580
input DAE.ComponentRef cr;
15811581
output Boolean b;

0 commit comments

Comments
 (0)