Skip to content

Commit 2357b68

Browse files
author
Jens Frenkel
committed
- minor fixes for new dynamic state selection
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12048 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 1e14e3e commit 2357b68

File tree

3 files changed

+56
-45
lines changed

3 files changed

+56
-45
lines changed

Compiler/BackEnd/BackendDAETransform.mo

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,35 +1703,31 @@ public function reachableNodes "function: reachableNodes
17031703
that n1 solves for a variable (e.g. \'a\') that is used in the equation
17041704
of n2, i.e. the equation of n1 must be solved before the equation of n2.
17051705
"
1706-
input Integer inInteger1;
1707-
input BackendDAE.IncidenceMatrix inIncidenceMatrix2;
1708-
input BackendDAE.IncidenceMatrixT inIncidenceMatrixT3;
1709-
input array<Integer> inIntegerArray4;
1710-
input array<Integer> inIntegerArray5;
1706+
input Integer eqn;
1707+
input BackendDAE.IncidenceMatrix m;
1708+
input BackendDAE.IncidenceMatrixT mt;
1709+
input array<Integer> a1;
1710+
input array<Integer> a2;
17111711
output list<Integer> outIntegerLst;
17121712
algorithm
17131713
outIntegerLst:=
1714-
matchcontinue (inInteger1,inIncidenceMatrix2,inIncidenceMatrixT3,inIntegerArray4,inIntegerArray5)
1714+
matchcontinue (eqn,m,mt,a1,a2)
17151715
local
1716-
BackendDAE.Value var,pos,eqn;
1717-
list<BackendDAE.Value> reachable,reachable_1,reachable_2;
1718-
array<list<BackendDAE.Value>> m,mt;
1719-
array<BackendDAE.Value> a1,a2;
1716+
BackendDAE.Value var;
1717+
list<BackendDAE.Value> reachable,reachable_1;
17201718
String eqnstr;
1721-
case (eqn,m,mt,a1,a2)
1719+
case (_,_,_,_,_)
17221720
equation
17231721
var = a2[eqn];
17241722
reachable = mt[var] "Got the variable that is solved in the equation" ;
17251723
reachable_1 = BackendDAEUtil.removeNegative(reachable) "in which other equations is this variable present ?" ;
1726-
pos = List.position(eqn, reachable_1) ".. except this one" ;
1727-
reachable_2 = listDelete(reachable_1, pos);
17281724
then
1729-
reachable_2;
1725+
List.removeOnTrue(eqn, intEq, reachable_1);
17301726
else
17311727
equation
17321728
true = Flags.isSet(Flags.FAILTRACE);
17331729
Debug.trace("-reachable_nodes failed, eqn: ");
1734-
eqnstr = intString(inInteger1);
1730+
eqnstr = intString(eqn);
17351731
Debug.traceln(eqnstr);
17361732
then
17371733
fail();

Compiler/BackEnd/IndexReduction.mo

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ algorithm
372372
DAE.FunctionTree functionTree;
373373
BackendDAE.SymbolicJacobians symjacs;
374374
DAE.ComponentRef cr,cr1,cr2,scr;
375-
Boolean negate,b1,b2;
375+
Boolean negate,b1,b2,b;
376376
DAE.Exp exp1,exp2;
377377
BackendDAE.Var var1,var2;
378378
BackendDAE.ConstraintEquations orgEqnsLst;
@@ -403,16 +403,17 @@ algorithm
403403
e1 = inAss1[i];
404404
//ass1 = arrayUpdate(inAss1,i,e);
405405
//ass2 = arrayUpdate(inAss2,e,i);
406-
//ass2 = Debug.bcallret3(intGt(e1,0),arrayUpdate,ass2,e1,-1,ass2);
407-
ass1 = arrayUpdate(inAss1,i,-1);
408-
ass2 = arrayUpdate(inAss2,e,-1);
409-
ass2 = Debug.bcallret3(intGt(e1,0),arrayUpdate,ass2,e1,-1,ass2);
406+
//ass2 = Debug.bcallret3(intGt(e1,0),arrayUpdate,ass2,e1,-1,ass2);
407+
b = intGt(e1,0);
408+
ass1 = Debug.bcallret3(b,arrayUpdate,inAss1,i,-1,inAss1);
409+
//ass2 = arrayUpdate(inAss2,e,-1);
410+
ass2 = Debug.bcallret3(b,arrayUpdate,inAss2,e1,-1,inAss2);
410411
syst = BackendDAE.EQSYSTEM(v1,eqns_1,SOME(m),SOME(mt),matching);
411412
shared = BackendDAE.SHARED(kv,ev,av,ie,seqns,ae1,al1,constrs,complEqs,functionTree,BackendDAE.EVENT_INFO(wclst1,zc),eoc,btp,symjacs);
412413
syst = BackendDAEUtil.updateIncidenceMatrix(syst, shared, changedEqns);
413414
Debug.fcall(Flags.BLT_DUMP, BackendDump.debugStrCrefStrCrefStr,("Found Alias State ",cr," := ",scr,"\n Update Incidence Matrix: "));
414415
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,(changedEqns,intString," ","\n"));
415-
//changedEqns = listAppend(changedEqns,inchangedEqns);
416+
changedEqns = List.consOnTrue(b, e1, {e});
416417
changedEqns = List.unionOnTrue(inchangedEqns, changedEqns, intEq);
417418
(syst,shared,ass1,ass2,so1,orgEqnsLst,changedEqns,eqnslst) = differentiateAliasEqns(syst,shared,es,ass1,ass2,so,orgEqnsLst,changedEqns,iEqnsAcc);
418419
then
@@ -507,8 +508,6 @@ algorithm
507508
shared = BackendDAE.SHARED(kv,ev,av,ie,seqns,ae1,al1,constrs,complEqs,functionTree,BackendDAE.EVENT_INFO(wclst1,zc),eoc,btp,symjacs);
508509
syst = BackendDAEUtil.updateIncidenceMatrix(syst, shared, eqnslst1);
509510
orgEqnsLst = BackendDAETransform.addOrgEqn(inOrgEqnsLst,e,eqn);
510-
//changedEqns = listAppend(inchangedEqns,eqnslst);
511-
//changedEqns = e::changedEqns;
512511
changedEqns = List.unionOnTrue(inchangedEqns, e::eqnslst, intEq);
513512
(syst,shared,ass1,ass2,derivedAlgs1,derivedMultiEqn1,so1,orgEqnsLst,changedEqns) = differentiateEqns(syst,shared,es,ass1,ass2,derivedAlgs,derivedMultiEqn,so,orgEqnsLst,changedEqns);
514513
then
@@ -1585,7 +1584,7 @@ algorithm
15851584
Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpAdjacencyMatrixTEnhanced,meT);
15861585
(hov1,dummystates,lov,syst,shared) = selectDummyDerivatives1(me,meT,vars1,varSize,eqns,eqnsSize,eqnindxlst,hov,inDummyStates,isyst,ishared,inLov);
15871586
then
1588-
(hov1,dummystates,lov,syst,shared);
1587+
(hov1,dummystates,lov,syst,shared);
15891588
case(_,_,_,_,_,_,_,_,_,_)
15901589
equation
15911590
// try to select dummy vars heuristic based
@@ -1598,6 +1597,8 @@ algorithm
15981597
crlst = List.map(varlst,BackendVariable.varCref);
15991598
states = List.threadTuple(crlst,List.intRange2(1,varSize));
16001599
states = BackendDAETransform.sortStateCandidates(states,syst);
1600+
//states = List.sort(states,stateSortFund);
1601+
//states = listReverse(states);
16011602
Debug.fcall(Flags.BLT_DUMP, print, ("Select as dummyStates:\n"));
16021603
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,((states,BackendDAETransform.dumpStates,"\n","\n")));
16031604
(hov1,lov,dummystates) = selectDummyStates(states,1,eqnsSize,vars,hov,inLov,inDummyStates);
@@ -1615,6 +1616,14 @@ algorithm
16151616
end matchcontinue;
16161617
end selectDummyDerivatives;
16171618

