Skip to content

Commit

Permalink
- run remove simple equations also in past optimisation phase
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8059 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Mar 2, 2011
1 parent 9c202be commit f49830e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 35 deletions.
27 changes: 27 additions & 0 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -107,6 +107,33 @@ end lateInlineDAE;
* remove simply equations stuff
*/

public function removeSimpleEquationsPast
"function lateInlineDAE"
input BackendDAE.BackendDAE inDAE;
input DAE.FunctionTree inFunctionTree;
input BackendDAE.IncidenceMatrix inM;
input BackendDAE.IncidenceMatrix inMT;
input array<Integer> inAss1;
input array<Integer> inAss2;
input list<list<Integer>> inComps;
output BackendDAE.BackendDAE outDAE;
output BackendDAE.IncidenceMatrix outM;
output BackendDAE.IncidenceMatrix outMT;
output array<Integer> outAss1;
output array<Integer> outAss2;
output list<list<Integer>> outComps;
output Boolean outRunMatching;
protected
Option<BackendDAE.IncidenceMatrix> om,omT;
algorithm
(outDAE,om,omT) := removeSimpleEquations(inDAE,inFunctionTree,SOME(inM),SOME(inMT));
(outM,outMT) := BackendDAEUtil.getIncidenceMatrixfromOption(outDAE,om,omT);
outAss1 := inAss1;
outAss2 := inAss2;
outComps := inComps;
outRunMatching := true; // until remove simple equations does not update incidence matrix
end removeSimpleEquationsPast;

public function removeSimpleEquations
"function: removeSimpleEquations
This function moves simple equations on the form a=b from equations 2nd
Expand Down
35 changes: 5 additions & 30 deletions Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -48,8 +48,6 @@ public import DAE;


protected import BackendDump;
protected import BackendDAECreate;
protected import BackendDAEOptimize;
protected import BackendDAEUtil;
protected import BackendEquation;
protected import BackendVariable;
Expand Down Expand Up @@ -110,17 +108,10 @@ algorithm
BackendDAE.Value nvars,neqns,memsize;
String ns,ne;
BackendDAE.Assignments assign1,assign2,ass1,ass2;
BackendDAE.BackendDAE dae,dae_1,dae_2;
BackendDAE.Variables v,kv,vars,exv;
BackendDAE.AliasVariables av;
BackendDAE.EquationArray e,re,ie,eqns;
array<BackendDAE.MultiDimEquation> ae;
array<DAE.Algorithm> al;
BackendDAE.EventInfo ev,einfo;
BackendDAE.BackendDAE dae;
BackendDAE.Variables vars;
BackendDAE.EquationArray eqns;
array<list<BackendDAE.Value>> m,mt,m_1,mt_1;
BackendDAE.BinTree s;
list<BackendDAE.Equation> e_lst,re_lst,ie_lst;
list<BackendDAE.MultiDimEquation> ae_lst;
array<BackendDAE.Value> vec1,vec2;
BackendDAE.MatchingOptions match_opts;
/* fail case if daelow is empty */
Expand All @@ -147,27 +138,11 @@ algorithm
memsize = nvars + nvars "Worst case, all eqns are differentiated once. Create nvars2 assignment elements" ;
assign1 = assignmentsCreate(nvars, memsize, 0);
assign2 = assignmentsCreate(nvars, memsize, 0);
(ass1,ass2,dae,m,mt,_,_) = matchingAlgorithm2(dae, m, mt, nvars, neqns, 1, assign1, assign2, match_opts,inFunctions,{},{});
/* NOTE: Here it could be possible to run removeSimpleEquations again, since algebraic equations
could potentially be removed after a index reduction has been done. However, removing equations here
also require that e.g. zero crossings, array equations, etc. must be recalculated. */
(dae_1,_,_) = BackendDAEOptimize.removeSimpleEquations(dae,inFunctions,SOME(m),SOME(mt));
m_1 = BackendDAEUtil.incidenceMatrix(dae_1, BackendDAE.NORMAL())
"Rerun matching to get updated assignments and incidence matrices
TODO: instead of rerunning: find out which equations are removed
and remove those from assignments and incidence matrix.";
mt_1 = BackendDAEUtil.transposeMatrix(m_1);
BackendDAEEXT.clearDifferentiated();
nvars = arrayLength(m_1);
neqns = arrayLength(mt_1);
memsize = nvars + nvars;
assign1 = assignmentsCreate(nvars, memsize, 0);
assign2 = assignmentsCreate(nvars, memsize, 0);
(ass1,ass2,dae_2,m,mt,_,_) = matchingAlgorithm2(dae_1, m_1, mt_1, nvars, neqns, 1, assign1, assign2, match_opts, inFunctions,{},{});
(ass1,ass2,dae,m_1,mt_1,_,_) = matchingAlgorithm2(dae, m, mt, nvars, neqns, 1, assign1, assign2, match_opts,inFunctions,{},{});
vec1 = assignmentsVector(ass1);
vec2 = assignmentsVector(ass2);
then
(vec1,vec2,dae_2,m,mt);
(vec1,vec2,dae,m_1,mt_1);

