Skip to content

Commit

Permalink
- minor fixes for new dynamic state selection
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12048 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jun 13, 2012
1 parent 1e14e3e commit 2357b68
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 45 deletions.
26 changes: 11 additions & 15 deletions Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -1703,35 +1703,31 @@ public function reachableNodes "function: reachableNodes
that n1 solves for a variable (e.g. \'a\') that is used in the equation
of n2, i.e. the equation of n1 must be solved before the equation of n2.
"
input Integer inInteger1;
input BackendDAE.IncidenceMatrix inIncidenceMatrix2;
input BackendDAE.IncidenceMatrixT inIncidenceMatrixT3;
input array<Integer> inIntegerArray4;
input array<Integer> inIntegerArray5;
input Integer eqn;
input BackendDAE.IncidenceMatrix m;
input BackendDAE.IncidenceMatrixT mt;
input array<Integer> a1;
input array<Integer> a2;
output list<Integer> outIntegerLst;
algorithm
outIntegerLst:=
matchcontinue (inInteger1,inIncidenceMatrix2,inIncidenceMatrixT3,inIntegerArray4,inIntegerArray5)
matchcontinue (eqn,m,mt,a1,a2)
local
BackendDAE.Value var,pos,eqn;
list<BackendDAE.Value> reachable,reachable_1,reachable_2;
array<list<BackendDAE.Value>> m,mt;
array<BackendDAE.Value> a1,a2;
BackendDAE.Value var;
list<BackendDAE.Value> reachable,reachable_1;
String eqnstr;
case (eqn,m,mt,a1,a2)
case (_,_,_,_,_)
equation
var = a2[eqn];
reachable = mt[var] "Got the variable that is solved in the equation" ;
reachable_1 = BackendDAEUtil.removeNegative(reachable) "in which other equations is this variable present ?" ;
pos = List.position(eqn, reachable_1) ".. except this one" ;
reachable_2 = listDelete(reachable_1, pos);
then
reachable_2;
List.removeOnTrue(eqn, intEq, reachable_1);
else
equation
true = Flags.isSet(Flags.FAILTRACE);
Debug.trace("-reachable_nodes failed, eqn: ");
eqnstr = intString(inInteger1);
eqnstr = intString(eqn);
Debug.traceln(eqnstr);
then
fail();
Expand Down
33 changes: 23 additions & 10 deletions Compiler/BackEnd/IndexReduction.mo
Expand Up @@ -372,7 +372,7 @@ algorithm
DAE.FunctionTree functionTree;
BackendDAE.SymbolicJacobians symjacs;
DAE.ComponentRef cr,cr1,cr2,scr;
Boolean negate,b1,b2;
Boolean negate,b1,b2,b;
DAE.Exp exp1,exp2;
BackendDAE.Var var1,var2;
BackendDAE.ConstraintEquations orgEqnsLst;
Expand Down Expand Up @@ -403,16 +403,17 @@ algorithm
e1 = inAss1[i];
//ass1 = arrayUpdate(inAss1,i,e);
//ass2 = arrayUpdate(inAss2,e,i);
//ass2 = Debug.bcallret3(intGt(e1,0),arrayUpdate,ass2,e1,-1,ass2);
ass1 = arrayUpdate(inAss1,i,-1);
ass2 = arrayUpdate(inAss2,e,-1);
ass2 = Debug.bcallret3(intGt(e1,0),arrayUpdate,ass2,e1,-1,ass2);
//ass2 = Debug.bcallret3(intGt(e1,0),arrayUpdate,ass2,e1,-1,ass2);
b = intGt(e1,0);
ass1 = Debug.bcallret3(b,arrayUpdate,inAss1,i,-1,inAss1);
//ass2 = arrayUpdate(inAss2,e,-1);
ass2 = Debug.bcallret3(b,arrayUpdate,inAss2,e1,-1,inAss2);
syst = BackendDAE.EQSYSTEM(v1,eqns_1,SOME(m),SOME(mt),matching);
shared = BackendDAE.SHARED(kv,ev,av,ie,seqns,ae1,al1,constrs,complEqs,functionTree,BackendDAE.EVENT_INFO(wclst1,zc),eoc,btp,symjacs);
syst = BackendDAEUtil.updateIncidenceMatrix(syst, shared, changedEqns);
Debug.fcall(Flags.BLT_DUMP, BackendDump.debugStrCrefStrCrefStr,("Found Alias State ",cr," := ",scr,"\n Update Incidence Matrix: "));
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,(changedEqns,intString," ","\n"));
//changedEqns = listAppend(changedEqns,inchangedEqns);
changedEqns = List.consOnTrue(b, e1, {e});
changedEqns = List.unionOnTrue(inchangedEqns, changedEqns, intEq);
(syst,shared,ass1,ass2,so1,orgEqnsLst,changedEqns,eqnslst) = differentiateAliasEqns(syst,shared,es,ass1,ass2,so,orgEqnsLst,changedEqns,iEqnsAcc);
then
Expand Down Expand Up @@ -507,8 +508,6 @@ algorithm
shared = BackendDAE.SHARED(kv,ev,av,ie,seqns,ae1,al1,constrs,complEqs,functionTree,BackendDAE.EVENT_INFO(wclst1,zc),eoc,btp,symjacs);
syst = BackendDAEUtil.updateIncidenceMatrix(syst, shared, eqnslst1);
orgEqnsLst = BackendDAETransform.addOrgEqn(inOrgEqnsLst,e,eqn);
//changedEqns = listAppend(inchangedEqns,eqnslst);
//changedEqns = e::changedEqns;
changedEqns = List.unionOnTrue(inchangedEqns, e::eqnslst, intEq);
(syst,shared,ass1,ass2,derivedAlgs1,derivedMultiEqn1,so1,orgEqnsLst,changedEqns) = differentiateEqns(syst,shared,es,ass1,ass2,derivedAlgs,derivedMultiEqn,so,orgEqnsLst,changedEqns);
then
Expand Down Expand Up @@ -1585,7 +1584,7 @@ algorithm
Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpAdjacencyMatrixTEnhanced,meT);
(hov1,dummystates,lov,syst,shared) = selectDummyDerivatives1(me,meT,vars1,varSize,eqns,eqnsSize,eqnindxlst,hov,inDummyStates,isyst,ishared,inLov);
then
(hov1,dummystates,lov,syst,shared);
(hov1,dummystates,lov,syst,shared);
case(_,_,_,_,_,_,_,_,_,_)
equation
// try to select dummy vars heuristic based
Expand All @@ -1598,6 +1597,8 @@ algorithm
crlst = List.map(varlst,BackendVariable.varCref);
states = List.threadTuple(crlst,List.intRange2(1,varSize));
states = BackendDAETransform.sortStateCandidates(states,syst);
//states = List.sort(states,stateSortFund);
//states = listReverse(states);
Debug.fcall(Flags.BLT_DUMP, print, ("Select as dummyStates:\n"));
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,((states,BackendDAETransform.dumpStates,"\n","\n")));
(hov1,lov,dummystates) = selectDummyStates(states,1,eqnsSize,vars,hov,inLov,inDummyStates);
Expand All @@ -1615,6 +1616,14 @@ algorithm
end matchcontinue;
end selectDummyDerivatives;

