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

Commit a7c9258

Browse files
committed
Merge branch 'master' into maintenance/v1.13
2 parents bbaaf2b + f4aa462 commit a7c9258

File tree

246 files changed

+16460
-4341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+16460
-4341
lines changed

3rdParty

Submodule 3rdParty updated 414 files

Compiler/BackEnd/BackendDAE.mo

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,7 @@ uniontype Equation
394394
.DAE.Exp iter "the iterator variable";
395395
.DAE.Exp start "start of iteration";
396396
.DAE.Exp stop "end of iteration";
397-
.DAE.Exp left;
398-
.DAE.Exp right;
397+
Equation body "iterated equation";
399398
.DAE.ElementSource source "origin of equation";
400399
EquationAttributes attr;
401400
end FOR_EQUATION;

Compiler/BackEnd/BackendDAECreate.mo

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,13 @@ algorithm
424424
then
425425
();
426426

427+
// for equation
428+
case DAE.FOR_EQUATION()
429+
algorithm
430+
(outEqns, outREqns, outIEqns) := lowerEqn(el, inFunctions, outEqns, outREqns, outIEqns, false);
431+
then
432+
();
433+
427434
// initial array equations
428435
case DAE.INITIAL_ARRAY_EQUATION()
429436
algorithm
@@ -434,7 +441,7 @@ algorithm
434441
// when equations
435442
case DAE.WHEN_EQUATION(condition = e, equations = dae_elts)
436443
algorithm
437-
if intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33) and Types.isClockOrSubTypeClock(Expression.typeof(e)) then
444+
if Config.synchronousFeaturesAllowed() and Types.isClockOrSubTypeClock(Expression.typeof(e)) then
438445

439446
(outEqns, outVars, eq_attrs) := createWhenClock(whenClkCnt, e, outEqns, outVars);
440447
whenClkCnt := whenClkCnt + 1;
@@ -692,6 +699,7 @@ algorithm
692699
DAE.ComponentRef cr;
693700
DAE.ElementSource src;
694701
DAE.Exp e1, e2;
702+
DAE.Dimensions dims;
695703
BackendDAE.EquationAttributes attr;
696704
BackendDAE.Var var;
697705
list<BackendDAE.Equation> assert_eqs;
@@ -710,7 +718,12 @@ algorithm
710718
outVars := lowerDynamicVar(inElement, inFunctions) :: outVars;
711719
e1 := Expression.crefExp(cr);
712720
attr := BackendDAE.EQ_ATTR_DEFAULT_BINDING;
713-
outEqns := BackendDAE.EQUATION(e1, e2, src, attr) :: outEqns;
721+
(_, dims) := ComponentReference.crefTypeFull2(cr);
722+
if listEmpty(dims) then
723+
outEqns := BackendDAE.EQUATION(e1, e2, src, attr) :: outEqns;
724+
else
725+
outEqns := BackendDAE.ARRAY_EQUATION(Expression.dimensionsSizes(dims), e1, e2, src, attr) :: outEqns;
726+
end if;
714727
then
715728
();
716729

@@ -1295,8 +1308,14 @@ algorithm
12951308

12961309
case DAE.EQUEQUATION(cr1 = cr1, cr2 = cr2,source = source)
12971310
equation
1298-
e1 = Expression.crefExp(cr1);
1299-
e2 = Expression.crefExp(cr2);
1311+
if Flags.isSet(Flags.NF_SCALARIZE) then
1312+
e1 = Expression.crefExp(cr1);
1313+
e2 = Expression.crefExp(cr2);
1314+
else
1315+
// consider array dimensions
1316+
e1 = Expression.crefToExp(cr1);
1317+
e2 = Expression.crefToExp(cr2);
1318+
end if;
13001319
eqns = lowerExtendedRecordEqn(e1,e2,source,BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC,functionTree,inEquations);
13011320
then
13021321
(eqns,inREquations,inIEquations);
@@ -1356,6 +1375,16 @@ algorithm
13561375
then
13571376
(inEquations,inREquations,eqns);
13581377

