Skip to content

Commit

Permalink
- fix differentiate that results in a zeroExp.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24248 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Jan 28, 2015
1 parent c94f64d commit 52c412c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Compiler/BackEnd/Differentiate.mo
Expand Up @@ -2033,7 +2033,7 @@ algorithm
is last. Otherwise expressions is always traversed twice
when differentiating.";
tp = Expression.typeof(inExp);
(zero, _) = Expression.makeZeroExpression(Expression.arrayDimension(tp));
zero = Expression.createZeroExpression(tp);
then
(zero, inFunctionTree);

Expand All @@ -2046,7 +2046,6 @@ algorithm
end matchcontinue;
end differentiateFunctionCall;


protected function differentiateFunctionCallPartial"
Author: Frenkel TUD, wbraun

Expand Down
45 changes: 45 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -4175,6 +4175,51 @@ algorithm
outExp := makeRealArray(l);
end makeRealArrayOfZeros;

public function createZeroExpression
input DAE.Type inType;
output DAE.Exp outExp;
algorithm
(outExp) := match (inType)
local
DAE.Exp e;
list<DAE.Type> typeLst;
list<DAE.Exp> expLst;
DAE.Dimensions dims;
DAE.ComponentRef cr;
list<DAE.ComponentRef> crefs;
Absyn.Path path;
list<DAE.Var> varLst;
list<String> varNames;

// real and integer
case (_) guard(isIntegerOrReal(inType)) then makeConstZero(inType);

case DAE.T_TUPLE(types=typeLst) equation
expLst = List.map(typeLst, createZeroExpression);
e = DAE.TUPLE(expLst);
then e;

case DAE.T_ARRAY(dims=dims) equation
(e, _) = makeZeroExpression(dims);
then e;

// record type
case DAE.T_COMPLEX(varLst=varLst,complexClassType=ClassInf.RECORD(path)) equation
cr = DAE.CREF_IDENT("$TMP", inType, {});
crefs = ComponentReference.expandCref(cr, true);
expLst = List.map(crefs, crefExp);
typeLst = List.map(expLst, typeof);
expLst = List.map(typeLst, createZeroExpression);
varNames = List.map(varLst, varName);
e = DAE.RECORD(path, expLst, varNames, inType);
then e;

// all other are failing cases
else fail();
end match;
end createZeroExpression;


public function makeZeroExpression
" creates a Real or array<Real> zero expression with given dimensions, also returns its type"
input DAE.Dimensions inDims;
Expand Down

0 comments on commit 52c412c

Please sign in to comment.