Skip to content

Commit 2b6d157

Browse files
author
Jens Frenkel
committed
- check if expression is equal before report warning about different start values in case of alias variables.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13282 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent b8269ef commit 2b6d157

File tree

3 files changed

+99
-53
lines changed

3 files changed

+99
-53
lines changed

Compiler/BackEnd/BackendDAECreate.mo

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ algorithm
19211921
false = BackendVariable.isStateVar(v2);
19221922
replaceableAlias(v2);
19231923
// merge fixed,start,nominal
1924-
var = BackendVariable.mergeAliasVars(v1,v2,false);
1924+
var = BackendVariable.mergeAliasVars(v1,v2,false,iKnVars);
19251925
// setAliasType
19261926
ops = DAEUtil.getSymbolicTransformations(source);
19271927
avar = BackendVariable.mergeVariableOperations(v2,DAE.SOLVED(cr2,e1)::ops);
@@ -1945,7 +1945,7 @@ algorithm
19451945
false = BackendVariable.isStateVar(v1);
19461946
replaceableAlias(v1);
19471947
// merge fixed,start,nominal
1948-
var = BackendVariable.mergeAliasVars(v2,v1,false);
1948+
var = BackendVariable.mergeAliasVars(v2,v1,false,iKnVars);
19491949
// setAliasType
19501950
ops = DAEUtil.getSymbolicTransformations(source);
19511951
avar = BackendVariable.mergeVariableOperations(v1,DAE.SOLVED(cr1,e2)::ops);
@@ -1978,7 +1978,7 @@ algorithm
19781978
// select alias
19791979
((acr,avar,aindx,ae,cr,var,e)) = Util.if_(b,(cr2,v2,index2,e2,cr1,v1,e1),(cr1,v1,index1,e1,cr2,v2,e2));
19801980
// merge fixed,start,nominal
1981-
var = BackendVariable.mergeAliasVars(var,avar,false);
1981+
var = BackendVariable.mergeAliasVars(var,avar,false,iKnVars);
19821982
// setAliasType
19831983
ops = DAEUtil.getSymbolicTransformations(source);
19841984
avar = BackendVariable.mergeVariableOperations(avar,DAE.SOLVED(acr,e)::ops);
@@ -2002,7 +2002,7 @@ algorithm
20022002
// check if replacable
20032003
replaceableAlias(v1);
20042004
// merge fixed,start,nominal
2005-
var = BackendVariable.mergeAliasVars(v2,v1,false);
2005+
var = BackendVariable.mergeAliasVars(v2,v1,false,iKnVars);
20062006
// setAliasType
20072007
ops = DAEUtil.getSymbolicTransformations(source);
20082008
avar = BackendVariable.mergeVariableOperations(v1,DAE.SOLVED(cr1,e2)::ops);
@@ -2026,7 +2026,7 @@ algorithm
20262026
// check if replacable
20272027
replaceableAlias(v2);
20282028
// merge fixed,start,nominal
2029-
var = BackendVariable.mergeAliasVars(v1,v2,false);
2029+
var = BackendVariable.mergeAliasVars(v1,v2,false,iKnVars);
20302030
// setAliasType
20312031
ops = DAEUtil.getSymbolicTransformations(source);
20322032
avar = BackendVariable.mergeVariableOperations(v2,DAE.SOLVED(cr2,e1)::ops);
@@ -2050,7 +2050,7 @@ algorithm
20502050
// check if replacable
20512051
replaceableAlias(v1);
20522052
// merge fixed,start,nominal
2053-
var = BackendVariable.mergeAliasVars(v2,v1,false);
2053+
var = BackendVariable.mergeAliasVars(v2,v1,false,iKnVars);
20542054
// setAliasType
20552055
ops = DAEUtil.getSymbolicTransformations(source);
20562056
avar = BackendVariable.mergeVariableOperations(v1,DAE.SOLVED(cr1,e2)::ops);
@@ -2074,7 +2074,7 @@ algorithm
20742074
// check if replacable
20752075
replaceableAlias(v2);
20762076
// merge fixed,start,nominal
2077-
var = BackendVariable.mergeAliasVars(v1,v2,false);
2077+
var = BackendVariable.mergeAliasVars(v1,v2,false,iKnVars);
20782078
// setAliasType
20792079
ops = DAEUtil.getSymbolicTransformations(source);
20802080
avar = BackendVariable.mergeVariableOperations(v2,DAE.SOLVED(cr2,e1)::ops);