1378+
case DAE.FOR_EQUATION(iter = s, range = e1, equations = eqnslst, source = source)
1379+
equation
1380+
// create one backend for-equation for each equation element in the loop
1381+
(eqns, reqns, ieqns) = lowerEqns(eqnslst, functionTree, {}, {}, {}, inInitialization);
1382+
eqns = listAppend(List.map2(eqns, lowerForEquation, s, e1), inEquations);
1383+
reqns = listAppend(List.map2(reqns, lowerForEquation, s, e1), inREquations);
1384+
ieqns = listAppend(List.map2(ieqns, lowerForEquation, s, e1), inIEquations);
1385+
then
1386+
(eqns, reqns, ieqns);
1387+
13591388
// if equation that cannot be translated to if expression but have initial() as condition
13601389
case DAE.IF_EQUATION(condition1 = {DAE.CALL(path=Absyn.IDENT("initial"))},equations2={eqnslst},equations3={})
13611390
equation
@@ -1425,6 +1454,25 @@ algorithm
14251454
end match;
14261455
end lowerEqn;
14271456

1457+
protected
1458+
function lowerForEquation
1459+
"Wrap one equation into a for-equation.
1460+
author: rfranke"
1461+
input BackendDAE.Equation eq;
1462+
input DAE.Ident iter;
1463+
input DAE.Exp range;
1464+
output BackendDAE.Equation forEq;
1465+
protected
1466+
DAE.Exp iterExp, start, stop;
1467+
DAE.Type ty;
1468+
algorithm
1469+
DAE.RANGE(ty=ty, start=start, stop=stop) := range;
1470+
iterExp := DAE.CREF(DAE.CREF_IDENT(iter, ty, {}), ty);
1471+
forEq := BackendDAE.FOR_EQUATION(iterExp, start, stop, eq,
1472+
BackendEquation.equationSource(eq),
1473+
BackendEquation.getEquationAttributes(eq));
1474+
end lowerForEquation;
1475+
14281476
protected function lowerIfEquation
14291477
input list<DAE.Exp> conditions;
14301478
input list<list<DAE.Element>> theneqns;

Compiler/BackEnd/BackendDAEOptimize.mo

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ end simplifyAllExpressions;
116116
// OM introduces $OMC$PosetiveMax which can simplified using min or max attribute
117117
// see Modelica spec for inStream
118118
// author: Vitalij Ruge
119-
// see. #3885, 4441
119+
// see. #3885, 4441, 5104
120120
// =============================================================================
121121

122122
public function simplifyInStream
@@ -140,6 +140,14 @@ protected function simplifyInStreamWork
140140
output list<BackendDAE.Variables> outVars = inVars;
141141
algorithm
142142
outExp := Expression.traverseExpBottomUp(inExp, simplifyInStreamWork2, outVars);
143+
144+
// with #5104 we remove max(x, eps)
145+
// so in case max(x,eps)*y/max(x,eps) => x*y/x
146+
// now x can be equal 0, so we need simplify x*y/x = y
147+
// it's seem no other models silplyfied it
148+
if not Expression.expEqual(outExp, inExp) then
149+
outExp := ExpressionSimplify.simplify(outExp);
150+
end if;
143151
end simplifyInStreamWork;
144152

145153
protected function simplifyInStreamWork2
@@ -152,44 +160,70 @@ algorithm
152160
local
153161
DAE.Type tp;
154162
DAE.ComponentRef cr;
155-
DAE.Exp e, expr, a, b;
163+
DAE.Exp e, expr, ret;
156164
Option<DAE.Exp> eMin, eMax;
157-
Boolean isZero;
158165

