Skip to content

Commit

Permalink
- BackendEquation.mo
Browse files Browse the repository at this point in the history
  - add functions traverseBackendDAEExpsEqnList, traverseBackendDAEExpsEqn
  - use traverseBackendDAEExpsEqnList for equationsCrefs
- BackendDAEUtil.mo
  - use BackendEquation.traverseBackendDAEExpsEqns for traverseBackendDAEExpsEqns
- BackendDAECreate.mo
  - use BackendEquation.traverseBackendDAEExpsEqns for expandDerOperator

git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/sjoelund-functiontree@6895 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Nov 5, 2010
1 parent 1b999ce commit 475d82a
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 236 deletions.
104 changes: 2 additions & 102 deletions Compiler/BackendDAECreate.mo
Expand Up @@ -44,7 +44,6 @@ public import BackendDAE;
public import DAE;

protected import Algorithm;
protected import BackendDump;
protected import BackendDAEUtil;
protected import BackendDAEOptimize;
protected import BackendEquation;
Expand Down Expand Up @@ -2250,96 +2249,14 @@ algorithm
(outEqns, outIeqns,outAeqns,outAlgs,outVars) :=
matchcontinue(vars,eqns,ieqns,aeqns,algs,functions)
case(vars,eqns,ieqns,aeqns,algs,functions) equation
(eqns,(vars,_)) = expandDerOperatorEqns(eqns,(vars,functions));
(ieqns,(vars,_)) = expandDerOperatorEqns(ieqns,(vars,functions));
(eqns,(vars,_)) = BackendEquation.traverseBackendDAEExpsEqnList(eqns,expandDerExp,(vars,functions));
(ieqns,(vars,_)) = BackendEquation.traverseBackendDAEExpsEqnList(ieqns,expandDerExp,(vars,functions));
(aeqns,(vars,_)) = expandDerOperatorArrEqns(aeqns,(vars,functions));
(algs,(vars,_)) = expandDerOperatorAlgs(algs,(vars,functions));
then(eqns,ieqns,aeqns,algs,vars);
end matchcontinue;
end expandDerOperator;

protected function expandDerOperatorEqns
"Help function to expandDerOperator"
input list<BackendDAE.Equation> eqns;
input tuple<BackendDAE.Variables,DAE.FunctionTree> vars;
output list<BackendDAE.Equation> outEqns;
output tuple<BackendDAE.Variables,DAE.FunctionTree> outVars;
algorithm
(outEqns,outVars) := matchcontinue(eqns,vars)
local BackendDAE.Equation e;
case({},vars) then ({},vars);
case(e::eqns,vars) equation
(e,vars) = expandDerOperatorEqn(e,vars);
(eqns,vars) = expandDerOperatorEqns(eqns,vars);
then (e::eqns,vars);
case(_,_) equation
Debug.fprint("failtrace", "-BackendDAECreate.expandDerOperatorEqns failed\n");
then fail();
end matchcontinue;
end expandDerOperatorEqns;

protected function expandDerOperatorEqn
"Help function to expandDerOperator, handles Equations"
input BackendDAE.Equation eqn;
input tuple<BackendDAE.Variables,DAE.FunctionTree> vars;
output BackendDAE.Equation outEqn;
output tuple<BackendDAE.Variables,DAE.FunctionTree> outVars;
algorithm
(outEqn,outVars) := matchcontinue(eqn,vars)
local
DAE.Exp e1,e2; list<DAE.Exp> expl; Integer i;
DAE.ComponentRef cr; BackendDAE.WhenEquation wheneq;
DAE.ElementSource source "the element source";

case(BackendDAE.EQUATION(e1,e2,source),vars) equation
((e1,vars)) = Expression.traverseExp(e1,expandDerExp,vars);
((e2,vars)) = Expression.traverseExp(e2,expandDerExp,vars);
then (BackendDAE.EQUATION(e1,e2,source),vars);
case(BackendDAE.COMPLEX_EQUATION(i,e1,e2,source),vars) equation
((e1,vars)) = Expression.traverseExp(e1,expandDerExp,vars);
((e2,vars)) = Expression.traverseExp(e2,expandDerExp,vars);
then (BackendDAE.COMPLEX_EQUATION(i,e1,e2,source),vars);
case (BackendDAE.ARRAY_EQUATION(i,expl,source),vars)
then (BackendDAE.ARRAY_EQUATION(i,expl,source),vars);
case (BackendDAE.SOLVED_EQUATION(cr,e1,source),vars) equation
((e1,vars)) = Expression.traverseExp(e1,expandDerExp,vars);
then (BackendDAE.SOLVED_EQUATION(cr,e1,source),vars);
case(BackendDAE.RESIDUAL_EQUATION(e1,source),vars) equation
((e1,vars)) = Expression.traverseExp(e1,expandDerExp,vars);
then (BackendDAE.RESIDUAL_EQUATION(e1,source),vars);
case (eqn as BackendDAE.ALGORITHM(index = _),vars) then (eqn,vars);
case (BackendDAE.WHEN_EQUATION(wheneq,source),vars) equation
(wheneq,vars) = expandDerOperatorWhenEqn(wheneq,vars);
then (BackendDAE.WHEN_EQUATION(wheneq,source),vars);
case (eqn ,vars) equation
true = RTOpts.debugFlag("failtrace");
Debug.fprint("failtrace", "- BackendDAECreate.expandDerOperatorEqn, eqn =");
Debug.fprint("failtrace", BackendDump.equationStr(eqn));
Debug.fprint("failtrace", " failed\n");
then fail();
end matchcontinue;
end expandDerOperatorEqn;

