Skip to content

Commit 11366f6

Browse files
author
Vitalij Ruge
committed
ExpressionSolve: improved handling of modelica functions
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23913 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 744bd1c commit 11366f6

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4958,7 +4958,7 @@ algorithm
49584958
cr1 = ComponentReference.crefPrefixDer(cr);
49594959
e = Expression.crefExp(cr);
49604960
((e,_)) = Expression.replaceExp(Expression.expSub(e1,e2), DAE.CALL(Absyn.IDENT("der"),{e},DAE.callAttrBuiltinReal), Expression.crefExp(cr1));
4961-
de = Differentiate.differentiateExpSolve(e, cr1);
4961+
de = Differentiate.differentiateExpSolve(e, cr1, NONE());
49624962
(de,_) = ExpressionSimplify.simplify(de);
49634963
(_,crlst) = Expression.traverseExp(de, Expression.traversingComponentRefFinder, {});
49644964
solvab = adjacencyRowEnhanced2(cr1,de,crlst,vars,kvars);
@@ -4972,7 +4972,7 @@ algorithm
49724972
// de/dvar
49734973
BackendDAE.VAR(varName=cr) = BackendVariable.getVarAt(vars, rabs);
49744974
e = Expression.expSub(e1,e2);
4975-
de = Differentiate.differentiateExpSolve(e, cr);
4975+
de = Differentiate.differentiateExpSolve(e, cr, NONE());
49764976
(de,_) = ExpressionSimplify.simplify(de);
49774977
(_,crlst) = Expression.traverseExpTopDown(de, Expression.traversingComponentRefFinderNoPreDer, {});
49784978
solvab = adjacencyRowEnhanced2(cr,de,crlst,vars,kvars);

Compiler/BackEnd/Differentiate.mo

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,27 +160,34 @@ public function differentiateExpSolve
160160
Differentiates an equation with respect to the cref variable."
161161
input DAE.Exp inExp;
162162
input DAE.ComponentRef inCref;
163+
input Option<DAE.FunctionTree> functions;
163164
output DAE.Exp outExp;
164165
algorithm
165166
outExp := matchcontinue(inExp, inCref)
166167
local
167168
String msg;
168-
DAE.Exp dexp, zero;
169+
DAE.Exp dexp;
169170
BackendDAE.DifferentiateInputData diffData;
170-
DAE.Type tp;
171+
DAE.FunctionTree fun;
171172

172-
case (_, _)
173+
case (_,_)
173174
equation
175+
fun = match(functions)
176+
local DAE.FunctionTree fun_;
177+
case(SOME(fun_)) then fun_;
178+
else DAE.emptyFuncTree;
179+
end match;
174180
diffData = BackendDAE.DIFFINPUTDATA(NONE(), NONE(), NONE(), NONE(), SOME({}), NONE(), NONE());
175-
(dexp, _) = differentiateExp(inExp, inCref, diffData, BackendDAE.SIMPLE_DIFFERENTIATION(), DAE.emptyFuncTree);
181+
(dexp, _) = differentiateExp(inExp, inCref, diffData, BackendDAE.SIMPLE_DIFFERENTIATION(), fun);
176182
(dexp,_) = ExpressionSimplify.simplify(dexp);
177183
then dexp;
178184

179185
else
180186
equation
181-
true = Flags.isSet(Flags.FAILTRACE);
182-
msg = "\nDifferentiate.differentiateExpSolve failed for " + ExpressionDump.printExpStr(inExp) + "\n\n";
183-
Error.addMessage(Error.NON_EXISTING_DERIVATIVE, {msg});
187+
if Flags.isSet(Flags.FAILTRACE) then
188+
msg = "\nDifferentiate.differentiateExpSolve failed for " + ExpressionDump.printExpStr(inExp) + "\n\n";
189+
Error.addMessage(Error.NON_EXISTING_DERIVATIVE, {msg});
190+
end if;
184191
then fail();
185192

186193
end matchcontinue;

Compiler/BackEnd/ExpressionSolve.mo

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ algorithm
352352
(outExp, outAsserts, eqnForNewVars1, newVarsCrefs1, depth) := matchcontinue(e1, e2, inExp3)
353353
case(DAE.IFEXP(),_,_) then solveIfExp(e1, e2, inExp3, functions, uniqueEqIndex, depth);
354354
case(_,_,_) then solveSimple(e1, e2, inExp3, depth);
355-
case(_,_,_) then solveLinearSystem(e1, e2, inExp3, depth);
355+
case(_,_,_) then solveLinearSystem(e1, e2, inExp3, functions, depth);
356356
else fail();
357357
end matchcontinue;
358358

@@ -659,6 +659,13 @@ preprocessing for solve1,
659659
inlineFun := false;
660660
end if;
661661

662+
if con and collect then
663+
(lhsX, lhsY) := preprocessingSolve5(x, inExp3, true);
664+
(rhsX, rhsY) := preprocessingSolve5(y, inExp3, false);
665+
x := Expression.expSub(lhsX, rhsX);
666+
y := Expression.expSub(rhsY, lhsY);
667+
end if;
668+
662669
iter := iter + 1;
663670
//print("\nx ");print(ExpressionDump.printExpStr(x));print("\ny ");print(ExpressionDump.printExpStr(y));
664671
end while;
@@ -1240,7 +1247,8 @@ algorithm
12401247
case(_,_)
12411248
equation
12421249
(funX,_) = Expression.traverseExpTopDown(inExp1, inlineCallX, (inExp3, functions));
1243-
then (funX, not Expression.expEqual(funX, inExp1));
1250+
b = not Expression.expEqual(funX, inExp1);
1251+
then (funX, b);
12441252
else (inExp1, false);
12451253
end matchcontinue;
12461254
end solveFunCalls;
@@ -1857,6 +1865,7 @@ protected function solveLinearSystem
18571865
input DAE.Exp inExp1;
18581866
input DAE.Exp inExp2;
18591867
input DAE.Exp inExp3;
1868+
input Option<DAE.FunctionTree> functions;
18601869
input Integer idepth;
18611870
output DAE.Exp outExp;
18621871
output list<DAE.Statement> outAsserts;
@@ -1880,7 +1889,9 @@ algorithm
18801889
e = Expression.makeDiff(inExp1,inExp2);
18811890
(e,_) = ExpressionSimplify.simplify1(e);
18821891
({},_) = List.split1OnTrue(Expression.factors(e),isCrefInIFEXP,cr); // check: differentiateExpSolve is allowed
1883-
dere = Differentiate.differentiateExpSolve(e, cr);
1892+
//print("\n\ne: ");print(ExpressionDump.printExpStr(e));
1893+
dere = Differentiate.differentiateExpSolve(e, cr, functions);
1894+
//print("\nder(e): ");print(ExpressionDump.printExpStr(dere));
18841895
(dere,_) = ExpressionSimplify.simplify(dere);
18851896
false = Expression.isZero(dere);
18861897
false = Expression.expHasCrefNoPreOrStart(dere, cr);

Compiler/BackEnd/OnRelaxation.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3708,7 +3708,7 @@ algorithm
37083708
cr = BackendVariable.varCref(v);
37093709
(_,i::_) = BackendVariable.getVar(cr,vars);
37103710
false = intGt(vec1[i],0);
3711-
e1 = Differentiate.differentiateExpSolve(e, cr);
3711+
e1 = Differentiate.differentiateExpSolve(e, cr,NONE());
37123712
(e2,_) = ExpressionSimplify.simplify(e1);
37133713
true = Expression.isConstOne(e2) or Expression.isConstMinusOne(e2);
37143714
then

0 commit comments

Comments
 (0)