Compiler/BackEnd/BackendDAEOptimize.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ algorithm
19551955
knvars = BackendVariable.daeKnVars(shared);
19561956
(v::{},_) = BackendVariable.getVar(cra,knvars);
19571957
// merge fixed,start,nominal
1958-
v1 = BackendVariable.mergeAliasVars(v,var,negate);
1958+
v1 = BackendVariable.mergeAliasVars(v,var,negate,knvars);
19591959
shared = BackendVariable.addKnVarDAE(v1,shared);
19601960
// store changed var
19611961
vars = BackendVariable.daeVars(syst);
@@ -2140,7 +2140,7 @@ protected
21402140
algorithm
21412141
Debug.fcall(Flags.DEBUG_ALIAS,BackendDump.debugStrCrefStrExpStr,("Alias Equation ",acr," = ",e," found (3).\n"));
21422142
// merge fixed,start,nominal
2143-
v1 := BackendVariable.mergeAliasVars(ivar,avar,negate);
2143+
v1 := BackendVariable.mergeAliasVars(ivar,avar,negate,BackendVariable.daeKnVars(shared));
21442144
osyst := BackendVariable.addVarDAE(v1,syst);
21452145
// store changed var
21462146
ops := DAEUtil.getSymbolicTransformations(source);

Compiler/BackEnd/BackendVariable.mo

