Skip to content

Commit

Permalink
add module simplifyTimeIndepFuncCalls
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12047 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jun 13, 2012
1 parent 710c467 commit 1e14e3e
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 23 deletions.
160 changes: 139 additions & 21 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -8279,6 +8279,144 @@ algorithm
end matchcontinue;
end residualForm2;

/*
* simplify time independent function calls
*
*/

public function simplifyTimeIndepFuncCalls
"function simplifyTimeIndepFuncCalls
simplifies time independent built in function calls like
pre(param) -> param
der(param) -> 0.0
change(param) -> false
edge(param) -> false
author: Frenkel TUD 2012-06"
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
output Boolean outRunMatching;
algorithm
(outDAE,outRunMatching) := BackendDAEUtil.mapEqSystemAndFold(inDAE,simplifyTimeIndepFuncCalls0,false);
outDAE := simplifyTimeIndepFuncCallsShared(outDAE);
end simplifyTimeIndepFuncCalls;

protected function simplifyTimeIndepFuncCalls0
"function simplifyTimeIndepFuncCalls0
author: Frenkel TUD 2012-06"
input BackendDAE.EqSystem isyst;
input tuple<BackendDAE.Shared,Boolean> sharedChanged;
output BackendDAE.EqSystem osyst;
output tuple<BackendDAE.Shared,Boolean> osharedChanged;
algorithm
(osyst,osharedChanged) :=
matchcontinue(isyst,sharedChanged)
local
BackendDAE.Variables orderedVars "orderedVars ; ordered Variables, only states and alg. vars" ;
BackendDAE.EquationArray orderedEqs "orderedEqs ; ordered Equations" ;
Option<BackendDAE.IncidenceMatrix> m;
Option<BackendDAE.IncidenceMatrixT> mT;
BackendDAE.Matching matching;
BackendDAE.EqSystem syst;
BackendDAE.Shared shared;
case (BackendDAE.EQSYSTEM(orderedVars,orderedEqs,m,mT,matching),(shared, _))
equation
((_,true)) = BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(orderedEqs,traversersimplifyTimeIndepFuncCalls,(BackendVariable.daeKnVars(shared),false));
then
(BackendDAE.EQSYSTEM(orderedVars,orderedEqs,m,mT,matching),(shared,true));
else
(isyst,sharedChanged);
end matchcontinue;
end simplifyTimeIndepFuncCalls0;

protected function traversersimplifyTimeIndepFuncCalls
"function traversersimplifyTimeIndepFuncCalls
author: Frenkel TUD 2012-06"
input tuple<DAE.Exp,tuple<BackendDAE.Variables,Boolean>> tpl;
output tuple<DAE.Exp,tuple<BackendDAE.Variables,Boolean>> outTpl;
protected
DAE.Exp e;
tuple<BackendDAE.Variables,Boolean> tpl;
algorithm
(e,tpl) := tpl;
outTpl := Expression.traverseExp(e,traverserExpsimplifyTimeIndepFuncCalls,tpl);
end traversersimplifyTimeIndepFuncCalls;

protected function traverserExpsimplifyTimeIndepFuncCalls
"function traverserExpsimplifyTimeIndepFuncCalls
author: Frenkel TUD 2012-06"
input tuple<DAE.Exp,tuple<BackendDAE.Variables,Boolean>> tpl;
output tuple<DAE.Exp,tuple<BackendDAE.Variables,Boolean>> outTpl;
algorithm
outTpl := matchcontinue(tpl)
local
BackendDAE.Variables vars;
DAE.Type tp;
DAE.Exp e,zero;
DAE.ComponentRef cr;
case((DAE.CALL(path=Absyn.IDENT(name = "der"),expLst={DAE.CREF(componentRef=cr,ty=tp)}),(vars,_)))
equation
(_,_) = BackendVariable.getVar(cr, vars);
(zero,_) = Expression.makeZeroExpression(Expression.arrayDimension(tp));
then
((zero,(vars,true)));
case((DAE.CALL(path=Absyn.IDENT(name = "pre"),expLst={e as DAE.CREF(componentRef=cr,ty=tp)}),(vars,_)))
equation
(_,_) = BackendVariable.getVar(cr, vars);
then
((e,(vars,true)));
case((DAE.CALL(path=Absyn.IDENT(name = "change"),expLst={e as DAE.CREF(componentRef=cr,ty=tp)}),(vars,_)))
equation
(_,_) = BackendVariable.getVar(cr, vars);
then
((DAE.BCONST(false),(vars,true)));
case((DAE.CALL(path=Absyn.IDENT(name = "edge"),expLst={e as DAE.CREF(componentRef=cr,ty=tp)}),(vars,_)))
equation
(_,_) = BackendVariable.getVar(cr, vars);
then
((DAE.BCONST(false),(vars,true)));
case tpl then tpl;
end matchcontinue;
end traverserExpsimplifyTimeIndepFuncCalls;

