Skip to content

Commit

Permalink
- add module replaceEdgeChange
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13940 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Nov 17, 2012
1 parent 1fde101 commit 0a0f193
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
108 changes: 108 additions & 0 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -14152,6 +14152,114 @@ algorithm
end matchcontinue;
end removeConstantsFinder;


/*
* reaplace edge and change with (b and not pre(b)) and (v <> pre(v)
*
*/
public function replaceEdgeChange "function replaceEdgeChange
replace
edge(b) = b and not pre(b)
change(b) = v <> pre(v)
author: Frenkel TUD 2012-11"
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
(outDAE,_) := BackendDAEUtil.mapEqSystemAndFold(inDAE,replaceEdgeChange0,false);
outDAE := replaceEdgeChangeShared(outDAE);
end replaceEdgeChange;

protected function replaceEdgeChange0 "function replaceEdgeChange0
author: Frenkel TUD 2012-11"
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;
BackendDAE.EquationArray orderedEqs;
Option<BackendDAE.IncidenceMatrix> m;
Option<BackendDAE.IncidenceMatrixT> mT;
BackendDAE.Matching matching;
BackendDAE.Shared shared;
case (BackendDAE.EQSYSTEM(orderedVars,orderedEqs,m,mT,matching),(shared, _))
equation
true = BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(orderedEqs,traverserreplaceEdgeChange,false);
then
(BackendDAE.EQSYSTEM(orderedVars,orderedEqs,m,mT,matching),(shared,true));
else
(isyst,sharedChanged);
end matchcontinue;
end replaceEdgeChange0;

protected function traverserreplaceEdgeChange "function
author: Frenkel TUD 2012-11"
input tuple<DAE.Exp,Boolean> itpl;
output tuple<DAE.Exp,Boolean> outTpl;
protected
DAE.Exp e;
Boolean b;
algorithm
(e,b) := itpl;
outTpl := Expression.traverseExp(e,traverserExpreplaceEdgeChange,b);
end traverserreplaceEdgeChange;

protected function traverserExpreplaceEdgeChange "function traverserExpreplaceEdgeChange
author: Frenkel TUD 2012-11"
input tuple<DAE.Exp,Boolean> tpl;
output tuple<DAE.Exp,Boolean> outTpl;
algorithm
outTpl := matchcontinue(tpl)
local
DAE.Exp e;
DAE.Type ty;
// change(v) -> v <> pre(v)
case((DAE.CALL(path=Absyn.IDENT(name = "change"),expLst={e}),_))
equation
ty = Expression.typeof(e);
then
((DAE.RELATION(e,DAE.NEQUAL(ty),DAE.CALL(Absyn.IDENT("pre"),{e},DAE.CALL_ATTR(ty,false,true,DAE.NO_INLINE(),DAE.NO_TAIL())),-1,NONE()),true));
// edge(b) = b and not pre(b)
case((DAE.CALL(path=Absyn.IDENT(name = "edge"),expLst={e}),_))
equation
ty = Expression.typeof(e);
then
((DAE.LBINARY(e,DAE.AND(ty),DAE.LUNARY(DAE.NOT(ty),DAE.CALL(Absyn.IDENT("pre"),{e},DAE.CALL_ATTR(ty,false,true,DAE.NO_INLINE(),DAE.NO_TAIL())))),true));
case _ then tpl;
end matchcontinue;
end traverserExpreplaceEdgeChange;

protected function replaceEdgeChangeShared "function replaceEdgeChangeShared
author: Frenkel TUD 2012-11"
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
outDAE:= match (inDAE)
local
BackendDAE.Variables knvars,exobj,aliasVars;
BackendDAE.EquationArray remeqns,inieqns;
array<DAE.Constraint> constrs;
array<DAE.ClassAttributes> clsAttrs;
Env.Cache cache;
Env.Env env;
DAE.FunctionTree funcTree;
BackendDAE.ExternalObjectClasses eoc;
BackendDAE.SymbolicJacobians symjacs;
BackendDAE.EventInfo eventInfo;
BackendDAE.BackendDAEType btp;
BackendDAE.EqSystems systs;
case (BackendDAE.DAE(systs,BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcTree,eventInfo,eoc,btp,symjacs)))
equation
_ = BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(remeqns,traverserreplaceEdgeChange,false);
then
BackendDAE.DAE(systs,BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcTree,eventInfo,eoc,btp,symjacs));
end match;
end replaceEdgeChangeShared;


/*
* optimize inital system
*
Expand Down
1 change: 1 addition & 0 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -8728,6 +8728,7 @@ algorithm
(BackendDAEOptimize.collapseIndependentBlocks,"collapseIndependentBlocks",true),
(BackendDAECreate.expandDerOperator,"expandDerOperator",false),
(BackendDAEOptimize.simplifyIfEquations,"simplifyIfEquations",false),
(BackendDAEOptimize.replaceEdgeChange,"replaceEdgeChange",false),
(BackendDAEOptimize.residualForm,"residualForm",false)
};
strPreOptModules := getPreOptModulesString();
Expand Down
1 change: 1 addition & 0 deletions Compiler/Util/Flags.mo
Expand Up @@ -573,6 +573,7 @@ public constant ConfigFlag PRE_OPT_MODULES = CONFIG_FLAG(12, "preOptModules",
("collapseIndependentBlocks", Util.gettext("Collapses all equation systems back into one big system again (undo partitionIndependentBlocks)")),
("expandDerOperator", Util.notrans("DESCRIBE ME")),
("simplifyIfEquations", Util.gettext("tries to simplify if equations by use of information from evaluated parameters")),
("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"))})),
Util.gettext("Sets the pre optimization modules to use in the back end. See +help=optmodules for more info."));
constant ConfigFlag CHEAPMATCHING_ALGORITHM = CONFIG_FLAG(13, "cheapmatchingAlgorithm",
Expand Down

0 comments on commit 0a0f193

Please sign in to comment.