Skip to content

Commit 4ed9d5a

Browse files
author
Leonardo Laguna
committed
Fixing bug in VarTransform.replaceExpRepeated
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18798 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent f597bc5 commit 4ed9d5a

File tree

4 files changed

+91
-79
lines changed

4 files changed

+91
-79
lines changed

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public import BackendDAE;
5252
public import BackendDAEFunc;
5353
public import DAE;
5454
public import Env;
55+
public import SCode;
5556
public import Util;
5657
public import HpcOmEqSystems;
5758

@@ -89,7 +90,6 @@ protected import List;
8990
protected import Matching;
9091
protected import OnRelaxation;
9192
protected import RemoveSimpleEquations;
92-
protected import SCode;
9393
protected import System;
9494
protected import Tearing;
9595
protected import Types;
@@ -1302,6 +1302,64 @@ algorithm
13021302
end matchcontinue;
13031303
end addAliasVariables;
13041304

1305+
public function isApproximatedEquation
1306+
input BackendDAE.Equation eqn;
1307+
output Boolean out;
1308+
algorithm
1309+
out:= match(eqn)
1310+
local
1311+
list<SCode.Comment> comment;
1312+
Boolean ret;
1313+
case(BackendDAE.EQUATION(source=DAE.SOURCE(comment=comment)))
1314+
equation
1315+
ret = isApproximatedEquation2(comment);
1316+
then
1317+
ret;
1318+
case(_)
1319+
then
1320+
false;
1321+
end match;
1322+
end isApproximatedEquation;
1323+
1324+
public function isApproximatedEquation2
1325+
input list<SCode.Comment> commentIn;
1326+
output Boolean out;
1327+
algorithm
1328+
out:= matchcontinue(commentIn)
1329+
local
1330+
SCode.Comment h;
1331+
list<SCode.Comment> t;
1332+
Boolean ret;
1333+
list<SCode.SubMod> subModLst;
1334+
case({})
1335+
equation
1336+
then false;
1337+
case(SCode.COMMENT(annotation_=SOME(SCode.ANNOTATION(SCode.MOD(subModLst=subModLst))))::t)
1338+
equation
1339+
ret = (List.exist(subModLst,isApproximatedEquation3)) or isApproximatedEquation2(t);
1340+
then
1341+
ret;
1342+
case(h::t)
1343+
equation
1344+
ret = isApproximatedEquation2(t);
1345+
then
1346+
ret;
1347+
end matchcontinue;
1348+
end isApproximatedEquation2;
1349+
1350+
protected function isApproximatedEquation3
1351+
input SCode.SubMod m;
1352+
output Boolean out;
1353+
algorithm
1354+
out:= match(m)
1355+
case(SCode.NAMEMOD("__OpenModelica_ApproximatedEquation",SCode.MOD(binding = SOME((Absyn.BOOL(true),_)))))
1356+
equation
1357+
then true;
1358+
case(_) equation
1359+
then false;
1360+
end match;
1361+
end isApproximatedEquation3;
1362+
13051363
public function isDiscreteEquation
13061364
input BackendDAE.Equation eqn;
13071365
input BackendDAE.Variables vars;