159-
case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e as DAE.CREF(componentRef=cr), expr}) algorithm
166+
// positiveMax(cref, eps) = 0 if variable(cref).max <= 0
167+
// positiveMax(cref, eps) = cref if variable(cref).min >= 0
168+
case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e as DAE.CREF(componentRef=cr), expr})
169+
algorithm
160170
(eMin, eMax) := simplifyInStreamWorkExpresion(cr, outVars);
161-
isZero := simplifyInStreamWorkSimplify(eMin, false);
162-
tp := ComponentReference.crefTypeFull(cr);
163-
then if isZero then Expression.createZeroExpression(tp) else Expression.makePureBuiltinCall("max", {e, expr}, tp);
171+
if simplifyInStreamWorkSimplify(eMax, true) then // var.max <= 0.0
172+
tp := ComponentReference.crefTypeFull(cr);
173+
ret := Expression.createZeroExpression(tp);
174+
elseif simplifyInStreamWorkSimplify(eMin, false) then // var.min >= 0.0
175+
ret := e;
176+
else
177+
tp := ComponentReference.crefTypeFull(cr);
178+
ret := Expression.makePureBuiltinCall("max", {e, expr}, tp);
179+
end if;
180+
then
181+
ret;
164182

165-
case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e as DAE.UNARY(DAE.UMINUS(tp), DAE.CREF(componentRef=cr)), expr}) algorithm
183+
//positiveMax(-cref, eps) = 0 if variable(cref).min >= 0
184+
//positiveMax(-cref, eps) = -cref if variable(cref).max <= 0
185+
case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e as DAE.UNARY(DAE.UMINUS(tp), DAE.CREF(componentRef=cr)), expr})
186+
algorithm
166187
(eMin, eMax) := simplifyInStreamWorkExpresion(cr, outVars);
167-
isZero := simplifyInStreamWorkSimplify(eMax, true);
168-
then if isZero then Expression.createZeroExpression(tp) else Expression.makePureBuiltinCall("max", {e, expr}, tp);
188+
if simplifyInStreamWorkSimplify(eMin, false) then // var.min >= 0.0
189+
ret := Expression.createZeroExpression(tp);
190+
elseif simplifyInStreamWorkSimplify(eMax, true) then // var.max <= 0.0
191+
ret := e;
192+
else
193+
ret := Expression.makePureBuiltinCall("max", {e, expr}, tp);
194+
end if;
195+
then
196+
ret;
169197

170-
case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e, expr}) guard Expression.isZero(e)
198+
//positiveMax(cref, eps) = cref where cref >= 0
199+
case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e, expr}) guard Expression.isPositiveOrZero(e)
171200
then e;
172201

202+
// e.g. positiveMax(cref, eps) = max(cref,eps) = eps where cref < 0
173203
case DAE.CALL(path=Absyn.IDENT("$OMC$PositiveMax"),expLst={e, expr})
174204
//print("\nsimplifyInStreamWork: ");
175205
//print(ExpressionDump.printExpStr(inExp));
176206
//print(" <-> ");
177207
//print(ExpressionDump.printExpStr(e));
178-
then Expression.makePureBuiltinCall("max", {e, expr}, Expression.typeof(e));
208+
then
209+
Expression.makePureBuiltinCall("max", {e, expr}, Expression.typeof(e));
179210

180211
case DAE.CALL(path=Absyn.IDENT("$OMC$inStreamDiv"),expLst={e, expr})
181212
algorithm
182213
e := ExpressionSimplify.simplify(e);
183-
expr := match(e)
184-
case DAE.BINARY(a, DAE.DIV(), b)
185-
guard Expression.isZero(a) and Expression.isZero(b)
186-
then
187-
expr;
188-
else
189-
e;
214+
ret := match(e)
215+
local
216+
DAE.Exp a,b;
217+
218+
case DAE.BINARY(a, DAE.DIV(), b)
219+
guard Expression.isZero(a) and Expression.isZero(b)
220+
then expr;
221+
222+
else e;
223+
190224
end match;
191225
then
192-
expr;
226+
ret;
193227