1619+
protected function stateSortFund
1620+
input tuple<DAE.ComponentRef, Integer> inA;
1621+
input tuple<DAE.ComponentRef, Integer> inB;
1622+
output Boolean b;
1623+
algorithm
1624+
b:= ComponentReference.crefSortFunc(Util.tuple21(inA),Util.tuple21(inB));
1625+
end stateSortFund;
1626+
16181627
protected function selectDummyDerivatives1
16191628
"function: selectDummyDerivatives1
16201629
author: Frenkel TUD 2012-05
@@ -1763,8 +1772,9 @@ algorithm
17631772
list<DAE.Exp> explst;
17641773
list<BackendDAE.Equation> selecteqns,dselecteqns;
17651774
list<BackendDAE.WhenClause> wclst;
1766-
case(_,{},{},_,_,_,_,_,_,_,_,_,_,_,_)
1775+
case(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)
17671776
equation
1777+
true = intEq(listLength(dstates),eqnsSize);
17681778
Debug.fcall(Flags.BLT_DUMP, print, ("Select as dummyStates:\n"));
17691779
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,((dstates,BackendDAETransform.dumpStates,"\n","\n")));
17701780
Debug.fcall(Flags.BLT_DUMP, BackendDump.debugStrIntStrIntStr, ("Select ",varSize-eqnsSize," from ",varSize,"\n"));
@@ -1776,6 +1786,9 @@ algorithm
17761786
// for now only implemented for one equation
17771787
true = intEq(eqnsSize,1);
17781788
rang = eqnsSize-listLength(states);
1789+
// workaround to avoid state changes
1790+
//states = List.sort(states,stateSortFund);
1791+
//states = listReverse(states);
17791792
Debug.fcall(Flags.BLT_DUMP, BackendDump.debugStrIntStrIntStr, ("Select ",varSize-eqnsSize," from ",varSize,"\n"));
17801793
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,((states,BackendDAETransform.dumpStates,"\n","\n")));
17811794
Debug.fcall(Flags.BLT_DUMP, print, ("Select as dummyStates:\n"));