Compiler/BackEnd/RemoveSimpleEquations.mo

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -601,40 +601,46 @@ algorithm
601601
Integer index;
602602
array<list<Integer>> mT;
603603
Boolean b, differentiated;
604-
case (BackendDAE.EQUATION(exp=e1, scalar=e2, source=source, differentiated=differentiated), _)
604+
BackendDAE.Equation e;
605+
case (e as BackendDAE.EQUATION(exp=e1, scalar=e2, source=source, differentiated=differentiated), _)
605606
equation
607+
//false = BackendDAEUtil.isApproximatedEquation(e);
606608
Debug.fcall(Flags.DEBUG_ALIAS, BackendDump.debugStrExpStrExpStr, ("Found Equation ", e1, " = ", e2, " to handle.\n"));
607-
then
609+
then
608610
simpleEquationAcausal(e1, e2, (source, differentiated), false, inTpl);
609-
610-
case (BackendDAE.ARRAY_EQUATION(left=e1, right=e2, source=source, differentiated=differentiated), _)
611+
612+
case (e as BackendDAE.ARRAY_EQUATION(left=e1, right=e2, source=source, differentiated=differentiated), _)
611613
equation
614+
//false = BackendDAEUtil.isApproximatedEquation(e);
612615
Debug.fcall(Flags.DEBUG_ALIAS, BackendDump.debugStrExpStrExpStr, ("Found Array Equation ", e1, " = ", e2, " to handle.\n"));
613-
then
616+
then
614617
simpleEquationAcausal(e1, e2, (source, differentiated), false, inTpl);
615-
616-
case (BackendDAE.SOLVED_EQUATION(componentRef=cr, exp=e2, source=source, differentiated=differentiated), _)
618+
619+
case (e as BackendDAE.SOLVED_EQUATION(componentRef=cr, exp=e2, source=source, differentiated=differentiated), _)
617620
equation
621+
//false = BackendDAEUtil.isApproximatedEquation(e);
618622
e1 = Expression.crefExp(cr);
619623
Debug.fcall(Flags.DEBUG_ALIAS, BackendDump.debugStrExpStrExpStr, ("Found Solved Equation ", e1, " = ", e2, " to handle.\n"));
620-
then
624+
then
621625
simpleEquationAcausal(e1, e2, (source, differentiated), false, inTpl);
622-
623-
case (BackendDAE.RESIDUAL_EQUATION(exp=e1, source=source, differentiated=differentiated), _)
626+
627+
case (e as BackendDAE.RESIDUAL_EQUATION(exp=e1, source=source, differentiated=differentiated), _)
624628
equation
629+
//false = BackendDAEUtil.isApproximatedEquation(e);
625630
Debug.fcall(Flags.DEBUG_ALIAS, BackendDump.debugStrExpStr, ("Found Residual Equation ", e1, " to handle.\n"));
626-
then
631+
then
627632
simpleExpressionAcausal(e1, (source, differentiated), false, inTpl);
628-
629-
case (BackendDAE.COMPLEX_EQUATION(left=e1, right=e2, source=source, differentiated=differentiated), _)
633+
634+
case (e as BackendDAE.COMPLEX_EQUATION(left=e1, right=e2, source=source, differentiated=differentiated), _)
630635
equation
636+
//false = BackendDAEUtil.isApproximatedEquation(e);
631637
Debug.fcall(Flags.DEBUG_ALIAS, BackendDump.debugStrExpStrExpStr, ("Found Complex Equation ", e1, " = ", e2, " to handle.\n"));
632-
then
638+
then
633639
simpleEquationAcausal(e1, e2, (source, differentiated), false, inTpl);
634-
640+
635641
case (_, (v, s, eqns, seqns, index, mT, b))
636642
then ((v, s, eqn::eqns, seqns, index, mT, b));
637-
643+
638644
end matchcontinue;
639645
end simpleEquationsFinder;
640646

Compiler/BackEnd/Uncertainties.mo

Lines changed: 9 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ algorithm
162162
approximatedEquations_one = getEquationsWithApproximatedAnnotation(dlow_1);
163163
approximatedEquations = List.flatten(List.map1r(approximatedEquations_one,listGet,arrayList(mapEqnIncRow)));
164164

165+
//////////////////////////////
165166
mExt=removeEquations(mExt,approximatedEquations);
166167

167168
printSep(getMathematicaText("Approximated equations to be removed"));
@@ -170,6 +171,9 @@ algorithm
170171
printSep(getMathematicaText("After eliminating approximated equations"));
171172
printSep(equationsToMathematicaGrid(getEquationsNumber(mExt),allEqs,allVars,sharedVars,mapIncRowEqn));
172173

174+
//////////////////////
175+
176+
173177
// get the variable indices after the elimination
174178
variables = List.intRange(BackendVariable.varsSize(allVars));
175179
(knowns,distributions) = getUncertainRefineVariableIndexes(allVars,variables);
@@ -205,7 +209,9 @@ algorithm
205209

206210
printSep(getMathematicaText("Remaining equations"));
207211
printSep(equationsToMathematicaGrid(remainingEquations,allEqs,allVars,sharedVars,mapIncRowEqn));
212+
///////////////////
208213

214+
/////////////////////////////////////////////////////////////
209215
(setC,removed_equations_squared)=getEquationsForKnownsSystem(mExt,knowns,unknowns,setS,allEqs,allVars,sharedVars,mapIncRowEqn);
210216

