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

Commit bd785a4

Browse files
Willi BraunOpenModelica-Hudson
authored andcommitted
[DAEmode] Introduce evaluation stages on equation level
For the simulation it is needed to evaluate the related equations at four different stages: - *dynamic* - Evaluate all dependent equations to obtain the residuals for the integration. - *algebraic* - Evaluate equations needed at the output points. - *zerocross* - Evaluate equations, which are needed to obtain the zeroCrossings expressions. - *discrete* - Evaluate the equations depending on the discrete equations. Enabled for now only in DAE mode, but it's also applicable in ODE mode. Belonging to [master]: - #2349 - OpenModelica/OpenModelica-testsuite#920
1 parent 5e99e61 commit bd785a4

19 files changed

+476
-128
lines changed

Compiler/BackEnd/BackendDAE.mo

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,19 +303,31 @@ public uniontype EquationKind "equation kind"
303303
end UNKNOWN_EQUATION_KIND;
304304
end EquationKind;
305305

306+
public uniontype EvaluationStages "evaluation stages"
307+
record EVALUATION_STAGES
308+
Boolean dynamicEval;
309+
Boolean algebraicEval;
310+
Boolean zerocrossEval;
311+
Boolean discreteEval;
312+
end EVALUATION_STAGES;
313+
end EvaluationStages;
314+
315+
public constant EvaluationStages defaultEvalStages = EVALUATION_STAGES(false,false,false,false);
316+
306317
public uniontype EquationAttributes
307318
record EQUATION_ATTRIBUTES
308319
Boolean differentiated "true if the equation was differentiated, and should not differentiated again to avoid equal equations";
309320
EquationKind kind;
321+
EvaluationStages evalStages;
310322
end EQUATION_ATTRIBUTES;
311323
end EquationAttributes;
312324

313-
public constant EquationAttributes EQ_ATTR_DEFAULT_DYNAMIC = EQUATION_ATTRIBUTES(false, DYNAMIC_EQUATION());
314-
public constant EquationAttributes EQ_ATTR_DEFAULT_BINDING = EQUATION_ATTRIBUTES(false, BINDING_EQUATION());
315-
public constant EquationAttributes EQ_ATTR_DEFAULT_INITIAL = EQUATION_ATTRIBUTES(false, INITIAL_EQUATION());
316-
public constant EquationAttributes EQ_ATTR_DEFAULT_DISCRETE = EQUATION_ATTRIBUTES(false, DISCRETE_EQUATION());
317-
public constant EquationAttributes EQ_ATTR_DEFAULT_AUX = EQUATION_ATTRIBUTES(false, AUX_EQUATION());
318-
public constant EquationAttributes EQ_ATTR_DEFAULT_UNKNOWN = EQUATION_ATTRIBUTES(false, UNKNOWN_EQUATION_KIND());
325+
public constant EquationAttributes EQ_ATTR_DEFAULT_DYNAMIC = EQUATION_ATTRIBUTES(false, DYNAMIC_EQUATION(),defaultEvalStages);
326+
public constant EquationAttributes EQ_ATTR_DEFAULT_BINDING = EQUATION_ATTRIBUTES(false, BINDING_EQUATION(),defaultEvalStages);
327+
public constant EquationAttributes EQ_ATTR_DEFAULT_INITIAL = EQUATION_ATTRIBUTES(false, INITIAL_EQUATION(),defaultEvalStages);
328+
public constant EquationAttributes EQ_ATTR_DEFAULT_DISCRETE = EQUATION_ATTRIBUTES(false, DISCRETE_EQUATION(),defaultEvalStages);
329+
public constant EquationAttributes EQ_ATTR_DEFAULT_AUX = EQUATION_ATTRIBUTES(false, AUX_EQUATION(),defaultEvalStages);
330+
public constant EquationAttributes EQ_ATTR_DEFAULT_UNKNOWN = EQUATION_ATTRIBUTES(false, UNKNOWN_EQUATION_KIND(),defaultEvalStages);
319331

320332
public
321333
uniontype Equation

