Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 9c759d9

Browse files
lochelOpenModelica-Hudson
authored andcommitted
Merge postOptModules that detect sparse pattern
- detectJacobianSparsePattern - generateSymbolicJacobian Flag --generateSymbolicJacobian can be used to additionally generate the symbolic Jacobian itself. Belonging to [master]: - #2217 - OpenModelica/OpenModelica-testsuite#857
1 parent 5163543 commit 9c759d9

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7643,8 +7643,7 @@ public function allPostOptimizationModules
76437643
(BackendDAEOptimize.addTimeAsState, "addTimeAsState"),
76447644
(SymbolicJacobian.calculateStrongComponentJacobians, "calculateStrongComponentJacobians"),
76457645
(SymbolicJacobian.calculateStateSetsJacobians, "calculateStateSetsJacobians"),
7646-
(SymbolicJacobian.detectSparsePatternODE, "detectJacobianSparsePattern"),
7647-
(SymbolicJacobian.generateSymbolicJacobianPast, "generateSymbolicJacobian"),
7646+
(SymbolicJacobian.symbolicJacobian, "symbolicJacobian"),
76487647
(SymbolicJacobian.generateSymbolicSensitivities, "generateSymbolicSensitivities"),
76497648
(SymbolicJacobian.generateSymbolicLinearizationPast, "generateSymbolicLinearization"),
76507649
(BackendDAEOptimize.removeConstants, "removeConstants"),
@@ -7803,11 +7802,6 @@ algorithm
78037802
enabledModules := deprecatedConfigFlag(Flags.CSE_EACHCALL, enabledModules, "wrapFunctionCalls", "postOptModules+");
78047803
enabledModules := deprecatedDebugFlag(Flags.ON_RELAXATION, enabledModules, "relaxSystem", "postOptModules+");
78057804

7806-
if Flags.getConfigBool(Flags.GENERATE_SYMBOLIC_JACOBIAN) then
7807-
enabledModules := "generateSymbolicJacobian"::enabledModules;
7808-
disabledModules := "detectJacobianSparsePattern"::disabledModules;
7809-
end if;
7810-
78117805
if Flags.getConfigBool(Flags.DISABLE_LINEAR_TEARING) then
78127806
Flags.setConfigInt(Flags.MAX_SIZE_LINEAR_TEARING, 0);
78137807
Error.addCompilerWarning("Deprecated flag --disableLinearTearing detected. Use --maxSizeLinearTearing=0 instead.");

Compiler/BackEnd/SymbolicJacobian.mo

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ import Util;
7777
import Values;
7878
import ValuesUtil;
7979

80+
// =============================================================================
81+
// section for postOptModule >>symbolicJacobian<<
82+
//
83+
// Detects the sparse pattern of the ODE system and calculates also the symbolic
84+
// Jacobian if flag "--generateSymbolicJacobian" is enabled.
85+
// =============================================================================
86+
87+
public function symbolicJacobian "author: lochel
88+
Detects the sparse pattern of the ODE system and calculates also the symbolic
89+
Jacobian if flag '--generateSymbolicJacobian' is enabled."
90+
input BackendDAE.BackendDAE inDAE;
91+
output BackendDAE.BackendDAE outDAE;
92+
algorithm
93+
if Flags.getConfigBool(Flags.GENERATE_SYMBOLIC_JACOBIAN) then
94+
outDAE := generateSymbolicJacobianPast(inDAE);
95+
else
96+
outDAE := detectSparsePatternODE(inDAE);
97+
end if;
98+
end symbolicJacobian;
99+
80100
// =============================================================================
81101
// section for postOptModule >>calculateStateSetsJacobians<<
82102
//
@@ -128,7 +148,7 @@ end constantLinearSystem;
128148
//
129149
// Generate sparse pattern
130150
// =============================================================================
131-
public function detectSparsePatternODE
151+
protected function detectSparsePatternODE
132152
input BackendDAE.BackendDAE inBackendDAE;
133153
output BackendDAE.BackendDAE outBackendDAE;
134154
protected
@@ -238,7 +258,7 @@ end detectSparsePatternDAE;
238258
// Symbolic Jacobian subsection
239259
// =============================================================================
240260

241-
public function generateSymbolicJacobianPast
261+
protected function generateSymbolicJacobianPast
242262
input BackendDAE.BackendDAE inBackendDAE;
243263
output BackendDAE.BackendDAE outBackendDAE;
244264
protected

Compiler/Util/Flags.mo

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
868868
"inputDerivativesUsed",
869869
"calculateStrongComponentJacobians",
870870
"calculateStateSetsJacobians",
871-
"detectJacobianSparsePattern",
871+
"symbolicJacobian",
872872
"removeConstants",
873873
"simplifyTimeIndepFuncCalls",
874874
"simplifyAllExpressions",
@@ -886,13 +886,11 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
886886
("countOperations", Util.gettext("Count the mathematical operations of the system.")),
887887
("createAliasVarsForOutputStates", Util.gettext("Module creates alias variables for output states.")),
888888
("cseBinary", Util.gettext("Common Sub-expression Elimination")),
889-
("detectJacobianSparsePattern", Util.gettext("Detects the sparse pattern for jacobian :math:`\\frac{f_{ode}}{x}` in the causalized representation :math:`\\dot{x} = f(x,t)`.")),
890889
("dumpComponentsGraphStr", Util.notrans("Dumps the assignment graph used to determine strong components to format suitable for Mathematica")),
891890
("dumpDAE", Util.gettext("dumps the DAE representation of the current transformation state")),
892891
("dumpDAEXML", Util.gettext("dumps the DAE as xml representation of the current transformation state")),
893892
("evaluateParameters", Util.gettext("Evaluates parameters with annotation(Evaluate=true). Use '--evaluateFinalParameters=true' or '--evaluateProtectedParameters=true' to specify additional parameters to be evaluated. Use '--replaceEvaluatedParameters=true' if the evaluated parameters should be replaced in the DAE. To evaluate all parameters in the Frontend use -d=evaluateAllParameters.")),
894893
("extendDynamicOptimization", Util.gettext("Move loops to constraints.")),
895-
("generateSymbolicJacobian", Util.gettext("Generates symbolic Jacobian matrix, where der(x) is differentiated w.r.t. x. This matrix can be used by dassl or ida solver with simulation flag '-jacobian'.")),
896894
("generateSymbolicLinearization", Util.gettext("Generates symbolic linearization matrices A,B,C,D for linear model:\n\t:math:`\\dot{x} = Ax + Bu `\n\t:math:`y = Cx +Du`")),
897895
("generateSymbolicSensitivities", Util.gettext("Generates symbolic Sensivities matrix, where der(x) is differentiated w.r.t. param.")),
898896
("inlineArrayEqn", Util.gettext("This module expands all array equations to scalar equations.")),
@@ -917,6 +915,7 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
917915
("solveLinearSystem", Util.notrans("solve linear system with newton step")),
918916
("solveSimpleEquations", Util.notrans("Solves simple equations")),
919917
("symSolver", Util.notrans("Rewrites the ode system for implicit Euler method. This module requires +symSolver.")),
918+
("symbolicJacobian", Util.notrans("Detects the sparse pattern of the ODE system and calculates also the symbolic Jacobian if flag '--generateSymbolicJacobian' is enabled.")),
920919
("tearingSystem", Util.notrans("For method selection use flag tearingMethod.")),
921920
("wrapFunctionCalls", Util.gettext("This module introduces variables for each function call and substitutes all these calls with the newly introduced variables."))
922921
})),

0 commit comments

Comments
 (0)