Skip to content

Commit

Permalink
- fix bugs
Browse files Browse the repository at this point in the history
- BackendDAECreate.mo
  use traverseExp and traverseDAE2 for state search

git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/sjoelund-functiontree@6664 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Oct 27, 2010
1 parent 1bdff37 commit cf8d72a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 185 deletions.
208 changes: 29 additions & 179 deletions Compiler/BackendDAECreate.mo
Expand Up @@ -1802,74 +1802,12 @@ algorithm
DAE.FunctionTree funcs;
list<DAE.Element> daeElts;

case ({},bt) then bt;

case (DAE.EQUATION(exp = e1,scalar = e2) :: xs,bt)
equation
bt = states(xs, bt);
bt = statesExp(e1, bt);
bt = statesExp(e2, bt);
then
bt;

case (DAE.COMPLEX_EQUATION(lhs = e1,rhs = e2) :: xs,bt)
equation
bt = states(xs, bt);
bt = statesExp(e1, bt);
bt = statesExp(e2, bt);
then
bt;

case (DAE.INITIALEQUATION(exp1 = e1, exp2 = e2) :: xs,bt)
equation
bt = states(xs, bt);
bt = statesExp(e1, bt);
bt = statesExp(e2, bt);
then
bt;

case (DAE.DEFINE(componentRef = _, exp = e2) :: xs,bt)
case (inElems,bt)
equation
bt = states(xs, bt);
bt = statesExp(e2, bt);
then
bt;

case (DAE.INITIALDEFINE(componentRef = _, exp = e2) :: xs,bt)
equation
bt = states(xs, bt);
bt = statesExp(e2, bt);
then
bt;

case (DAE.ARRAY_EQUATION(exp = e1,array = e2) :: xs,bt)
equation
bt = states(xs, bt);
bt = statesExp(e1, bt);
bt = statesExp(e2, bt);
then
bt;

case (DAE.INITIAL_ARRAY_EQUATION(exp = e1, array = e2) :: xs, bt)
equation
bt = states(xs, bt);
bt = statesExp(e1, bt);
bt = statesExp(e2, bt);
then
bt;

case (DAE.COMP(dAElist = daeElts) :: xs,bt)
equation
bt = states(daeElts, bt);
bt = states(xs, bt);
then
bt;

case (_ :: xs,bt)
equation
bt = states(xs, bt);
(_,bt) = DAEUtil.traverseDAE2(inElems,statesExp, bt);
then
bt;
case (_,bt) then bt;
end matchcontinue;
end states;

Expand All @@ -1878,128 +1816,40 @@ protected function statesExp
Helper function to states."
input DAE.Exp inExp;
input BackendDAE.BinTree inBinTree;
output DAE.Exp outExp;
output BackendDAE.BinTree outBinTree;
algorithm
outBinTree := matchcontinue (inExp,inBinTree)
(outExp,outBinTree) := matchcontinue (inExp,inBinTree)
local
DAE.Exp e;
BackendDAE.BinTree bt;
DAE.Exp e1,e2,e,e3;
DAE.ComponentRef cr_1,cr;
list<DAE.Exp> expl;
list<list<tuple<DAE.Exp, Boolean>>> m;

