Skip to content

Commit

Permalink
- moved also calculation of jacobians of dynamic StateSet from SimCo…
Browse files Browse the repository at this point in the history
…deUtil to Backend module

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19412 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Mar 4, 2014
1 parent 1b3bdf2 commit cfcb3b0
Show file tree
Hide file tree
Showing 8 changed files with 509 additions and 460 deletions.
1 change: 1 addition & 0 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -405,6 +405,7 @@ uniontype StateSet
list< Equation> oeqns;
.DAE.ComponentRef crJ;
list< Var> varJ;
Jacobian jacobian;
end STATESET;
end StateSet;

Expand Down
417 changes: 353 additions & 64 deletions Compiler/BackEnd/BackendDAEOptimize.mo

Large diffs are not rendered by default.

136 changes: 135 additions & 1 deletion Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -7091,6 +7091,139 @@ algorithm
end matchcontinue;
end traverseBackendDAEExps;

public function traverseBackendDAEExpsEqSystemJacobians "author: wbraun

This function goes through the all jacobians and stateSets and finds all the
expressions and performs the function on them in a list
an extra argument passed through the function.
"
replaceable type Type_a subtypeof Any;
input BackendDAE.EqSystem syst;
input FuncExpType func;
input Type_a inTypeA;
output Type_a outTypeA;
partial function FuncExpType
input tuple<DAE.Exp, Type_a> inTpl;
output tuple<DAE.Exp, Type_a> outTpl;
end FuncExpType;
algorithm
outTypeA :=
matchcontinue(syst, func, inTypeA)
local
BackendDAE.StrongComponents comps;
BackendDAE.StateSets stateSets;
Type_a arg;
case (BackendDAE.EQSYSTEM(stateSets = stateSets), _, _)
equation
comps = getStrongComponents(syst);
arg = traverseStrongComponentsJacobiansExp(comps, func, inTypeA);
arg = traverseStateSetsJacobiansExp(stateSets, func, arg);
then arg;
case (_, _, _) then inTypeA;
end matchcontinue;
end traverseBackendDAEExpsEqSystemJacobians;

public function traverseStrongComponentsJacobiansExp
"author: wbraun"
replaceable type Type_a subtypeof Any;
input BackendDAE.StrongComponents inComps;
input FuncExpType inFunc;
input Type_a inTypeA;
output Type_a outTypeA;
partial function FuncExpType
input tuple<DAE.Exp, Type_a> inTpl;
output tuple<DAE.Exp, Type_a> outTpl;
end FuncExpType;
algorithm
outTypeA :=
matchcontinue(inComps, inFunc, inTypeA)
local
BackendDAE.StrongComponents rest;
BackendDAE.StrongComponent comp;
list<tuple<Integer, Integer, BackendDAE.Equation>> jac;
BackendDAE.BackendDAE bdae;
Type_a arg;
case ({}, _, _) then inTypeA;
case (BackendDAE.EQUATIONSYSTEM(jac=BackendDAE.FULL_JACOBIAN(SOME(jac)))::rest, _, _)
equation
arg = traverseBackendDAEExpsJacobianEqn(jac, inFunc, inTypeA);
then
traverseStrongComponentsJacobiansExp(rest, inFunc, arg);
case (BackendDAE.EQUATIONSYSTEM(jac=BackendDAE.GENERIC_JACOBIAN(jacobian = (bdae,_,_,_,_)))::rest, _, _)
equation
arg = traverseBackendDAEExps(bdae, inFunc, inTypeA);
then
traverseStrongComponentsJacobiansExp(rest, inFunc, arg);
case (BackendDAE.TORNSYSTEM(jac=BackendDAE.GENERIC_JACOBIAN(jacobian = (bdae,_,_,_,_)))::rest, _, _)
equation
arg = traverseBackendDAEExps(bdae, inFunc, inTypeA);
then
traverseStrongComponentsJacobiansExp(rest, inFunc, arg);
case (BackendDAE.MIXEDEQUATIONSYSTEM(condSystem=comp)::rest, _, _)
equation
arg = traverseStrongComponentsJacobiansExp({comp}, inFunc, inTypeA);
then
traverseStrongComponentsJacobiansExp(rest, inFunc, arg);
case (_::rest, _, _) then
traverseStrongComponentsJacobiansExp(rest, inFunc, inTypeA);
end matchcontinue;
end traverseStrongComponentsJacobiansExp;

protected function traverseBackendDAEExpsJacobianEqn "author: wbraun
Helper for traverseBackendDAEExpsEqn."
replaceable type Type_a subtypeof Any;
input list<tuple<Integer, Integer, BackendDAE.Equation>> inJacEntry;
input FuncExpType func;
input Type_a inTypeA;
output Type_a outTypeA;
partial function FuncExpType
input tuple<DAE.Exp, Type_a> inTpl;
output tuple<DAE.Exp, Type_a> outTpl;
end FuncExpType;
algorithm
outTypeA :=
matchcontinue (inJacEntry, func, inTypeA)
local
list<tuple<Integer, Integer, BackendDAE.Equation>> rest;
Integer i,j;
BackendDAE.Equation eqn;
Type_a typeA;
case ({}, _, _) then inTypeA;
case ((i,j,eqn)::rest, _, _)
equation
typeA = traverseBackendDAEExpsOptEqn(SOME(eqn),func,inTypeA);
then typeA;
end matchcontinue;
end traverseBackendDAEExpsJacobianEqn;