protected function stateSortFund
input tuple<DAE.ComponentRef, Integer> inA;
input tuple<DAE.ComponentRef, Integer> inB;
output Boolean b;
algorithm
b:= ComponentReference.crefSortFunc(Util.tuple21(inA),Util.tuple21(inB));
end stateSortFund;

protected function selectDummyDerivatives1
"function: selectDummyDerivatives1
author: Frenkel TUD 2012-05
Expand Down Expand Up @@ -1763,8 +1772,9 @@ algorithm
list<DAE.Exp> explst;
list<BackendDAE.Equation> selecteqns,dselecteqns;
list<BackendDAE.WhenClause> wclst;
case(_,{},{},_,_,_,_,_,_,_,_,_,_,_,_)
case(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)
equation
true = intEq(listLength(dstates),eqnsSize);
Debug.fcall(Flags.BLT_DUMP, print, ("Select as dummyStates:\n"));
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,((dstates,BackendDAETransform.dumpStates,"\n","\n")));
Debug.fcall(Flags.BLT_DUMP, BackendDump.debugStrIntStrIntStr, ("Select ",varSize-eqnsSize," from ",varSize,"\n"));
Expand All @@ -1776,6 +1786,9 @@ algorithm
// for now only implemented for one equation
true = intEq(eqnsSize,1);
rang = eqnsSize-listLength(states);
// workaround to avoid state changes
//states = List.sort(states,stateSortFund);
//states = listReverse(states);
Debug.fcall(Flags.BLT_DUMP, BackendDump.debugStrIntStrIntStr, ("Select ",varSize-eqnsSize," from ",varSize,"\n"));
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,((states,BackendDAETransform.dumpStates,"\n","\n")));
Debug.fcall(Flags.BLT_DUMP, print, ("Select as dummyStates:\n"));
Expand Down
42 changes: 22 additions & 20 deletions Compiler/BackEnd/Matching.mo
Expand Up @@ -5809,13 +5809,13 @@ protected function getEqnsforIndexReduction
output list<Integer> eqns;
algorithm
eqns := match(U,neqns,m,ass2)
local array<Boolean> rowmmarks;
local array<Boolean> colummarks;
case({},_,_,_) then {};
else
equation
rowmmarks = arrayCreate(neqns,false);
colummarks = arrayCreate(neqns,false);
then
getEqnsforIndexReduction1(U,m,rowmmarks,ass2,{});
getEqnsforIndexReduction1(U,m,colummarks,ass2,{});
end match;
end getEqnsforIndexReduction;

