Skip to content

Commit

Permalink
- DAELow.mo
Browse files Browse the repository at this point in the history
  - extend all unextended array componentref so the rest of the backen would work right
- SimCode.mo
  - replace der operator also in multidimequations
now multibody double pendulum model generates compilable code

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5782 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jul 1, 2010
1 parent 957c669 commit b4a2e7d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 27 deletions.
64 changes: 40 additions & 24 deletions Compiler/DAELow.mo
Expand Up @@ -5789,46 +5789,62 @@ algorithm
equation
e1_1 = Inline.inlineExp(e1,(NONE(),SOME(funcs),{DAE.NORM_INLINE()}));
e2_1 = Inline.inlineExp(e2,(NONE(),SOME(funcs),{DAE.NORM_INLINE()}));
e1_2 = extendArrEqn(e1_1);
e2_2 = extendArrEqn(e2_1);
e1_2 = extendArrExp(e1_1,funcs);
e2_2 = extendArrExp(e2_1,funcs);
then
MULTIDIM_EQUATION(ds,e1_2,e2_2,source);

case (DAE.INITIAL_ARRAY_EQUATION(dimension = ds, exp = e1, array = e2, source = source),funcs)
equation
e1_1 = Inline.inlineExp(e1,(NONE(),SOME(funcs),{DAE.NORM_INLINE()}));
e2_1 = Inline.inlineExp(e2,(NONE(),SOME(funcs),{DAE.NORM_INLINE()}));
e1_2 = extendArrEqn(e1_1);
e2_2 = extendArrEqn(e2_1);
e1_2 = extendArrExp(e1_1,funcs);
e2_2 = extendArrExp(e2_1,funcs);
then
MULTIDIM_EQUATION(ds, e1_2, e2_2, source);
end matchcontinue;
end lowerArrEqn;

protected function extendArrEqn
protected function extendArrExp "
Author: Frenkel TUD 2010-07"
input DAE.Exp inExp;
input DAE.FunctionTree funcs;
output DAE.Exp outExp;
algorithm
outExp := matchcontinue (inExp)
local
DAE.Exp e,e1,e2;
list<DAE.Exp> expl;
DAE.ExpType ty;
case(e)
equation
e1 = Exp.simplify(e);
({e2},_) = extendExp(e1);
then
e2;
case(e)
algorithm
outExp := matchcontinue(inExp,funcs)
local DAE.Exp e;
case(inExp,funcs)
equation
e1 = Exp.simplify(e);
(expl,_) = extendExp(e1);
ty = Exp.typeof(e);
((e,_)) = Exp.traverseExp(inExp, traversingextendArrExp, funcs);
then
DAE.ARRAY(ty,true,expl);
end matchcontinue;
end extendArrEqn;
e;
end matchcontinue;
end extendArrExp;

protected function traversingextendArrExp "
Author: Frenkel TUD 2010-07."
input tuple<DAE.Exp, DAE.FunctionTree > inExp;
output tuple<DAE.Exp, DAE.FunctionTree > outExp;
algorithm outExp := matchcontinue(inExp)
local
DAE.FunctionTree funcs;
DAE.ComponentRef cr;
list<DAE.ComponentRef> crlst;
DAE.ExpType t,ty;
list<Option<Integer>> ad;
list<list<DAE.Subscript>> subslst,subslst1;
list<DAE.Exp> expl;
case( (DAE.CREF(componentRef=cr,ty= t as DAE.ET_ARRAY(ty=ty,arrayDimensions=ad)), funcs) )
equation
subslst = arrayDimensionsToRange(ad);
subslst1 = rangesToSubscripts(subslst);
crlst = Util.listMap1r(subslst1,Exp.subscriptCref,cr);
expl = Util.listMap1(crlst,Exp.makeCrefExp,ty);
then
((DAE.ARRAY(t,true,expl), funcs ));
case(inExp) then inExp;
end matchcontinue;
end traversingextendArrExp;