Compiler/BackEnd/BackendDAECreate.mo

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ algorithm
709709
// Add the binding as an equation and remove the binding from the variable.
710710
outVars := lowerDynamicVar(inElement, inFunctions) :: outVars;
711711
e1 := Expression.crefExp(cr);
712-
attr := BackendDAE.EQUATION_ATTRIBUTES(false, BackendDAE.BINDING_EQUATION());
712+
attr := BackendDAE.EQ_ATTR_DEFAULT_BINDING;
713713
outEqns := BackendDAE.EQUATION(e1, e2, src, attr) :: outEqns;
714714
then
715715
();
@@ -1255,29 +1255,29 @@ algorithm
12551255
case DAE.EQUATION(e1 as DAE.TUPLE(_),e2 as DAE.CALL(),source)
12561256
equation
12571257
(DAE.EQUALITY_EXPS(e1_1,e2_1), source) = ExpressionSimplify.simplifyAddSymbolicOperation(DAE.EQUALITY_EXPS(e1,e2),source);
1258-
eqns = lowerExtendedRecordEqn(e1_1,e2_1,source,BackendDAE.DYNAMIC_EQUATION(),functionTree,inEquations);
1258+
eqns = lowerExtendedRecordEqn(e1_1,e2_1,source,BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC,functionTree,inEquations);
12591259
then
12601260
(eqns,inREquations,inIEquations);
12611261

12621262
case DAE.EQUATION(e2 as DAE.CALL(),e1 as DAE.TUPLE(_),source)
12631263
equation
12641264
(DAE.EQUALITY_EXPS(e1_1,e2_1), source) = ExpressionSimplify.simplifyAddSymbolicOperation(DAE.EQUALITY_EXPS(e1,e2),source);
1265-
eqns = lowerExtendedRecordEqn(e1_1,e2_1,source,BackendDAE.DYNAMIC_EQUATION(),functionTree,inEquations);
1265+
eqns = lowerExtendedRecordEqn(e1_1,e2_1,source,BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC,functionTree,inEquations);
12661266
then
12671267
(eqns,inREquations,inIEquations);
12681268

12691269
// Only succeds for initial tuple equations, i.e. (a,b,c) = foo(x,y,z) or foo(x,y,z) = (a,b,c)
12701270
case DAE.INITIALEQUATION(e1 as DAE.TUPLE(_),e2 as DAE.CALL(),source)
12711271
equation
12721272
(DAE.EQUALITY_EXPS(e1_1,e2_1), source) = ExpressionSimplify.simplifyAddSymbolicOperation(DAE.EQUALITY_EXPS(e1,e2),source);
1273-
eqns = lowerExtendedRecordEqn(e1_1,e2_1,source,BackendDAE.INITIAL_EQUATION(),functionTree,inIEquations);
1273+
eqns = lowerExtendedRecordEqn(e1_1,e2_1,source,BackendDAE.EQ_ATTR_DEFAULT_INITIAL,functionTree,inIEquations);
12741274
then
12751275
(inEquations,inREquations,eqns);
12761276

12771277
case DAE.INITIALEQUATION(e2 as DAE.CALL(), e1 as DAE.TUPLE(_),source)
12781278
equation
12791279
(DAE.EQUALITY_EXPS(e1_1,e2_1), source) = ExpressionSimplify.simplifyAddSymbolicOperation(DAE.EQUALITY_EXPS(e1,e2),source);
1280-
eqns = lowerExtendedRecordEqn(e1_1,e2_1,source,BackendDAE.INITIAL_EQUATION(),functionTree,inIEquations);
1280+
eqns = lowerExtendedRecordEqn(e1_1,e2_1,source,BackendDAE.EQ_ATTR_DEFAULT_INITIAL,functionTree,inIEquations);
12811281
then
12821282
(inEquations,inREquations,eqns);
12831283

@@ -1297,7 +1297,7 @@ algorithm
12971297
equation
12981298
e1 = Expression.crefExp(cr1);
12991299
e2 = Expression.crefExp(cr2);
1300-
eqns = lowerExtendedRecordEqn(e1,e2,source,BackendDAE.DYNAMIC_EQUATION(),functionTree,inEquations);
1300+
eqns = lowerExtendedRecordEqn(e1,e2,source,BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC,functionTree,inEquations);
13011301
then
13021302
(eqns,inREquations,inIEquations);
13031303

