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

Commit 74ffe70

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Expand equations marked inlineAfterIndexReduction
This seems to be required for the multibody models. The sorting+matching should probably have been modified rather than making it depend on removeSimpleEquations. This is a quick fix.
1 parent 789abbe commit 74ffe70

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Compiler/BackEnd/RemoveSimpleEquations.mo

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,13 +1149,23 @@ protected
11491149
list<Integer> ds;
11501150
list<list<DAE.Subscript>> subslst;
11511151
list<DAE.Exp> elst1, elst2;
1152+
Boolean hasInlineAfterIndexReduction, expandLhs, expandRhs;
11521153
algorithm
11531154
dims := Expression.arrayDimension(ty);
11541155
ds := Expression.dimensionsSizes(dims);
11551156
subslst := List.map(ds, Expression.dimensionSizeSubscripts);
11561157
subslst := Expression.rangesToSubscripts(subslst);
1157-
(elst1,true) := List.mapFold(subslst, function Expression.applyExpSubscriptsFoldCheckSimplify(exp=lhs), false);
1158-
(elst2,true) := List.mapFold(subslst, function Expression.applyExpSubscriptsFoldCheckSimplify(exp=rhs), false) "Do not expand equation if it doesn't help with anything... Like x=f(...); => x[1]=f()[1], ..., x[n]=f()[n]";
1158+
(,hasInlineAfterIndexReduction) := Expression.traverseExpTopDown(lhs, Expression.findCallIsInlineAfterIndexReduction, false);
1159+
(,hasInlineAfterIndexReduction) := Expression.traverseExpTopDown(rhs, Expression.findCallIsInlineAfterIndexReduction, hasInlineAfterIndexReduction);
1160+
(elst1,expandLhs) := List.mapFold(subslst, function Expression.applyExpSubscriptsFoldCheckSimplify(exp=lhs), false);
1161+
(elst2,expandRhs) := List.mapFold(subslst, function Expression.applyExpSubscriptsFoldCheckSimplify(exp=rhs), false);
1162+
if not hasInlineAfterIndexReduction then
1163+
// If inlining after index reduction or i, we need to expand equations to pass sorting+matching
1164+
// Note: We *should* be looking for the derivative annotation here, but it's not available directly
1165+
// and better would be if sorting+matching could expand/split equations when necessary
1166+
true := expandLhs and expandRhs "Do not expand equation if it doesn't help with anything... Like x=f(...); => x[1]=f()[1], ..., x[n]=f()[n]";
1167+
else
1168+
end if;
11591169
outTpl := List.threadFold2(elst1, elst2, simpleEquationAcausal, eqnAttributes, true, inTpl);
11601170
end simpleArrayEquationAcausal;
11611171

Compiler/FrontEnd/Expression.mo

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13117,5 +13117,19 @@ algorithm
1311713117
end match;
1311813118
end isInvariantExpNoTraverse;
1311913119

13120+
public function findCallIsInlineAfterIndexReduction
13121+
input output DAE.Exp e;
13122+
output Boolean cont;
13123+
input output Boolean res;
13124+
algorithm
13125+
if not res then
13126+
res := match e
13127+
case DAE.CALL(attr=DAE.CALL_ATTR(inlineType=DAE.AFTER_INDEX_RED_INLINE())) then true;
13128+
else false;
13129+
end match;
13130+
end if;
13131+
cont := not res;
13132+
end findCallIsInlineAfterIndexReduction;
13133+
1312013134
annotation(__OpenModelica_Interface="frontend");
1312113135
end Expression;

0 commit comments

Comments
 (0)