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

Commit

Permalink
[NF] Array equation fixes.
Browse files Browse the repository at this point in the history
- Use DAE.UMINUS_ARR in NFOperator.toDAE for array types instead of
  the scalar operator DAE.UMINUS.
- Simplify InlineArrayEquations.getScalarArrayEqns1.

Belonging to [master]:
  - #2575
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jul 11, 2018
1 parent 65d1390 commit 06e511f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 59 deletions.
97 changes: 40 additions & 57 deletions Compiler/BackEnd/InlineArrayEquations.mo
Expand Up @@ -134,67 +134,50 @@ protected function getScalarArrayEqns1
output list<BackendDAE.Equation> outEqnLst;
output Boolean outFound;
algorithm
(outEqnLst, outFound) := matchcontinue(inEqn, inAccEqnLst)
(outEqnLst, outFound) := matchcontinue inEqn
local
DAE.ElementSource source;
DAE.Exp lhs, rhs, e1_1, e2_1;
DAE.Exp lhs, rhs, e1, e2;
list<DAE.Exp> ea1, ea2;
list<BackendDAE.Equation> eqns;
BackendDAE.EquationAttributes eqAttr;

case (BackendDAE.ARRAY_EQUATION(left=lhs, right=rhs, source=source, attr=eqAttr), _) equation
true = Expression.isArray(lhs) or Expression.isMatrix(lhs);
true = Expression.isArray(rhs) or Expression.isMatrix(rhs);
ea1 = Expression.flattenArrayExpToList(lhs);
ea2 = Expression.flattenArrayExpToList(rhs);
((_, eqns)) = List.threadFold3(ea1, ea2, generateScalarArrayEqns2, source, eqAttr, DAE.EQUALITY_EXPS(lhs, rhs), (1, inAccEqnLst));
then (eqns, true);

case (BackendDAE.ARRAY_EQUATION(left=(lhs as DAE.CREF()), right=rhs, source=source, attr=eqAttr), _) equation
// the lhs array is expressed as a cref
true = Expression.isArray(rhs) or Expression.isMatrix(rhs);
(e1_1, _) = Expression.extendArrExp(lhs, false);
ea1 = Expression.flattenArrayExpToList(e1_1);
ea2 = Expression.flattenArrayExpToList(rhs);
((_, eqns)) = List.threadFold3(ea1, ea2, generateScalarArrayEqns2, source, eqAttr, DAE.EQUALITY_EXPS(lhs, rhs), (1, inAccEqnLst));
then (eqns, true);

case (BackendDAE.ARRAY_EQUATION(left=lhs, right=rhs as DAE.CREF(), source=source, attr=eqAttr), _) equation
true = Expression.isArray(lhs) or Expression.isMatrix(lhs);
(e2_1, _) = Expression.extendArrExp(rhs,false);
ea1 = Expression.flattenArrayExpToList(lhs);
ea2 = Expression.flattenArrayExpToList(e2_1);
((_, eqns)) = List.threadFold3(ea1, ea2, generateScalarArrayEqns2, source, eqAttr, DAE.EQUALITY_EXPS(lhs, rhs), (1, inAccEqnLst));
then (eqns,true);

case (BackendDAE.ARRAY_EQUATION(left=lhs as DAE.CREF(),right=rhs as DAE.CREF(), source=source, attr=eqAttr), _) equation
(e1_1, _) = Expression.extendArrExp(lhs, false);
(e2_1, _) = Expression.extendArrExp(rhs, false);
ea1 = Expression.flattenArrayExpToList(e1_1);
ea2 = Expression.flattenArrayExpToList(e2_1);
((_, eqns)) = List.threadFold3(ea1, ea2, generateScalarArrayEqns2, source, eqAttr, DAE.EQUALITY_EXPS(lhs, rhs), (1, inAccEqnLst));
then (eqns, true);