case ((dae as BackendDAE.DAE(orderedVars = vars,orderedEqs = eqns)),m,mt,(match_opts as (_,_,BackendDAE.KEEP_SIMPLE_EQN())),inFunctions)
equation
Expand Down
1 change: 1 addition & 0 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -5576,6 +5576,7 @@ protected
list<tuple<pastoptimiseDAEModule,String>> allPastOptModules;
algorithm
allPastOptModules := {(BackendDAEOptimize.lateInlineDAE,"lateInline"),
(BackendDAEOptimize.removeSimpleEquationsPast,"removeSimpleEquations"),
(BackendDump.dumpComponentsGraphStr,"dumpComponentsGraphStr")};
pastOptModules := selectOptModules(strPastOptModules,allPastOptModules,{});
pastOptModules := listReverse(pastOptModules);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -939,7 +939,7 @@ algorithm
funcs = Env.getFunctionTree(cache);
dlow = BackendDAECreate.lower(dae,funcs,true);
preOptModules = {"removeSimpleEquations","removeParameterEqns","expandDerOperator"};
pastOptModules = {"lateInline"};
pastOptModules = {"lateInline","removeSimpleEquations"};
(dlow_1,m,mT,ass1,ass2,comps) = BackendDAEUtil.getSolvedSystem(cache, env, dlow, funcs,
preOptModules, BackendDAETransform.dummyDerivative, pastOptModules);
Debug.fprintln("dynload", "translateModel: Generating simulation code and functions.");
Expand Down Expand Up @@ -1068,7 +1068,7 @@ algorithm
funcs = Env.getFunctionTree(cache);
dlow = BackendDAECreate.lower(dae,funcs,true);
preOptModules = {"removeSimpleEquations","removeParameterEqns","expandDerOperator"};
pastOptModules = {"lateInline"};
pastOptModules = {"lateInline","removeSimpleEquations"};
(dlow_1,m,mT,ass1,ass2,comps) = BackendDAEUtil.getSolvedSystem(cache, env, dlow, funcs,
preOptModules, BackendDAETransform.dummyDerivative, pastOptModules);
(indexed_dlow_1,libs,file_dir,timeBackend,timeSimCode,timeTemplates) =
Expand Down
1 change: 0 additions & 1 deletion Compiler/BackEnd/XMLDump.mo
Expand Up @@ -90,7 +90,6 @@ protected import Algorithm;
protected import BackendDAEUtil;
protected import BackendDAETransform;
protected import BackendVariable;
protected import BackendDAEOptimize;
protected import ComponentReference;
protected import DAEUtil;
protected import Dump;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Main/Main.mo
Expand Up @@ -779,7 +779,7 @@ algorithm
dlow = BackendDAECreate.lower(dae,funcs,true);
preOptModules = {"removeSimpleEquations","removeParameterEqns","expandDerOperator"};
pastOptModules = Util.listConsOnTrue(RTOpts.debugFlag("dumpcompgraph"),"dumpComponentsGraphStr",{});
pastOptModules = "lateInline"::pastOptModules;
pastOptModules = "removeSimpleEquations"::("lateInline"::pastOptModules);
(dlow_1,m,mT,v1,v2,comps) = BackendDAEUtil.getSolvedSystem(cache,env,dlow,funcs,preOptModules,BackendDAETransform.dummyDerivative,pastOptModules);
modpar(dlow_1,v1,v2,comps);
simcodegen(dlow_1,funcs,classname,p,ap,daeimpl,m,mT,v1,v2,comps);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Script/CevalScript.mo
Expand Up @@ -3186,7 +3186,7 @@ algorithm
funcs = Env.getFunctionTree(cache);
dlow = BackendDAECreate.lower(dae, funcs, true);
preOptModules = {"removeSimpleEquations","removeParameterEqns","expandDerOperator"};
pastOptModules = {"lateInline"};
pastOptModules = {"lateInline","removeSimpleEquations"};
(indexed_dlow,_,_,_,_,_) = BackendDAEUtil.getSolvedSystem(cache, env, dlow, funcs,
preOptModules, BackendDAETransform.dummyDerivative, pastOptModules);
xml_filename = stringAppendList({filenameprefix,".xml"});
Expand Down

0 comments on commit f49830e

Please sign in to comment.