194228
else inExp;
195229
end match;
@@ -207,7 +241,7 @@ algorithm
207241
try
208242
(v, _) := BackendVariable.getVarSingle(cr, vars);
209243
(outMin, outMax) := BackendVariable.getMinMaxAttribute(v);
210-
return;
244+
break;
211245
else
212246
// search
213247
end try;
@@ -5602,15 +5636,15 @@ algorithm
56025636
varlst = List.map1r(vlst, BackendVariable.getVarAt, inVars);
56035637
false = listEmpty(varlst);
56045638

5605-
warning = "Iteration variables of equation system w/o analytic Jacobian:\n" + warnAboutVars(varlst);
5639+
warning = "Iteration variables of equation system with analytic Jacobian:\n" + warnAboutVars(varlst);
56065640
warningList = listAllIterationVariables2(rest, inVars);
56075641
then warning::warningList;
56085642

56095643
case (BackendDAE.EQUATIONSYSTEM(vars=vlst, jacType=BackendDAE.JAC_NO_ANALYTIC())::rest, _) equation
56105644
varlst = List.map1r(vlst, BackendVariable.getVarAt, inVars);
56115645
false = listEmpty(varlst);
56125646

5613-
warning = "Iteration variables of equation system w/o analytic Jacobian:\n" + warnAboutVars(varlst);
5647+
warning = "Iteration variables of equation system without analytic Jacobian:\n" + warnAboutVars(varlst);
56145648
warningList = listAllIterationVariables2(rest, inVars);
56155649
then warning::warningList;
56165650

@@ -5852,6 +5886,7 @@ algorithm
58525886
tasks := List.sort(listAppend(predecessors,listAppend(outputTasks,stateTasks)),intGt);
58535887
//print("predecessors of outputs and states "+stringDelimitList(List.map(tasks,intString),", ")+"\n");
58545888
compsNew := List.map1(tasks,List.getIndexFirst,comps);
5889+
compsNew := List.unique(compsNew);
58555890
print("There have been "+intString(listLength(comps))+" SCCs and now there are "+intString(listLength(compsNew))+" SCCs.\n");
58565891

58575892
//get vars and equations from the new reduced set of comps and make a equationIdxMap

Compiler/BackEnd/BackendDAETransform.mo

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,11 @@ algorithm
565565
(outEquation, outTypeA) := matchcontinue (inEquation)
566566
local
567567
DAE.Exp e1_1, e2_1, e1, e2, cond;
568+
DAE.Exp iter, start, stop;
568569
DAE.ComponentRef cr, cr1;
569570
Integer size;
570571
list<DAE.Exp> expl;
571-
BackendDAE.Equation res;
572+
BackendDAE.Equation eqn;
572573
BackendDAE.WhenEquation elsepartRes;
573574
BackendDAE.WhenEquation elsepart;
574575
Option<BackendDAE.WhenEquation> oelsepart;
@@ -596,6 +597,10 @@ algorithm
596597
source = List.foldr(ops, ElementSource.addSymbolicTransformation, source);
597598
then (BackendDAE.ARRAY_EQUATION(dimSize, e1_1, e2_1, source, eqAttr), ext_arg_2);
598599

600+
case BackendDAE.FOR_EQUATION(iter = iter, start = start, stop = stop, body = eqn, source = source, attr = eqAttr) equation
601+
(eqn, outTypeA) = traverseBackendDAEExpsEqnWithSymbolicOperation(eqn, func, inTypeA);
602+
then (BackendDAE.FOR_EQUATION(iter, start, stop, eqn, source, eqAttr), outTypeA);
603+
599604
case BackendDAE.SOLVED_EQUATION(componentRef = cr, exp = e2, source=source, attr=eqAttr) equation
600605
e1 = Expression.crefExp(cr);
601606
(DAE.CREF(cr1, _), (ops, ext_arg_1)) = func(e1, ({}, inTypeA));
@@ -626,8 +631,8 @@ algorithm
626631
oelsepart = NONE();
627632
ext_arg_3 = ext_arg_2;
628633
end if;
629-
res = BackendDAE.WHEN_EQUATION(size, BackendDAE.WHEN_STMTS(cond, whenStmtLst, oelsepart), source, eqAttr);
630-
then (res, ext_arg_3);
634+
eqn = BackendDAE.WHEN_EQUATION(size, BackendDAE.WHEN_STMTS(cond, whenStmtLst, oelsepart), source, eqAttr);
635+
then (eqn, ext_arg_3);
631636

