Skip to content

Commit c22c35b

Browse files
ptaeuberOpenModelica-Hudson
authored andcommitted
Fix problems with ExpressionSolve
ExpressionSolve solved equations wrongly due to wrong replacement handling. ticket:4253 Belonging to [master]: - OpenModelica/OMCompiler#1892 - OpenModelica/OpenModelica-testsuite#739
1 parent ebb0ea8 commit c22c35b

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

Compiler/BackEnd/ExpressionSolve.mo

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ preprocessing for solve1,
506506
// TODO: use new defined function, which missing in the cpp runtime
507507
if not stringEqual(Config.simCodeTarget(), "Cpp") then
508508
(x, y, new_x, eqnForNewVars, newVarsCrefs, depth) := preprocessingSolveTmpVars(x, y, inExp3, uniqueEqIndex, eqnForNewVars, newVarsCrefs, depth);
509-
con := new_x or con;
509+
con := new_x or con;
510510
end if;
511511

512512
if (not con) then
@@ -1218,7 +1218,7 @@ end removeSimpleCalls2;
12181218

12191219
protected function inlineCallX
12201220
"
1221-
inline function call if depends on X where X is cref oder der(cref)
1221+
inline function call if depends on X where X is cref or der(cref)
12221222
DAE.Exp inExp2 DAE.CREF or 'der(DAE.CREF())'
12231223
author: vitalij
12241224
"
@@ -1346,7 +1346,7 @@ algorithm
13461346
(rhs, eqnForNewVars_, newVarsCrefs_) = makeTmpEqnAndCrefFromExp(inExp2, tp, "Y$SINH", uniqueEqIndex, idepth, ieqnForNewVars, inewVarsCrefs,false);
13471347

13481348
tp = Expression.typeof(e1);
1349-
exP = makeIntialGuess(e1,tp,inExp3,e1);
1349+
exP = makeInitialGuess(tp,inExp3,e1);
13501350
(exP, eqnForNewVars_, newVarsCrefs_) = makeTmpEqnAndCrefFromExp(exP, tp, "SIGN$SINH", uniqueEqIndex, idepth, eqnForNewVars_, newVarsCrefs_,false);
13511351

13521352

@@ -1373,7 +1373,7 @@ algorithm
13731373
acosy = Expression.makePureBuiltinCall("acos", {rhs}, tp);
13741374
(acosy, eqnForNewVars_, newVarsCrefs_) = makeTmpEqnAndCrefFromExp(acosy, tp, "ACOS$COS", uniqueEqIndex, idepth, eqnForNewVars_, newVarsCrefs_,false);
13751375

1376-
exP = makeIntialGuess(e1,tp,inExp3,e1);
1376+
exP = makeInitialGuess(tp,inExp3,e1);
13771377
(exP, eqnForNewVars_, newVarsCrefs_) = makeTmpEqnAndCrefFromExp(exP, tp, "PREX$COS", uniqueEqIndex, idepth, eqnForNewVars_, newVarsCrefs_, false);
13781378

13791379
k1 = helpInvCos(acosy, exP, tp, true);
@@ -1404,7 +1404,7 @@ algorithm
14041404
acosy = Expression.makePureBuiltinCall("asin", {rhs}, tp);
14051405
(acosy, eqnForNewVars_, newVarsCrefs_) = makeTmpEqnAndCrefFromExp(acosy, tp, "ASIN$SIN", uniqueEqIndex, idepth, eqnForNewVars_, newVarsCrefs_,false);
14061406

1407-
exP = makeIntialGuess(e1,tp,inExp3,e1);
1407+
exP = makeInitialGuess(tp,inExp3,e1);
14081408
(exP, eqnForNewVars_, newVarsCrefs_) = makeTmpEqnAndCrefFromExp(exP, tp, "PREX$SIN", uniqueEqIndex, idepth, eqnForNewVars_, newVarsCrefs_, false);
14091409

14101410
k1 = helpInvSin(acosy, e1, tp, true);
@@ -1433,7 +1433,7 @@ algorithm
14331433
acosy = Expression.makePureBuiltinCall("atan", {rhs}, tp);
14341434
(acosy, eqnForNewVars_, newVarsCrefs_) = makeTmpEqnAndCrefFromExp(acosy, tp, "ATAN$TAN", uniqueEqIndex, idepth, eqnForNewVars_, newVarsCrefs_,false);
14351435

1436-
exP = makeIntialGuess(e1,tp,inExp3,e1);
1436+
exP = makeInitialGuess(tp,inExp3,e1);
14371437
(exP, eqnForNewVars_, newVarsCrefs_) = makeTmpEqnAndCrefFromExp(exP, tp, "PREX$TAN", uniqueEqIndex, idepth, eqnForNewVars_, newVarsCrefs_, false);
14381438
e = DAE.RCONST(3.1415926535897932384626433832795028841971693993751058);
14391439

@@ -1453,7 +1453,7 @@ algorithm
14531453
false = expHasCref(inExp2, inExp3);
14541454

