From 19f18d65222d3f33c80ef658517bcb738c142491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Franke?= Date: Tue, 20 Nov 2018 16:04:49 +0100 Subject: [PATCH] [BE] Improve inlining and solution of array equations Belonging to [master]: - OpenModelica/OMCompiler#2793 - OpenModelica/OpenModelica-testsuite#1079 --- Compiler/BackEnd/BackendInline.mo | 7 ++++++- Compiler/BackEnd/Differentiate.mo | 3 ++- Compiler/FrontEnd/ExpressionSimplify.mo | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Compiler/BackEnd/BackendInline.mo b/Compiler/BackEnd/BackendInline.mo index 69d0b3a19f..e9c1828d7f 100644 --- a/Compiler/BackEnd/BackendInline.mo +++ b/Compiler/BackEnd/BackendInline.mo @@ -210,8 +210,13 @@ algorithm (e1_1,source,b1,_) = Inline.inlineExp(e1,fns,source); (e2_1,source,b2,_) = Inline.inlineExp(e2,fns,source); true = b1 or b2; + eqn = match (e1_1, e2_1) + case (DAE.ARRAY(array = {e1}), DAE.ARRAY(array = {e2})) + then BackendDAE.EQUATION(e1,e2,source,attr); // flatten if size==1 + else BackendDAE.ARRAY_EQUATION(dimSize,e1_1,e2_1,source,attr); + end match; then - (BackendDAE.ARRAY_EQUATION(dimSize,e1_1,e2_1,source,attr),true); + (eqn, true); case(BackendDAE.FOR_EQUATION(e, e1, e2, eqn, source, attr), _) equation diff --git a/Compiler/BackEnd/Differentiate.mo b/Compiler/BackEnd/Differentiate.mo index a256614b99..0ff23ef7fa 100644 --- a/Compiler/BackEnd/Differentiate.mo +++ b/Compiler/BackEnd/Differentiate.mo @@ -1056,6 +1056,7 @@ algorithm // case for arrays case ((e as DAE.CREF(ty = DAE.T_ARRAY())), _, _, diffType, _) guard ( match diffType case BackendDAE.GENERIC_GRADIENT() then false; else true; end match ) equation + true = Flags.isSet(Flags.NF_SCALARIZE); // only expand if scalarize (e1,true) = Expression.extendArrExp(e,false); (res, outFunctionTree) = differentiateExp(e1, inDiffwrtCref, inInputData, inDiffType, inFunctionTree, maxIter); then @@ -1070,7 +1071,7 @@ algorithm case (DAE.CREF(componentRef = cr, ty = tp), _, _, _, _) equation true = ComponentReference.crefEqual(cr, inDiffwrtCref); - one = Expression.makeConstOne(tp); + (one,_) = Expression.makeOneExpression(Expression.arrayDimension(tp)); then (one, inFunctionTree); diff --git a/Compiler/FrontEnd/ExpressionSimplify.mo b/Compiler/FrontEnd/ExpressionSimplify.mo index 9172a21307..40185abcb6 100644 --- a/Compiler/FrontEnd/ExpressionSimplify.mo +++ b/Compiler/FrontEnd/ExpressionSimplify.mo @@ -2397,6 +2397,13 @@ algorithm then exp; + // Scalar product of any expression with zeros + case (_, _) + equation + true = Expression.isZero(inVector1) or Expression.isZero(inVector2); + then + Expression.makeConstZero(DAE.T_REAL_DEFAULT); + end match; end simplifyScalarProduct;