Skip to content

Commit

Permalink
- DAELow.mo
Browse files Browse the repository at this point in the history
  - extend arrays in algorithms
  - fix bug DAE.STMT_ASSIGN_ARR results in error " Too few equations, underdetermined system. The.."
- SimCode.mo
  - check index of array to test singleAlgorithmSection
- ToDo: SimCodeC.tpl   array = f(...), (array,array) = f(...)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5859 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jul 14, 2010
1 parent fcad441 commit bf4f3e2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 31 deletions.
71 changes: 47 additions & 24 deletions Compiler/DAELow.mo
Expand Up @@ -4509,7 +4509,7 @@ algorithm
DAE.Exp e1,e2,c;
list<Value> ds;
Value count,count_1;
DAE.Algorithm a,a1;
DAE.Algorithm a,a1,a2;
DAE.DAElist dae;
DAE.ExpType ty;
DAE.ComponentRef cr;
Expand Down Expand Up @@ -4600,10 +4600,11 @@ algorithm
equation
a = lowerTupleEquation(e);
a1 = Inline.inlineAlgorithm(a,(NONE(),SOME(funcs),{DAE.NORM_INLINE()}));
a2 = extendAlgorithm(a1,SOME(funcs));
(vars,knvars,extVars,eqns,reqns,ieqns,aeqns,iaeqns,algs,whenclauses_1,extObjCls,states)
= lower2(DAE.DAE(xs,funcs), states, vars, knvars, extVars, whenclauses);
then
(vars,knvars,extVars,eqns,reqns,ieqns,aeqns,iaeqns,a1::algs,whenclauses_1,extObjCls,states);
(vars,knvars,extVars,eqns,reqns,ieqns,aeqns,iaeqns,a2::algs,whenclauses_1,extObjCls,states);

/* tuple-tuple assignments are split into one equation for each tuple
* element, i.e. (i1, i2) = (4, 6) => i1 = 4; i2 = 6; */
Expand Down Expand Up @@ -4761,8 +4762,9 @@ algorithm
(vars,knvars,extVars,eqns,reqns,ieqns,aeqns,iaeqns,algs,whenclauses_1,extObjCls,states)
= lower2(DAE.DAE(xs,funcs), states, vars, knvars, extVars, whenclauses);
a1 = Inline.inlineAlgorithm(a,(NONE(),SOME(funcs),{DAE.NORM_INLINE()}));
a2 = extendAlgorithm(a1,SOME(funcs));
then
(vars,knvars,extVars,eqns,reqns,ieqns,aeqns,iaeqns,(a1 :: algs),whenclauses_1,extObjCls,states);
(vars,knvars,extVars,eqns,reqns,ieqns,aeqns,iaeqns,(a2 :: algs),whenclauses_1,extObjCls,states);

/* flat class / COMP */
case (DAE.DAE(DAE.COMP(dAElist = daeElts) :: xs,funcs),states,vars,knvars,extVars,whenclauses)
Expand Down Expand Up @@ -5298,6 +5300,8 @@ algorithm
list<DAE.Exp> inputs,inputs1,inputs2,inputs3,outputs,outputs1,outputs2;
list<DAE.ComponentRef> crefs;
DAE.Exp exp1;
list<Option<Integer>> ad;
list<list<DAE.Subscript>> subslst,subslst1;
// a := expr;
case (vars,DAE.STMT_ASSIGN(type_ = tp,exp1 = exp1,exp = e))
equation
Expand Down Expand Up @@ -5328,13 +5332,14 @@ algorithm
(inputs,outputs);

// v := expr where v is array.
// adrpo: FIXME! TODO! this fails for
// model bug Real x[2]; algorithm x := {1,1}; end bug;
// Error: Too few equations, underdetermined system. The model has 1 equation(s) and 2 variable(s)
case (vars,DAE.STMT_ASSIGN_ARR(type_ = tp, componentRef = cr, exp = e))
case (vars,DAE.STMT_ASSIGN_ARR(type_ = DAE.ET_ARRAY(ty=tp,arrayDimensions=ad), componentRef = cr, exp = e))
equation
inputs = statesAndVarsExp(e,vars);
then (inputs,{DAE.CREF(cr,tp)});
inputs = statesAndVarsExp(e,vars);
subslst = arrayDimensionsToRange(ad);
subslst1 = rangesToSubscripts(subslst);
crefs = Util.listMap1r(subslst1,Exp.subscriptCref,cr);
expl = Util.listMap1(crefs,Exp.makeCrefExp,tp);
then (inputs,expl);

case(vars,DAE.STMT_IF(exp = e, statementLst = stmts, else_ = elsebranch))
equation
Expand Down Expand Up @@ -5455,7 +5460,7 @@ algorithm
/* Special Case for unextended arrays */
case ((e as DAE.CREF(componentRef = cr,ty = DAE.ET_ARRAY(arrayDimensions=_))),vars)
equation
e1 = extendArrExp(e,NONE());
(e1,_) = extendArrExp(e,NONE());
res = statesAndVarsExp(e1, vars);
then
res;
Expand Down Expand Up @@ -5866,8 +5871,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 = extendArrExp(e1_1,SOME(funcs));
e2_2 = extendArrExp(e2_1,SOME(funcs));
(e1_2,_) = extendArrExp(e1_1,SOME(funcs));
(e2_2,_) = extendArrExp(e2_1,SOME(funcs));
e1_3 = Exp.simplify(e1_2);
e2_3 = Exp.simplify(e2_2);
then
Expand All @@ -5877,29 +5882,47 @@ 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 = extendArrExp(e1_1,SOME(funcs));
e2_2 = extendArrExp(e2_1,SOME(funcs));
(e1_2,_) = extendArrExp(e1_1,SOME(funcs));
(e2_2,_) = extendArrExp(e2_1,SOME(funcs));
e1_3 = Exp.simplify(e1_2);
e2_3 = Exp.simplify(e2_2);
then
MULTIDIM_EQUATION(ds,e1_3,e2_3,source);
end matchcontinue;
end lowerArrEqn;