632637
case BackendDAE.COMPLEX_EQUATION(size=size, left = e1, right = e2, source = source, attr=eqAttr) equation
633638
(e1_1, (ops, ext_arg_1)) = func(e1, ({}, inTypeA));
@@ -842,6 +847,8 @@ protected
842847
list<Integer> ds;
843848
Integer len;
844849
list<DAE.Exp> exps;
850+
DAE.Exp exp1;
851+
Absyn.Ident call1, call2;
845852
DAE.ComponentRef cr1,cr2;
846853
list<DAE.Subscript> subs;
847854
Integer ndim;
@@ -859,7 +866,18 @@ algorithm
859866
ndim := listLength(ds);
860867
len := product(i for i in ds);
861868
true := len > 0;
862-
(DAE.CREF(componentRef=cr1)::exps) := Expression.flattenArrayExpToList(e); // TODO: Use a better routine? We now get all expressions even if no expression is a cref...
869+
//(DAE.CREF(componentRef=cr1)::exps) := Expression.flattenArrayExpToList(e); // TODO: Use a better routine? We now get all expressions even if no expression is a cref...
870+
(exp1::exps) := Expression.flattenArrayExpToList(e);
871+
(cr1, call1) := match exp1
872+
case DAE.CREF(componentRef=cr1) then (cr1, "");
873+
case DAE.CALL(path=Absyn.IDENT(name=call1), expLst={DAE.CREF(componentRef=cr1)}) then (cr1, call1);
874+
else fail();
875+
end match;
876+
if call1 <> "" and Config.simCodeTarget() <> "Cpp" or call1 == "pre" then
877+
// only Cpp runtime supports collapsed calls, except pre(array), see e.g.
878+
// Modelica_Synchronous.Examples.Elementary.RealSignals.SampleWithADeffects
879+
fail();
880+
end if;
863881
// Check that the first element starts at index [1,...,1]
864882
subs := ComponentReference.crefLastSubs(cr1);
865883
true := ndim==listLength(subs);
@@ -870,14 +888,23 @@ algorithm
870888
// Same number of expressions as expected...
871889
true := (1+listLength(exps))==len;
872890
for exp in exps loop
873-
DAE.CREF(componentRef=cr2) := exp;
891+
//DAE.CREF(componentRef=cr2) := exp;
892+
(cr2, call2) := match exp
893+
case DAE.CREF(componentRef=cr2) then (cr2, "");
894+
case DAE.CALL(path=Absyn.IDENT(name=call2), expLst={DAE.CREF(componentRef=cr2)}) then (cr2, call2);
895+
else fail();
896+
end match;
874897
true := ndim==listLength(ComponentReference.crefLastSubs(cr2));
875898
true := ComponentReference.crefEqualWithoutSubs(cr1,cr2);
876899
true := 1==ComponentReference.crefCompareIntSubscript(cr2,cr1); // cr2 > cr1
900+
true := call1==call2;
877901
cr1 := cr2;
878902
end for;
879903
// All of the crefs are in ascending order; the first one starts at 1,1; the length is the full array... So it is the complete cref!
880904
e := Expression.makeCrefExp(ComponentReference.crefStripLastSubs(cr1), ty);
905+
if call1 <> "" then
906+
e := DAE.CALL(Absyn.IDENT(name = call1), {e}, DAE.callAttrBuiltinImpureReal);
907+
end if;
881908
end collapseArrayCrefExpWork2;
882909

883910
annotation(__OpenModelica_Interface="backend");

0 commit comments

Comments
 (0)