Skip to content

Commit

Permalink
Adapted optimization modules for Jacobians
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel committed Sep 22, 2015
1 parent e7e6f99 commit bbce7fe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
36 changes: 17 additions & 19 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -6978,42 +6978,39 @@ end postOptimizeDAE;
// end match;
// end countComponents;

public function getSolvedSystemforJacobians
" Run the equation system pipeline."
public function getSolvedSystemforJacobians "Run the equation system pipeline."
input BackendDAE.BackendDAE inDAE;
input Option<list<String>> strPreOptModules;
input Option<String> strmatchingAlgorithm;
input Option<String> strdaeHandler;
input Option<list<String>> strpostOptModules;
output BackendDAE.BackendDAE outSODE;
input Option<String> strMatchingAlgorithm;
input Option<String> strDAEHandler;
input Option<list<String>> strPostOptModules;
output BackendDAE.BackendDAE outDAE;
protected
BackendDAE.BackendDAE dae,optdae,sode;
BackendDAE.BackendDAE dae;
list<tuple<BackendDAEFunc.preOptimizationDAEModule,String,Boolean>> preOptModules;
list<tuple<BackendDAEFunc.postOptimizationDAEModule,String,Boolean>> postOptModules;
tuple<BackendDAEFunc.StructurallySingularSystemHandlerFunc,String,BackendDAEFunc.stateDeselectionFunc,String> daeHandler;
tuple<BackendDAEFunc.matchingAlgorithmFunc,String> matchingAlgorithm;
algorithm
preOptModules := getPreOptModules(strPreOptModules);
postOptModules := getPostOptModules(strpostOptModules);
matchingAlgorithm := getMatchingAlgorithm(strmatchingAlgorithm);
daeHandler := getIndexReductionMethod(strdaeHandler);
postOptModules := getPostOptModules(strPostOptModules);
matchingAlgorithm := getMatchingAlgorithm(strMatchingAlgorithm);
daeHandler := getIndexReductionMethod(strDAEHandler);

//fcall2(Flags.DUMP_DAE_LOW, BackendDump.dumpBackendDAE, inDAE, "dumpdaelow");
// pre optimisation phase
_ := traverseBackendDAEExps(inDAE,ExpressionSimplify.simplifyTraverseHelper,0) "simplify all expressions";
optdae := preOptimizeDAE(inDAE,preOptModules);
dae := preOptimizeDAE(inDAE, preOptModules);

// transformation phase (matching and sorting using a index reduction method
sode := causalizeDAE(optdae,NONE(),matchingAlgorithm,daeHandler,true);
//fcall(Flags.DUMP_DAE_LOW, BackendDump.bltdump, ("bltdump",sode));
dae := causalizeDAE(dae, NONE(), matchingAlgorithm, daeHandler, true);
//fcall(Flags.DUMP_DAE_LOW, BackendDump.bltdump, ("bltdump", dae));

// post-optimization phase
outSODE := postOptimizeDAE(sode,postOptModules,matchingAlgorithm,daeHandler);
_ := traverseBackendDAEExps(outSODE,ExpressionSimplify.simplifyTraverseHelper,0) "simplify all expressions";
outDAE := postOptimizeDAE(dae, postOptModules, matchingAlgorithm, daeHandler);

//fcall2(Flags.DUMP_INDX_DAE, BackendDump.dumpBackendDAE, outSODE, "dumpindxdae");
//bcall(Flags.isSet(Flags.DUMP_BACKENDDAE_INFO) or Flags.isSet(Flags.DUMP_STATESELECTION_INFO) or Flags.isSet(Flags.DUMP_DISCRETEVARS_INFO), BackendDump.dumpCompShort, outSODE);
//fcall2(Flags.DUMP_EQNINORDER, BackendDump.dumpEqnsSolved, outSODE, "system for jacobians");
//fcall2(Flags.DUMP_INDX_DAE, BackendDump.dumpBackendDAE, outDAE, "dumpindxdae");
//bcall(Flags.isSet(Flags.DUMP_BACKENDDAE_INFO) or Flags.isSet(Flags.DUMP_STATESELECTION_INFO) or Flags.isSet(Flags.DUMP_DISCRETEVARS_INFO), BackendDump.dumpCompShort, outDAE);
//fcall2(Flags.DUMP_EQNINORDER, BackendDump.dumpEqnsSolved, outDAE, "system for jacobians");
end getSolvedSystemforJacobians;

/*************************************************
Expand Down Expand Up @@ -7178,6 +7175,7 @@ algorithm
(BackendDAEOptimize.removeUnusedVariables, "removeUnusedVariables", false),
(BackendDAEOptimize.replaceEdgeChange, "replaceEdgeChange", false),
(BackendDAEOptimize.residualForm, "residualForm", false),
(BackendDAEOptimize.simplifyAllExpressions, "simplifyAllExpressions", false),
(BackendDAEOptimize.simplifyIfEquations, "simplifyIfEquations", false),
(BackendDAEOptimize.sortEqnsVars, "sortEqnsVars", false),
(BackendDump.dumpDAE, "dumpDAE", false),
Expand Down
8 changes: 6 additions & 2 deletions Compiler/BackEnd/SymbolicJacobian.mo
Expand Up @@ -1823,7 +1823,10 @@ algorithm
end if;

backendDAE2 = BackendDAEUtil.getSolvedSystemforJacobians(backendDAE,
SOME({"evalFunc","removeEqualFunctionCalls","removeSimpleEquations"}),
SOME({"simplifyAllExpressions",
"evalFunc",
"removeEqualFunctionCalls",
"removeSimpleEquations"}),
NONE(),
NONE(),
SOME({"inlineArrayEqn",
Expand All @@ -1833,7 +1836,8 @@ algorithm
"tearingSystem",
"solveSimpleEquations",
"simplifyTimeIndepFuncCalls",
"calculateStrongComponentJacobians"}));
"calculateStrongComponentJacobians",
"simplifyAllExpressions"}));
_ = Flags.set(Flags.EXEC_STAT, b);
if Flags.isSet(Flags.JAC_DUMP) then
BackendDump.bltdump("Symbolic Jacobian",backendDAE2);
Expand Down
1 change: 1 addition & 0 deletions Compiler/Util/Flags.mo
Expand Up @@ -716,6 +716,7 @@ constant ConfigFlag PRE_OPT_MODULES = CONFIG_FLAG(12, "preOptModules",
("replaceEdgeChange", Util.gettext("Replace edge(b) = b and not pre(b) and change(b) = v <> pre(v).")),
("residualForm", Util.gettext("Transforms simple equations x=y to zero-sum equations 0=y-x.")),
("resolveLoops", Util.gettext("resolves linear equations in loops")),
("simplifyAllExpressions", Util.notrans("Does simplifications on all expressions.")),
("simplifyIfEquations", Util.gettext("Tries to simplify if equations by use of information from evaluated parameters.")),
("sortEqnsVars", Util.notrans("Heuristic sorting for equations and variables. This module requires +d=sortEqnsAndVars.")),
("stateMachineElab", Util.gettext("Does the elaboration of state machines.")),
Expand Down

0 comments on commit bbce7fe

Please sign in to comment.