Skip to content

Commit 9f2dcd2

Browse files
author
Jens Frenkel
committed
- remove unused code
- rewrite collect zero crossings function interface to run it only once(not in lower and matching) git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8057 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 8898c8f commit 9f2dcd2

File tree

5 files changed

+54
-49
lines changed

5 files changed

+54
-49
lines changed

Compiler/BackEnd/BackendDAECreate.mo

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected
8787
BackendDAE.AliasVariables aliasVars "hash table with alias vars' replacements (a=b or a=-b)";
8888
list<BackendDAE.Equation> eqns,reqns,ieqns,algeqns,algeqns1,ialgeqns,multidimeqns,imultidimeqns,eqns_1;
8989
list<BackendDAE.MultiDimEquation> aeqns,aeqns1,iaeqns;
90-
list<DAE.Algorithm> algs,algs_1,ialgs;
90+
list<DAE.Algorithm> algs,ialgs;
9191
list<BackendDAE.WhenClause> whenclauses,whenclauses_1;
9292
BackendDAE.EquationArray eqnarr,reqnarr,ieqnarr;
9393
array<BackendDAE.MultiDimEquation> arr_md_eqns;
@@ -127,13 +127,12 @@ algorithm
127127
vars_1 := detectImplicitDiscrete(vars, eqns);
128128
vars_1 := detectImplicitDiscreteAlgs(vars_1,knvars, algs);
129129
eqns_1 := sortEqn(eqns);
130-
(zero_crossings,eqns_1,aeqns,whenclauses_1,algs_1) := findZeroCrossings(vars_1,knvars,eqns_1,aeqns,whenclauses_1,algs);
131130
eqnarr := BackendDAEUtil.listEquation(eqns_1);
132131
reqnarr := BackendDAEUtil.listEquation(reqns);
133132
ieqnarr := BackendDAEUtil.listEquation(ieqns);
134133
arr_md_eqns := listArray(aeqns);
135-
algarr := listArray(algs_1);
136-
einfo := Inline.inlineEventInfo(BackendDAE.EVENT_INFO(whenclauses_1,zero_crossings),(SOME(functionTree),{DAE.NORM_INLINE()}));
134+
algarr := listArray(algs);
135+
einfo := Inline.inlineEventInfo(BackendDAE.EVENT_INFO(whenclauses_1,{}),(SOME(functionTree),{DAE.NORM_INLINE()}));
137136
aliasVars := BackendDAEUtil.emptyAliasVariables();
138137
outBackendDAE := BackendDAE.DAE(vars_1,knvars,extVars,aliasVars,eqnarr,reqnarr,ieqnarr,arr_md_eqns,algarr,einfo,extObjCls);
139138
end lower;
@@ -2788,21 +2787,39 @@ end differentZeroCrossing;
27882787
public function findZeroCrossings "function: findZeroCrossings
27892788

27902789
This function finds all zerocrossings in the list of equations and
2791-
the list of when clauses. Used in lower2.
2790+
the list of when clauses.
27922791
"
2793-
input BackendDAE.Variables vars;
2794-
input BackendDAE.Variables knvars;
2795-
input list<BackendDAE.Equation> eq;
2796-
input list<BackendDAE.MultiDimEquation> multiDimEqs;
2797-
input list<BackendDAE.WhenClause> wc;
2798-
input list<DAE.Algorithm> algs;
2799-
output list<BackendDAE.ZeroCrossing> res_1;
2800-
output list<BackendDAE.Equation> outEquationLst;
2801-
output list<BackendDAE.MultiDimEquation> outMultiDimEqs;
2802-
output list<BackendDAE.WhenClause> outWhenClauseLst;
2803-
output list<DAE.Algorithm> outAlgs;
2792+
input BackendDAE.BackendDAE inDAE;
2793+
output BackendDAE.BackendDAE outDAE;
28042794
algorithm
2805-
(res_1,outEquationLst,outMultiDimEqs,outWhenClauseLst,outAlgs) := findZeroCrossings2(vars, knvars,eq,multiDimEqs,0, wc, 0, algs,0,{},0);
2795+
outDAE:=
2796+
match (inDAE)
2797+
local
2798+
BackendDAE.Variables vars,knvars,exobj;
2799+
BackendDAE.AliasVariables av;
2800+
BackendDAE.EquationArray eqns,remeqns,inieqns,eqns1;
2801+
array<BackendDAE.MultiDimEquation> arreqns,arreqns1;
2802+
array<DAE.Algorithm> algorithms,algorithms1;
2803+
BackendDAE.EventInfo einfo,einfo1;
2804+
BackendDAE.ExternalObjectClasses eoc;
2805+
list<BackendDAE.WhenClause> whenclauses,whenclauses1;
2806+
list<BackendDAE.Equation> eqs_lst,eqs_lst1;
2807+
list<BackendDAE.MultiDimEquation> arreqns_lst,arreqns_lst1;
2808+
list<DAE.Algorithm> algs_lst,algs_lst1;
2809+
list<BackendDAE.ZeroCrossing> zero_crossings;
2810+
case (BackendDAE.DAE(vars,knvars,exobj,av,eqns,remeqns,inieqns,arreqns,algorithms,einfo as BackendDAE.EVENT_INFO(whenClauseLst=whenclauses),eoc))
2811+
equation
2812+
eqs_lst = BackendDAEUtil.equationList(eqns);
2813+
arreqns_lst = arrayList(arreqns);
2814+
algs_lst = arrayList(algorithms);
2815+
(zero_crossings,eqs_lst1,arreqns_lst1,whenclauses1,algs_lst1) = findZeroCrossings2(vars, knvars,eqs_lst,arreqns_lst,0, whenclauses, 0, algs_lst,0,{},0);
2816+
eqns1 = BackendDAEUtil.listEquation(eqs_lst1);
2817+
arreqns1 = listArray(arreqns_lst);
2818+
algorithms1 = listArray(algs_lst1);
2819+
einfo1 = BackendDAE.EVENT_INFO(whenclauses1,zero_crossings);
2820+
then
2821+
(BackendDAE.DAE(vars,knvars,exobj,av,eqns1,remeqns,inieqns,arreqns1,algorithms1,einfo1,eoc));
2822+
end match;
28062823
end findZeroCrossings;
28072824

