Skip to content

Commit

Permalink
- fix bug in calculaton of jacobian, in case of state jacobian have t…
Browse files Browse the repository at this point in the history
…o generated for der(x) not for x

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12082 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jun 18, 2012
1 parent fa0fa4e commit f19610c
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -6015,24 +6015,37 @@ protected function calculateJacobianRow2 "function: calculateJacobianRow2
int list) /* var indexes */
outputs: ((int int Equation) list option)"
input DAE.Exp inExp;
input Variables inVariables;
input Integer inInteger;
input Variables vars;
input Integer eqn_indx;
input list<Integer> inIntegerLst;
input Boolean differentiateIfExp "If true, allow differentiation of if-expressions";
output Option<list<tuple<Integer, Integer, BackendDAE.Equation>>> outTplIntegerIntegerEquationLstOption;
algorithm
outTplIntegerIntegerEquationLstOption := match (inExp,inVariables,inInteger,inIntegerLst,differentiateIfExp)
outTplIntegerIntegerEquationLstOption := matchcontinue (inExp,vars,eqn_indx,inIntegerLst,differentiateIfExp)
local
DAE.Exp e,e_1,e_2;
DAE.Exp e,e_1,e_2,dcrexp;
Var v;
DAE.ComponentRef cr;
DAE.ComponentRef cr,dcr;
list<tuple<BackendDAE.Value, BackendDAE.Value, BackendDAE.Equation>> es;
Variables vars;
BackendDAE.Value eqn_indx,vindx;
BackendDAE.Value vindx;
list<BackendDAE.Value> vindxs;

case (e,_,_,{},_) then SOME({});
case (e,vars,eqn_indx,(vindx :: vindxs),differentiateIfExp)
case (e,_,_,(vindx :: vindxs),_)
equation
v = BackendVariable.getVarAt(vars, vindx);
true = BackendVariable.isStateVar(v);
cr = BackendVariable.varCref(v);
dcr = ComponentReference.crefPrefixDer(cr);
dcrexp = Expression.crefExp(cr);
dcrexp = DAE.CALL(Absyn.IDENT("der"),{dcrexp},DAE.callAttrBuiltinReal);
((e,_)) = Expression.replaceExp(e, dcrexp, Expression.crefExp(dcr));
e_1 = Derive.differentiateExp(e, dcr, differentiateIfExp);
(e_2,_) = ExpressionSimplify.simplify(e_1);
SOME(es) = calculateJacobianRow2(inExp, vars, eqn_indx, vindxs, differentiateIfExp);
then
SOME(((eqn_indx,vindx,BackendDAE.RESIDUAL_EQUATION(e_2,DAE.emptyElementSource)) :: es));
case (e,_,_,(vindx :: vindxs),_)
equation
v = BackendVariable.getVarAt(vars, vindx);
cr = BackendVariable.varCref(v);
Expand All @@ -6041,7 +6054,7 @@ algorithm
SOME(es) = calculateJacobianRow2(e, vars, eqn_indx, vindxs, differentiateIfExp);
then
SOME(((eqn_indx,vindx,BackendDAE.RESIDUAL_EQUATION(e_2,DAE.emptyElementSource)) :: es));
end match;
end matchcontinue;
end calculateJacobianRow2;

public function analyzeJacobian "function: analyzeJacobian
Expand Down

0 comments on commit f19610c

Please sign in to comment.