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

Commit

Permalink
[BE] Improve inlining and solution of array equations
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Nov 20, 2018
1 parent f80c21e commit 19f18d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Compiler/BackEnd/BackendInline.mo
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Compiler/BackEnd/Differentiate.mo
Expand Up @@ -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
Expand All @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -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;

Expand Down

0 comments on commit 19f18d6

Please sign in to comment.