Lines changed: 90 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3394,6 +3394,7 @@ public function mergeAliasVars
33943394
input BackendDAE.Var inVar;
33953395
input BackendDAE.Var inAVar "the alias var";
33963396
input Boolean negate;
3397+
input BackendDAE.Variables knVars "the KnownVars, needd to report Warnings";
33973398
output BackendDAE.Var outVar;
33983399
protected
33993400
BackendDAE.Var v,va,v1,v2;
@@ -3408,7 +3409,7 @@ algorithm
34083409
// start
34093410
sv := varStartValueOption(inVar);
34103411
sva := varStartValueOption(inAVar);
3411-
(v1) := mergeStartFixed(inVar,fixed,sv,inAVar,fixeda,sva,negate);
3412+
(v1) := mergeStartFixed(inVar,fixed,sv,inAVar,fixeda,sva,negate,knVars);
34123413
// nominal
34133414
v2 := mergeNominalAttribute(inAVar,v1,negate);
34143415
// minmax
@@ -3424,72 +3425,61 @@ protected function mergeStartFixed
34243425
input Boolean fixeda;
34253426
input Option<DAE.Exp> sva;
34263427
input Boolean negate;
3428+
input BackendDAE.Variables knVars "the KnownVars, needd to report Warnings";
34273429
output BackendDAE.Var outVar;
34283430
algorithm
34293431
outVar :=
3430-
matchcontinue (inVar,fixed,sv,inAVar,fixeda,sva,negate)
3432+
matchcontinue (inVar,fixed,sv,inAVar,fixeda,sva,negate,knVars)
34313433
local
34323434
BackendDAE.Var v,va,v1,v2;
34333435
DAE.ComponentRef cr,cra;
34343436
DAE.Exp sa,sb,e;
34353437
String s,s1,s2,s3,s4,s5;
3436-
case (v as BackendDAE.VAR(varName=cr),true,SOME(sa),va as BackendDAE.VAR(varName=cra),true,SOME(sb),_)
3438+
case (v as BackendDAE.VAR(varName=cr),true,SOME(sa),va as BackendDAE.VAR(varName=cra),true,SOME(sb),_,_)
34373439
equation
34383440
e = getNonZeroStart(sa,sb,negate);
34393441
v1 = setVarStartValue(v,e);
34403442
then v1;
3441-
case (v as BackendDAE.VAR(varName=cr),true,SOME(sa),va as BackendDAE.VAR(varName=cra),true,SOME(sb),_)
3443+
case (v as BackendDAE.VAR(varName=cr),true,SOME(sa),va as BackendDAE.VAR(varName=cra),true,SOME(sb),_,_)
34423444
equation
3443-
s1 = ComponentReference.printComponentRefStr(cr);
3444-
s2 = Util.if_(negate," = -"," = ");
3445-
s3 = ComponentReference.printComponentRefStr(cra);
3446-
s4 = ExpressionDump.printExpStr(sa);
3447-
s5 = ExpressionDump.printExpStr(sb);
3448-
s = stringAppendList({"Alias variables ",s1,s2,s3," both fixed and have start values ",s4," != ",s5,". Use value from ",s1,".\n"});
3449-
Error.addMessage(Error.COMPILER_WARNING,{s});
3445+
mergeStartFixed1(cr,sa,cra,sb,negate," both fixed and have start values ","",knVars);
34503446
then v;
3451-
case (v,true,SOME(sa),va,true,NONE(),_)
3447+
case (v,true,SOME(sa),va,true,NONE(),_,_)
34523448
then v;
3453-
case (v,true,SOME(sa),va,false,SOME(sb),_)
3449+
case (v,true,SOME(sa),va,false,SOME(sb),_,_)
34543450
equation
34553451
e = getNonZeroStart(sa,sb,negate);
34563452
v1 = setVarStartValue(v,e);
34573453
then v1;
3458-
case (v as BackendDAE.VAR(varName=cr),true,SOME(sa),va as BackendDAE.VAR(varName=cra),false,SOME(sb),_)
3454+
case (v as BackendDAE.VAR(varName=cr),true,SOME(sa),va as BackendDAE.VAR(varName=cra),false,SOME(sb),_,_)
34593455
equation
3460-
s1 = ComponentReference.printComponentRefStr(cr);
3461-
s2 = Util.if_(negate," = -"," = ");
3462-
s3 = ComponentReference.printComponentRefStr(cra);
3463-
s4 = ExpressionDump.printExpStr(sa);
3464-
s5 = ExpressionDump.printExpStr(sb);
3465-
s = stringAppendList({"Alias variables ",s1,s2,s3," have start values ",s4," != ",s5,". Use value from ",s1," because this is fixed.\n"});
3466-
Error.addMessage(Error.COMPILER_WARNING,{s});
3456+
mergeStartFixed1(cr,sa,cra,sb,negate," have start values "," because this is fixed",knVars);
34673457
then v;
3468-
case (v,true,SOME(sa),va,false,NONE(),_)
3458+
case (v,true,SOME(sa),va,false,NONE(),_,_)
34693459
then v;
3470-
case (v,true,NONE(),va,true,SOME(sb),_)
3460+
case (v,true,NONE(),va,true,SOME(sb),_,_)
34713461
equation
34723462
v1 = setVarStartValue(v,sb);
34733463
then v1;
3474-
case (v,true,NONE(),va,true,NONE(),_)
3464+
case (v,true,NONE(),va,true,NONE(),_,_)
34753465
then v;
3476-
case (v,true,NONE(),va,false,SOME(sb),_)
3466+
case (v,true,NONE(),va,false,SOME(sb),_,_)
34773467
equation
34783468
v1 = setVarStartValue(v,sb);
34793469
then v1;
3480-
case (v,true,NONE(),va,false,NONE(),_)
3470+
case (v,true,NONE(),va,false,NONE(),_,_)
34813471
then v;
3482-
case (v,false,SOME(sa),va,true,SOME(sb),_)
3472+
case (v,false,SOME(sa),va,true,SOME(sb),_,_)
34833473
equation
34843474
e = getNonZeroStart(sa,sb,negate);
34853475
v1 = setVarStartValue(v,e);
34863476
v2 = setVarFixed(v1,true);
34873477
then v2;
3488-
case (v,false,SOME(sa),va,true,NONE(),_)
3478+
case (v,false,SOME(sa),va,true,NONE(),_,_)
34893479
equation
34903480
v1 = setVarFixed(v,true);
34913481
then v1;
3492-
case (v,false,SOME(sa),va,false,SOME(sb),_)
3482+
case (v,false,SOME(sa),va,false,SOME(sb),_,_)
34933483
equation
34943484
e = getNonZeroStart(sa,sb,negate);
34953485
v1 = setVarStartValue(v,e);
@@ -3498,45 +3488,101 @@ algorithm
34983488
// adrpo: TODO! FIXME! maybe we should use another heuristic here such as:
34993489
// use the value from the variable that is closer to the top of the
35003490
// hierarchy i.e. A.B value has priority over X.Y.Z value!
3501-
case (v as BackendDAE.VAR(varName=cr),false,SOME(sa),va as BackendDAE.VAR(varName=cra),false,SOME(sb),_)
3491+
case (v as BackendDAE.VAR(varName=cr),false,SOME(sa),va as BackendDAE.VAR(varName=cra),false,SOME(sb),_,_)
35023492
equation
35033493
true = intGt(ComponentReference.crefDepth(cr), ComponentReference.crefDepth(cra));
35043494
// invert arguments
3505-
v = mergeStartFixed(inAVar,fixeda,sva,inVar,fixed,sv,negate);
3495+
v = mergeStartFixed(inAVar,fixeda,sva,inVar,fixed,sv,negate,knVars);
35063496
then v;
35073497

