Skip to content

Commit

Permalink
- add size information to when equation
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12290 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jul 5, 2012
1 parent 28ac996 commit 6e0a8ad
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 33 deletions.
1 change: 1 addition & 0 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -143,6 +143,7 @@ uniontype Equation "- Equation"
end ALGORITHM;

record WHEN_EQUATION
Integer size "size of equation";
WhenEquation whenEquation "whenEquation" ;
.DAE.ElementSource source "origin of equation";
end WHEN_EQUATION;
Expand Down
24 changes: 14 additions & 10 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -1359,34 +1359,37 @@ algorithm
(outEquationLst,outReinitStatementLst):=
matchcontinue (inDAEElementLst,inWhenClauseIndex,functionTree,iEquationLst,iReinitStatementLst)
local
BackendDAE.Value i;
Integer i,size;
list<BackendDAE.Equation> eqnl;
list<BackendDAE.WhenOperator> reinit;
DAE.Exp cre,e,cond;
DAE.ComponentRef cr;
list<DAE.Element> xs;
DAE.Element el;
DAE.ElementSource source;
DAE.Dimensions ds;

case ({},_,_,_,_) then (iEquationLst,iReinitStatementLst);
case ((DAE.EQUATION(exp = (cre as DAE.CREF(componentRef = cr)),scalar = e, source = source) :: xs),i,_,_,_)
equation
(e,source) = Inline.inlineExp(e, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
(eqnl,reinit) = lowerWhenEqn2(xs, i + 1, functionTree, BackendDAE.WHEN_EQUATION(BackendDAE.WHEN_EQ(i,cr,e,NONE()),source) :: iEquationLst, iReinitStatementLst);
(eqnl,reinit) = lowerWhenEqn2(xs, i + 1, functionTree, BackendDAE.WHEN_EQUATION(1,BackendDAE.WHEN_EQ(i,cr,e,NONE()),source) :: iEquationLst, iReinitStatementLst);
then
(eqnl,reinit);

case ((DAE.COMPLEX_EQUATION(lhs = (cre as DAE.CREF(componentRef = cr)),rhs = e,source = source) :: xs),i,_,_,_)
equation
size = Expression.sizeOf(Expression.typeof(cre));
(e,source) = Inline.inlineExp(e, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
(eqnl,reinit) = lowerWhenEqn2(xs, i + 1, functionTree, BackendDAE.WHEN_EQUATION(BackendDAE.WHEN_EQ(i,cr,e,NONE()),source) :: iEquationLst, iReinitStatementLst);
(eqnl,reinit) = lowerWhenEqn2(xs, i + 1, functionTree, BackendDAE.WHEN_EQUATION(size,BackendDAE.WHEN_EQ(i,cr,e,NONE()),source) :: iEquationLst, iReinitStatementLst);
then
(eqnl,reinit);

case ((DAE.ARRAY_EQUATION(exp = (cre as DAE.CREF(componentRef = cr)),array = e,source = source) :: xs),i,_,_,_)
case ((DAE.ARRAY_EQUATION(dimension=ds,exp = (cre as DAE.CREF(componentRef = cr)),array = e,source = source) :: xs),i,_,_,_)
equation
size = List.fold(Expression.dimensionsSizes(ds),intMul,1);
(e,source) = Inline.inlineExp(e, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
(eqnl,reinit) = lowerWhenEqn2(xs, i + 1, functionTree, BackendDAE.WHEN_EQUATION(BackendDAE.WHEN_EQ(i,cr,e,NONE()),source) :: iEquationLst, iReinitStatementLst);
(eqnl,reinit) = lowerWhenEqn2(xs, i + 1, functionTree, BackendDAE.WHEN_EQUATION(size,BackendDAE.WHEN_EQ(i,cr,e,NONE()),source) :: iEquationLst, iReinitStatementLst);
then
(eqnl,reinit);

Expand Down Expand Up @@ -3122,12 +3125,13 @@ algorithm
list<BackendDAE.WhenClause> outClauseList;
BackendDAE.WhenEquation foundEquation;
list<BackendDAE.Equation> elseEqnsRest;
DAE.ElementSource source "the element source";
DAE.ElementSource source;
Integer size;

case (BackendDAE.WHEN_EQUATION(BackendDAE.WHEN_EQ(index = ind,left = cr,right=rightSide),source)::trueEqns, elseEqns,trueCls,elseCls,nextInd)
case (BackendDAE.WHEN_EQUATION(size=size,whenEquation=BackendDAE.WHEN_EQ(index = ind,left = cr,right=rightSide),source=source)::trueEqns, elseEqns,trueCls,elseCls,nextInd)
equation
(foundEquation, elseEqnsRest) = getWhenEquationFromVariable(cr,elseEqns);
res = BackendDAE.WHEN_EQUATION(BackendDAE.WHEN_EQ(ind,cr,rightSide,SOME(foundEquation)),source);
res = BackendDAE.WHEN_EQUATION(size,BackendDAE.WHEN_EQ(ind,cr,rightSide,SOME(foundEquation)),source);
(resRest, outNextIndex, outClauseList) = mergeClauses(trueEqns,elseEqnsRest,trueCls, elseCls,nextInd);
then (res::resRest, outNextIndex, outClauseList);

Expand Down Expand Up @@ -3155,12 +3159,12 @@ algorithm
BackendDAE.Equation eq2;
list<BackendDAE.Equation> rest, rest2;

case (cr1,BackendDAE.WHEN_EQUATION(eq as BackendDAE.WHEN_EQ(left=cr2),_)::rest)
case (cr1,BackendDAE.WHEN_EQUATION(whenEquation=eq as BackendDAE.WHEN_EQ(left=cr2))::rest)
equation
true = ComponentReference.crefEqualNoStringCompare(cr1,cr2);
then (eq, rest);

case (cr1,(eq2 as BackendDAE.WHEN_EQUATION(BackendDAE.WHEN_EQ(left=cr2),_))::rest)
case (cr1,(eq2 as BackendDAE.WHEN_EQUATION(whenEquation=BackendDAE.WHEN_EQ(left=cr2)))::rest)
equation
false = ComponentReference.crefEqualNoStringCompare(cr1,cr2);
(eq,rest2) = getWhenEquationFromVariable(cr1,rest);
Expand Down
10 changes: 5 additions & 5 deletions Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -3359,25 +3359,25 @@ algorithm
(statementLst,(ops,ext_arg_1)) = DAEUtil.traverseDAEEquationsStmts(statementLst, func, ({},inTypeA));
source = List.foldr(ops, DAEUtil.addSymbolicTransformation, source);
then (BackendDAE.ALGORITHM(size,DAE.ALGORITHM_STMTS(statementLst),source),wclst,ext_arg_1);
case (BackendDAE.WHEN_EQUATION(whenEquation =
case (BackendDAE.WHEN_EQUATION(size=size,whenEquation =
BackendDAE.WHEN_EQ(index = i,left = cr,right = e1,elsewhenPart=NONE()),source = source),wclst,_,_)
equation
e2 = Expression.crefExp(cr);
((e1_1,(ops,ext_arg_1))) = func((e1,({},inTypeA)));
((DAE.CREF(cr1,_),(ops,ext_arg_2))) = func((e2,(ops,ext_arg_1)));
source = List.foldr(ops, DAEUtil.addSymbolicTransformation, source);
res = BackendDAE.WHEN_EQUATION(BackendDAE.WHEN_EQ(i,cr1,e1_1,NONE()),source);
res = BackendDAE.WHEN_EQUATION(size,BackendDAE.WHEN_EQ(i,cr1,e1_1,NONE()),source);
(wclst1,(_,ext_arg_3)) = traverseBackendDAEExpsWhenClause(SOME(i),wclst,func,({} /*TODO: Save me?*/,ext_arg_2));
then
(res,wclst1,ext_arg_3);

case (BackendDAE.WHEN_EQUATION(whenEquation =
case (BackendDAE.WHEN_EQUATION(size=size,whenEquation =
BackendDAE.WHEN_EQ(index = i,left = cr,right = e1,elsewhenPart=SOME(elsepart)),source = source),wclst,_,_)
equation
((e1_1,(ops,ext_arg_1))) = func((e1,({},inTypeA)));
source = List.foldr(ops, DAEUtil.addSymbolicTransformation, source);
(BackendDAE.WHEN_EQUATION(elsepartRes,source),wclst1,ext_arg_2) = traverseBackendDAEExpsEqnWithSymbolicOperation(BackendDAE.WHEN_EQUATION(elsepart,source),wclst,func,ext_arg_1);
res = BackendDAE.WHEN_EQUATION(BackendDAE.WHEN_EQ(i,cr,e1_1,SOME(elsepartRes)),source);
(BackendDAE.WHEN_EQUATION(whenEquation=elsepartRes,source=source),wclst1,ext_arg_2) = traverseBackendDAEExpsEqnWithSymbolicOperation(BackendDAE.WHEN_EQUATION(size,elsepart,source),wclst,func,ext_arg_1);
res = BackendDAE.WHEN_EQUATION(size,BackendDAE.WHEN_EQ(i,cr,e1_1,SOME(elsepartRes)),source);
(wclst2,(_,ext_arg_3)) = traverseBackendDAEExpsWhenClause(SOME(i),wclst1,func,({} /* TODO: Save me?*/,ext_arg_2));
then
(res,wclst2,ext_arg_3);
Expand Down
26 changes: 13 additions & 13 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -593,23 +593,23 @@ algorithm
((e_1,ext_arg_1)) = func((e1,inTypeA));
then
(BackendDAE.RESIDUAL_EQUATION(e_1,source),ext_arg_1);
case (BackendDAE.WHEN_EQUATION(whenEquation = BackendDAE.WHEN_EQ(index=index,left = cr,right = e2,elsewhenPart=NONE()),source = source),func,inTypeA)
case (BackendDAE.WHEN_EQUATION(size=size,whenEquation = BackendDAE.WHEN_EQ(index=index,left = cr,right = e2,elsewhenPart=NONE()),source = source),func,inTypeA)
equation
tp = Expression.typeof(e2);
e1 = Expression.makeCrefExp(cr,tp);
((DAE.CREF(cr1,_),ext_arg_1)) = func((e1,inTypeA));
((e_2,ext_arg_2)) = func((e2,ext_arg_1));
then
(BackendDAE.WHEN_EQUATION(BackendDAE.WHEN_EQ(index,cr1,e_2,NONE()),source),ext_arg_2);
case (BackendDAE.WHEN_EQUATION(whenEquation = BackendDAE.WHEN_EQ(index=index,left=cr,right=e2,elsewhenPart=SOME(elsePart)),source = source),func,inTypeA)
(BackendDAE.WHEN_EQUATION(size,BackendDAE.WHEN_EQ(index,cr1,e_2,NONE()),source),ext_arg_2);
case (BackendDAE.WHEN_EQUATION(size=size,whenEquation = BackendDAE.WHEN_EQ(index=index,left=cr,right=e2,elsewhenPart=SOME(elsePart)),source = source),func,inTypeA)
equation
tp = Expression.typeof(e2);
e1 = Expression.makeCrefExp(cr,tp);
((DAE.CREF(cr1,_),ext_arg_1)) = func((e1,inTypeA));
((e_2,ext_arg_2)) = func((e2,ext_arg_1));
(BackendDAE.WHEN_EQUATION(whenEquation=elsePart1),ext_arg_3) = traverseBackendDAEExpsEqn(BackendDAE.WHEN_EQUATION(elsePart,source),func,ext_arg_2);
(BackendDAE.WHEN_EQUATION(whenEquation=elsePart1),ext_arg_3) = traverseBackendDAEExpsEqn(BackendDAE.WHEN_EQUATION(size,elsePart,source),func,ext_arg_2);
then
(BackendDAE.WHEN_EQUATION(BackendDAE.WHEN_EQ(index,cr1,e_2,SOME(elsePart1)),source),ext_arg_3);
(BackendDAE.WHEN_EQUATION(size,BackendDAE.WHEN_EQ(index,cr1,e_2,SOME(elsePart1)),source),ext_arg_3);
case (BackendDAE.ALGORITHM(size=size,alg=alg as DAE.ALGORITHM_STMTS(statementLst = stmts),source=source),func,inTypeA)
equation
(stmts1,ext_arg_1) = DAEUtil.traverseDAEEquationsStmts(stmts,func,inTypeA);
Expand Down Expand Up @@ -730,25 +730,25 @@ algorithm
((e_1,b1,ext_arg_1)) = func((e1,inTypeA));
then
(BackendDAE.RESIDUAL_EQUATION(e_1,source),b1,ext_arg_1);
case (BackendDAE.WHEN_EQUATION(whenEquation = BackendDAE.WHEN_EQ(index=index,left = cr,right = e2,elsewhenPart=NONE()),source = source),func,inTypeA)
case (BackendDAE.WHEN_EQUATION(size=size,whenEquation = BackendDAE.WHEN_EQ(index=index,left = cr,right = e2,elsewhenPart=NONE()),source = source),func,inTypeA)
equation
tp = Expression.typeof(e2);
e1 = Expression.makeCrefExp(cr,tp);
((DAE.CREF(cr1,_),b1,ext_arg_1)) = func((e1,inTypeA));
((e_2,b2,ext_arg_2)) = func((e2,ext_arg_1));
bres = Util.boolOrList({b1,b2});
then
(BackendDAE.WHEN_EQUATION(BackendDAE.WHEN_EQ(index,cr1,e_2,NONE()),source),bres,ext_arg_2);
case (eq as BackendDAE.WHEN_EQUATION(whenEquation = BackendDAE.WHEN_EQ(index=index,left=cr,right=e2,elsewhenPart=SOME(elsePart)),source = source),func,inTypeA)
(BackendDAE.WHEN_EQUATION(size,BackendDAE.WHEN_EQ(index,cr1,e_2,NONE()),source),bres,ext_arg_2);
case (eq as BackendDAE.WHEN_EQUATION(size=size,whenEquation = BackendDAE.WHEN_EQ(index=index,left=cr,right=e2,elsewhenPart=SOME(elsePart)),source = source),func,inTypeA)
equation
tp = Expression.typeof(e2);
e1 = Expression.makeCrefExp(cr,tp);
((DAE.CREF(cr1,_),b1,ext_arg_1)) = func((e1,inTypeA));
((e_2,b2,ext_arg_2)) = func((e2,ext_arg_1));
(BackendDAE.WHEN_EQUATION(whenEquation=elsePart1),b3,ext_arg_3) = traverseBackendDAEExpsEqnOutEqn(BackendDAE.WHEN_EQUATION(elsePart,source),func,ext_arg_2);
(BackendDAE.WHEN_EQUATION(whenEquation=elsePart1),b3,ext_arg_3) = traverseBackendDAEExpsEqnOutEqn(BackendDAE.WHEN_EQUATION(size,elsePart,source),func,ext_arg_2);
bres = Util.boolOrList({b1,b2,b3});
then
(BackendDAE.WHEN_EQUATION(BackendDAE.WHEN_EQ(index,cr1,e_2,SOME(elsePart1)),source),bres,ext_arg_3);
(BackendDAE.WHEN_EQUATION(size,BackendDAE.WHEN_EQ(index,cr1,e_2,SOME(elsePart1)),source),bres,ext_arg_3);
case (BackendDAE.ALGORITHM(size=size,alg=alg,source=source),func,inTypeA)
then
(BackendDAE.ALGORITHM(size,alg,source),false,inTypeA);
Expand Down Expand Up @@ -1488,7 +1488,7 @@ algorithm
size;
case BackendDAE.SOLVED_EQUATION(source=_) then 1;
case BackendDAE.RESIDUAL_EQUATION(source=_) then 1;
case BackendDAE.WHEN_EQUATION(source=_) then 1;
case BackendDAE.WHEN_EQUATION(size=size) then 1;
case BackendDAE.ALGORITHM(size=size) then size;
case BackendDAE.COMPLEX_EQUATION(size=size) then size;
case BackendDAE.IF_EQUATION(eqnsfalse=eqnsfalse)
Expand Down Expand Up @@ -1800,10 +1800,10 @@ algorithm
equation
source = DAEUtil.addSymbolicTransformation(source,op);
then BackendDAE.ALGORITHM(size,alg,source);
case (BackendDAE.WHEN_EQUATION(whenEquation,source),op)
case (BackendDAE.WHEN_EQUATION(size,whenEquation,source),op)
equation
source = DAEUtil.addSymbolicTransformation(source,op);
then BackendDAE.WHEN_EQUATION(whenEquation,source);
then BackendDAE.WHEN_EQUATION(size,whenEquation,source);
case (BackendDAE.COMPLEX_EQUATION(size,e1,e2,source),op)
equation
source = DAEUtil.addSymbolicTransformation(source,op);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendVarTransform.mo
Expand Up @@ -1140,11 +1140,11 @@ algorithm
source = DAEUtil.addSymbolicTransformationSubstitution(true,source,e,e_2);
then
replaceEquations2(es, repl,BackendDAE.RESIDUAL_EQUATION(e_2,source)::inAcc);
case ((BackendDAE.WHEN_EQUATION(whenEqn,source) :: es),repl,_)
case ((BackendDAE.WHEN_EQUATION(size,whenEqn,source) :: es),repl,_)
equation
whenEqn1 = replaceWhenEquation(whenEqn,repl);
then
replaceEquations2(es, repl,BackendDAE.WHEN_EQUATION(whenEqn1,source)::inAcc);
replaceEquations2(es, repl,BackendDAE.WHEN_EQUATION(size,whenEqn1,source)::inAcc);

case ((BackendDAE.IF_EQUATION(conditions=expl, eqnstrue=eqnslst, eqnsfalse=eqns, source = source) :: es),repl,_)
equation
Expand Down
6 changes: 3 additions & 3 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -3686,7 +3686,7 @@ algorithm
// ignore when equations if we should not generate them
case (false, skipDiscInZc, genDiscrete, skipDiscInAlgorithm, linearSystem, syst as BackendDAE.EQSYSTEM(orderedEqs=eqns), shared, BackendDAE.SINGLEEQUATION(eqn=index) :: restComps, helpVarInfo, _)
equation
BackendDAE.WHEN_EQUATION(_,_) = BackendDAEUtil.equationNth(eqns, index-1);
BackendDAE.WHEN_EQUATION(size=_) = BackendDAEUtil.equationNth(eqns, index-1);
(equations,noDiscEquations,uniqueEqIndex) = createEquations(false, skipDiscInZc, genDiscrete, skipDiscInAlgorithm, linearSystem, syst, shared, restComps, helpVarInfo, iuniqueEqIndex);
then
(equations,noDiscEquations,uniqueEqIndex);
Expand Down Expand Up @@ -3862,7 +3862,7 @@ algorithm
BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns),BackendDAE.SHARED(eventInfo=BackendDAE.EVENT_INFO(whenClauseLst=wcl)),
helpVarInfo, false, skipDiscInAlgorithm,_)
equation
BackendDAE.WHEN_EQUATION(whenEquation,source) = BackendDAEUtil.equationNth(eqns, eqNum-1);
BackendDAE.WHEN_EQUATION(whenEquation=whenEquation,source=source) = BackendDAEUtil.equationNth(eqns, eqNum-1);
BackendDAE.WHEN_EQ(wcIndex, left, right, NONE()) = whenEquation;
conditions = getConditionList(wcl, wcIndex);
conditionsWithHindex = List.map2(conditions, addHelpForCondition, helpVarInfo, helpVarInfo);
Expand All @@ -3874,7 +3874,7 @@ algorithm
BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns), BackendDAE.SHARED(eventInfo=BackendDAE.EVENT_INFO(whenClauseLst=wcl)),
helpVarInfo, false, skipDiscInAlgorithm,_)
equation
BackendDAE.WHEN_EQUATION(whenEquation,source) = BackendDAEUtil.equationNth(eqns, eqNum-1);
BackendDAE.WHEN_EQUATION(whenEquation=whenEquation,source=source) = BackendDAEUtil.equationNth(eqns, eqNum-1);
BackendDAE.WHEN_EQ(wcIndex, left, right, SOME(elseWhen)) = whenEquation;
elseWhenEquation = createElseWhenEquation(elseWhen,wcl,helpVarInfo,source);
conditions = getConditionList(wcl, wcIndex);
Expand Down

0 comments on commit 6e0a8ad

Please sign in to comment.