@@ -1319,7 +1319,7 @@ algorithm
13191319
equation
13201320
//TODO: remove inline
13211321
(DAE.EQUALITY_EXPS(e1_1,e2_1), source) = Inline.simplifyAndForceInlineEquationExp(DAE.EQUALITY_EXPS(e1,e2), (SOME(functionTree), {DAE.NORM_INLINE(), DAE.DEFAULT_INLINE()}), source);
1322-
eqns = lowerExtendedRecordEqn(e1_1,e2_1,source,BackendDAE.DYNAMIC_EQUATION(),functionTree,inEquations);
1322+
eqns = lowerExtendedRecordEqn(e1_1,e2_1,source,BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC,functionTree,inEquations);
13231323
then
13241324
(eqns,inREquations,inIEquations);
13251325

@@ -1337,22 +1337,22 @@ algorithm
13371337
(DAE.EQUALITY_EXPS(e1_1,e2_1), source) = ExpressionSimplify.simplifyAddSymbolicOperation(DAE.EQUALITY_EXPS(e1,e2),source);
13381338
b1 = stringEq(Absyn.pathLastIdent(path),"equalityConstraint");
13391339
eqns = if b1 then inREquations else inEquations;
1340-
eqns = lowerArrayEqn(dims,e1_1, e2_1,source,BackendDAE.DYNAMIC_EQUATION(),eqns);
1340+
eqns = lowerArrayEqn(dims,e1_1, e2_1,source,BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC,eqns);
13411341
((eqns,_)) = if b1 then (inEquations,eqns) else (eqns,inREquations);
13421342
then
13431343
(eqns,inREquations,inIEquations);
13441344

13451345
case DAE.ARRAY_EQUATION(dimension=dims,exp = e1,array = e2,source = source)
13461346
equation
13471347
(DAE.EQUALITY_EXPS(e1_1,e2_1), source) = ExpressionSimplify.simplifyAddSymbolicOperation(DAE.EQUALITY_EXPS(e1,e2),source);
1348-
eqns = lowerArrayEqn(dims,e1_1,e2_1,source,BackendDAE.DYNAMIC_EQUATION(),inEquations);
1348+
eqns = lowerArrayEqn(dims,e1_1,e2_1,source,BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC,inEquations);
13491349
then
13501350
(eqns,inREquations,inIEquations);
13511351

13521352
case DAE.INITIAL_ARRAY_EQUATION(dimension=dims,exp = e1,array = e2,source = source)
13531353
equation
13541354
(DAE.EQUALITY_EXPS(e1_1,e2_1), source) = ExpressionSimplify.simplifyAddSymbolicOperation(DAE.EQUALITY_EXPS(e1,e2),source);
1355-
eqns = lowerArrayEqn(dims,e1_1,e2_1,source,BackendDAE.DYNAMIC_EQUATION(),inIEquations);
1355+
eqns = lowerArrayEqn(dims,e1_1,e2_1,source,BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC,inIEquations);
13561356
then
13571357
(inEquations,inREquations,eqns);
13581358

@@ -1680,35 +1680,35 @@ protected function lowerExtendedRecordEqns "author: Frenkel TUD 2012-06"
16801680
input list<DAE.Exp> explst1;
16811681
input list<DAE.Exp> explst2;
16821682
input DAE.ElementSource source;
1683-
input BackendDAE.EquationKind inEqKind;
1683+
input BackendDAE.EquationAttributes inEqAttributes;
16841684
input DAE.FunctionTree functionTree;
16851685
input list<BackendDAE.Equation> inEqns;
16861686
output list<BackendDAE.Equation> outEqns;
16871687
algorithm
1688-
outEqns := match(explst1, explst2, source, inEqKind, functionTree, inEqns)
1688+
outEqns := match(explst1, explst2, source, inEqAttributes, functionTree, inEqns)
16891689
local
16901690
DAE.Exp e1, e2;
16911691
list<DAE.Exp> elst1, elst2;
16921692
list<BackendDAE.Equation> eqns;
16931693
case({}, {}, _, _, _, _) then inEqns;
16941694
case(e1::elst1, e2::elst2, _, _, _, _)
16951695
equation
1696-
eqns = lowerExtendedRecordEqn(e1, e2, source, inEqKind, functionTree, inEqns);
1696+
eqns = lowerExtendedRecordEqn(e1, e2, source, inEqAttributes, functionTree, inEqns);
16971697
then
1698-
lowerExtendedRecordEqns(elst1, elst2, source, inEqKind, functionTree, eqns);
1698+
lowerExtendedRecordEqns(elst1, elst2, source, inEqAttributes, functionTree, eqns);
16991699
end match;
17001700
end lowerExtendedRecordEqns;
17011701

