Skip to content

Commit

Permalink
improved extends dynamic optimization formulation
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25181 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed Mar 20, 2015
1 parent 27c2636 commit 056f99f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
23 changes: 15 additions & 8 deletions Compiler/BackEnd/DynamicOptimization.mo
Expand Up @@ -54,6 +54,7 @@ protected import Config;

protected import Expression;
protected import ExpressionSolve;
protected import ExpressionSimplify;
protected import Error;
protected import Flags;
protected import List;
Expand Down Expand Up @@ -619,21 +620,24 @@ protected
DAE.ComponentRef cr, cr_var;
list<String> name_lst = List.map(cr_lst,ComponentReference.crefStr);
DAE.Exp e, res;
Integer ind;
list<Integer> ind_lst = vindx;
Integer ind_e, ind_v;
list<Integer> ind_lst_v = List.map(vindx,intAbs);
list<Integer> ind_lst_e = eindex;
BackendDAE.Variables knvars;
algorithm
({},_) := List.splitOnTrue(var_lst, BackendVariable.isStateVar);

BackendDAE.SHARED(knownVars=knvars) := oshared;

for name in name_lst loop

// res -> con
var_::var_lst := var_lst;
cr_var :: cr_lst := cr_lst;
eqn :: eqn_lst := eqn_lst;
ind :: ind_lst := ind_lst;
ind_e :: ind_lst_e := ind_lst_e;
ind_v :: ind_lst_v := ind_lst_v;

cr := ComponentReference.makeCrefIdent("$OMC$con$" + name, DAE.T_REAL_DEFAULT , {});
cr := ComponentReference.makeCrefIdent("$OMC$con$Loop$" + intString(ind_e), DAE.T_REAL_DEFAULT , {});
e := Expression.crefExp(cr);

var := BackendVariable.makeVar(cr);
Expand All @@ -642,18 +646,21 @@ algorithm

ovars := BackendVariable.addNewVar(var, ovars);
res := BackendDAEOptimize.makeEquationToResidualExp(eqn);
res := Expression.createResidualExp(res, Expression.makeConstZeroE(res));

//oeqns := BackendEquation.addEquation(BackendDAE.EQUATION(e, res, DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN), oeqns);
oeqns := BackendEquation.setAtIndex(oeqns,ind, BackendDAE.EQUATION(e, res, DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN));
oeqns := BackendEquation.setAtIndex(oeqns,ind_e, BackendDAE.EQUATION(e, res, DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN));
// new input(resvar)
(cr,var) := makeVar("OMC$Input" + intString(ind));
(cr,var) := makeVar("OMC$Input" + intString(ind_v));
var := BackendVariable.setVarDirection(var, DAE.INPUT());
var := BackendVariable.mergeAliasVars(var, var_, false, knvars);
oshared := BackendVariable.addKnVarDAE(var, oshared);
// resvar = new input(resvar)
if BackendVariable.isStateVar(var) then
cr_var := ComponentReference.crefPrefixDer(cr);
end if;
oeqns := BackendEquation.addEquation(BackendDAE.EQUATION(Expression.crefExp(cr_var), Expression.crefExp(cr), DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN), oeqns);


end for;


Expand Down
20 changes: 17 additions & 3 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -4129,6 +4129,17 @@ algorithm
end matchcontinue;
end makeConstZero;

public function makeConstZeroE
"Generates a zero constant, using type from inExp"
input DAE.Exp iExp;
output DAE.Exp const;
protected
DAE.Type tp = typeof(iExp);
algorithm
const := makeConstZero(tp);
end makeConstZeroE;


public function makeListOfZeros
input Integer inDimension;
output list<DAE.Exp> outList;
Expand Down Expand Up @@ -11948,18 +11959,21 @@ algorithm
case(DAE.CALL(path = Absyn.IDENT("sqrt"), expLst={e1}), DAE.RCONST(0.0))
then (e1,iExp2,true);
// sqrt(f(x)) = c -> f(x) = c^2
case(DAE.CALL(path = Absyn.IDENT("sqrt"), expLst={e1}), DAE.RCONST())
case(DAE.CALL(path = Absyn.IDENT("sqrt"), expLst={e1}), e2)
guard(Expression.isConst(e2))
equation
e = Expression.expPow(iExp2, DAE.RCONST(2.0));
then (e1,e,true);
// log(f(x)) = c -> f(x) = exp(c)
case(DAE.CALL(path = Absyn.IDENT("log"), expLst={e1}), DAE.RCONST())
case(DAE.CALL(path = Absyn.IDENT("log"), expLst={e1}), e2)
guard(Expression.isConst(e2))
equation
tp = Expression.typeof(iExp2);
e = Expression.makePureBuiltinCall("exp", {iExp2}, tp);
then (e1,e,true);
// log10(f(x)) = c -> f(x) = 10^(c)
case(DAE.CALL(path = Absyn.IDENT("log10"), expLst={e1}), DAE.RCONST())
case(DAE.CALL(path = Absyn.IDENT("log10"), expLst={e1}), e2)
guard(Expression.isConst(e2))
equation
e = Expression.expPow(DAE.RCONST(10.0),iExp2);
then (e1,e,true);
Expand Down

0 comments on commit 056f99f

Please sign in to comment.