Skip to content

Commit

Permalink
- BackendDAEUtil: avoid Zero entries in JacMatrix
Browse files Browse the repository at this point in the history
- fix order in equationToExp for arrayEquations
- fix order in createNonlinearResidualEquations for arrayEquations

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12261 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jul 2, 2012
1 parent 13c4858 commit abb60e1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
25 changes: 23 additions & 2 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -6689,16 +6689,18 @@ algorithm
((e,_)) = Expression.replaceExp(inExp, dcrexp, Expression.crefExp(dcr));
e_1 = Derive.differentiateExp(e, dcr, differentiateIfExp);
(e_2,_) = ExpressionSimplify.simplify(e_1);
es = calculateJacobianRow3(eqn_indx,vindx,e_2,source,iAcc);
then
calculateJacobianRow2(inExp, vars, eqn_indx, vindxs, differentiateIfExp,source,(eqn_indx,vindx,BackendDAE.RESIDUAL_EQUATION(e_2,source)) :: iAcc);
calculateJacobianRow2(inExp, vars, eqn_indx, vindxs, differentiateIfExp,source,es);
case (_,_,_,vindx :: vindxs,_,_,_)
equation
v = BackendVariable.getVarAt(vars, vindx);
cr = BackendVariable.varCref(v);
e_1 = Derive.differentiateExp(inExp, cr, differentiateIfExp);
(e_2,_) = ExpressionSimplify.simplify(e_1);
es = calculateJacobianRow3(eqn_indx,vindx,e_2,source,iAcc);
then
calculateJacobianRow2(inExp, vars, eqn_indx, vindxs, differentiateIfExp,source,(eqn_indx,vindx,BackendDAE.RESIDUAL_EQUATION(e_2,source)) :: iAcc);
calculateJacobianRow2(inExp, vars, eqn_indx, vindxs, differentiateIfExp,source,es);
case (_,_,_,_,_,_,_)
equation
true = Flags.isSet(Flags.FAILTRACE);
Expand All @@ -6709,6 +6711,25 @@ algorithm
end matchcontinue;
end calculateJacobianRow2;

protected function calculateJacobianRow3
input Integer eqn_indx;
input Integer vindx;
input DAE.Exp inExp;
input DAE.ElementSource source;
input list<tuple<Integer, Integer, BackendDAE.Equation>> iAcc;
output list<tuple<Integer, Integer, BackendDAE.Equation>> outLst;
algorithm
outLst := matchcontinue(eqn_indx,vindx,inExp,source,iAcc)
case (_,_,_,_,_)
equation
true = Expression.isZero(inExp);
then
iAcc;
else
(eqn_indx,vindx,BackendDAE.RESIDUAL_EQUATION(inExp,source)) :: iAcc;
end matchcontinue;
end calculateJacobianRow3;

public function analyzeJacobian "function: analyzeJacobian
author: PA
Analyze the jacobian to find out if the jacobian of system of equations
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -1417,7 +1417,7 @@ algorithm
explst1 = List.map1(explst1,BackendDAEUtil.getEqnsysRhsExp,v);
explst1 = List.map(explst1,Expression.negate);
explst1 = ExpressionSimplify.simplifyList(explst1, {});
explst = listAppend(explst1,explst);
explst = listAppend(listReverse(explst1),explst);
sources = List.consN(equationSize(eqn), source, sources);
then ((eqn,(v,explst,sources)));

Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/SimCode.mo
Expand Up @@ -4370,7 +4370,7 @@ algorithm
subslst = BackendDAEUtil.rangesToSubscripts(subslst);
explst = List.map1r(subslst,Expression.applyExpSubscripts,res_exp);
(eqSystemsRest,uniqueEqIndex) = createNonlinearResidualEquations(rest, repl,iuniqueEqIndex);
(eqSystlst,uniqueEqIndex) = List.map1Fold(explst,makeSES_RESIDUAL,source,uniqueEqIndex);
(eqSystlst,uniqueEqIndex) = List.map1Fold(listReverse(explst),makeSES_RESIDUAL,source,uniqueEqIndex);
eqSystemsRest = listAppend(eqSystlst,eqSystemsRest);
then
(eqSystemsRest,uniqueEqIndex+1);
Expand Down

0 comments on commit abb60e1

Please sign in to comment.