Skip to content

Commit

Permalink
- BackendDAEOptimize: -improve merging of start values
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8542 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Apr 7, 2011
1 parent 594521e commit 1bc9bba
Showing 1 changed file with 39 additions and 17 deletions.
56 changes: 39 additions & 17 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -1164,16 +1164,15 @@ algorithm
BackendDAE.Var v,va,v1,v2;
DAE.ComponentRef cr,cra;
DAE.Exp sa,sb,e;
Boolean b1,b2,b3;
String s;
case (v as BackendDAE.VAR(varName=cr),true,SOME(sa),va as BackendDAE.VAR(varName=cra),true,SOME(sb),negate)
equation
e = negateif(negate,sb);
true = Expression.expEqual(sa,e);
then v;
e = getNonZeroStart(sa,sb,negate);
v1 = BackendVariable.setVarStartValue(v,e);
then v1;
case (v as BackendDAE.VAR(varName=cr),true,SOME(sa),va as BackendDAE.VAR(varName=cra),true,SOME(sb),negate)
equation
e = negateif(negate,sb);
false = Expression.expEqual(sa,e);
print("Warning alias variables ");
print(ComponentReference.printComponentRefStr(cr));
s = Util.if_(negate," = -"," = ");
Expand All @@ -1188,13 +1187,11 @@ algorithm
then v;
case (v,true,SOME(sa),va,false,SOME(sb),negate)
equation
e = Util.if_(negate,Expression.negate(sb),sb);
true = Expression.expEqual(sa,e);
then v;
e = getNonZeroStart(sa,sb,negate);
v1 = BackendVariable.setVarStartValue(v,e);
then v1;
case (v as BackendDAE.VAR(varName=cr),true,SOME(sa),va as BackendDAE.VAR(varName=cra),false,SOME(sb),negate)
equation
e = negateif(negate,sb);
false = Expression.expEqual(sa,e);
print("Warning alias variables ");
print(ComponentReference.printComponentRefStr(cr));
s = Util.if_(negate," = -"," = ");
Expand Down Expand Up @@ -1224,7 +1221,7 @@ algorithm
then v;
case (v,false,SOME(sa),va,true,SOME(sb),negate)
equation
e = negateif(negate,sb);
e = getNonZeroStart(sa,sb,negate);
v1 = BackendVariable.setVarStartValue(v,e);
v2 = BackendVariable.setVarFixed(v1,true);
then v2;
Expand All @@ -1234,14 +1231,11 @@ algorithm
then v1;
case (v,false,SOME(sa),va,false,SOME(sb),negate)
equation
e = negateif(negate,sb);
true = Expression.expEqual(sa,e);
then
v;
e = getNonZeroStart(sa,sb,negate);
v1 = BackendVariable.setVarStartValue(v,e);
then v1;
case (v as BackendDAE.VAR(varName=cr),false,SOME(sa),va as BackendDAE.VAR(varName=cra),false,SOME(sb),negate)
equation
e = negateif(negate,sb);
false = Expression.expEqual(sa,e);
print("Warning alias variables ");
print(ComponentReference.printComponentRefStr(cr));
s = Util.if_(negate," = -"," = ");
Expand Down Expand Up @@ -1277,6 +1271,34 @@ algorithm
end matchcontinue;
end mergeStartFixed;

protected function getNonZeroStart
"autor: Frenkel TUD 2011-04"
input DAE.Exp exp1;
input DAE.Exp exp2;
input Boolean negate;
output DAE.Exp outExp;
algorithm
outExp :=
matchcontinue (exp1,exp2,negate)
local
DAE.Exp ne;
case (exp1,exp2,negate)
equation
true = Expression.isZero(exp2);
then exp1;
case (exp1,exp2,negate)
equation
true = Expression.isZero(exp1);
ne = negateif(negate,exp2);
then ne;
case (exp1,exp2,negate)
equation
ne = negateif(negate,exp2);
true = Expression.expEqual(exp1,ne);
then ne;
end matchcontinue;
end getNonZeroStart;

protected function negateif
"autor: Frenkel TUD 2011-04"
input Boolean negate;
Expand Down

0 comments on commit 1bc9bba

Please sign in to comment.