protected function extendAlgorithm "
Author: Frenkel TUD 2010-07"
input DAE.Algorithm inAlg;
input Option<DAE.FunctionTree> funcs;
output DAE.Algorithm outAlg;
algorithm
outAlg := matchcontinue(inAlg,funcs)
local list<DAE.Statement> statementLst;
case(DAE.ALGORITHM_STMTS(statementLst=statementLst),funcs)
equation
(statementLst,_) = DAEUtil.traverseDAEEquationsStmts(statementLst, extendArrExp, funcs);
then
DAE.ALGORITHM_STMTS(statementLst);
case(inAlg,funcs) then inAlg;
end matchcontinue;
end extendAlgorithm;

protected function extendArrExp "
Author: Frenkel TUD 2010-07"
input DAE.Exp inExp;
input Option<DAE.FunctionTree> funcs;
input Option<DAE.FunctionTree> infuncs;
output DAE.Exp outExp;
output Option<DAE.FunctionTree> outfuncs;
algorithm
outExp := matchcontinue(inExp,funcs)
(outExp,outfuncs) := matchcontinue(inExp,infuncs)
local DAE.Exp e;
case(inExp,funcs)
case(inExp,infuncs)
equation
((e,_)) = Exp.traverseExp(inExp, traversingextendArrExp, funcs);
((e,outfuncs)) = Exp.traverseExp(inExp, traversingextendArrExp, infuncs);
then
e;
case(inExp,funcs) then inExp;
(e,outfuncs);
case(inExp,infuncs) then (inExp,infuncs);
end matchcontinue;
end extendArrExp;

Expand Down Expand Up @@ -16278,8 +16301,8 @@ algorithm
// array types to array equations
case ((e1 as DAE.CREF(componentRef=cr1,ty=DAE.ET_ARRAY(arrayDimensions=ad)),e2),source,inFuncs)
equation
e1_1 = extendArrExp(e1,SOME(inFuncs));
e2_1 = extendArrExp(e2,SOME(inFuncs));
(e1_1,_) = extendArrExp(e1,SOME(inFuncs));
(e2_1,_) = extendArrExp(e2,SOME(inFuncs));
e2_2 = Exp.simplify(e2_1);
dss = Util.listMap(ad,Util.genericOption);
ds = Util.listFlatten(dss);
Expand All @@ -16290,8 +16313,8 @@ algorithm
equation
tp = Exp.typeof(e1);
false = DAEUtil.expTypeComplex(tp);
e1_1 = extendArrExp(e1,SOME(inFuncs));
e2_1 = extendArrExp(e2,SOME(inFuncs));
(e1_1,_) = extendArrExp(e1,SOME(inFuncs));
(e2_1,_) = extendArrExp(e2,SOME(inFuncs));
e2_2 = Exp.simplify(e2_1);
eqn = generateEQUATION((e1_1,e2_2),source);
then
Expand Down
23 changes: 16 additions & 7 deletions Compiler/SimCode.mo
Expand Up @@ -5412,7 +5412,7 @@ algorithm
list<DAELow.Equation> eqns;
/* A single algorithm section (consists of several eqns) is not mixed system */
case (vs,eqns) equation
singleAlgorithmSection2(eqns);
singleAlgorithmSection2(eqns,NONE());
then false;
case (vs,eqns)
equation
Expand Down Expand Up @@ -5555,22 +5555,31 @@ algorithm
case (DAELow.DAELOW(orderedVars = vars,orderedEqs = eqnarr))
equation
eqn_lst = DAELow.equationList(eqnarr);
singleAlgorithmSection2(eqn_lst);
singleAlgorithmSection2(eqn_lst,NONE());
then
();
end matchcontinue;
end singleAlgorithmSection;

protected function singleAlgorithmSection2
input list<DAELow.Equation> inDAELowEquationLst;
input Option<Integer> Index;
algorithm
_:=
matchcontinue (inDAELowEquationLst)
local list<DAELow.Equation> res;
case ({}) then ();
case ((DAELow.ALGORITHM(index = _) :: res))
matchcontinue (inDAELowEquationLst,Index)
local
list<DAELow.Equation> res;
Integer i,i1;
case ({},_) then ();
case ((DAELow.ALGORITHM(index = i) :: res),NONE())
equation
singleAlgorithmSection2(res,SOME(i));
then
();
case ((DAELow.ALGORITHM(index = i) :: res),SOME(i1))
equation
singleAlgorithmSection2(res);
true = intEq(i,i1);
singleAlgorithmSection2(res,SOME(i1));
then
();
end matchcontinue;
Expand Down

0 comments on commit bf4f3e2

Please sign in to comment.