Skip to content

Commit

Permalink
- add derivative for ARR_ADD, ARR_SUB, CREF array
Browse files Browse the repository at this point in the history
- lower MultiDimEquations to normal equations after inlining if it is possible 

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5701 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jun 21, 2010
1 parent 94ab80f commit c6c93df
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
23 changes: 21 additions & 2 deletions Compiler/DAELow.mo
Expand Up @@ -4585,15 +4585,34 @@ algorithm

/* array equations */
case (DAE.DAE((e as DAE.ARRAY_EQUATION(dimension = ds,exp = e1,array = e2)) :: xs,funcs),states,vars,knvars,extVars,whenclauses)
local MultiDimEquation e_1,e_2;
local
MultiDimEquation e_1,e_2;
DAE.Exp e_11,e_21;
list<DAE.Exp> ea1,ea2;
list<tuple<DAE.Exp,DAE.Exp>> ealst;
equation
(vars,knvars,extVars,eqns,reqns,ieqns,aeqns,algs,whenclauses_1,extObjCls)
= lower2(DAE.DAE(xs,funcs), states, vars, knvars, extVars, whenclauses);
e_1 = lowerArrEqn(e);
MULTIDIM_EQUATION(left=e_11 as DAE.ARRAY(scalar=true,array=ea1),
right=e_21 as DAE.ARRAY(scalar=true,array=ea2),source=source)
= Inline.inlineMultiDimEqs(e_1,(NONE(),SOME(funcs),{DAE.NORM_INLINE()}));
ealst = Util.listThreadTuple(ea1,ea2);
re = Util.listMap1(ealst,generateEQUATION,source);
eqns = listAppend(re, eqns);
then
(vars,knvars,extVars,eqns,reqns,ieqns,aeqns,algs,whenclauses_1,extObjCls);
case (DAE.DAE((e as DAE.ARRAY_EQUATION(dimension = ds,exp = e1,array = e2)) :: xs,funcs),states,vars,knvars,extVars,whenclauses)
local
MultiDimEquation e_1,e_2;
equation
(vars,knvars,extVars,eqns,reqns,ieqns,aeqns,algs,whenclauses_1,extObjCls)
= lower2(DAE.DAE(xs,funcs), states, vars, knvars, extVars, whenclauses);
e_1 = lowerArrEqn(e);
e_2 = Inline.inlineMultiDimEqs(e_1,(NONE(),SOME(funcs),{DAE.NORM_INLINE()}));
then
(vars,knvars,extVars,eqns,reqns,ieqns,(e_2 :: aeqns),algs,whenclauses_1,extObjCls);

/* initial array equations */
case (DAE.DAE((e as DAE.INITIAL_ARRAY_EQUATION(dimension = ds, exp = e1, array = e2)) :: xs, funcs),
states, vars, knvars, extVars, whenclauses)
Expand Down
26 changes: 24 additions & 2 deletions Compiler/Derive.mo
Expand Up @@ -149,7 +149,7 @@ algorithm
equation
print("-differentiate_equation_time on complex equations not impl yet.\n");
then
fail();
fail();
case (DAELow.ARRAY_EQUATION(index = _),_,_,_,_,_,_)
equation
print("-differentiate_equation_time on array equations not impl yet.\n");
Expand Down Expand Up @@ -407,7 +407,17 @@ algorithm
then
exp;

case ((e as DAE.CREF(componentRef = cr,ty = tp)),(timevars,functions)) /* list_member(cr,timevars) => false */ then DAE.RCONST(0.0);
case ((e as DAE.CREF(componentRef = cr,ty = tp as DAE.ET_ARRAY(arrayDimensions=aDim))),(timevars,functions)) /* list_member(cr,timevars) => false */
local
list<Option<Integer>> aDim;
list<Integer> ilst;
equation
// generade zeros
ilst = Util.listMap1(aDim,Util.getOptionOrDefault,0);
i = Util.listFold(ilst,intAdd,0);
expl_1 = Util.listFill(DAE.RCONST(0.0),i);
then DAE.ARRAY(tp,true,expl_1);
case ((e as DAE.CREF(componentRef = cr,ty = tp)),(timevars,functions)) /* list_member(cr,timevars) => false */ then DAE.RCONST(0.0);
case (DAE.BINARY(exp1 = e1,operator = DAE.ADD(ty = tp),exp2 = e2),(timevars,functions))
equation
e1_1 = differentiateExpTime(e1, (timevars,functions));
Expand Down Expand Up @@ -486,6 +496,18 @@ algorithm
expl_1 = Util.listMap1(expl, differentiateExpTime, (timevars,functions));
then
DAE.ARRAY(tp,b,expl_1);
case (DAE.BINARY(exp1 = e1,operator = DAE.ADD_ARR(ty = tp),exp2 = e2),(timevars,functions))
equation
e1_1 = differentiateExpTime(e1, (timevars,functions));
e2_1 = differentiateExpTime(e2, (timevars,functions));
then
DAE.BINARY(e1_1,DAE.ADD_ARR(tp),e2_1);
case (DAE.BINARY(exp1 = e1,operator = DAE.SUB_ARR(ty = tp),exp2 = e2),(timevars,functions))
equation
e1_1 = differentiateExpTime(e1, (timevars,functions));
e2_1 = differentiateExpTime(e2, (timevars,functions));
then
DAE.BINARY(e1_1,DAE.SUB_ARR(tp),e2_1);
case ((e as DAE.MATRIX(ty = _)),_)
equation
Error.addMessage(Error.UNSUPPORTED_LANGUAGE_FEATURE,
Expand Down

0 comments on commit c6c93df

Please sign in to comment.