protected function simplifyTimeIndepFuncCallsShared
"function simplifyTimeIndepFuncCallsShared
simplifies time independent built in function calls like
pre(param) -> param
der(param) -> 0.0
change(param) -> false
edge(param) -> false
author: Frenkel TUD 2012-06"
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
outDAE:= match (inDAE)
local
BackendDAE.Variables knvars,exobj;
BackendDAE.AliasVariables aliasVars;
BackendDAE.EquationArray remeqns,inieqns;
array<BackendDAE.MultiDimEquation> arreqns;
array<DAE.Algorithm> algorithms;
array<DAE.Constraint> constrs;
array<BackendDAE.ComplexEquation> complEqs;
DAE.FunctionTree funcTree;
BackendDAE.EventInfo einfo;
BackendDAE.ExternalObjectClasses eoc;
BackendDAE.SymbolicJacobians symjacs;
BackendDAE.EventInfo eventInfo;
BackendDAE.BackendDAEType btp;
BackendDAE.EqSystems systs;
BackendDAE.Shared shared;
case (BackendDAE.DAE(systs,BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,arreqns,algorithms,constrs,complEqs,funcTree,eventInfo,eoc,btp,symjacs)))
equation
_ = BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(inieqns,traversersimplifyTimeIndepFuncCalls,(knvars,false));
_ = BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(remeqns,traversersimplifyTimeIndepFuncCalls,(knvars,false));
(arreqns,_) = BackendDAEUtil.traverseBackendDAEArrayNoCopyWithUpdate(arreqns,traversersimplifyTimeIndepFuncCalls,BackendEquation.traverseBackendDAEExpsArrayEqnWithUpdate,1,arrayLength(arreqns),(knvars,false));
(algorithms,_) = BackendDAEUtil.traverseBackendDAEArrayNoCopyWithUpdate(algorithms,traversersimplifyTimeIndepFuncCalls,BackendEquation.traverseBackendDAEExpsAlgortihmWithUpdate,1,arrayLength(algorithms),(knvars,false));
(complEqs,_) = BackendDAEUtil.traverseBackendDAEArrayNoCopyWithUpdate(complEqs,traversersimplifyTimeIndepFuncCalls,BackendEquation.traverseBackendDAEExpsComplexWithUpdate,1,arrayLength(complEqs),(knvars,false));
then
BackendDAE.DAE(systs,BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,arreqns,algorithms,constrs,complEqs,funcTree,eventInfo,eoc,btp,symjacs));
end match;
end simplifyTimeIndepFuncCallsShared;

/*
* tearing
Expand Down Expand Up @@ -8306,29 +8444,9 @@ algorithm
(osyst,osharedChanged) :=
matchcontinue(isyst,sharedChanged)
local
BackendDAE.BackendDAE dae,dae1;
DAE.FunctionTree funcs;
BackendDAE.Variables vars,knvars,exobj,avars,vars1,knvars1;
BackendDAE.AliasVariables aliasVars;
BackendDAE.EquationArray eqns,remeqns,inieqns,eqns1;
array<BackendDAE.MultiDimEquation> arreqns;
array<DAE.Algorithm> algorithms;
array<DAE.Constraint> constrs;
array<BackendDAE.ComplexEquation> complEqs;
BackendDAE.EventInfo einfo;
list<BackendDAE.WhenClause> whenClauseLst;
BackendDAE.ExternalObjectClasses eoc;
BackendDAE.SymbolicJacobians symjacs;
BackendDAE.IncidenceMatrix m;
BackendDAE.IncidenceMatrix mT;
array<Integer> ass1,ass2;
BackendDAE.StrongComponents comps,comps1;
BackendDAE.StrongComponents comps;
Boolean b,b1,b2;
list<Integer> eqnlst;
BackendDAE.BinTree movedVars;
BackendDAE.Shared shared;
BackendDAE.BackendDAEType btp;
BackendDAE.Matching matching;
BackendDAE.EqSystem syst;

case (syst as BackendDAE.EQSYSTEM(matching=BackendDAE.MATCHING(comps=comps)),(shared, b1))
Expand Down
3 changes: 2 additions & 1 deletion Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -8235,7 +8235,8 @@ algorithm
(BackendDAEOptimize.generateSymbolicJacobianPast,"generateSymbolicJacobian",false),
(BackendDAEOptimize.generateSymbolicLinearizationPast,"generateSymbolicLinearization",false),
(BackendDAEOptimize.collapseIndependentBlocksPast,"collapseIndependentBlocks",true),
(BackendDAEOptimize.removeUnusedFunctionsPast,"removeUnusedFunctions",false)};
(BackendDAEOptimize.removeUnusedFunctionsPast,"removeUnusedFunctions",false),
(BackendDAEOptimize.simplifyTimeIndepFuncCalls,"simplifyTimeIndepFuncCalls",false)};
strPastOptModules := getPastOptModulesString();
strPastOptModules := Util.getOptionOrDefault(ostrPastOptModules,strPastOptModules);
pastOptModules := selectOptModules(strPastOptModules,allPastOptModules,{});
Expand Down
4 changes: 3 additions & 1 deletion Compiler/Util/Flags.mo
Expand Up @@ -573,7 +573,9 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(15, "postOptModules",
("generateSymbolicJacobian", "Generates symbolic jacobian"),
("generateSymbolicLinearization", "Generates symbolic Linearization Matrixes A,B,C,D for Linear Model:\n\t\t\\dot x = Ax + Bu\n\t\ty = Cx +Du"),
("collapseIndependentBlocks", "Collapses all equation systems back into one big system again (undo partitionIndependentBlocks)"),
("removeUnusedFunctions", "removed all unused functions from functionTree")})),
("removeUnusedFunctions", "removed all unused functions from functionTree"),
("simplifyTimeIndepFuncCalls","simplifies time independent built in function calls like pre(param) -> param, der(param) -> 0.0, change(param) -> false, edge(param) -> false")
})),
"Sets the post optimisation modules to use in the back end. See +help=optmodules for more info.");
constant ConfigFlag SIMCODE_TARGET = CONFIG_FLAG(16, "simCodeTarget",
NONE(), EXTERNAL(), STRING_FLAG("C"),
Expand Down

0 comments on commit 1e14e3e

Please sign in to comment.