case (BackendDAE.ARRAY_EQUATION(left=lhs,right=rhs, source=source, attr=eqAttr), _) equation
(e1_1, _) = Expression.extendArrExp(lhs, false);
(e2_1, _) = Expression.extendArrExp(rhs, false);
(e1_1,_) = ExpressionSimplify.simplify(e1_1);
(e2_1,_) = ExpressionSimplify.simplify(e2_1);
true = Expression.isArray(e1_1) or Expression.isMatrix(e1_1);
true = Expression.isArray(e2_1) or Expression.isMatrix(e2_1);
ea1 = Expression.flattenArrayExpToList(e1_1);
ea2 = Expression.flattenArrayExpToList(e2_1);
((_, eqns)) = List.threadFold3(ea1, ea2, generateScalarArrayEqns2, source, eqAttr, DAE.EQUALITY_EXPS(lhs, rhs), (1, inAccEqnLst));
then (eqns, true);

case (BackendDAE.COMPLEX_EQUATION(left=lhs, right=rhs, source=source, attr=eqAttr), _) equation
ea1 = Expression.splitRecord(lhs,Expression.typeof(lhs));
ea2 = Expression.splitRecord(rhs,Expression.typeof(rhs));
((_, eqns)) = List.threadFold3(ea1, ea2, generateScalarArrayEqns2, source, eqAttr, DAE.EQUALITY_EXPS(lhs, rhs), (1, inAccEqnLst));
then (eqns, true);

case (_, _)
then (inEqn::inAccEqnLst, false);
BackendDAE.EquationAttributes attr;
DAE.Exp e1_1, e2_1;

case BackendDAE.ARRAY_EQUATION(left = lhs, right = rhs, source = source, attr = attr)
algorithm
if Expression.isArray(lhs) or Expression.isMatrix(lhs) then
ea1 := Expression.flattenArrayExpToList(lhs);
else
e1 := Expression.extendArrExp(lhs);
e1 := ExpressionSimplify.simplify(e1);
true := Expression.isArray(e1) or Expression.isMatrix(e1);
ea1 := Expression.flattenArrayExpToList(e1);
end if;

if Expression.isArray(rhs) or Expression.isMatrix(rhs) then
ea2 := Expression.flattenArrayExpToList(rhs);
else
e2 := Expression.extendArrExp(rhs);
e2 := ExpressionSimplify.simplify(e2);
true := Expression.isArray(e2) or Expression.isMatrix(e2);
ea2 := Expression.flattenArrayExpToList(e2);
end if;

((_, eqns)) := List.threadFold3(ea1, ea2, generateScalarArrayEqns2,
source, attr, DAE.EQUALITY_EXPS(lhs, rhs), (1, inAccEqnLst));
then
(eqns, true);

case BackendDAE.COMPLEX_EQUATION(left = lhs, right = rhs, source = source, attr = attr)
algorithm
ea1 := Expression.splitRecord(lhs, Expression.typeof(lhs));
ea2 := Expression.splitRecord(rhs, Expression.typeof(rhs));
((_, eqns)) := List.threadFold3(ea1, ea2, generateScalarArrayEqns2,
source, attr, DAE.EQUALITY_EXPS(lhs, rhs), (1, inAccEqnLst));
then
(eqns, true);

else (inEqn :: inAccEqnLst, false);
end matchcontinue;
end getScalarArrayEqns1;

Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Expression.mo
Expand Up @@ -12093,7 +12093,7 @@ end expandExpression;
public function extendArrExp "author: Frenkel TUD 2010-07
alternative name: vectorizeExp"
input DAE.Exp inExp;
input Boolean inExpanded "True if something was expanded, otherwise false.";
input Boolean inExpanded = false "True if something was expanded, otherwise false.";
output DAE.Exp outExp;
output Boolean outExpanded;
algorithm
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFOperator.mo
Expand Up @@ -165,7 +165,7 @@ public
case Op.POW_SCALAR_ARRAY then DAE.POW_SCALAR_ARRAY(ty);
case Op.POW_ARRAY_SCALAR then DAE.POW_ARRAY_SCALAR(ty);
case Op.POW_MATRIX then DAE.POW_ARR(ty);
case Op.UMINUS then DAE.UMINUS(ty);
case Op.UMINUS then if Type.isArray(op.ty) then DAE.UMINUS_ARR(ty) else DAE.UMINUS(ty);
case Op.AND then DAE.AND(ty);
case Op.OR then DAE.OR(ty);
case Op.NOT then DAE.NOT(ty);
Expand Down

0 comments on commit 06e511f

Please sign in to comment.