Skip to content

Commit

Permalink
- update new index reduction method
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9463 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jul 12, 2011
1 parent 0c6ddd9 commit 0752e1b
Show file tree
Hide file tree
Showing 8 changed files with 2,155 additions and 662 deletions.
8 changes: 6 additions & 2 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -42,6 +42,7 @@ public import DAE;
public import SCode;
public import Values;
public import HashTable2;
public import HashTable3;
public import HashTable4;
public import HashTableCG;

Expand Down Expand Up @@ -428,13 +429,16 @@ uniontype DAEHandlerJop
end DAEHandlerJop;

public
type DAEHandlerArg = tuple<StateOrder,list<tuple<Integer,list<tuple<Equation,Boolean>>>>>;
type DAEHandlerArg = tuple<StateOrder,ConstraintEquations>;

public
type ConstraintEquations = list<tuple<Integer,list<Equation>>>;

public
uniontype StateOrder
record STATEORDER
HashTableCG.HashTable hashTable "x -> dx.";
HashTableCG.HashTable invHashTable "dx -> x.";
HashTable3.HashTable invHashTable "dx -> x.";
end STATEORDER;
end StateOrder;

Expand Down
164 changes: 18 additions & 146 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -936,7 +936,7 @@ algorithm
pos_1 = pos-1;
eqns = BackendEquation.daeEqns(dae);
(eqn as BackendDAE.EQUATION(source=source)) = BackendDAEUtil.equationNth(eqns,pos_1);
(cr,cr2,e1,e2,negate) = aliasEquation(eqn);
(cr,cr2,e1,e2,negate) = BackendEquation.aliasEquation(eqn);
// select candidate
(cr,es,k,dae1,newvars) = selectAlias(cr,cr2,e1,e2,dae,mavars,negate,source);
then (cr,k,es,dae1,mvars,newvars,1);
Expand Down Expand Up @@ -1106,133 +1106,6 @@ algorithm
end matchcontinue;
end selectAlias;