protected function expandDerOperatorWhenEqn
"Helper function to expandDerOperatorWhenEqn"
input BackendDAE.WhenEquation wheneq;
input tuple<BackendDAE.Variables,DAE.FunctionTree> vars;
output BackendDAE.WhenEquation outWheneq;
output tuple<BackendDAE.Variables,DAE.FunctionTree> outVars;
algorithm
(outWheneq, outVars) := matchcontinue(wheneq,vars)
local DAE.ComponentRef cr; DAE.Exp e1; Integer indx; BackendDAE.WhenEquation elsewheneq;
case(BackendDAE.WHEN_EQ(indx,cr,e1,SOME(elsewheneq)),vars) equation
((e1,vars)) = Expression.traverseExp(e1,expandDerExp,vars);
(elsewheneq,vars) = expandDerOperatorWhenEqn(elsewheneq,vars);
then (BackendDAE.WHEN_EQ(indx,cr,e1,SOME(elsewheneq)),vars);

case(BackendDAE.WHEN_EQ(indx,cr,e1,NONE()),vars) equation
((e1,vars)) = Expression.traverseExp(e1,expandDerExp,vars);
then (BackendDAE.WHEN_EQ(indx,cr,e1,NONE()),vars);
end matchcontinue;
end expandDerOperatorWhenEqn;

protected function expandDerOperatorAlgs
"Help function to expandDerOperator"
input list<DAE.Algorithm> algs;
Expand Down Expand Up @@ -2417,23 +2334,6 @@ algorithm
end matchcontinue;
end expandDerOperatorArrEqn;

protected function expandDerExps
"Help function to e.g. expandDerOperatorEqn"
input list<DAE.Exp> expl;
input tuple<BackendDAE.Variables,DAE.FunctionTree> vars;
output list<DAE.Exp> outExpl;
output tuple<BackendDAE.Variables,DAE.FunctionTree> outVars;
algorithm
(outExpl,outVars) := matchcontinue(expl,vars)
local DAE.Exp e;
case({},vars) then ({},vars);
case(e::expl,vars) equation
((e,vars)) = Expression.traverseExp(e,expandDerExp,vars);
(expl,vars) = expandDerExps(expl,vars);
then (e::expl,vars);
end matchcontinue;
end expandDerExps;

protected function expandDerExp
"Help function to e.g. expandDerOperatorEqn"
input tuple<DAE.Exp,tuple<BackendDAE.Variables,DAE.FunctionTree>> tpl;
Expand Down
83 changes: 6 additions & 77 deletions Compiler/BackendDAEUtil.mo
Expand Up @@ -4381,7 +4381,7 @@ algorithm
local
array<Option<BackendDAE.Equation>> equOptArr;
case ((BackendDAE.EQUATION_ARRAY(equOptArr = equOptArr)),func,inTypeA)
then traverseBackendDAEExpsArrayNoCopy(equOptArr,func,traverseBackendDAEExpsEqn,1,arrayLength(equOptArr),inTypeA);
then traverseBackendDAEExpsArrayNoCopy(equOptArr,func,traverseBackendDAEExpsOptEqn,1,arrayLength(equOptArr),inTypeA);
case (_,_,_)
equation
Debug.fprintln("failtrace", "- BackendDAE.traverseBackendDAEExpsEqns failed");
Expand All @@ -4390,7 +4390,7 @@ algorithm
end matchcontinue;
end traverseBackendDAEExpsEqns;