17021702
protected function lowerExtendedRecordEqn "author: Frenkel TUD 2012-06"
17031703
input DAE.Exp inExp1;
17041704
input DAE.Exp inExp2;
17051705
input DAE.ElementSource source;
1706-
input BackendDAE.EquationKind inEqKind;
1706+
input BackendDAE.EquationAttributes inEqAttributes;
17071707
input DAE.FunctionTree functionTree;
17081708
input list<BackendDAE.Equation> inEqns;
17091709
output list<BackendDAE.Equation> outEqns;
17101710
algorithm
1711-
outEqns := matchcontinue(inExp1, inExp2, source, inEqKind, functionTree, inEqns)
1711+
outEqns := matchcontinue(inExp1, inExp2, source, inEqAttributes, functionTree, inEqns)
17121712
local
17131713
DAE.Type tp;
17141714
Integer size;
@@ -1723,7 +1723,7 @@ algorithm
17231723
explst1 = Expression.splitRecord(inExp1, Expression.typeof(inExp1));
17241724
explst2 = Expression.splitRecord(inExp2, Expression.typeof(inExp2));
17251725
then
1726-
lowerExtendedRecordEqns(explst1, explst2, source, inEqKind, functionTree, inEqns);
1726+
lowerExtendedRecordEqns(explst1, explst2, source, inEqAttributes, functionTree, inEqns);
17271727

17281728
// complex types to complex equations
17291729
case (_, _, _, _, _, _)
@@ -1732,7 +1732,7 @@ algorithm
17321732
true = DAEUtil.expTypeComplex(tp);
17331733
size = Expression.sizeOf(tp);
17341734
then
1735-
BackendDAE.COMPLEX_EQUATION(size, inExp1, inExp2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind))::inEqns;
1735+
BackendDAE.COMPLEX_EQUATION(size, inExp1, inExp2, source, inEqAttributes)::inEqns;
17361736

17371737
// array types to array equations
17381738
case (_, _, _, _, _, _)
@@ -1741,7 +1741,7 @@ algorithm
17411741
true = DAEUtil.expTypeArray(tp);
17421742
dims = Expression.arrayDimension(tp);
17431743
then
1744-
lowerArrayEqn(dims, inExp1, inExp2, source, inEqKind, inEqns);
1744+
lowerArrayEqn(dims, inExp1, inExp2, source, inEqAttributes, inEqns);
17451745

17461746
// tuple types to complex equations
17471747
case (_, _, _, _, _, _)
@@ -1750,7 +1750,7 @@ algorithm
17501750
true = Types.isTuple(tp);
17511751
size = Expression.sizeOf(tp);
17521752
then
1753-
BackendDAE.COMPLEX_EQUATION(size, inExp1, inExp2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind))::inEqns;
1753+
BackendDAE.COMPLEX_EQUATION(size, inExp1, inExp2, source, inEqAttributes)::inEqns;
17541754

17551755
// other types
17561756
case (_, _, _, _, _, _)
@@ -1762,7 +1762,7 @@ algorithm
17621762
false = b1 or b2 or b3;
17631763
//Error.assertionOrAddSourceMessage(not b1, Error.INTERNAL_ERROR, {str}, Absyn.dummyInfo);
17641764
then
1765-
BackendDAE.EQUATION(inExp1, inExp2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind))::inEqns;
1765+
BackendDAE.EQUATION(inExp1, inExp2, source, inEqAttributes)::inEqns;
17661766
else
17671767
equation
17681768
// show only on failtrace!
@@ -1778,11 +1778,11 @@ protected function lowerArrayEqn "author: Frenkel TUD 2012-06"
17781778
input DAE.Exp e1;
17791779
input DAE.Exp e2;
17801780
input DAE.ElementSource source;
1781-
input BackendDAE.EquationKind inEqKind;
1781+
input BackendDAE.EquationAttributes inEqAttributes;
17821782
input list<BackendDAE.Equation> iAcc;
17831783
output list<BackendDAE.Equation> outEqsLst;
17841784
algorithm
1785-
outEqsLst := matchcontinue (dims, e1, e2, source, inEqKind, iAcc)
1785+
outEqsLst := matchcontinue (dims, e1, e2, source, inEqAttributes, iAcc)
17861786
local
17871787
list<DAE.Exp> ea1, ea2;
17881788
list<Integer> ds;
@@ -1795,7 +1795,7 @@ algorithm
17951795
true = Expression.isArray(e2) or Expression.isMatrix(e2);
17961796
ea1 = Expression.flattenArrayExpToList(e1);
17971797
ea2 = Expression.flattenArrayExpToList(e2);
1798-
then generateEquations(ea1, ea2, source, inEqKind, iAcc);
1798+
then generateEquations(ea1, ea2, source, inEqAttributes, iAcc);
17991799