3508-
case (v as BackendDAE.VAR(varName=cr),false,SOME(sa),va as BackendDAE.VAR(varName=cra),false,SOME(sb),_)
3498+
case (v as BackendDAE.VAR(varName=cr),false,SOME(sa),va as BackendDAE.VAR(varName=cra),false,SOME(sb),_,_)
35093499
equation
3510-
s1 = ComponentReference.printComponentRefStr(cr);
3511-
s2 = Util.if_(negate," = -"," = ");
3512-
s3 = ComponentReference.printComponentRefStr(cra);
3513-
s4 = ExpressionDump.printExpStr(sa);
3514-
s5 = ExpressionDump.printExpStr(sb);
3515-
s = stringAppendList({"Alias variables ",s1,s2,s3," have start values ",s4," != ",s5,". Use value from ",s1,".\n"});
3516-
Error.addMessage(Error.COMPILER_WARNING,{s});
3500+
mergeStartFixed1(cr,sa,cra,sb,negate," have start values ","",knVars);
35173501
then v;
3518-
case (v,false,SOME(sa),va,false,NONE(),_)
3502+
case (v,false,SOME(sa),va,false,NONE(),_,_)
35193503
then v;
3520-
case (v,false,NONE(),va,true,SOME(sb),_)
3504+
case (v,false,NONE(),va,true,SOME(sb),_,_)
35213505
equation
35223506
e = Debug.bcallret1(negate,Expression.negate,sb,sb);
35233507
v1 = setVarStartValue(v,e);
35243508
v2 = setVarFixed(v1,true);
35253509
then v2;
3526-
case (v,false,NONE(),va,true,NONE(),_)
3510+
case (v,false,NONE(),va,true,NONE(),_,_)
35273511
equation
35283512
v1 = setVarFixed(v,true);
35293513
then v1;
3530-
case (v,false,NONE(),va,false,SOME(sb),_)
3514+
case (v,false,NONE(),va,false,SOME(sb),_,_)
35313515
equation
35323516
e = Debug.bcallret1(negate,Expression.negate,sb,sb);
35333517
v1 = setVarStartValue(v,e);
35343518
then v1;
3535-
case (v,false,NONE(),va,false,NONE(),_)
3519+
case (v,false,NONE(),va,false,NONE(),_,_)
35363520
then v;
35373521
end matchcontinue;
35383522
end mergeStartFixed;
35393523

3524+
protected function mergeStartFixed1
3525+
"autor: Frenkel TUD 2011-04"
3526+
input DAE.ComponentRef cr;
3527+
input DAE.Exp sv;
3528+
input DAE.ComponentRef cra;
3529+
input DAE.Exp sva;
3530+
input Boolean negate;
3531+
input String s4;
3532+
input String s7;
3533+
input BackendDAE.Variables knVars "the KnownVars, needd to report Warnings";
3534+
algorithm
3535+
_ :=
3536+
matchcontinue (cr,sv,cra,sva,negate,s4,s7,knVars)
3537+
local
3538+
String s,s1,s2,s3,s5,s6;
3539+
DAE.Exp sv1,sva1;
3540+
// report nothing if equal start values
3541+
case (_,_,_,_,_,_,_,_)
3542+
equation
3543+
true = Expression.expEqual(sv, sva);
3544+
then
3545+
();
3546+
case (_,_,_,_,_,_,_,_)
3547+
equation
3548+
((sv1, _)) = Expression.traverseExp(sv, replaceCrefWithBindExp, knVars);
3549+
((sva1, _)) = Expression.traverseExp(sva, replaceCrefWithBindExp, knVars);
3550+
true = Expression.expEqual(sv1, sva1);
3551+
then
3552+
();
3553+
case (_,_,_,_,_,_,_,_)
3554+
equation
3555+
s1 = ComponentReference.printComponentRefStr(cr);
3556+
s2 = Util.if_(negate," = -"," = ");
3557+
s3 = ComponentReference.printComponentRefStr(cra);
3558+
s5 = ExpressionDump.printExpStr(sv);
3559+
s6 = ExpressionDump.printExpStr(sva);
3560+
s = stringAppendList({"Alias variables ",s1,s2,s3,s4,s5," != ",s6,". Use value from ",s1,s7,".\n"});
3561+
Error.addMessage(Error.COMPILER_WARNING,{s});
3562+
then
3563+
();
3564+
end matchcontinue;
3565+
end mergeStartFixed1;
3566+
3567+
public function replaceCrefWithBindExp
3568+
input tuple<DAE.Exp, BackendDAE.Variables> inTuple;
3569+
output tuple<DAE.Exp, BackendDAE.Variables> outTuple;
3570+
algorithm
3571+
outTuple := matchcontinue(inTuple)
3572+
local
3573+
DAE.Exp e;
3574+
BackendDAE.Variables vars;
3575+
DAE.ComponentRef cr;
3576+
case ((DAE.CREF(componentRef=cr), vars))
3577+
equation
3578+
({BackendDAE.VAR(bindExp = SOME(e))}, _) = getVar(cr, vars);
3579+
((e, _)) = Expression.traverseExp(e, replaceCrefWithBindExp, vars);
3580+
then
3581+
((e, vars));
3582+
else then inTuple;
3583+
end matchcontinue;
3584+
end replaceCrefWithBindExp;
3585+
35403586
protected function getNonZeroStart
35413587
"autor: Frenkel TUD 2011-04"
35423588
input DAE.Exp exp1;

0 commit comments

Comments
 (0)