protected function traverseBackendDAEExpsEqn "function: traverseBackendDAEExpsEqn
protected function traverseBackendDAEExpsOptEqn "function: traverseBackendDAEExpsOptEqn
author: PA
Helper for traverseBackendDAEExpsEqn."
replaceable type Type_a subtypeof Any;
Expand All @@ -4405,6 +4405,7 @@ protected function traverseBackendDAEExpsEqn "function: traverseBackendDAEExpsEq
algorithm
outTypeA:= matchcontinue (inEquation,func,inTypeA)
local
BackendDAE.Equation eqn;
DAE.Exp e1,e2,e;
list<DAE.Exp> expl,exps;
DAE.ExpType tp;
Expand All @@ -4414,85 +4415,13 @@ algorithm
DAE.ElementSource source;
Type_a ext_arg_1,ext_arg_2,ext_arg_3;
case (NONE(),func,inTypeA) then inTypeA;
case (SOME(BackendDAE.EQUATION(exp = e1,scalar = e2)),func,inTypeA)
equation
((_,ext_arg_1)) = func((e1,inTypeA));
((_,ext_arg_2)) = func((e2,ext_arg_1));
then
ext_arg_2;
case (SOME(BackendDAE.ARRAY_EQUATION(crefOrDerCref = expl)),func,inTypeA)
case (SOME(eqn),func,inTypeA)
equation
ext_arg_1 = traverseBackendDAEExpList(expl,func,inTypeA);
(_,ext_arg_1) = BackendEquation.traverseBackendDAEExpsEqn(eqn,func,inTypeA);
then
ext_arg_1;
case (SOME(BackendDAE.SOLVED_EQUATION(componentRef = cr,exp = e)),func,inTypeA)
equation
tp = Expression.typeof(e);
((_,ext_arg_1)) = func((DAE.CREF(cr,tp),inTypeA));
((_,ext_arg_2)) = func((e,ext_arg_1));
then
ext_arg_2;
case (SOME(BackendDAE.RESIDUAL_EQUATION(exp = e)),func,inTypeA)
equation
((_,ext_arg_1)) = func((e,inTypeA));
then
ext_arg_1;
case (SOME(BackendDAE.WHEN_EQUATION(whenEquation = BackendDAE.WHEN_EQ(left = cr,right = e,elsewhenPart=NONE()))),func,inTypeA)
equation
tp = Expression.typeof(e);
((_,ext_arg_1)) = func((DAE.CREF(cr,tp),inTypeA));
((_,ext_arg_2)) = func((e,ext_arg_1));
then
ext_arg_2;
case (SOME(BackendDAE.WHEN_EQUATION(whenEquation = BackendDAE.WHEN_EQ(_,cr,e,SOME(elsePart)),source = source)),func,inTypeA)
equation
tp = Expression.typeof(e);
((_,ext_arg_1)) = func((DAE.CREF(cr,tp),inTypeA));
((_,ext_arg_2)) = func((e,ext_arg_1));
ext_arg_3 = traverseBackendDAEExpsEqn(SOME(BackendDAE.WHEN_EQUATION(elsePart,source)),func,ext_arg_2);
then
ext_arg_3;
case (SOME(BackendDAE.ALGORITHM(index = ind,in_ = expl,out = exps)),func,inTypeA)
equation
ext_arg_1 = traverseBackendDAEExpList(expl,func,inTypeA);
ext_arg_2 = traverseBackendDAEExpList(exps,func,ext_arg_1);
then
ext_arg_2;
case (SOME(BackendDAE.COMPLEX_EQUATION(index = ind, lhs = e1, rhs = e2)),func,inTypeA)
equation
((_,ext_arg_1)) = func((e1,inTypeA));
((_,ext_arg_2)) = func((e2,ext_arg_1));
then
ext_arg_2;
end matchcontinue;
end traverseBackendDAEExpsEqn;

public function traverseBackendDAEExpList
"function traverseBackendDAEExps
author Frenkel TUD:
Calls user function for each element of list."
replaceable type Type_a subtypeof Any;
input list<DAE.Exp> expl;
input FuncExpType rel;
input Type_a ext_arg;
output Type_a outTypeA;
partial function FuncExpType
input tuple<DAE.Exp, Type_a> inTpl;
output tuple<DAE.Exp, Type_a> outTpl;
end FuncExpType;
algorithm
outTypeA := matchcontinue(expl,rel,ext_arg)
local
DAE.Exp e;
list<DAE.Exp> expl1;
Type_a ext_arg_1,ext_arg_2,ext_arg_3;
case({},_,ext_arg_1) then ext_arg_1;
case(e::expl1,rel,ext_arg_1) equation
((_,ext_arg_2)) = rel((e, ext_arg_1));
ext_arg_3 = traverseBackendDAEExpList(expl1,rel,ext_arg_2);
then ext_arg_3;
end matchcontinue;
end traverseBackendDAEExpList;
end traverseBackendDAEExpsOptEqn;

protected function traverseBackendDAEExpsArrayEqn "function: traverseBackendDAEExpsArrayEqn
author: Frenkel TUD
Expand Down

0 comments on commit 475d82a

Please sign in to comment.