18001800
// array type with record
18011801
case (_, _, _, _, _, _)
@@ -1808,30 +1808,30 @@ algorithm
18081808
ds = List.map1(ds, intMul, i);
18091809
//For COMPLEX_EQUATION
18101810
//i = List.fold(ds, intMul, 1);
1811-
then BackendDAE.ARRAY_EQUATION(ds, e1, e2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind))::iAcc;
1811+
then BackendDAE.ARRAY_EQUATION(ds, e1, e2, source, inEqAttributes)::iAcc;
18121812

18131813
case (_, _, _, _, _, _)
18141814
equation
18151815
ds = Expression.dimensionsSizes(dims);
1816-
then BackendDAE.ARRAY_EQUATION(ds, e1, e2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind))::iAcc;
1816+
then BackendDAE.ARRAY_EQUATION(ds, e1, e2, source, inEqAttributes)::iAcc;
18171817
end matchcontinue;
18181818
end lowerArrayEqn;
18191819

18201820
protected function generateEquations "author: Frenkel TUD 2012-06"
18211821
input list<DAE.Exp> iE1lst;
18221822
input list<DAE.Exp> iE2lst;
18231823
input DAE.ElementSource source;
1824-
input BackendDAE.EquationKind inEqKind;
1824+
input BackendDAE.EquationAttributes inEqAttributes;
18251825
input list<BackendDAE.Equation> iAcc;
18261826
output list<BackendDAE.Equation> oEqns;
18271827
algorithm
1828-
oEqns := match(iE1lst, iE2lst, source, inEqKind, iAcc)
1828+
oEqns := match(iE1lst, iE2lst, source, inEqAttributes, iAcc)
18291829
local
18301830
DAE.Exp e1, e2;
18311831
list<DAE.Exp> e1lst, e2lst;
18321832
case ({}, {}, _, _, _) then iAcc;
18331833
case (e1::e1lst, e2::e2lst, _, _, _)
1834-
then generateEquations(e1lst, e2lst, source, inEqKind, BackendDAE.EQUATION(e1, e2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind))::iAcc);
1834+
then generateEquations(e1lst, e2lst, source, inEqAttributes, BackendDAE.EQUATION(e1, e2, source, inEqAttributes)::iAcc);
18351835
end match;
18361836
end generateEquations;
18371837

@@ -1861,7 +1861,7 @@ algorithm
18611861
outEqs := BackendDAE.EQUATION( exp = DAE.CREF(componentRef = cr, ty = DAE.T_CLOCK_DEFAULT),
18621862
scalar = e, source = DAE.emptyElementSource,
18631863
attr = BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC ) :: inEqs;
1864-
outEqAttrs := BackendDAE.EQUATION_ATTRIBUTES(false, BackendDAE.CLOCKED_EQUATION(whenClkCnt));
1864+
outEqAttrs := BackendEquation.defaultClockedEqAttr(whenClkCnt);
18651865
end createWhenClock;
18661866

18671867

@@ -2527,7 +2527,7 @@ algorithm
25272527
case (target::rest_targets, source::rest_sources, _, _, _)
25282528
equation
25292529
(DAE.EQUALITY_EXPS(target,source), eq_source) = ExpressionSimplify.simplifyAddSymbolicOperation(DAE.EQUALITY_EXPS(target,source),inEq_source);
2530-
eqns = lowerExtendedRecordEqn(target, source, inEq_source, BackendDAE.UNKNOWN_EQUATION_KIND(), funcs, iEqns);
2530+
eqns = lowerExtendedRecordEqn(target, source, inEq_source, BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN, funcs, iEqns);
25312531
then
25322532
lowerTupleAssignment(rest_targets, rest_sources, eq_source, funcs, eqns);
25332533
end match;

0 commit comments

Comments
 (0)