Skip to content

Commit

Permalink
- DAELowUtil.mo
Browse files Browse the repository at this point in the history
  - finish function to check that a variable (cref) used in an equation or algorithm is actually
present in the declared variables. bug #1302
- Exp.mo
  - add function traverseExpTopDown, is used for DAELowUtil.mo

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6568 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Oct 25, 2010
1 parent 8dd7126 commit 7d41002
Show file tree
Hide file tree
Showing 4 changed files with 339 additions and 73 deletions.
33 changes: 23 additions & 10 deletions Compiler/DAELow.mo
Expand Up @@ -654,7 +654,7 @@ algorithm
algarr = listArray(algs);
funcs = DAEUtil.daeFunctionTree(lst);
einfo = Inline.inlineEventInfo(EVENT_INFO(whenclauses_1,zero_crossings),(NONE(),SOME(funcs),{DAE.NORM_INLINE()}));
//DAELowUtil.checkDEALowWithErrorMsg(DAELOW(vars_1,knvars,extVars,aliasVars,eqnarr,reqnarr,ieqnarr,arr_md_eqns,algarr,einfo,extObjCls));
DAELowUtil.checkDEALowWithErrorMsg(DAELOW(vars_1,knvars,extVars,aliasVars,eqnarr,reqnarr,ieqnarr,arr_md_eqns,algarr,einfo,extObjCls));
then DAELOW(vars_1,knvars,extVars,aliasVars,eqnarr,reqnarr,ieqnarr,arr_md_eqns,algarr,einfo,extObjCls);

case(lst, addDummyDerivativeIfNeeded, false) // do not simplify
Expand Down Expand Up @@ -691,7 +691,7 @@ algorithm
algarr = listArray(algs);
funcs = DAEUtil.daeFunctionTree(lst);
einfo = Inline.inlineEventInfo(EVENT_INFO(whenclauses_1,zero_crossings),(NONE(),SOME(funcs),{DAE.NORM_INLINE()}));
//DAELowUtil.checkDEALowWithErrorMsg(DAELOW(vars_1,knvars,extVars,aliasVars,eqnarr,reqnarr,ieqnarr,arr_md_eqns,algarr,einfo,extObjCls));
DAELowUtil.checkDEALowWithErrorMsg(DAELOW(vars_1,knvars,extVars,aliasVars,eqnarr,reqnarr,ieqnarr,arr_md_eqns,algarr,einfo,extObjCls));
then DAELOW(vars_1,knvars,extVars,aliasVars,eqnarr,reqnarr,ieqnarr,arr_md_eqns,algarr,einfo,extObjCls);
end matchcontinue;
end lower;
Expand Down Expand Up @@ -6132,17 +6132,17 @@ algorithm
then
EQUATION(e1,e2,source);

case (DAE.DEFINE(componentRef = cr1, exp = e1, source = source))
case (DAE.DEFINE(componentRef = cr1, exp = e2, source = source))
equation
e1 = Exp.simplify(DAE.CREF(cr1, DAE.ET_OTHER()));
e2 = Exp.simplify(e1);
e2 = Exp.simplify(e2);
then
EQUATION(e1,e2,source);

case (DAE.INITIALDEFINE(componentRef = cr1, exp = e1, source = source))
case (DAE.INITIALDEFINE(componentRef = cr1, exp = e2, source = source))
equation
e1 = Exp.simplify(DAE.CREF(cr1, DAE.ET_OTHER()));
e2 = Exp.simplify(e1);
e2 = Exp.simplify(e2);
then
EQUATION(e1,e2,source);
end matchcontinue;
Expand Down Expand Up @@ -15416,6 +15416,7 @@ public function traverseDEALowExps "function: traverseDEALowExps
replaceable type Type_a subtypeof Any;
replaceable type Type_b subtypeof Any;
input DAELow inDAELow;
input Boolean traverseAlgorithms "true if traverse also algorithms";
input FuncExpType func;
input Type_a inTypeA;
output list<Type_b> outTypeBLst;
Expand All @@ -15426,7 +15427,7 @@ public function traverseDEALowExps "function: traverseDEALowExps
end FuncExpType;
algorithm
outTypeBLst:=
matchcontinue (inDAELow,func,inTypeA)
matchcontinue (inDAELow,traverseAlgorithms,func,inTypeA)
local
list<Type_b> exps1,exps2,exps3,exps4,exps5,exps6,exps7,exps;
list<DAE.Algorithm> alglst;
Expand All @@ -15435,7 +15436,7 @@ algorithm
MultiDimEquation[:] ae;
DAE.Algorithm[:] algs;
case (DAELOW(orderedVars = vars1,knownVars = vars2,orderedEqs = eqns,removedEqs = reqns,
initialEqs = ieqns,arrayEqs = ae,algorithms = algs),func,inTypeA)
initialEqs = ieqns,arrayEqs = ae,algorithms = algs),true,func,inTypeA)
equation
exps1 = traverseDEALowExpsVars(vars1,func,inTypeA);
exps2 = traverseDEALowExpsVars(vars2,func,inTypeA);
Expand All @@ -15448,7 +15449,19 @@ algorithm
exps = Util.listFlatten({exps1,exps2,exps3,exps4,exps5,exps6,exps7});
then
exps;
case (_,_,_)
case (DAELOW(orderedVars = vars1,knownVars = vars2,orderedEqs = eqns,removedEqs = reqns,
initialEqs = ieqns,arrayEqs = ae,algorithms = algs),false,func,inTypeA)
equation
exps1 = traverseDEALowExpsVars(vars1,func,inTypeA);
exps2 = traverseDEALowExpsVars(vars2,func,inTypeA);
exps3 = traverseDEALowExpsEqns(eqns,func,inTypeA);
exps4 = traverseDEALowExpsEqns(reqns,func,inTypeA);
exps5 = traverseDEALowExpsEqns(ieqns,func,inTypeA);
exps6 = traverseDEALowExpsArrayEqns(ae,func,inTypeA);
exps = Util.listFlatten({exps1,exps2,exps3,exps4,exps5,exps6});
then
exps;
case (_,_,_,_)
equation
Debug.fprintln("failtrace", "- DAELow.traverseDEALowExps failed");
then
Expand Down Expand Up @@ -17190,7 +17203,7 @@ algorithm
end matchcontinue;
end extendRecordEqns;