public function traverseStateSetsJacobiansExp
"author: wbraun"
replaceable type Type_a subtypeof Any;
input BackendDAE.StateSets inStateSets;
input FuncExpType inFunc;
input Type_a inTypeA;
output Type_a outTypeA;
partial function FuncExpType
input tuple<DAE.Exp, Type_a> inTpl;
output tuple<DAE.Exp, Type_a> outTpl;
end FuncExpType;
algorithm
outTypeA :=
match(inStateSets, inFunc, inTypeA)
local
BackendDAE.StateSets rest;
BackendDAE.StateSet set;
BackendDAE.BackendDAE bdae;
Type_a arg;
case ({}, _, _) then inTypeA;
case (BackendDAE.STATESET(jacobian = BackendDAE.GENERIC_JACOBIAN(jacobian = (bdae,_,_,_,_)))::rest, _, _)
equation
arg = traverseBackendDAEExps(bdae, inFunc, inTypeA);
then
traverseStateSetsJacobiansExp(rest, inFunc, arg);
end match;
end traverseStateSetsJacobiansExp;

public function traverseBackendDAEExpsNoCopyWithUpdate "
This function goes through the BackendDAE structure and finds all the
expressions and performs the function on them in a list
Expand Down Expand Up @@ -8683,7 +8816,8 @@ algorithm
(BackendDAEOptimize.partitionIndependentBlocks, "partitionIndependentBlocks", true),
(Tearing.tearingSystem, "tearingSystem", false),
(BackendDAEOptimize.addInitialStmtsToAlgorithms, "addInitialStmtsToAlgorithms", false),
(BackendDAEOptimize.calculateStrongComponentJacobians, "calculateStrongComponentJacobians", false)
(BackendDAEOptimize.calculateStrongComponentJacobians, "calculateStrongComponentJacobians", false),
(BackendDAEOptimize.calculateStateSetsJacobians, "calculateStateSetsJacobians", false)
//(BackendDAEOptimize.resolveLoopsInComps,"resolveLoops", false)
};

Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/IndexReduction.mo
Expand Up @@ -1840,7 +1840,7 @@ algorithm
stateCandidates = List.map1(stateCandidates,BackendVariable.setVarKind,BackendDAE.DUMMY_STATE());
otherVars = List.map1(otherVars,BackendVariable.setVarKind,BackendDAE.DUMMY_STATE());
// generate state set;
(setIndex,vars,eqns,stateSets) = generateStateSets(rest,iSetIndex+1,vars,eqns,BackendDAE.STATESET(rang,crset,crA,aVars,stateCandidates,otherVars,cEqnsLst,oEqnLst,crJ,varJ)::iStateSets);
(setIndex,vars,eqns,stateSets) = generateStateSets(rest,iSetIndex+1,vars,eqns,BackendDAE.STATESET(rang,crset,crA,aVars,stateCandidates,otherVars,cEqnsLst,oEqnLst,crJ,varJ,BackendDAE.EMPTY_JACOBIAN())::iStateSets);
then
(setIndex,vars,eqns,stateSets);
end match;
Expand Down
5 changes: 3 additions & 2 deletions Compiler/BackEnd/RemoveSimpleEquations.mo
Expand Up @@ -3518,8 +3518,9 @@ algorithm
BackendVarTransform.VariableReplacements repl;
HashSet.HashSet hs;
Boolean b, b1;
BackendDAE.Jacobian jac;
case ({}, _, _, _, _, _) then (listReverse(iAcc), inB, iStatesetrepl);
case (BackendDAE.STATESET(rang, states, crA, varA, statescandidates, ovars, eqns, oeqns, crJ, varJ)::stateSets, _, _, _, _, _)
case (BackendDAE.STATESET(rang, states, crA, varA, statescandidates, ovars, eqns, oeqns, crJ, varJ, jac)::stateSets, _, _, _, _, _)
equation
repl = getAliasReplacements(iStatesetrepl, aliasVars);
// do not replace the set variables
Expand All @@ -3530,7 +3531,7 @@ algorithm
(oeqns, b1) = BackendVarTransform.replaceEquations(oeqns, repl, SOME(BackendVarTransform.skipPreChangeEdgeOperator));
oeqns = List.fold(oeqns, removeEqualLshRshEqns, {});
oeqns = listReverse(oeqns);
(stateSets, b, oStatesetrepl) = removeAliasVarsStateSets(stateSets, SOME(repl), vars, aliasVars, BackendDAE.STATESET(rang, states, crA, varA, statescandidates, ovars, eqns, oeqns, crJ, varJ)::iAcc, b or b1);
(stateSets, b, oStatesetrepl) = removeAliasVarsStateSets(stateSets, SOME(repl), vars, aliasVars, BackendDAE.STATESET(rang, states, crA, varA, statescandidates, ovars, eqns, oeqns, crJ, varJ, jac)::iAcc, b or b1);
then
(stateSets, b, oStatesetrepl);
end match;
Expand Down

0 comments on commit cfcb3b0

Please sign in to comment.