Skip to content

Commit

Permalink
Merge postOptModules that detect sparse pattern
Browse files Browse the repository at this point in the history
- detectJacobianSparsePattern
- generateSymbolicJacobian

Flag --generateSymbolicJacobian can be used to additionally
generate the symbolic Jacobian itself.

Belonging to [master]:
  - OpenModelica/OMCompiler#2217
  - OpenModelica/OpenModelica-testsuite#857
  • Loading branch information
lochel authored and OpenModelica-Hudson committed Feb 16, 2018
1 parent 5163543 commit 9c759d9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
8 changes: 1 addition & 7 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -7643,8 +7643,7 @@ public function allPostOptimizationModules
(BackendDAEOptimize.addTimeAsState, "addTimeAsState"),
(SymbolicJacobian.calculateStrongComponentJacobians, "calculateStrongComponentJacobians"),
(SymbolicJacobian.calculateStateSetsJacobians, "calculateStateSetsJacobians"),
(SymbolicJacobian.detectSparsePatternODE, "detectJacobianSparsePattern"),
(SymbolicJacobian.generateSymbolicJacobianPast, "generateSymbolicJacobian"),
(SymbolicJacobian.symbolicJacobian, "symbolicJacobian"),
(SymbolicJacobian.generateSymbolicSensitivities, "generateSymbolicSensitivities"),
(SymbolicJacobian.generateSymbolicLinearizationPast, "generateSymbolicLinearization"),
(BackendDAEOptimize.removeConstants, "removeConstants"),
Expand Down Expand Up @@ -7803,11 +7802,6 @@ algorithm
enabledModules := deprecatedConfigFlag(Flags.CSE_EACHCALL, enabledModules, "wrapFunctionCalls", "postOptModules+");
enabledModules := deprecatedDebugFlag(Flags.ON_RELAXATION, enabledModules, "relaxSystem", "postOptModules+");

if Flags.getConfigBool(Flags.GENERATE_SYMBOLIC_JACOBIAN) then
enabledModules := "generateSymbolicJacobian"::enabledModules;
disabledModules := "detectJacobianSparsePattern"::disabledModules;
end if;

if Flags.getConfigBool(Flags.DISABLE_LINEAR_TEARING) then
Flags.setConfigInt(Flags.MAX_SIZE_LINEAR_TEARING, 0);
Error.addCompilerWarning("Deprecated flag --disableLinearTearing detected. Use --maxSizeLinearTearing=0 instead.");
Expand Down
24 changes: 22 additions & 2 deletions Compiler/BackEnd/SymbolicJacobian.mo
Expand Up @@ -77,6 +77,26 @@ import Util;
import Values;
import ValuesUtil;

// =============================================================================
// section for postOptModule >>symbolicJacobian<<
//
// Detects the sparse pattern of the ODE system and calculates also the symbolic
// Jacobian if flag "--generateSymbolicJacobian" is enabled.
// =============================================================================

public function symbolicJacobian "author: lochel
Detects the sparse pattern of the ODE system and calculates also the symbolic
Jacobian if flag '--generateSymbolicJacobian' is enabled."
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
if Flags.getConfigBool(Flags.GENERATE_SYMBOLIC_JACOBIAN) then
outDAE := generateSymbolicJacobianPast(inDAE);
else
outDAE := detectSparsePatternODE(inDAE);
end if;
end symbolicJacobian;

// =============================================================================
// section for postOptModule >>calculateStateSetsJacobians<<
//
Expand Down Expand Up @@ -128,7 +148,7 @@ end constantLinearSystem;
//
// Generate sparse pattern
// =============================================================================
public function detectSparsePatternODE
protected function detectSparsePatternODE
input BackendDAE.BackendDAE inBackendDAE;
output BackendDAE.BackendDAE outBackendDAE;
protected
Expand Down Expand Up @@ -238,7 +258,7 @@ end detectSparsePatternDAE;
// Symbolic Jacobian subsection
// =============================================================================

public function generateSymbolicJacobianPast
protected function generateSymbolicJacobianPast
input BackendDAE.BackendDAE inBackendDAE;
output BackendDAE.BackendDAE outBackendDAE;
protected
Expand Down
5 changes: 2 additions & 3 deletions Compiler/Util/Flags.mo
Expand Up @@ -868,7 +868,7 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
"inputDerivativesUsed",
"calculateStrongComponentJacobians",
"calculateStateSetsJacobians",
"detectJacobianSparsePattern",
"symbolicJacobian",
"removeConstants",
"simplifyTimeIndepFuncCalls",
"simplifyAllExpressions",
Expand All @@ -886,13 +886,11 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
("countOperations", Util.gettext("Count the mathematical operations of the system.")),
("createAliasVarsForOutputStates", Util.gettext("Module creates alias variables for output states.")),
("cseBinary", Util.gettext("Common Sub-expression Elimination")),
("detectJacobianSparsePattern", Util.gettext("Detects the sparse pattern for jacobian :math:`\\frac{f_{ode}}{x}` in the causalized representation :math:`\\dot{x} = f(x,t)`.")),
("dumpComponentsGraphStr", Util.notrans("Dumps the assignment graph used to determine strong components to format suitable for Mathematica")),
("dumpDAE", Util.gettext("dumps the DAE representation of the current transformation state")),
("dumpDAEXML", Util.gettext("dumps the DAE as xml representation of the current transformation state")),
("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.")),
("extendDynamicOptimization", Util.gettext("Move loops to constraints.")),
("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'.")),
("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`")),
("generateSymbolicSensitivities", Util.gettext("Generates symbolic Sensivities matrix, where der(x) is differentiated w.r.t. param.")),
("inlineArrayEqn", Util.gettext("This module expands all array equations to scalar equations.")),
Expand All @@ -917,6 +915,7 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
("solveLinearSystem", Util.notrans("solve linear system with newton step")),
("solveSimpleEquations", Util.notrans("Solves simple equations")),
("symSolver", Util.notrans("Rewrites the ode system for implicit Euler method. This module requires +symSolver.")),
("symbolicJacobian", Util.notrans("Detects the sparse pattern of the ODE system and calculates also the symbolic Jacobian if flag '--generateSymbolicJacobian' is enabled.")),
("tearingSystem", Util.notrans("For method selection use flag tearingMethod.")),
("wrapFunctionCalls", Util.gettext("This module introduces variables for each function call and substitutes all these calls with the newly introduced variables."))
})),
Expand Down

0 comments on commit 9c759d9

Please sign in to comment.