protected function lowerComplexEqn
"function: lowerComplexEqn
Expand Down
36 changes: 33 additions & 3 deletions Compiler/SimCode.mo
Expand Up @@ -2442,6 +2442,7 @@ algorithm
DAELow.JacobianType jac_tp;
String s;
DAELow.MultiDimEquation[:] ae;
list<DAELow.MultiDimEquation> mdelst;
Algorithm.Algorithm[:] al;
DAELow.EventInfo ev;
Integer[:] ass1,ass2;
Expand All @@ -2460,6 +2461,8 @@ algorithm
(eqn_lst,var_lst) = Util.listMap32(block_, getEquationAndSolvedVar, eqns, vars, ass2);
eqn_lst = replaceDerOpInEquationList(eqn_lst);
true = isMixedSystem(var_lst,eqn_lst);
mdelst = Util.listMap(arrayList(ae),replaceDerOpMultiDimEquations);
ae = listArray(mdelst);
(cont_eqn,cont_var,disc_eqn,disc_var) = splitMixedEquations(eqn_lst, var_lst);
// States are solved for der(x) not x.
cont_var1 = Util.listMap(cont_var, transformXToXd);
Expand All @@ -2484,6 +2487,8 @@ algorithm
(eqn_lst,var_lst) = Util.listMap32(block_, getEquationAndSolvedVar, eqns, vars, ass2);
eqn_lst = replaceDerOpInEquationList(eqn_lst);
true = isMixedSystem(var_lst,eqn_lst);
mdelst = Util.listMap(arrayList(ae),replaceDerOpMultiDimEquations);
ae = listArray(mdelst);
(cont_eqn,cont_var,disc_eqn,disc_var) = splitMixedEquations(eqn_lst, var_lst);
// States are solved for der(x) not x.
cont_var1 = Util.listMap(cont_var, transformXToXd);
Expand Down Expand Up @@ -2522,6 +2527,8 @@ algorithm
true = RTOpts.debugFlag("tearing");
(eqn_lst,var_lst) = Util.listMap32(block_, getEquationAndSolvedVar, eqns, vars, ass2) "extract the variables and equations of the block." ;
eqn_lst = replaceDerOpInEquationList(eqn_lst);
mdelst = Util.listMap(arrayList(ae),replaceDerOpMultiDimEquations);
ae = listArray(mdelst);
var_lst_1 = Util.listMap(var_lst, transformXToXd); // States are solved for der(x) not x.
vars_1 = DAELow.listVar(var_lst_1);
// because listVar orders the elements not like listEquation the pairs of (var is solved in equation)
Expand Down Expand Up @@ -2551,6 +2558,8 @@ algorithm
// extract the variables and equations of the block.
(eqn_lst,var_lst) = Util.listMap32(block_, getEquationAndSolvedVar, eqns, vars, ass2);
eqn_lst = replaceDerOpInEquationList(eqn_lst);
mdelst = Util.listMap(arrayList(ae),replaceDerOpMultiDimEquations);
ae = listArray(mdelst);
// States are solved for der(x) not x.
var_lst_1 = Util.listMap(var_lst, transformXToXd);
vars_1 = DAELow.listVar(var_lst_1);
Expand Down Expand Up @@ -2891,14 +2900,35 @@ algorithm
fail();
end matchcontinue;
end createOdeSystem2;

protected function replaceDerOpInEquationList
"Replaces all der(cref) with $DER.cref in a list of equations."
input list<DAELow.Equation> inEqns;
output list<DAELow.Equation> outEqns;
algorithm
outEqns := Util.listMap(inEqns, replaceDerOpInEquation);
end replaceDerOpInEquationList;
end replaceDerOpInEquationList;

protected function replaceDerOpMultiDimEquations
"Replaces all der(cref) with $DER.cref in an multidimequation."
input DAELow.MultiDimEquation inMultiDimEquation;
output DAELow.MultiDimEquation outMultiDimEquation;
algorithm
outMultiDimEquation := matchcontinue(inMultiDimEquation)
local
list<Integer> ilst;
DAE.Exp e1,e1_1,e2,e2_1;
DAE.ElementSource source;

case(DAELow.MULTIDIM_EQUATION(ilst,e1,e2,source))
equation
e1_1 = replaceDerOpInExp(e1);
e2_1 = replaceDerOpInExp(e2);
then
DAELow.MULTIDIM_EQUATION(ilst,e1_1,e2_1,source);
case(inMultiDimEquation) then inMultiDimEquation;
end matchcontinue;
end replaceDerOpMultiDimEquations;

protected function replaceDerOpInEquation
"Replaces all der(cref) with $DER.cref in an equation."
Expand Down Expand Up @@ -2954,7 +2984,7 @@ algorithm
local
DAE.ComponentRef cr, der_cr;
DAE.Exp cref_exp;
DAE.ComponentRef cref;
DAE.ComponentRef cref;
case ((DAE.CALL(path = Absyn.IDENT("der"),
expLst = {DAE.CREF(componentRef = cr)}),
SOME(cref)))
Expand Down

0 comments on commit b4a2e7d

Please sign in to comment.