28082825
protected function findZeroCrossings2 "function: findZeroCrossings2

Compiler/BackEnd/BackendDAETransform.mo

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ algorithm
123123
list<BackendDAE.MultiDimEquation> ae_lst;
124124
array<BackendDAE.Value> vec1,vec2;
125125
BackendDAE.MatchingOptions match_opts;
126-
BackendDAE.ExternalObjectClasses eoc;
127-
list<BackendDAE.WhenClause> whenclauses;
128-
list<BackendDAE.ZeroCrossing> zero_crossings;
129-
list<DAE.Algorithm> algs;
130126
/* fail case if daelow is empty */
131127
case ((dae as BackendDAE.DAE(orderedVars = vars,orderedEqs = eqns)),m,mt,match_opts,inFunctions)
132128
equation
@@ -155,16 +151,7 @@ algorithm
155151
/* NOTE: Here it could be possible to run removeSimpleEquations again, since algebraic equations
156152
could potentially be removed after a index reduction has been done. However, removing equations here
157153
also require that e.g. zero crossings, array equations, etc. must be recalculated. */
158-
(dae as BackendDAE.DAE(v,kv,exv,av,e,re,ie,ae,al,ev,eoc),_,_) = BackendDAEOptimize.removeSimpleEquations(dae,inFunctions,SOME(m),SOME(mt));
159-
BackendDAE.EVENT_INFO(whenClauseLst=whenclauses) = ev;
160-
e_lst = BackendDAEUtil.equationList(e);
161-
ae_lst = arrayList(ae);
162-
algs = arrayList(al);
163-
(zero_crossings,e_lst,ae_lst,whenclauses,algs) = BackendDAECreate.findZeroCrossings(v,kv,e_lst,ae_lst,whenclauses,algs);
164-
e = BackendDAEUtil.listEquation(e_lst);
165-
ae = listArray(ae_lst);
166-
einfo = BackendDAE.EVENT_INFO(whenclauses,zero_crossings);
167-
dae_1 = BackendDAE.DAE(v,kv,exv,av,e,re,ie,ae,al,einfo,eoc);
154+
(dae_1,_,_) = BackendDAEOptimize.removeSimpleEquations(dae,inFunctions,SOME(m),SOME(mt));
168155
m_1 = BackendDAEUtil.incidenceMatrix(dae_1, BackendDAE.NORMAL())
169156
"Rerun matching to get updated assignments and incidence matrices
170157
TODO: instead of rerunning: find out which equations are removed
@@ -481,7 +468,7 @@ algorithm
481468

