From bbce7feaf6421b2e1d7e5db7475e7d1b84a14236 Mon Sep 17 00:00:00 2001 From: Lennart Ochel Date: Tue, 22 Sep 2015 11:57:15 +0200 Subject: [PATCH] Adapted optimization modules for Jacobians --- Compiler/BackEnd/BackendDAEUtil.mo | 36 +++++++++++++--------------- Compiler/BackEnd/SymbolicJacobian.mo | 8 +++++-- Compiler/Util/Flags.mo | 1 + 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Compiler/BackEnd/BackendDAEUtil.mo b/Compiler/BackEnd/BackendDAEUtil.mo index 9fca83dfa74..db25e8fc27f 100644 --- a/Compiler/BackEnd/BackendDAEUtil.mo +++ b/Compiler/BackEnd/BackendDAEUtil.mo @@ -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> strPreOptModules; - input Option strmatchingAlgorithm; - input Option strdaeHandler; - input Option> strpostOptModules; - output BackendDAE.BackendDAE outSODE; + input Option strMatchingAlgorithm; + input Option strDAEHandler; + input Option> strPostOptModules; + output BackendDAE.BackendDAE outDAE; protected - BackendDAE.BackendDAE dae,optdae,sode; + BackendDAE.BackendDAE dae; list> preOptModules; list> postOptModules; tuple daeHandler; tuple 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; /************************************************* @@ -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), diff --git a/Compiler/BackEnd/SymbolicJacobian.mo b/Compiler/BackEnd/SymbolicJacobian.mo index 40617926f53..d0df2f6af09 100644 --- a/Compiler/BackEnd/SymbolicJacobian.mo +++ b/Compiler/BackEnd/SymbolicJacobian.mo @@ -1823,7 +1823,10 @@ algorithm end if; backendDAE2 = BackendDAEUtil.getSolvedSystemforJacobians(backendDAE, - SOME({"evalFunc","removeEqualFunctionCalls","removeSimpleEquations"}), + SOME({"simplifyAllExpressions", + "evalFunc", + "removeEqualFunctionCalls", + "removeSimpleEquations"}), NONE(), NONE(), SOME({"inlineArrayEqn", @@ -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); diff --git a/Compiler/Util/Flags.mo b/Compiler/Util/Flags.mo index a3f56514f55..2cee027838a 100644 --- a/Compiler/Util/Flags.mo +++ b/Compiler/Util/Flags.mo @@ -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.")),