211217
print(Util.if_(List.isNotEmpty(removed_equations_squared),"Warning: the system is ill-posed. One or more equations have been removed from squared system of knowns.\n",""));
@@ -532,7 +538,7 @@ algorithm
532538
{};
533539
case(h::t,i)
534540
equation
535-
true=isApproximatedEquation(h);
541+
true=BackendDAEUtil.isApproximatedEquation(h);
536542
inner_ret = getEquationsWithApproximatedAnnotation2(t,i+1);
537543
then
538544
i::inner_ret;
@@ -544,64 +550,6 @@ algorithm
544550
end matchcontinue;
545551
end getEquationsWithApproximatedAnnotation2;
546552

547-
protected function isApproximatedEquation
548-
input BackendDAE.Equation eqn;
549-
output Boolean out;
550-
algorithm
551-
out:= match(eqn)
552-
local
553-
list<SCode.Comment> comment;
554-
Boolean ret;
555-
case(BackendDAE.EQUATION(source=DAE.SOURCE(comment=comment)))
556-
equation
557-
ret = isApproximatedEquation2(comment);
558-
then
559-
ret;
560-
case(_)
561-
then
562-
false;
563-
end match;
564-
end isApproximatedEquation;
565-
566-
protected function isApproximatedEquation2
567-
input list<SCode.Comment> commentIn;
568-
output Boolean out;
569-
algorithm
570-
out:= matchcontinue(commentIn)
571-
local
572-
SCode.Comment h;
573-
list<SCode.Comment> t;
574-
Boolean ret;
575-
list<SCode.SubMod> subModLst;
576-
case({})
577-
equation
578-
then false;
579-
case(SCode.COMMENT(annotation_=SOME(SCode.ANNOTATION(SCode.MOD(subModLst=subModLst))))::t)
580-
equation
581-
ret = (List.exist(subModLst,isApproximatedEquation3)) or isApproximatedEquation2(t);
582-
then
583-
ret;
584-
case(h::t)
585-
equation
586-
ret = isApproximatedEquation2(t);
587-
then
588-
ret;
589-
end matchcontinue;
590-
end isApproximatedEquation2;
591-
592-
protected function isApproximatedEquation3
593-
input SCode.SubMod m;
594-
output Boolean out;
595-
algorithm
596-
out:= match(m)
597-
case(SCode.NAMEMOD("__OpenModelica_ApproximatedEquation",SCode.MOD(binding = SOME((Absyn.BOOL(true),_)))))
598-
then true;
599-
case(_)
600-
then false;
601-
end match;
602-
end isApproximatedEquation3;
603-
604-
605553
protected function flattenModel
606554
input Absyn.Path className;
607555
input Absyn.Program p;
@@ -2912,7 +2860,7 @@ protected function getSourceIfApproximated "Returns SOME(source) if the equation
29122860
protected DAE.ElementSource temp;
29132861
algorithm
29142862
temp:=BackendEquation.equationSource(eqn);
2915-
source:=Util.if_(isApproximatedEquation(eqn),SOME(temp),NONE());
2863+
source:=Util.if_(BackendDAEUtil.isApproximatedEquation(eqn),SOME(temp),NONE());
29162864
end getSourceIfApproximated;
29172865

29182866
/* Set handling functions */
@@ -3175,7 +3123,7 @@ algorithm
31753123
then ();
31763124
case(SOME(DAE.SOURCE(comment=comment)))
31773125
equation
3178-
str = Util.if_(isApproximatedEquation2(comment),"true","false");
3126+
str = Util.if_(BackendDAEUtil.isApproximatedEquation2(comment),"true","false");
31793127
print(" *Approximated = "+&str);
31803128
then ();
31813129
end match;

Compiler/Util/VarTransform.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ algorithm
13921392
true = i > maxIter;
13931393
then e;
13941394
case (_,_,_,_,_,true) then e;
1395-
case (_,_,_,_,_,true)
1395+
case (_,_,_,_,_,_)
13961396
equation
13971397
(e1,b) = replaceExp(e,repl,func);
13981398
res = replaceExpRepeated2(e1,repl,func,maxIter,i+1,not b /*Expression.expEqual(e,e1)*/);

0 commit comments

Comments
 (0)