482469
case (dae,m,mt,nv,nf,i,ass1,ass2,(BackendDAE.INDEX_REDUCTION(),eq_cons,r_simple),inFunctions,derivedAlgs,derivedMultiEqn)
483470
equation
484-
((dae as BackendDAE.DAE(BackendDAE.VARIABLES(_,_,_,_,nv_1),BackendDAE.VARIABLES(_,_,_,_,nkv),_,_,eqns,_,_,_,_,_,_)),m,mt,derivedAlgs1,derivedMultiEqn1) = reduceIndexDummyDer(dae, m, mt, nv, nf, i, inFunctions,derivedAlgs,derivedMultiEqn)
471+
(dae,m,mt,derivedAlgs1,derivedMultiEqn1) = reduceIndexDummyDer(dae, m, mt, nv, nf, i, inFunctions,derivedAlgs,derivedMultiEqn)
485472
"path_found failed, Try index reduction using dummy derivatives.
486473
When a constraint exist between states and index reduction is needed
487474
the dummy derivative will select one of the states as a dummy state
@@ -492,6 +479,7 @@ algorithm
492479
In the dummy derivative method this equation is added and the original equation
493480
u1=u2 is kept. This is not the case for the original pantilides algorithm, where
494481
the original equation is removed from the system." ;
482+
eqns = BackendEquation.daeEqns(dae);
495483
nf_1 = BackendDAEUtil.equationSize(eqns) "and try again, restarting. This could be optimized later. It should not
496484
be necessary to restart the matching, according to Bernard Bachmann. Instead one
497485
could continue the matching as usual. This was tested (2004-11-22) and it does not
@@ -501,6 +489,7 @@ algorithm
501489
2004-12-29 PA. This was a bug, assignment lists needed to be expanded with the size
502490
of the system in order to work. SO: Matching is not needed to be restarted from
503491
scratch." ;
492+
nv_1 = BackendVariable.varsSize(BackendVariable.daeVars(dae));
504493
nvd = nv_1 - nv;
505494
ass1_1 = assignmentsExpand(ass1, nvd);
506495
ass2_1 = assignmentsExpand(ass2, nvd);

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3966,7 +3966,7 @@ algorithm
39663966
e_1 = e - 1;
39673967
eqn = equationNth(daeeqns, e_1);
39683968
row = incidenceRow(vars, eqn,wc);
3969-
m_1 = Util.arrayReplaceAtWithFill(row, e_1 + 1, m, {});
3969+
m_1 = Util.arrayReplaceAtWithFill(row, e, m, {});
39703970
changedvars1 = varsInEqn(m_1, e);
39713971
(m_2,changedvars2) = updateIncidenceMatrix2(dae, m_1, eqns);
39723972
then
@@ -4001,14 +4001,13 @@ algorithm
40014001
array<list<BackendDAE.Value>> m,mt,mt_1,mt_2;
40024002
list<list<BackendDAE.Value>> mlst;
40034003
list<BackendDAE.Value> row_1,vars;
4004-
BackendDAE.Value v_1,v;
4004+
BackendDAE.Value v;
40054005
case ({},m,mt) then mt;
40064006
case ((v :: vars),m,mt)
40074007
equation
40084008
mlst = arrayList(m);
40094009
row_1 = transposeRow(mlst, v, 1);
4010-
v_1 = v - 1;
4011-
mt_1 = Util.arrayReplaceAtWithFill(row_1, v_1 + 1, mt, {});
4010+
mt_1 = Util.arrayReplaceAtWithFill(row_1, v, mt, {});
40124011
mt_2 = updateTransposedMatrix(vars, m, mt_1);
40134012
then
40144013
mt_2;
@@ -5291,7 +5290,7 @@ public function getSolvedSystem
52915290
output Boolean outRunMatching;
52925291
end pastoptimiseDAEModule;
52935292
protected
5294-
BackendDAE.BackendDAE dae,optdae,sode,optsode,indexed_dlow;
5293+
BackendDAE.BackendDAE dae,optdae,sode,sode1,optsode,indexed_dlow;
52955294
Option<BackendDAE.IncidenceMatrix> om,omT;
52965295
BackendDAE.IncidenceMatrix m,mT,m_1,mT_1;
52975296
array<Integer> v1,v2,v1_1,v2_1;
@@ -5321,8 +5320,9 @@ algorithm
53215320
Debug.fcall("execstat",print, "*** BackendMain -> pastoptimiseDAE at time: " +& realString(clock()) +& "\n" );
53225321
(sode,outM,outMT,outAss1,outAss2,outComps) := pastoptimiseDAE(sode,functionTree,pastOptModules,m,mT,v1,v2,comps,daeHandler);
53235322

5323+
sode1 := BackendDAECreate.findZeroCrossings(sode);
53245324
Debug.fcall("execstat",print, "*** BackendMain -> translateDae: " +& realString(clock()) +& "\n" );
5325-
indexed_dlow := translateDae(sode,NONE());
5325+
indexed_dlow := translateDae(sode1,NONE());
53265326
outSODE := calculateValues(inCache, inEnv, indexed_dlow);
53275327
Debug.fcall("dumpindxdae", BackendDump.dump, outSODE);
53285328
end getSolvedSystem;

