Skip to content

Commit

Permalink
Added new backend module "simplifyAllExpressions"
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel committed Sep 22, 2015
1 parent 9318f20 commit e7e6f99
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
7 changes: 7 additions & 0 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -84,6 +84,13 @@ protected import Util;
protected import Values;
protected import ValuesUtil;

public function simplifyAllExpressions "author: lochel"
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE = inDAE;
algorithm
_ := BackendDAEUtil.traverseBackendDAEExpsNoCopyWithUpdate(outDAE, ExpressionSimplify.simplifyTraverseHelper, 0);
end simplifyAllExpressions;

// =============================================================================
// simplify time independent function calls
//
Expand Down
23 changes: 10 additions & 13 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -5816,21 +5816,19 @@ algorithm
end match;
end traverseStateSetsJacobiansExp;

public function traverseBackendDAEExpsNoCopyWithUpdate "
This function goes through the BackendDAE structure and finds all the
public function traverseBackendDAEExpsNoCopyWithUpdate<A>
"This function goes through the BackendDAE structure 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;
an extra argument passed through the function."
input BackendDAE.BackendDAE inBackendDAE;
input FuncExpType func;
input Type_a inTypeA;
output Type_a outTypeA;
input A inTypeA;
output A outTypeA;
partial function FuncExpType
input DAE.Exp inExp;
input Type_a inTypeA;
input A inTypeA;
output DAE.Exp outExp;
output Type_a outA;
output A outA;
end FuncExpType;
algorithm
outTypeA := matchcontinue inBackendDAE
Expand Down Expand Up @@ -6551,9 +6549,6 @@ algorithm
simDAE := FindZeroCrossings.findZeroCrossings(simDAE);
SimCodeFunctionUtil.execStat("findZeroCrossings");

_ := traverseBackendDAEExpsNoCopyWithUpdate(simDAE, ExpressionSimplify.simplifyTraverseHelper, 0) "simplify all expressions";
SimCodeFunctionUtil.execStat("SimplifyAllExp");

outSimDAE := calculateValues(simDAE);
SimCodeFunctionUtil.execStat("calculateValue");

Expand Down Expand Up @@ -7235,6 +7230,7 @@ algorithm
(BackendDAEOptimize.removeEqualFunctionCalls, "removeEqualFunctionCalls", false),
(BackendDAEOptimize.removeUnusedParameter, "removeUnusedParameter", false),
(BackendDAEOptimize.removeUnusedVariables, "removeUnusedVariables", false),
(BackendDAEOptimize.simplifyAllExpressions, "simplifyAllExpressions", false),
(BackendDAEOptimize.simplifyComplexFunction, "simplifyComplexFunction", false),
(BackendDAEOptimize.simplifyLoops, "simplifyLoops", false),
(BackendDAEOptimize.simplifyTimeIndepFuncCalls, "simplifyTimeIndepFuncCalls", false),
Expand Down Expand Up @@ -7286,7 +7282,8 @@ protected
list<tuple<BackendDAEFunc.postOptimizationDAEModule, String, Boolean/*stopOnFailure*/>> allInitOptModules;
list<String> initOptModules;
algorithm
allInitOptModules := {(BackendDAEOptimize.simplifyComplexFunction, "simplifyComplexFunction", false),
allInitOptModules := {(BackendDAEOptimize.simplifyAllExpressions, "simplifyAllExpressions", false),
(BackendDAEOptimize.simplifyComplexFunction, "simplifyComplexFunction", false),
(BackendDAEOptimize.simplifyLoops, "simplifyLoops", false),
(DynamicOptimization.reduceDynamicOptimization, "reduceDynamicOptimization", false),
(DynamicOptimization.removeLoops, "extendDynamicOptimization", false),
Expand Down
6 changes: 5 additions & 1 deletion Compiler/Util/Flags.mo
Expand Up @@ -795,6 +795,7 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
"generateSymbolicLinearization",
"removeConstants",
"simplifyTimeIndepFuncCalls",
"simplifyAllExpressions",
"addInitialStmtsToAlgorithms"
}),
SOME(STRING_DESC_OPTION({
Expand Down Expand Up @@ -833,6 +834,7 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
("removeUnusedParameter", Util.gettext("Strips all parameter not present in the equations from the system to get speed up for compilation of target code.")),
("removeUnusedVariables", Util.notrans("Strips all variables not present in the equations from the system to get speed up for compilation of target code.")),
("reshufflePost", Util.gettext("Reshuffles algebraic loops.")),
("simplifyAllExpressions", Util.notrans("Does simplifications on all expressions.")),
("simplifyComplexFunction", Util.notrans("Some simplifications on complex functions (complex refers to the internal data structure)")),
("simplifyConstraints", Util.notrans("Rewrites nonlinear constraints into box constraints if possible. This module requires +gDynOpt.")),
("simplifyLoops", Util.notrans("Simplifies algebraic loops. This modules requires +simplifyLoops.")),
Expand Down Expand Up @@ -1152,7 +1154,8 @@ constant ConfigFlag INIT_OPT_MODULES = CONFIG_FLAG(78, "initOptModules",
"simplifyLoops",
"recursiveTearing",
"calculateStrongComponentJacobians",
"solveSimpleEquations"
"solveSimpleEquations",
"simplifyAllExpressions"
//"inputDerivativesUsed",
//"extendDynamicOptimization"
}),
Expand All @@ -1163,6 +1166,7 @@ constant ConfigFlag INIT_OPT_MODULES = CONFIG_FLAG(78, "initOptModules",
("inputDerivativesUsed", Util.gettext("Checks if derivatives of inputs are need to calculate the model.")),
("recursiveTearing", Util.notrans("inline and repeat tearing")),
("reduceDynamicOptimization", Util.notrans("Removes equations which are not needed for the calculations of cost and constraints. This module requires +d=reduceDynOpt.")),
("simplifyAllExpressions", Util.notrans("Does simplifications on all expressions.")),
("simplifyComplexFunction", Util.notrans("Some simplifications on complex functions (complex refers to the internal data structure)")),
("simplifyConstraints", Util.notrans("Rewrites nonlinear constraints into box constraints if possible. This module requires +gDynOpt.")),
("simplifyLoops", Util.notrans("Simplifies algebraic loops. This modules requires +simplifyLoops.")),
Expand Down

0 comments on commit e7e6f99

Please sign in to comment.