Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Fix solving of array equations
Browse files Browse the repository at this point in the history
- Do not solve crefL = crefR always for crefL,
  but consider the matching.
- Make getArrayOrRangeContents also work for
  qualified crefs.

This fixes ticket:4634

Belonging to [master]:
  - #2068
  • Loading branch information
ptaeuber authored and OpenModelica-Hudson committed Dec 7, 2017
1 parent cf618db commit 5cea0b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Expression.mo
Expand Up @@ -1842,7 +1842,7 @@ algorithm
ty = Types.unliftArray(ty);
es = List.map2(matrix,makeArray,ty,not Types.arrayType(ty));
then es;
case DAE.CREF(componentRef=DAE.CREF_IDENT(),ty=DAE.T_ARRAY(dims=DAE.DIM_INTEGER(istop)::_))
case DAE.CREF(ty=DAE.T_ARRAY(dims=DAE.DIM_INTEGER(istop)::_))
equation
es = List.map(ExpressionSimplify.simplifyRange(1,1,istop), makeIntegerExp);
es = List.map1r(es, makeASUBSingleSub, e);
Expand Down
20 changes: 18 additions & 2 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -6147,7 +6147,7 @@ algorithm
(equations_, noDiscequations, ouniqueEqIndex, otempvars) := matchcontinue(genDiscrete, inEquations, inVars, iuniqueEqIndex, itempvars, iextra)
local
list<Integer> ds;
DAE.Exp e1, e2, e1_1, e2_1, lhse;
DAE.Exp e1, e2, e1_1, e2_1, lhse, rhse;
list<DAE.Exp> ea1, ea2, expLst, expLstTmp;
list<BackendDAE.Equation> re;
list<BackendDAE.Var> vars;
Expand Down Expand Up @@ -6210,7 +6210,9 @@ algorithm

// An array equation
// cref = rhsexp
case (_, (BackendDAE.ARRAY_EQUATION(left=lhse as DAE.CREF(cr_1, _), right=e2, source=source))::_, BackendDAE.VAR()::_, _, _, _) equation
case (_, (BackendDAE.ARRAY_EQUATION(left=lhse as DAE.CREF(cr_1, _), right=e2, source=source))::_, BackendDAE.VAR(varName=cr)::_, _, _, _)
guard ComponentReference.crefEqual(cr_1, ComponentReference.crefStripLastSubs(cr))
equation
e1 = Expression.replaceDerOpInExp(lhse);
e2 = Expression.replaceDerOpInExp(e2);
(e1, _) = BackendDAEUtil.collateArrExp(e1, NONE());
Expand All @@ -6220,6 +6222,20 @@ algorithm
uniqueEqIndex = iuniqueEqIndex + 1;
then ({equation_}, {equation_}, uniqueEqIndex, itempvars);

// An array equation
// lhsexp = cref
case (_, (BackendDAE.ARRAY_EQUATION(left=e1, right=rhse as DAE.CREF(cr_1, _), source=source))::_, BackendDAE.VAR(varName=cr)::_, _, _, _)
guard ComponentReference.crefEqual(cr_1, ComponentReference.crefStripLastSubs(cr))
equation
e1 = Expression.replaceDerOpInExp(e1);
e2 = Expression.replaceDerOpInExp(rhse);
(e1, _) = BackendDAEUtil.collateArrExp(e1, NONE());
(e2, _) = BackendDAEUtil.collateArrExp(e2, NONE());
(e2, e1) = solveTrivialArrayEquation(cr_1, e2, e1);
equation_ = SimCode.SES_ARRAY_CALL_ASSIGN(iuniqueEqIndex, e2, e1, source);
uniqueEqIndex = iuniqueEqIndex + 1;
then ({equation_}, {equation_}, uniqueEqIndex, itempvars);

// failure
else equation
str = BackendDump.dumpEqnsStr(inEquations);
Expand Down

0 comments on commit 5cea0b5

Please sign in to comment.