Skip to content

Commit

Permalink
- consider type of cref when generate equation from aktive when equation
Browse files Browse the repository at this point in the history
- do not add variables with constant bindexpression to initial system

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14573 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Dec 29, 2012
1 parent 77dc365 commit 78e1b8c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
50 changes: 50 additions & 0 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -2169,6 +2169,56 @@ algorithm
end match;
end equationLstSize_impl;

public function generateEquation
"function generateEquation
author Frenkel TUD 2012-12
helper to generate an equation from lhs and rhs.
This function is called if an equation is found which is not simple"
input DAE.Exp lhs;
input DAE.Exp rhs;
input DAE.Type ty;
input DAE.ElementSource source;
input Boolean differentiated;
output BackendDAE.Equation outEqn;
algorithm
outEqn := matchcontinue (lhs,rhs,ty,source,differentiated)
local
Integer size;
DAE.Dimensions dims;
list<Integer> ds;
Boolean b1,b2;
// complex types to complex equations
case (_,_,_,_,_)
equation
true = DAEUtil.expTypeComplex(ty);
size = Expression.sizeOf(ty);
then
BackendDAE.COMPLEX_EQUATION(size,lhs,rhs,source,differentiated);
// array types to array equations
case (_,_,_,_,_)
equation
true = DAEUtil.expTypeArray(ty);
dims = Expression.arrayDimension(ty);
ds = Expression.dimensionsSizes(dims);
then
BackendDAE.ARRAY_EQUATION(ds,lhs,rhs,source,differentiated);
// other types
case (_,_,_,_,_)
equation
b1 = DAEUtil.expTypeComplex(ty);
b2 = DAEUtil.expTypeArray(ty);
false = b1 or b2;
then
BackendDAE.EQUATION(lhs,rhs,source,differentiated);
else
equation
// show only on failtrace!
true = Flags.isSet(Flags.FAILTRACE);
Debug.traceln("- BackendEquation.generateEquation failed on: " +& ExpressionDump.printExpStr(lhs) +& " = " +& ExpressionDump.printExpStr(rhs) +& "\n");
then
fail();
end matchcontinue;
end generateEquation;

public function generateEQUATION "
Author: Frenkel TUD 2010-05"
Expand Down
14 changes: 9 additions & 5 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -317,7 +317,7 @@ algorithm
(oEqns,oVars) := matchcontinue(inWEqn,hs,source,iEqns,iVars)
local
DAE.ComponentRef left;
DAE.Exp condition,right;
DAE.Exp condition,right,crexp;
BackendDAE.Equation eqn;
DAE.Type identType;
list< BackendDAE.Equation> eqns;
Expand All @@ -328,8 +328,9 @@ algorithm
case (BackendDAE.WHEN_EQ(condition=condition, left=left, right=right),_,_,_,_)
equation
true = Expression.containsInitialCall(condition, false); // do not use Expression.traverseExp
identType = ComponentReference.crefType(left);
eqn = BackendDAE.EQUATION(DAE.CREF(left, identType), right, source, false);
crexp = Expression.crefExp(left);
identType = Expression.typeof(crexp);
eqn = BackendEquation.generateEquation(crexp,right,identType,source,false);
then
(eqn::iEqns,iVars);

Expand Down Expand Up @@ -1652,9 +1653,12 @@ algorithm
fixvars = Debug.bcallret2(b, BackendVariable.addVar, var, fixvars, fixvars);
then ((var, (vars, fixvars)));

case((var as BackendDAE.VAR(bindExp=SOME(_)), (vars, fixvars))) equation
case((var as BackendDAE.VAR(bindExp=SOME(bindExp)), (vars, fixvars))) equation
isInput = BackendVariable.isVarOnTopLevelAndInput(var);
vars = Debug.bcallret2(not isInput, BackendVariable.addVar, var, vars, vars);
isFixed = Expression.isConst(bindExp);
b = isInput or isFixed;
vars = Debug.bcallret2(not b, BackendVariable.addVar, var, vars, vars);
fixvars = Debug.bcallret2(b, BackendVariable.addVar, var, fixvars, fixvars);
then ((var, (vars, fixvars)));

case ((var, _)) equation
Expand Down

0 comments on commit 78e1b8c

Please sign in to comment.