Skip to content

Commit

Permalink
- add the equation x = pre(x) for all non-discrete variables to the i…
Browse files Browse the repository at this point in the history
…nitialization system

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16820 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Aug 17, 2013
1 parent c5e0c5e commit 4aaf327
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
52 changes: 27 additions & 25 deletions Compiler/BackEnd/Initialization.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1626,32 +1626,34 @@ algorithm
DAE.ComponentRef cr, preCR;
Boolean isFixed;
DAE.Type ty;
DAE.InstDims arryDim;
Option<DAE.Exp> startValue;
HashSet.HashSet hs;
BackendDAE.VarKind varKind;

// discrete
case((var as BackendDAE.VAR(varName=cr, varKind=BackendDAE.DISCRETE(), varType=ty, arryDim=arryDim), (vars, fixvars, hs))) equation
case((var as BackendDAE.VAR(varName=cr, varKind=BackendDAE.DISCRETE()), (vars, fixvars, hs))) equation
isFixed = BackendVariable.varFixed(var);
startValue = BackendVariable.varStartValueOption(var);

preCR = ComponentReference.crefPrefixPre(cr); // cr => $PRE.cr
preVar = BackendDAE.VAR(preCR, BackendDAE.DISCRETE(), DAE.BIDIR(), DAE.NON_PARALLEL(), ty, NONE(), NONE(), arryDim, DAE.emptyElementSource, NONE(), NONE(), DAE.NON_CONNECTOR());
preVar = BackendVariable.copyVarNewName(preCR, var);
preVar = BackendVariable.setVarFixed(preVar, isFixed);
preVar = BackendVariable.setVarStartValueOption(preVar, startValue);

vars = Debug.bcallret2(not isFixed, BackendVariable.addVar, preVar, vars, vars);
fixvars = Debug.bcallret2(isFixed, BackendVariable.addVar, preVar, fixvars, fixvars);
then ((var, (vars, fixvars, hs)));

// additionally used pre-calls (e.g. continuous states)
case((var as BackendDAE.VAR(varName=cr, varKind=varKind, varType=ty, arryDim=arryDim), (vars, fixvars, hs))) equation
true = BaseHashSet.has(cr, hs);
// additionally used pre-calls (e.g. continuous states)
case((var as BackendDAE.VAR(varName=cr, varType=ty), (vars, fixvars, hs))) equation
true = BaseHashSet.has(cr, hs);

preCR = ComponentReference.crefPrefixPre(cr); // cr => $pre.cr
preVar = BackendDAE.VAR(preCR, varKind, DAE.BIDIR(), DAE.NON_PARALLEL(), ty, NONE(), NONE(), arryDim, DAE.emptyElementSource, NONE(), NONE(), DAE.NON_CONNECTOR());
then ((var, (vars, fixvars, hs)));
preCR = ComponentReference.crefPrefixPre(cr); // cr => $pre.cr
preVar = BackendVariable.copyVarNewName(preCR, var);
preVar = BackendVariable.setVarFixed(preVar, true);
preVar = BackendVariable.setVarStartValueOption(preVar, SOME(DAE.CREF(cr, ty)));

fixvars = BackendVariable.addVar(preVar, fixvars);
then ((var, (vars, fixvars, hs)));

else then inTpl;
end matchcontinue;
Expand Down Expand Up @@ -1731,37 +1733,37 @@ algorithm
end replaceDerPreCref;

protected function replaceDerPreCrefExp "author: Frenkel TUD 2011-05
helper for replaceDerCref"
helper for replaceDerPreCref"
input tuple<DAE.Exp, Integer> inExp;
output tuple<DAE.Exp, Integer> outExp;
algorithm
outExp := matchcontinue(inExp)
local
DAE.ComponentRef dummyder, cr;
DAE.ComponentRef dummy, cr;
DAE.Type ty;
Integer i;

case ((DAE.CALL(path = Absyn.IDENT(name = "der"), expLst = {DAE.CREF(componentRef = cr)}, attr=DAE.CALL_ATTR(ty=ty)), i)) equation
dummyder = ComponentReference.crefPrefixDer(cr);
then ((DAE.CREF(dummyder, ty), i+1));
case ((DAE.CALL(path = Absyn.IDENT(name="der"), expLst={DAE.CREF(componentRef=cr)}, attr=DAE.CALL_ATTR(ty=ty)), i)) equation
dummy = ComponentReference.crefPrefixDer(cr);
then ((DAE.CREF(dummy, ty), i+1));

case ((DAE.CALL(path = Absyn.IDENT(name = "pre"), expLst = {DAE.CREF(componentRef = cr)}, attr=DAE.CALL_ATTR(ty=ty)), i)) equation
dummyder = ComponentReference.crefPrefixPre(cr);
then ((DAE.CREF(dummyder, ty), i+1));
case ((DAE.CALL(path = Absyn.IDENT(name="pre"), expLst={DAE.CREF(componentRef=cr)}, attr=DAE.CALL_ATTR(ty=ty)), i)) equation
dummy = ComponentReference.crefPrefixPre(cr);
then ((DAE.CREF(dummy, ty), i+1));

else
then inExp;
end matchcontinue;
end replaceDerPreCrefExp;

// protected function collectInitialStateSetVars "author: Frenkel TUD
// add the vars for state set to the initial system
// Because the statevars are calculated by
// set.x = set.A*dummystates we add set.A to the
// initial system with set.A = {{1, 0, 0}, {0, 1, 0}}"
// input BackendDAE.StateSet inSet;
// input tuple<BackendDAE.Variables, BackendDAE.EquationArray> iTpl;
// output tuple<BackendDAE.Variables, BackendDAE.EquationArray> oTpl;
// add the vars for state set to the initial system
// Because the statevars are calculated by
// set.x = set.A*dummystates we add set.A to the
// initial system with set.A = {{1, 0, 0}, {0, 1, 0}}"
// input BackendDAE.StateSet inSet;
// input tuple<BackendDAE.Variables, BackendDAE.EquationArray> iTpl;
// output tuple<BackendDAE.Variables, BackendDAE.EquationArray> oTpl;
// protected
// BackendDAE.Variables vars;
// BackendDAE.EquationArray eqns;
Expand Down
25 changes: 12 additions & 13 deletions Compiler/FrontEnd/DAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1165,19 +1165,18 @@ end Mod;

public
uniontype Exp "Expressions
The `Exp\' datatype closely corresponds to the `Absyn.Exp\'
datatype, but is used for statically analyzed expressions. It
includes explicit type promotions and typed (non-overloaded)
operators. It also contains expression indexing with the `ASUB\'
constructor. Indexing arbitrary array expressions is currently
not supported in Modelica, but it is needed here.

When making additions, update at least the following functions:
* Expression.traverseExp
* Expression.traverseExpTopDown
* Expression.traverseExpBiDir
* ExpressionDump.printExpStr
"
The `Exp\' datatype closely corresponds to the `Absyn.Exp\'
datatype, but is used for statically analyzed expressions. It
includes explicit type promotions and typed (non-overloaded)
operators. It also contains expression indexing with the `ASUB\'
constructor. Indexing arbitrary array expressions is currently
not supported in Modelica, but it is needed here.

When making additions, update at least the following functions:
* Expression.traverseExp
* Expression.traverseExpTopDown
* Expression.traverseExpBiDir
* ExpressionDump.printExpStr"
record ICONST
Integer integer "Integer constants" ;
end ICONST;
Expand Down

0 comments on commit 4aaf327

Please sign in to comment.