From 5cea0b5a2b33652959ba51f3457928b794165b30 Mon Sep 17 00:00:00 2001 From: ptaeuber Date: Thu, 7 Dec 2017 18:48:51 +0100 Subject: [PATCH] Fix solving of array equations - 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]: - OpenModelica/OMCompiler#2068 --- Compiler/FrontEnd/Expression.mo | 2 +- Compiler/SimCode/SimCodeUtil.mo | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Compiler/FrontEnd/Expression.mo b/Compiler/FrontEnd/Expression.mo index eaa9749ad2..cb3d951960 100644 --- a/Compiler/FrontEnd/Expression.mo +++ b/Compiler/FrontEnd/Expression.mo @@ -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); diff --git a/Compiler/SimCode/SimCodeUtil.mo b/Compiler/SimCode/SimCodeUtil.mo index a92557ce19..21f3588341 100644 --- a/Compiler/SimCode/SimCodeUtil.mo +++ b/Compiler/SimCode/SimCodeUtil.mo @@ -6147,7 +6147,7 @@ algorithm (equations_, noDiscequations, ouniqueEqIndex, otempvars) := matchcontinue(genDiscrete, inEquations, inVars, iuniqueEqIndex, itempvars, iextra) local list ds; - DAE.Exp e1, e2, e1_1, e2_1, lhse; + DAE.Exp e1, e2, e1_1, e2_1, lhse, rhse; list ea1, ea2, expLst, expLstTmp; list re; list vars; @@ -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()); @@ -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);