Compiler/BackEnd/BackendVariable.mo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,9 +2177,9 @@ public function daeVars
21772177
output BackendDAE.Variables vars;
21782178
algorithm
21792179
vars := match (inBackendDAE)
2180-
local BackendDAE.Variables vars1,vars2;
2181-
case (BackendDAE.DAE(orderedVars = vars1, knownVars = vars2))
2182-
then vars1;
2180+
local BackendDAE.Variables vars;
2181+
case (BackendDAE.DAE(orderedVars = vars))
2182+
then vars;
21832183
end match;
21842184
end daeVars;
21852185

@@ -2188,9 +2188,9 @@ public function daeKnVars
21882188
output BackendDAE.Variables vars;
21892189
algorithm
21902190
vars := match (inBackendDAE)
2191-
local BackendDAE.Variables vars1,vars2;
2192-
case (BackendDAE.DAE(orderedVars = vars1, knownVars = vars2))
2193-
then vars2;
2191+
local BackendDAE.Variables vars;
2192+
case (BackendDAE.DAE(knownVars = vars))
2193+
then vars;
21942194
end match;
21952195
end daeKnVars;
21962196

Compiler/Script/CevalScript.mo

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,15 @@ protected import BackendDAEOptimize;
6868
protected import BackendDAETransform;
6969
protected import BackendEquation;
7070
protected import BackendVariable;
71-
protected import ConnectionGraph;
7271
protected import ClassInf;
7372
protected import ClassLoader;
74-
protected import Connect;
7573
protected import DAEQuery;
7674
protected import DAEUtil;
7775
protected import DAEDump;
7876
protected import Debug;
7977
protected import Dump;
8078
protected import Error;
8179
protected import Expression;
82-
protected import ExpressionDump;
8380
protected import Inst;
8481
protected import InnerOuter;
8582
protected import Lookup;
@@ -100,7 +97,6 @@ protected import Settings;
10097
protected import SimulationResults;
10198
protected import Tpl;
10299
protected import Types;
103-
protected import UnitAbsyn;
104100
protected import Unparsing;
105101
protected import Util;
106102
protected import ValuesUtil;
@@ -1775,6 +1771,7 @@ algorithm
17751771
elimLevel = RTOpts.eliminationLevel();
17761772
RTOpts.setEliminationLevel(0); // No variable eliminiation
17771773
dlow = BackendDAECreate.lower(dae, Env.getFunctionTree(cache), false);
1774+
dlow = BackendDAECreate.findZeroCrossings(dlow);
17781775
RTOpts.setEliminationLevel(elimLevel); // Reset elimination level
17791776
flatModelicaStr = DAEDump.dumpStr(dae,Env.getFunctionTree(cache));
17801777
flatModelicaStr = stringAppend("OldEqStr={'", flatModelicaStr);
@@ -3137,6 +3134,7 @@ algorithm
31373134
dlow = BackendDAECreate.lower(dae, funcs, true); //Verificare cosa fa
31383135
(dlow_1,_,_) = BackendDAEUtil.preOptimiseBackendDAE(dlow,funcs,
31393136
{"removeSimpleEquations","removeParameterEqns","expandDerOperator"},NONE(),NONE());
3137+
dlow_1 = BackendDAECreate.findZeroCrossings(dlow_1);
31403138
xml_filename = stringAppendList({filenameprefix,".xml"});
31413139
funcelems = DAEUtil.getFunctionList(funcs);
31423140
Print.clearBuf();
@@ -3162,7 +3160,8 @@ algorithm
31623160
dlow = BackendDAECreate.lower(dae, funcs, true); //Verificare cosa fa
31633161
(dlow_1,om,omT) = BackendDAEUtil.preOptimiseBackendDAE(dlow,funcs,
31643162
{"removeSimpleEquations","removeParameterEqns","expandDerOperator"},NONE(),NONE());
3165-
(dlow_1,_,_,_,_,_) = BackendDAEUtil.transformDAE(dlow_1,funcs,BackendDAETransform.dummyDerivative,om,omT);
3163+
(dlow_1,_,_,_,_,_) = BackendDAEUtil.transformDAE(dlow_1,funcs,BackendDAETransform.dummyDerivative,om,omT);
3164+
dlow_1 = BackendDAECreate.findZeroCrossings(dlow_1);
31663165
xml_filename = stringAppendList({filenameprefix,".xml"});
31673166
funcelems = DAEUtil.getFunctionList(Env.getFunctionTree(cache));
31683167
Print.clearBuf();

0 commit comments

Comments
 (0)