protected function aliasEquation
"function aliasEquation
autor Frenkel TUD 2011-04
Returns the two sides of an alias equation as expressions and cref.
If the equation is not simple, this function will fail."
input BackendDAE.Equation eqn;
output DAE.ComponentRef cr1;
output DAE.ComponentRef cr2;
output DAE.Exp e1;
output DAE.Exp e2;
output Boolean negate;
algorithm
(cr1,cr2,e1,e2,negate) := match (eqn)
local
DAE.Exp e,ne,ne1;
// a = b;
case (BackendDAE.EQUATION(exp=e1 as DAE.CREF(componentRef = cr1),scalar=e2 as DAE.CREF(componentRef = cr2)))
then (cr1,cr2,e1,e2,false);
// a = -b;
case (BackendDAE.EQUATION(exp=e1 as DAE.CREF(componentRef = cr1),scalar=e2 as DAE.UNARY(DAE.UMINUS(_),DAE.CREF(componentRef = cr2))))
equation
ne = Expression.negate(e1);
then (cr1,cr2,ne,e2,true);
case (BackendDAE.EQUATION(exp=e1 as DAE.CREF(componentRef = cr1),scalar=e2 as DAE.UNARY(DAE.UMINUS_ARR(_),DAE.CREF(componentRef = cr2))))
equation
ne = Expression.negate(e1);
then (cr1,cr2,ne,e2,true);
// -a = b;
case (BackendDAE.EQUATION(exp=e1 as DAE.UNARY(DAE.UMINUS(_),DAE.CREF(componentRef = cr1)),scalar=e2 as DAE.CREF(componentRef = cr2)))
equation
ne = Expression.negate(e2);
then (cr1,cr2,e1,ne,true);
case (BackendDAE.EQUATION(exp=e1 as DAE.UNARY(DAE.UMINUS_ARR(_),DAE.CREF(componentRef = cr1)),scalar=e2 as DAE.CREF(componentRef = cr2)))
equation
ne = Expression.negate(e2);
then (cr1,cr2,e1,ne,true);
// a + b = 0
case (BackendDAE.EQUATION(exp=DAE.BINARY(e1 as DAE.CREF(componentRef = cr1),DAE.ADD(ty=_),e2 as DAE.CREF(componentRef = cr2)),scalar=e))
equation
true = Expression.isZero(e);
ne1 = Expression.negate(e1);
ne = Expression.negate(e2);
then (cr1,cr2,ne1,ne,true);
case (BackendDAE.EQUATION(exp=DAE.BINARY(e1 as DAE.CREF(componentRef = cr1),DAE.ADD_ARR(ty=_),e2 as DAE.CREF(componentRef = cr2)),scalar=e))
equation
true = Expression.isZero(e);
ne1 = Expression.negate(e1);
ne = Expression.negate(e2);
then (cr1,cr2,ne1,ne,true);
// a - b = 0
case (BackendDAE.EQUATION(exp=DAE.BINARY(e1 as DAE.CREF(componentRef = cr1),DAE.SUB(ty=_),e2 as DAE.CREF(componentRef = cr2)),scalar=e))
equation
true = Expression.isZero(e);
then (cr1,cr2,e1,e2,false);
case (BackendDAE.EQUATION(exp=DAE.BINARY(e1 as DAE.CREF(componentRef = cr1),DAE.SUB_ARR(ty=_),e2 as DAE.CREF(componentRef = cr2)),scalar=e))
equation
true = Expression.isZero(e);
then (cr1,cr2,e1,e2,false);
// -a + b = 0
case (BackendDAE.EQUATION(exp=DAE.BINARY(e1 as DAE.UNARY(DAE.UMINUS(_),DAE.CREF(componentRef = cr1)),DAE.ADD(ty=_),e2 as DAE.CREF(componentRef = cr2)),scalar=e))
equation
true = Expression.isZero(e);
ne = Expression.negate(e1);
then (cr1,cr2,ne,e2,false);
case (BackendDAE.EQUATION(exp=DAE.BINARY(e1 as DAE.UNARY(DAE.UMINUS_ARR(_),DAE.CREF(componentRef = cr1)),DAE.ADD_ARR(ty=_),e2 as DAE.CREF(componentRef = cr2)),scalar=e))
equation
true = Expression.isZero(e);
ne = Expression.negate(e1);
then (cr1,cr2,ne,e2,false);
// -a - b = 0
case (BackendDAE.EQUATION(exp=DAE.BINARY(e1 as DAE.UNARY(DAE.UMINUS(_),DAE.CREF(componentRef = cr1)),DAE.SUB(ty=_),e2 as DAE.CREF(componentRef = cr2)),scalar=e))
equation
true = Expression.isZero(e);
ne = Expression.negate(e2);
then (cr1,cr2,e1,ne,true);
case (BackendDAE.EQUATION(exp=DAE.BINARY(e1 as DAE.UNARY(DAE.UMINUS_ARR(_),DAE.CREF(componentRef = cr1)),DAE.SUB_ARR(ty=_),e2 as DAE.CREF(componentRef = cr2)),scalar=e))
equation
true = Expression.isZero(e);
ne = Expression.negate(e2);
then (cr1,cr2,e1,ne,true);
// 0 = a + b
case (BackendDAE.EQUATION(exp=e,scalar=DAE.BINARY(e1 as DAE.CREF(componentRef = cr1),DAE.ADD(ty=_),e2 as DAE.CREF(componentRef = cr2))))
equation
true = Expression.isZero(e);
ne1 = Expression.negate(e1);
ne = Expression.negate(e2);
then (cr1,cr2,ne1,ne,true);
case (BackendDAE.EQUATION(exp=e,scalar=DAE.BINARY(e1 as DAE.CREF(componentRef = cr1),DAE.ADD_ARR(ty=_),e2 as DAE.CREF(componentRef = cr2))))
equation
true = Expression.isZero(e);
ne1 = Expression.negate(e1);
ne = Expression.negate(e2);
then (cr1,cr2,ne1,ne,true);
// 0 = a - b
case (BackendDAE.EQUATION(exp=e,scalar=DAE.BINARY(e1 as DAE.CREF(componentRef = cr1),DAE.SUB(ty=_),e2 as DAE.CREF(componentRef = cr2))))
equation
true = Expression.isZero(e);
then (cr1,cr2,e1,e2,false);
case (BackendDAE.EQUATION(exp=e,scalar=DAE.BINARY(e1 as DAE.CREF(componentRef = cr1),DAE.SUB_ARR(ty=_),e2 as DAE.CREF(componentRef = cr2))))
equation
true = Expression.isZero(e);
then (cr1,cr2,e1,e2,false);
// 0 = -a + b
case (BackendDAE.EQUATION(exp=e,scalar=DAE.BINARY(e1 as DAE.UNARY(DAE.UMINUS(_),DAE.CREF(componentRef = cr1)),DAE.ADD(ty=_),e2 as DAE.CREF(componentRef = cr2))))
equation
true = Expression.isZero(e);
ne = Expression.negate(e1);
then (cr1,cr2,ne,e2,false);
case (BackendDAE.EQUATION(exp=e,scalar=DAE.BINARY(e1 as DAE.UNARY(DAE.UMINUS_ARR(_),DAE.CREF(componentRef = cr1)),DAE.ADD_ARR(ty=_),e2 as DAE.CREF(componentRef = cr2))))
equation
true = Expression.isZero(e);
ne = Expression.negate(e1);
then (cr1,cr2,ne,e2,false);
// 0 = -a - b
case (BackendDAE.EQUATION(exp=e,scalar=DAE.BINARY(e1 as DAE.UNARY(DAE.UMINUS(_),DAE.CREF(componentRef = cr1)),DAE.SUB(ty=_),e2 as DAE.CREF(componentRef = cr2))))
equation
true = Expression.isZero(e);
ne = Expression.negate(e2);
then (cr1,cr2,e1,ne,true);
case (BackendDAE.EQUATION(exp=e,scalar=DAE.BINARY(e1 as DAE.UNARY(DAE.UMINUS_ARR(_),DAE.CREF(componentRef = cr1)),DAE.SUB_ARR(ty=_),e2 as DAE.CREF(componentRef = cr2))))
equation
true = Expression.isZero(e);
ne = Expression.negate(e2);
then (cr1,cr2,e1,ne,true);
end match;
end aliasEquation;