Compiler/BackEnd/Matching.mo

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5809,13 +5809,13 @@ protected function getEqnsforIndexReduction
58095809
output list<Integer> eqns;
58105810
algorithm
58115811
eqns := match(U,neqns,m,ass2)
5812-
local array<Boolean> rowmmarks;
5812+
local array<Boolean> colummarks;
58135813
case({},_,_,_) then {};
58145814
else
58155815
equation
5816-
rowmmarks = arrayCreate(neqns,false);
5816+
colummarks = arrayCreate(neqns,false);
58175817
then
5818-
getEqnsforIndexReduction1(U,m,rowmmarks,ass2,{});
5818+
getEqnsforIndexReduction1(U,m,colummarks,ass2,{});
58195819
end match;
58205820
end getEqnsforIndexReduction;
58215821

@@ -5824,24 +5824,27 @@ protected function getEqnsforIndexReduction1
58245824
autor: Frenkel TUD 2012-04"
58255825
input list<Integer> U;
58265826
input BackendDAE.IncidenceMatrix m "m[eqnindx] = list(varindx)";
5827-
input array<Boolean> rowmmarks;
5827+
input array<Boolean> colummarks;
58285828
input array<Integer> ass2 "ass[varindx]=eqnindx";
58295829
input list<Integer> inEqns;
58305830
output list<Integer> outEqns;
58315831
algorithm
5832-
outEqns:= matchcontinue (U,m,rowmmarks,ass2,inEqns)
5832+
outEqns:= matchcontinue (U,m,colummarks,ass2,inEqns)
58335833
local
58345834
list<Integer> rest,eqns;
58355835
Integer e;
58365836
case ({},_,_,_,_) then listReverse(inEqns);
58375837
case (e::rest,_,_,_,_)
58385838
equation
5839-
eqns = getEqnsforIndexReductionphase(e,m,rowmmarks,ass2,e::inEqns);
5839+
// row is not visited
5840+
false = colummarks[e];
5841+
_= arrayUpdate(colummarks,e,true);
5842+
eqns = getEqnsforIndexReductionphase(e,m,colummarks,ass2,e::inEqns);
58405843
then
5841-
getEqnsforIndexReduction1(rest,m,rowmmarks,ass2,eqns);
5844+
getEqnsforIndexReduction1(rest,m,colummarks,ass2,eqns);
58425845
case (_::rest,_,_,_,_)
58435846
then
5844-
getEqnsforIndexReduction1(rest,m,rowmmarks,ass2,inEqns);
5847+
getEqnsforIndexReduction1(rest,m,colummarks,ass2,inEqns);
58455848
end matchcontinue;
58465849
end getEqnsforIndexReduction1;
58475850