14551455
tp = Expression.typeof(e1);
1456-
exP = makeIntialGuess(e1,tp,inExp3,e1);
1456+
exP = makeInitialGuess(tp,inExp3,e1);
14571457
(exP, eqnForNewVars_, newVarsCrefs_) = makeTmpEqnAndCrefFromExp(exP, tp, "X$ABS", uniqueEqIndex, idepth, ieqnForNewVars, inewVarsCrefs, false);
14581458
e_1 = Expression.makePureBuiltinCall("$_signNoNull", {exP}, tp);
14591459
lhs = Expression.expMul(e_1, inExp2);
@@ -1466,11 +1466,14 @@ algorithm
14661466
true = expHasCref(e1, inExp3);
14671467
false = expHasCref(e2, inExp3);
14681468
tp = Expression.typeof(e1);
1469-
exP = makeIntialGuess(e1,tp,inExp3,e1);
1469+
exP = makeInitialGuess(tp,inExp3,e1);
1470+
// exP = makeInitialGuess(tp,inExp3,inExp2);
14701471
(exP, eqnForNewVars_, newVarsCrefs_) = makeTmpEqnAndCrefFromExp(exP, tp, "X$ABS", uniqueEqIndex, idepth, ieqnForNewVars, inewVarsCrefs, false);
14711472
e_1 = Expression.makePureBuiltinCall("$_signNoNull", {exP}, tp);
14721473
lhs = Expression.expPow(inExp2,Expression.inverseFactors(e2));
14731474
lhs = Expression.makePureBuiltinCall("abs", {lhs}, tp);
1475+
// lhs = Expression.makePureBuiltinCall("abs", {inExp2}, tp);
1476+
// lhs = Expression.expPow(lhs,Expression.inverseFactors(e2));
14741477
lhs = Expression.expMul(e_1,lhs);
14751478

14761479
then(e1, lhs, true, eqnForNewVars_, newVarsCrefs_, idepth + 1);
@@ -1643,7 +1646,7 @@ algorithm
16431646
(x2, eqnForNewVars, newVarsCrefs) := makeTmpEqnAndCrefFromExp(x2, tp, "x2$QE", uniqueEqIndex, idepth, eqnForNewVars, newVarsCrefs, false);
16441647

16451648
tp := Expression.typeof(e2);
1646-
exP := makeIntialGuess(e2,tp,inExp3,e2);
1649+
exP := makeInitialGuess(tp,inExp3,e2);
16471650
(exP, eqnForNewVars, newVarsCrefs) := makeTmpEqnAndCrefFromExp(exP, tp, "prex$QE", uniqueEqIndex, idepth, eqnForNewVars, newVarsCrefs, false);
16481651

16491652
x := helpInvCos3(x1,x2,exP,tp);
@@ -1933,22 +1936,21 @@ algorithm
19331936
end if;
19341937
end makeTmpEqnAndCrefFromExp;
19351938

1936-
protected function makeIntialGuess
1937-
input DAE.Exp iExp;
1939+
protected function makeInitialGuess
19381940
input DAE.Type tp;
1939-
input DAE.Exp iExp3;
1941+
input DAE.Exp iExp1;
19401942
input DAE.Exp iExp2;
19411943
output DAE.Exp oExp;
19421944
protected
19431945
DAE.Exp con, e;
19441946
algorithm
19451947
con := Expression.makePureBuiltinCall("initial", {}, tp);
1946-
e := Expression.traverseExpBottomUp(iExp2, makeIntialGuess2, (iExp3, "pre", tp, true));
1947-
oExp := Expression.traverseExpBottomUp(iExp2, makeIntialGuess2, (iExp3, "pre", tp, false));
1948+
e := Expression.traverseExpBottomUp(iExp2, makeInitialGuess2, (iExp1, "pre", tp, true));
1949+
oExp := Expression.traverseExpBottomUp(iExp2, makeInitialGuess2, (iExp1, "pre", tp, false));
19481950
oExp := DAE.IFEXP(con, e, oExp);
1949-
end makeIntialGuess;
1951+
end makeInitialGuess;
19501952

1951-
protected function makeIntialGuess2
1953+
protected function makeInitialGuess2
19521954
input DAE.Exp iExp;
19531955
input tuple<DAE.Exp, String, DAE.Type, Boolean> itpl;
19541956
output DAE.Exp oExp;
@@ -1968,17 +1970,17 @@ algorithm
19681970

19691971
case (_, (_, _, tp, true)) algorithm
19701972
try
1971-
SOME(e) := makeIntialGuess3(iExp, tp);
1973+
SOME(e) := makeInitialGuess3(iExp, tp);
19721974
else
19731975
e := iExp;
19741976
end try;
19751977
then e;
19761978

19771979
else iExp;
19781980
end match;
1979-
end makeIntialGuess2;
1981+
end makeInitialGuess2;
19801982

1981-
protected function makeIntialGuess3
1983+
protected function makeInitialGuess3
19821984
input DAE.Exp iExp;
19831985
input DAE.Type tp;
19841986
output Option<DAE.Exp> oExp;
@@ -2014,7 +2016,7 @@ algorithm
20142016

20152017
end match;
20162018

2017-
end makeIntialGuess3;
2019+
end makeInitialGuess3;
20182020

20192021
protected function helpInvCos
20202022
input DAE.Exp acosy;

Compiler/Util/VarTransform.mo

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,6 @@ protected
904904
HashTable3.HashTable invHt;
905905
algorithm
906906
REPLACEMENTS(ht,invHt) := outRepl;
907-
if BaseHashTable.hasKey(src, ht) then // TODO: Is this correct? Previously, we skipped this code which was a dead case
908-
return;
909-
end if;
910907
ht := BaseHashTable.add((src, dst), ht);
911908
invHt := addReplacementInv(invHt, src, dst);
912909
outRepl := REPLACEMENTS(ht,invHt);

0 commit comments

Comments
 (0)