protected function mergeAliasVars
"autor: Frenkel TUD 2011-04"
input BackendDAE.Var inVar;
Expand Down Expand Up @@ -1927,7 +1800,7 @@ algorithm
pos_1 = pos-1;
eqns = BackendEquation.daeEqns(dae);
(eqn as BackendDAE.EQUATION(source=source)) = BackendDAEUtil.equationNth(eqns,pos_1);
(_,_,_,_,_) = aliasEquation(eqn);
(_,_,_,_,_) = BackendEquation.aliasEquation(eqn);
then ();
end matchcontinue;
end countsimpleEquation;
Expand Down Expand Up @@ -4266,7 +4139,8 @@ algorithm
Debug.fcall("jacdump", print, "##################### daeLow-dump: jacobian #####################\n");
then jacobian;

case(_, _, _, _, _, _) equation
else
equation
Error.addMessage(Error.INTERNAL_ERROR, {"BackendDAEOptimize.generateSymbolicJacobian failed"});
then fail();
end matchcontinue;
Expand Down Expand Up @@ -4296,7 +4170,8 @@ algorithm
r = listAppend(r1, r2);
then (r,res);

case(_, _) equation
else
equation
Error.addMessage(Error.INTERNAL_ERROR, {"BackendDAEOptimize.generateJacobianVars failed"});
then fail();
end matchcontinue;
Expand Down Expand Up @@ -4342,7 +4217,8 @@ algorithm
r = listAppend({r1}, r2);
then (r,res);

case(_, _) equation
else
equation
Error.addMessage(Error.INTERNAL_ERROR, {"BackendDAEOptimize.generateJacobianVars2 failed"});
then fail();
end matchcontinue;
Expand Down Expand Up @@ -4390,7 +4266,8 @@ algorithm
derivedEquations = listAppend(currDerivedEquations, restDerivedEquations);
then derivedEquations;

case(_, _, _, _, _, _, _, _, _, _) equation
else
equation
Error.addMessage(Error.INTERNAL_ERROR, {"BackendDAEOptimize.deriveAll failed"});
then fail();
end matchcontinue;
Expand Down Expand Up @@ -4514,7 +4391,8 @@ algorithm
Error.addMessage(Error.INTERNAL_ERROR, {"BackendDAEOptimize.derive failed: COMPLEX_EQUATION-case"});
then fail();

case(_, _, _, _, _, _, _, _, _, _) equation
else
equation
Error.addMessage(Error.INTERNAL_ERROR, {"BackendDAEOptimize.derive failed"});
then fail();
end matchcontinue;
Expand All @@ -4525,31 +4403,25 @@ protected function createEqn
input DAE.Exp inRHS;
input DAE.ElementSource Source;
output BackendDAE.Equation outEqn;
algorithm outEqn := match(inLHS,inRHS,Source)
local
case (inLHS,inRHS,Source) then BackendDAE.EQUATION(inLHS,inRHS,Source);
end match;
algorithm
outEqn := BackendDAE.EQUATION(inLHS,inRHS,Source);
end createEqn;

protected function createSolvedEqn
input DAE.ComponentRef inCref;
input DAE.Exp inRHS;
input DAE.ElementSource Source;
output BackendDAE.Equation outEqn;
algorithm outEqn := match(inCref,inRHS,Source)
local
case (inCref,inRHS,Source) then BackendDAE.SOLVED_EQUATION(inCref,inRHS,Source);
end match;
algorithm
outEqn := BackendDAE.SOLVED_EQUATION(inCref,inRHS,Source);
end createSolvedEqn;

protected function createResidualEqn
input DAE.Exp inRHS;
input DAE.ElementSource Source;
output BackendDAE.Equation outEqn;
algorithm outEqn := match(inRHS,Source)
local
case (inRHS,Source) then BackendDAE.RESIDUAL_EQUATION(inRHS, Source);
end match;
algorithm
outEqn := BackendDAE.RESIDUAL_EQUATION(inRHS, Source);
end createResidualEqn;

protected function createAlgorithmEqnEmptyIn
Expand Down

0 comments on commit 0752e1b

Please sign in to comment.