case (DAE.BINARY(exp1 = e1,exp2 = e2),bt)
equation
bt = statesExp(e1, bt);
bt = statesExp(e2, bt);
then
bt;
case (DAE.UNARY(exp = e),bt)
equation
bt = statesExp(e, bt);
then
bt;
case (DAE.LBINARY(exp1 = e1,exp2 = e2),bt)
equation
bt = statesExp(e1, bt);
bt = statesExp(e2, bt);
then
bt;
case (DAE.LUNARY(exp = e),bt)
equation
bt = statesExp(e, bt);
then
bt;
case (DAE.RELATION(exp1 = e1,exp2 = e2),bt)
case (inExp,bt)
equation
bt = statesExp(e1, bt);
bt = statesExp(e2, bt);
((e,bt)) = Expression.traverseExp(inExp,traversingstatesExpFinder,bt);
then
bt;
case (DAE.IFEXP(expCond = e1,expThen = e2,expElse = e3),bt)
equation
bt = statesExp(e1, bt);
bt = statesExp(e2, bt);
bt = statesExp(e3, bt);
then
bt;
case (DAE.CALL(path = Absyn.IDENT(name = "der"),expLst = {DAE.CREF(componentRef = cr)}),bt)
equation
//cr_1 = Expression.stringifyComponentRef(cr) "value irrelevant, give zero" ;
bt = BackendDAEUtil.treeAdd(bt, cr, 0);
then
bt;
case (DAE.CALL(expLst = expl),bt)
equation
bt = Util.listFold(expl, statesExp, bt);
then
bt;
case (DAE.ARRAY(array = expl),bt)
equation
bt = Util.listFold(expl, statesExp, bt);
then
bt;
case (DAE.MATRIX(scalar = m),bt)
equation
bt = statesExpMatrix(m, bt);
then
bt;
case (DAE.TUPLE(PR = expl),bt)
equation
bt = Util.listFold(expl, statesExp, bt);
then
bt;
case (DAE.CAST(exp = e),bt)
equation
bt = statesExp(e, bt);
then
bt;
case (DAE.ASUB(exp = e),bt)
equation
bt = statesExp(e, bt);
then
bt;
case (DAE.REDUCTION(expr = e1,range = e2),bt)
equation
bt = statesExp(e1, bt);
bt = statesExp(e2, bt);
then
bt;
case (_,bt) then bt;
(e,bt);
case (e,bt) then (e,bt);
end matchcontinue;
end statesExp;

protected function statesExpMatrix
"function: statesExpMatrix
author: PA
Helper function to statesExpression. Deals with matrix exp list."
input list<list<tuple<DAE.Exp, Boolean>>> inTplExpExpBooleanLstLst;
input BackendDAE.BinTree inBinTree;
output BackendDAE.BinTree outBinTree;
algorithm
outBinTree := matchcontinue (inTplExpExpBooleanLstLst,inBinTree)
local
list<list<DAE.Exp>> expl_1;
list<DAE.Exp> expl_2;
BackendDAE.BinTree bt;
list<list<tuple<DAE.Exp, Boolean>>> expl;

case (expl,bt)
equation
expl_1 = Util.listListMap(expl, Util.tuple21);
expl_2 = Util.listFlatten(expl_1);
bt = Util.listFold(expl_2, statesExp, bt);
then
bt;
case (_,_)
equation
Debug.fprint("failtrace", "-states_exp_matrix failed\n");
then
fail();
end matchcontinue;
end statesExpMatrix;


public function traversingstatesExpFinder "
helper for statesExp
"
input tuple<DAE.Exp, BackendDAE.BinTree > inExp;
output tuple<DAE.Exp, BackendDAE.BinTree > outExp;
algorithm outExp := matchcontinue(inExp)
local
DAE.ComponentRef cr;
BackendDAE.BinTree bt;
DAE.Exp e;
case ((e as DAE.CALL(path = Absyn.IDENT(name = "der"),expLst = {DAE.CREF(componentRef = cr)}),bt))
equation
bt = BackendDAEUtil.treeAdd(bt, cr, 0);
then
((e,bt));
case(inExp) then inExp;
end matchcontinue;
end traversingstatesExpFinder;

protected function processDelayExpressions
"Assign each call to delay() with a unique id argument"
Expand Down Expand Up @@ -2689,7 +2539,7 @@ algorithm
case((DAE.CALL(Absyn.IDENT(name = "der"),{e1},tuple_ = false,builtin = true),(vars,funcs))) equation
e1 = Derive.differentiateExpTime(e1,(vars,funcs));
e1 = ExpressionSimplify.simplify(e1);
bt = statesExp(e1,BackendDAE.emptyBintree);
(_,bt) = statesExp(e1,BackendDAE.emptyBintree);
(newStates,_) = BackendDAEUtil.bintreeToList(bt);
vars = updateStatesVars(vars,newStates);
then ((e1,(vars,funcs)));
Expand Down
1 change: 1 addition & 0 deletions Compiler/BackendVariable.mo
Expand Up @@ -42,6 +42,7 @@ public import DAE;

