diff --git a/Compiler/DAELow.mo b/Compiler/DAELow.mo index b45293d8bdf..0330204b529 100644 --- a/Compiler/DAELow.mo +++ b/Compiler/DAELow.mo @@ -5789,8 +5789,8 @@ 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); @@ -5798,37 +5798,53 @@ 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); 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 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 inExp; + output tuple outExp; +algorithm outExp := matchcontinue(inExp) + local + DAE.FunctionTree funcs; + DAE.ComponentRef cr; + list crlst; + DAE.ExpType t,ty; + list> ad; + list> subslst,subslst1; + list 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 diff --git a/Compiler/SimCode.mo b/Compiler/SimCode.mo index 5b6de1cfc1b..2c563c9ec88 100644 --- a/Compiler/SimCode.mo +++ b/Compiler/SimCode.mo @@ -2442,6 +2442,7 @@ algorithm DAELow.JacobianType jac_tp; String s; DAELow.MultiDimEquation[:] ae; + list mdelst; Algorithm.Algorithm[:] al; DAELow.EventInfo ev; Integer[:] ass1,ass2; @@ -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); @@ -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); @@ -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) @@ -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); @@ -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 inEqns; output list 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 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." @@ -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)))