Expand All @@ -5824,24 +5824,27 @@ protected function getEqnsforIndexReduction1
autor: Frenkel TUD 2012-04"
input list<Integer> U;
input BackendDAE.IncidenceMatrix m "m[eqnindx] = list(varindx)";
input array<Boolean> rowmmarks;
input array<Boolean> colummarks;
input array<Integer> ass2 "ass[varindx]=eqnindx";
input list<Integer> inEqns;
output list<Integer> outEqns;
algorithm
outEqns:= matchcontinue (U,m,rowmmarks,ass2,inEqns)
outEqns:= matchcontinue (U,m,colummarks,ass2,inEqns)
local
list<Integer> rest,eqns;
Integer e;
case ({},_,_,_,_) then listReverse(inEqns);
case (e::rest,_,_,_,_)
equation
eqns = getEqnsforIndexReductionphase(e,m,rowmmarks,ass2,e::inEqns);
// row is not visited
false = colummarks[e];
_= arrayUpdate(colummarks,e,true);
eqns = getEqnsforIndexReductionphase(e,m,colummarks,ass2,e::inEqns);
then
getEqnsforIndexReduction1(rest,m,rowmmarks,ass2,eqns);
getEqnsforIndexReduction1(rest,m,colummarks,ass2,eqns);
case (_::rest,_,_,_,_)
then
getEqnsforIndexReduction1(rest,m,rowmmarks,ass2,inEqns);
getEqnsforIndexReduction1(rest,m,colummarks,ass2,inEqns);
end matchcontinue;
end getEqnsforIndexReduction1;

Expand All @@ -5850,21 +5853,21 @@ protected function getEqnsforIndexReductionphase
autor: Frenkel TUD 2012-04"
input Integer e;
input BackendDAE.IncidenceMatrix m;
input array<Boolean> rowmmarks;
input array<Boolean> colummarks;
input array<Integer> ass2;
input list<Integer> inEqns;
output list<Integer> outEqns;
algorithm
outEqns :=
match (e,m,rowmmarks,ass2,inEqns)
match (e,m,colummarks,ass2,inEqns)
local
list<Integer> rest,rows;
case (_,_,_,_,_)
equation
// traverse all adiacent rows
rows = List.select(m[e], Util.intPositive);
then
getEqnsforIndexReductiontraverseRows(rows,m,rowmmarks,ass2,inEqns);
getEqnsforIndexReductiontraverseRows(rows,m,colummarks,ass2,inEqns);
else
then
fail();
Expand All @@ -5876,32 +5879,31 @@ protected function getEqnsforIndexReductiontraverseRows
autor: Frenkel TUD 2012-04"
input list<Integer> rows;
input BackendDAE.IncidenceMatrix m;
input array<Boolean> rowmmarks;
input array<Boolean> colummarks;
input array<Integer> ass2;
input list<Integer> inEqns;
output list<Integer> outEqns;
algorithm
outEqns:=
matchcontinue (rows,m,rowmmarks,ass2,inEqns)
matchcontinue (rows,m,colummarks,ass2,inEqns)
local
list<Integer> rest,queue,queue2;
Integer rc,r;
Boolean b;
case ({},_,_,_,_) then inEqns;
case (r::rest,_,_,_,_)
equation
// row is not visited
false = rowmmarks[r];
_= arrayUpdate(rowmmarks,r,true);
// row is matched
rc = ass2[r];
false = intLt(rc,0);
queue = getEqnsforIndexReductionphase(rc,m,rowmmarks,ass2,rc::inEqns);
true = intGt(rc,0);
false = colummarks[rc];
_= arrayUpdate(colummarks,rc,true);
queue = getEqnsforIndexReductionphase(rc,m,colummarks,ass2,rc::inEqns);
then
getEqnsforIndexReductiontraverseRows(rest,m,rowmmarks,ass2,queue);
getEqnsforIndexReductiontraverseRows(rest,m,colummarks,ass2,queue);
case (_::rest,_,_,_,_)
then
getEqnsforIndexReductiontraverseRows(rest,m,rowmmarks,ass2,inEqns);
getEqnsforIndexReductiontraverseRows(rest,m,colummarks,ass2,inEqns);
end matchcontinue;
end getEqnsforIndexReductiontraverseRows;

Expand Down

0 comments on commit 2357b68

Please sign in to comment.