protected import Absyn;
protected import BackendDAEUtil;
protected import BackendDump;
protected import ComponentReference;
protected import DAELow;
protected import DAEUtil;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/CevalScript.mo
Expand Up @@ -3984,7 +3984,7 @@ algorithm
(ass1,ass2,dlow_1,m,mT) = DAELow.matchingAlgorithm(dlow, m, mT, (BackendDAE.INDEX_REDUCTION(),BackendDAE.EXACT(), BackendDAE.REMOVE_SIMPLE_EQN()),Env.getFunctionTree(cache));
(comps) = DAELow.strongComponents(m, mT, ass1, ass2);
indexed_dlow = BackendVariable.translateDae(dlow_1,NONE());
indexed_dlow_1 = BackendVariable.calculateValues(indexed_dlow);
indexed_dlow_1 = DAELow.calculateValues(indexed_dlow);
xml_filename = System.stringAppendList({filenameprefix,".xml"});
funcelems = DAEUtil.getFunctionList(Env.getFunctionTree(cache));
Print.clearBuf();
Expand Down
6 changes: 3 additions & 3 deletions Compiler/Main.mo
Expand Up @@ -853,8 +853,8 @@ algorithm
();
case (dae,ass1,ass2,comps)
equation
indexed_dae = BackendVariabletranslateDae(dae,NONE());
indexed_dae_1 = BackendVariable.calculateValues(indexed_dae);
indexed_dae = BackendVariable.translateDae(dae,NONE());
indexed_dae_1 = DAELow.calculateValues(indexed_dae);
TaskGraph.buildTaskgraph(indexed_dae_1, ass1, ass2, comps);
TaskGraphExt.dumpGraph("model.viz");
l = RTOpts.latency();
Expand Down Expand Up @@ -929,7 +929,7 @@ algorithm
Print.clearBuf();
Debug.fcall("execstat",print, "*** Main -> simcodgen -> translateDae: " +& realString(clock()) +& "\n" );
indexed_dlow = BackendVariable.translateDae(dlow,NONE());
indexed_dlow_1 = BackendVariable.calculateValues(indexed_dlow);
indexed_dlow_1 = DAELow.calculateValues(indexed_dlow);
Debug.fcall("dumpindxdae", BackendDump.dump, indexed_dlow_1);
cname_str = Absyn.pathString(classname);
//filename = System.stringAppendList({cname_str,".cpp"});
Expand Down
4 changes: 2 additions & 2 deletions Compiler/SimCode.mo
Expand Up @@ -838,7 +838,7 @@ algorithm
dlow_1 = Inline.inlineCalls(SOME(funcs),{DAE.NORM_INLINE(),DAE.AFTER_INDEX_RED_INLINE()},dlow_1);
(comps) = DAELow.strongComponents(m, mT, ass1, ass2);
indexed_dlow = BackendVariable.translateDae(dlow_1,NONE());
indexed_dlow_1 = BackendVariable.calculateValues(indexed_dlow);
indexed_dlow_1 = DAELow.calculateValues(indexed_dlow);
Debug.fprint("bltdump", "indexed DAE:\n");
Debug.fcall("bltdump", BackendDump.dumpIncidenceMatrix, m);
Debug.fcall("bltdump", BackendDump.dumpIncidenceMatrixT, mT);
Expand Down Expand Up @@ -964,7 +964,7 @@ algorithm
// late Inline
dlow_1 = Inline.inlineCalls(SOME(funcs),{DAE.NORM_INLINE(),DAE.AFTER_INDEX_RED_INLINE()},dlow_1);
(comps) = DAELow.strongComponents(m, mT, ass1, ass2);
indexed_dlow = DAELow.translateDae(dlow_1,NONE());
indexed_dlow = BackendVariable.translateDae(dlow_1,NONE());
indexed_dlow_1 = DAELow.calculateValues(indexed_dlow);
Debug.fprint("bltdump", "indexed DAE:\n");
Debug.fcall("bltdump", BackendDump.dumpIncidenceMatrix, m);
Expand Down

0 comments on commit cf8d72a

Please sign in to comment.