Skip to content

Commit 98c844c

Browse files
author
Jens Frenkel
committed
- in case of variables with variable indices (for example u[i,1]) replace the indices with WHOLEDIM (maybe this could be improved by evaluating i) to get at least all potential variables in the incidence matrix
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14314 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 0c145d7 commit 98c844c

File tree

2 files changed

+100
-2
lines changed

2 files changed

+100
-2
lines changed

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3833,12 +3833,14 @@ algorithm
38333833
(varslst,p) = BackendVariable.getVar(cr, vars);
38343834
res = incidenceRowExp1(varslst,p,pa,true);
38353835
then
3836-
((e,false,(vars,res)));
3836+
((e,true,(vars,res)));
38373837

38383838
case (((e as DAE.CALL(path = Absyn.IDENT(name = "der"),expLst = {DAE.CREF(componentRef = cr)}),(vars,pa))))
38393839
equation
38403840
(varslst,p) = BackendVariable.getVar(cr, vars);
38413841
res = incidenceRowExp1(varslst,p,pa,false);
3842+
/* check also indizes of cr */
3843+
(_,(_,res)) = Expression.traverseExpTopDownCrefHelper(cr, traversingincidenceRowExpFinder, (vars,res));
38423844
then
38433845
((e,false,(vars,res)));
38443846

@@ -3847,6 +3849,8 @@ algorithm
38473849
cr = ComponentReference.crefPrefixDer(cr);
38483850
(varslst,p) = BackendVariable.getVar(cr, vars);
38493851
res = incidenceRowExp1(varslst,p,pa,false);
3852+
/* check also indizes of cr */
3853+
(_,(_,res)) = Expression.traverseExpTopDownCrefHelper(cr, traversingincidenceRowExpFinder, (vars,res));
38503854
then
38513855
((e,false,(vars,res)));
38523856

Compiler/BackEnd/BackendVariable.mo

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3277,7 +3277,8 @@ algorithm
32773277
Integer indx;
32783278
list<Integer> indxs;
32793279
list<BackendDAE.Var> vLst;
3280-
list<DAE.ComponentRef> crlst;
3280+
list<DAE.ComponentRef> crlst;
3281+
DAE.ComponentRef cr1;
32813282
case (_,_)
32823283
equation
32833284
(v,indx) = getVar2(cr, inVariables) "if scalar found, return it" ;
@@ -3289,6 +3290,15 @@ algorithm
32893290
(vLst as _::_,indxs) = getVarLst(crlst,inVariables,{},{});
32903291
then
32913292
(vLst,indxs);
3293+
// try again check if variable indexes used
3294+
case (_,_)
3295+
equation
3296+
// replace variables with WHOLEDIM()
3297+
(cr1,true) = replaceVarWithWholeDim(cr, false);
3298+
crlst = ComponentReference.expandCref(cr1,true);
3299+
(vLst as _::_,indxs) = getVarLst(crlst,inVariables,{},{});
3300+
then
3301+
(vLst,indxs);
32923302
/* failure
32933303
case (cr,vars)
32943304
equation
@@ -3299,6 +3309,90 @@ algorithm
32993309
end matchcontinue;
33003310
end getVar;
33013311

3312+
protected function replaceVarWithWholeDim
3313+
"Helper function to traverseExp. Traverses any expressions in a
3314+
component reference (i.e. in it's subscripts)."
3315+
input DAE.ComponentRef inCref;
3316+
input Boolean iPerformed;
3317+
output DAE.ComponentRef outCref;
3318+
output Boolean oPerformed;
3319+
algorithm
3320+
(outCref, oPerformed) := match(inCref, iPerformed)
3321+
local
3322+
DAE.Ident name;
3323+
DAE.ComponentRef cr,cr_1;
3324+
DAE.Type ty;
3325+
list<DAE.Subscript> subs,subs_1;
3326+
Boolean b;
3327+
3328+
case (DAE.CREF_QUAL(ident = name, identType = ty, subscriptLst = subs, componentRef = cr), _)
3329+
equation
3330+
(subs_1, b) = replaceVarWithWholeDimSubs(subs, iPerformed);
3331+
(cr_1, b) = replaceVarWithWholeDim(cr, b);
3332+
then
3333+
(DAE.CREF_QUAL(name, ty, subs_1, cr_1), b);
3334+
3335+
case (DAE.CREF_IDENT(ident = name, identType = ty, subscriptLst = subs), _)
3336+
equation
3337+
(subs_1, b) = replaceVarWithWholeDimSubs(subs, iPerformed);
3338+
then
3339+
(DAE.CREF_IDENT(name, ty, subs_1), b);
3340+
3341+
case (DAE.CREF_ITER(ident = _), _) then (inCref, iPerformed);
3342+
case (DAE.OPTIMICA_ATTR_INST_CREF(componentRef = _), _) then (inCref, iPerformed);
3343+
case (DAE.WILD(), _) then (inCref, iPerformed);
3344+
3345+
else
3346+
equation
3347+
Error.addMessage(Error.INTERNAL_ERROR, {"BackendVariable.replaceVarWithWholeDim: Unknown cref"});
3348+
then fail();
3349+
end match;
3350+
end replaceVarWithWholeDim;
3351+
3352+
protected function replaceVarWithWholeDimSubs
3353+
input list<DAE.Subscript> inSubscript;
3354+
input Boolean iPerformed;
3355+
output list<DAE.Subscript> outSubscript;
3356+
output Boolean oPerformed;
3357+
algorithm
3358+
(outSubscript, oPerformed) := match(inSubscript, iPerformed)
3359+
local
3360+
DAE.Exp sub_exp,sub_exp_1;
3361+
list<DAE.Subscript> rest,res;
3362+
Boolean b,const;
3363+
3364+
case ({}, _) then (inSubscript,iPerformed);
3365+
case (DAE.WHOLEDIM()::rest, _)
3366+
equation
3367+
(res,b) = replaceVarWithWholeDimSubs(rest,iPerformed);
3368+
then (DAE.WHOLEDIM()::rest, b);
3369+
3370+
case (DAE.SLICE(exp = sub_exp)::rest, _)
3371+
equation
3372+
(res,b) = replaceVarWithWholeDimSubs(rest,iPerformed);
3373+
const = Expression.isConst(sub_exp);
3374+
res = Util.if_(const,DAE.SLICE(sub_exp)::rest,DAE.WHOLEDIM()::rest);
3375+
then
3376+
(res, b or not const);
3377+
3378+
case (DAE.INDEX(exp = sub_exp)::rest, _)
3379+
equation
3380+
(res,b) = replaceVarWithWholeDimSubs(rest,iPerformed);
3381+
const = Expression.isConst(sub_exp);
3382+
res = Util.if_(const,DAE.INDEX(sub_exp)::rest,DAE.WHOLEDIM()::rest);
3383+
then
3384+
(res, b or not const);
3385+
3386+
case (DAE.WHOLE_NONEXP(exp = sub_exp)::rest, _)
3387+
equation
3388+
(res,b) = replaceVarWithWholeDimSubs(rest,iPerformed);
3389+
const = Expression.isConst(sub_exp);
3390+
res = Util.if_(const,DAE.WHOLE_NONEXP(sub_exp)::rest,DAE.WHOLEDIM()::rest);
3391+
then
3392+
(res, b or not const);
3393+
end match;
3394+
end replaceVarWithWholeDimSubs;
3395+
33023396
public function getVarLst
33033397
input list<DAE.ComponentRef> inComponentRefLst;
33043398
input BackendDAE.Variables inVariables;

0 commit comments

Comments
 (0)