@@ -5850,21 +5853,21 @@ protected function getEqnsforIndexReductionphase
58505853
autor: Frenkel TUD 2012-04"
58515854
input Integer e;
58525855
input BackendDAE.IncidenceMatrix m;
5853-
input array<Boolean> rowmmarks;
5856+
input array<Boolean> colummarks;
58545857
input array<Integer> ass2;
58555858
input list<Integer> inEqns;
58565859
output list<Integer> outEqns;
58575860
algorithm
58585861
outEqns :=
5859-
match (e,m,rowmmarks,ass2,inEqns)
5862+
match (e,m,colummarks,ass2,inEqns)
58605863
local
58615864
list<Integer> rest,rows;
58625865
case (_,_,_,_,_)
58635866
equation
58645867
// traverse all adiacent rows
58655868
rows = List.select(m[e], Util.intPositive);
58665869
then
5867-
getEqnsforIndexReductiontraverseRows(rows,m,rowmmarks,ass2,inEqns);
5870+
getEqnsforIndexReductiontraverseRows(rows,m,colummarks,ass2,inEqns);
58685871
else
58695872
then
58705873
fail();
@@ -5876,32 +5879,31 @@ protected function getEqnsforIndexReductiontraverseRows
58765879
autor: Frenkel TUD 2012-04"
58775880
input list<Integer> rows;
58785881
input BackendDAE.IncidenceMatrix m;
5879-
input array<Boolean> rowmmarks;
5882+
input array<Boolean> colummarks;
58805883
input array<Integer> ass2;
58815884
input list<Integer> inEqns;
58825885
output list<Integer> outEqns;
58835886
algorithm
58845887
outEqns:=
5885-
matchcontinue (rows,m,rowmmarks,ass2,inEqns)
5888+
matchcontinue (rows,m,colummarks,ass2,inEqns)
58865889
local
58875890
list<Integer> rest,queue,queue2;
58885891
Integer rc,r;
58895892
Boolean b;
58905893
case ({},_,_,_,_) then inEqns;
58915894
case (r::rest,_,_,_,_)
58925895
equation
5893-
// row is not visited
5894-
false = rowmmarks[r];
5895-
_= arrayUpdate(rowmmarks,r,true);
58965896
// row is matched
58975897
rc = ass2[r];
5898-
false = intLt(rc,0);
5899-
queue = getEqnsforIndexReductionphase(rc,m,rowmmarks,ass2,rc::inEqns);
5898+
true = intGt(rc,0);
5899+
false = colummarks[rc];
5900+
_= arrayUpdate(colummarks,rc,true);
5901+
queue = getEqnsforIndexReductionphase(rc,m,colummarks,ass2,rc::inEqns);
59005902
then
5901-
getEqnsforIndexReductiontraverseRows(rest,m,rowmmarks,ass2,queue);
5903+
getEqnsforIndexReductiontraverseRows(rest,m,colummarks,ass2,queue);
59025904
case (_::rest,_,_,_,_)
59035905
then
5904-
getEqnsforIndexReductiontraverseRows(rest,m,rowmmarks,ass2,inEqns);
5906+
getEqnsforIndexReductiontraverseRows(rest,m,colummarks,ass2,inEqns);
59055907
end matchcontinue;
59065908
end getEqnsforIndexReductiontraverseRows;
59075909

0 commit comments

Comments
 (0)