protected function generateCrefsExpFromType "
public function generateCrefsExpFromType "
Author: Frenkel TUD 2010-05"
input DAE.ExpVar inVar;
input DAE.Exp inExp;
Expand Down
40 changes: 35 additions & 5 deletions Compiler/DAELowUtil.mo
Expand Up @@ -112,7 +112,7 @@ algorithm
varlst2 = DAELow.varList(vars2);
allvarslst = listAppend(varlst1,varlst2);
allvars = DAELow.listVar(allvarslst);
expcrefs = DAELow.traverseDEALowExps(inDAELow,checkDEALowExp,allvars);
expcrefs = DAELow.traverseDEALowExps(inDAELow,false,checkDEALowExp,allvars);
then
expcrefs;
case (_)
Expand All @@ -137,7 +137,7 @@ algorithm
list<tuple<DAE.Exp,list<DAE.ComponentRef>>> lstExpCrefs;
case (exp,vars)
equation
((_,(_,crefs))) = Exp.traverseExp(exp,traversecheckDEALowExp,((vars,{})));
((_,(_,crefs))) = Exp.traverseExpTopDown(exp,traversecheckDEALowExp,((vars,{})));
lstExpCrefs = Util.if_(listLength(crefs)>0,{(exp,crefs)},{});
then
lstExpCrefs;
Expand All @@ -154,15 +154,45 @@ algorithm
DAELow.Variables vars;
DAE.ComponentRef cr;
list<DAE.ComponentRef> crefs;
case ((e as (DAE.CREF(DAE.CREF_IDENT("time",_,_), _)),(vars,crefs)))
list<DAE.Exp> expl;
// special case for time, it is never part of the equation system
case ((e as DAE.CREF(componentRef = DAE.CREF_IDENT(ident="time")),(vars,crefs)))
then ((e, (vars,crefs)));
/* Special Case for Records */
case ((e as DAE.CREF(componentRef = cr),(vars,crefs)))
local
list<list<tuple<DAE.Exp,list<DAE.ComponentRef>>>> expcreflstlst;
list<tuple<DAE.Exp,list<DAE.ComponentRef>>> expcreflst;
list<list<DAE.ComponentRef>> creflstlst;
list<DAE.ComponentRef> crlst;
list<DAE.ExpVar> varLst;
equation
DAE.ET_COMPLEX(varLst=varLst) = Exp.crefLastType(cr);
expl = Util.listMap1(varLst,DAELow.generateCrefsExpFromType,e);
expcreflstlst = Util.listMap1(expl,checkDEALowExp,vars);
expcreflst = Util.listFlatten(expcreflstlst);
creflstlst = Util.listMap(expcreflst,Util.tuple22);
crlst = Util.listFlatten(creflstlst);
then
((e, (vars,listAppend(crlst,crefs))));
case ((e as DAE.REDUCTION(ident = ident),(vars,crefs)))
local
DAE.Ident ident;
DAELow.Var var;
equation
// add ident to vars
cr = DAE.CREF_IDENT(ident,DAE.ET_INT(),{});
var = DAELow.VAR(cr,DAELow.VARIABLE(),DAE.BIDIR(),DAELow.INT(),NONE(),NONE(),{},0,
DAE.emptyElementSource,NONE(),NONE(),DAE.NON_CONNECTOR(),DAE.NON_STREAM_CONNECTOR());
vars = DAELow.addVar(var,vars);
then
((e, (vars,crefs)));
case ((e as (DAE.CREF(cr, _)),(vars,crefs)))
case ((e as DAE.CREF(componentRef = cr),(vars,crefs)))
equation
(_,_) = DAELow.getVar(cr, vars);
then
((e, (vars,crefs)));
case ((e as (DAE.CREF(cr, _)),(vars,crefs)))
case ((e as DAE.CREF(componentRef = cr),(vars,crefs)))
equation
failure((_,_) = DAELow.getVar(cr, vars));
then
Expand Down

0 comments on commit 7d41002

Please sign in to comment.