Skip to content

Commit

Permalink
- remove unused functions from IndexReduction.mo
Browse files Browse the repository at this point in the history
  - function processComps
  - function processCompsWork
  - function processComps1New
  - function processComps2New
  - function processComps3New


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17845 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Oct 23, 2013
1 parent 7531301 commit a98130f
Showing 1 changed file with 0 additions and 367 deletions.
367 changes: 0 additions & 367 deletions Compiler/BackEnd/IndexReduction.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1873,113 +1873,6 @@ end traversinghigerOrderDerivativesFinder;

protected type StateSets = list<tuple<Integer,Integer,Integer,Integer,list<BackendDAE.Var>,list<BackendDAE.Equation>,list<BackendDAE.Var>,list<BackendDAE.Equation>>> "Level,nStates,nStateCandidates,nUnassignedEquations,StateCandidates,ConstraintEqns,OtherVars,OtherEqns";

protected function processComps
"author: Frenkel TUD 2012-05
process all strong connected components of the system and collect the
derived equations for dummy state selection"
input Integer cfreeStates;
input list<BackendDAE.Var> freeStates;
input Integer cOrgEqns;
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared ishared;
input BackendDAE.StructurallySingularSystemHandlerArg inArg;
input list<DAE.ComponentRef> inDummyStates;
input Integer iSetIndex;
output list<DAE.ComponentRef> outDummyStates;
output BackendDAE.EqSystem osyst;
output BackendDAE.Shared oshared;
output Integer oSetIndex;
algorithm
(outDummyStates,osyst,oshared,oSetIndex) :=
matchcontinue(cfreeStates,freeStates,cOrgEqns,isyst,ishared,inArg,inDummyStates,iSetIndex)
local
BackendDAE.StateOrder so;
list<DAE.ComponentRef> dummystates;
BackendDAE.EqSystem syst;
list<BackendDAE.Var> varlst;
Integer setIndex;
StateSets stateSets;
// number of free states and differentiated equations equal -> no state selection necessary
case (_,_,_,_,_,_,_,_)
equation
true = intEq(cfreeStates,cOrgEqns);
dummystates = List.map(freeStates,BackendVariable.varCref);
then (dummystates,isyst,ishared,iSetIndex);
// select states
case (_,_,_,_,_,(so,_,_,_,_),_,_)
equation
ErrorExt.setCheckpoint("DynamicStateSelection");
// get highest order derivatives
(varlst,_) = highestOrderDerivatives(BackendVariable.daeVars(isyst),so);
Debug.fcall(Flags.BLT_DUMP, print, "highest Order Derivatives:\n");
Debug.fcall(Flags.BLT_DUMP, BackendDump.printVarList, varlst);
(dummystates,stateSets) = processCompsWork(cfreeStates,freeStates,cOrgEqns,varlst,isyst,ishared,inArg,inDummyStates,{});
// add the found state sets for dynamic state selection to the system
(setIndex,syst) = addStateSets(stateSets,iSetIndex,isyst);
ErrorExt.rollBack("DynamicStateSelection");
then
(dummystates,syst,ishared,setIndex);
else
equation
ErrorExt.delCheckpoint("DynamicStateSelection");
then
fail();
end matchcontinue;
end processComps;

protected function processCompsWork
"author: Frenkel TUD 2012-05
process all strong connected components of the system and collect the
derived equations for dummy state selection"
input Integer cfreeStates;
input list<BackendDAE.Var> freeStates;
input Integer cOrgEqns;
input list<BackendDAE.Var> iHigestOrderVars;
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared ishared;
input BackendDAE.StructurallySingularSystemHandlerArg inArg;
input list<DAE.ComponentRef> inDummyStates;
input StateSets iStateSets;
output list<DAE.ComponentRef> outDummyStates;
output StateSets oStateSets;
algorithm
(outDummyStates,oStateSets) :=
matchcontinue(cfreeStates,freeStates,cOrgEqns,iHigestOrderVars,isyst,ishared,inArg,inDummyStates,iStateSets)
local
BackendDAE.Variables hov;
list<DAE.ComponentRef> dummystates;
BackendDAE.EqSystem syst;
BackendDAE.Shared shared;
Integer setIndex;
StateSets stateSets;
DAE.FunctionTree funcs;
BackendDAE.IncidenceMatrix m;
BackendDAE.IncidenceMatrixT mt;
array<list<Integer>> mapEqnIncRow;
array<Integer> mapIncRowEqn;
array<Integer> vec1,vec2;
list<list<Integer>> comps;
// try to select states without strong component information, this method take care on stateSelect attribute
case (_,_,_,_,_,_,_,_,_)
equation
(dummystates,stateSets) = processComps1New(isyst,ishared,inArg,iHigestOrderVars,inDummyStates,iStateSets);
then
(dummystates,stateSets);
// select states based on strong connected components, this method does not take care on stateSelect attribute
case (_,_,_,_,BackendDAE.EQSYSTEM(matching=BackendDAE.MATCHING(ass1=vec1,ass2=vec2)),_,_,_,_)
equation
hov = BackendVariable.listVar1(iHigestOrderVars);
// generate StrongComponents for second selection method
funcs = BackendDAEUtil.getFunctions(ishared);
(syst,m,mt,mapEqnIncRow,mapIncRowEqn) = BackendDAEUtil.getIncidenceMatrixScalar(isyst,BackendDAE.NORMAL(), SOME(funcs));
comps = BackendDAETransform.tarjanAlgorithm(mt,vec2);
Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpComponentsOLD,comps);
(dummystates,stateSets) = processComps1(comps,syst,ishared,vec2,inArg,hov,inDummyStates,iStateSets);
then
(dummystates,stateSets);
end matchcontinue;
end processCompsWork;

protected function addStateSets
"author: Frenkel TUD 2013-01
add the found state set to the system"
Expand Down Expand Up @@ -2772,266 +2665,6 @@ algorithm
end match;
end getIncidenceMatrixLevelEquations;

protected function processComps1New
"author: Frenkel TUD 2012-11
process all strong connected components of the system and collect the
derived equations for dummy state selection"
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared ishared;
input BackendDAE.StructurallySingularSystemHandlerArg inArg;
input list<BackendDAE.Var> hov;
input list<DAE.ComponentRef> inDummyStates;
input StateSets iStateSets;
output list<DAE.ComponentRef> outDummyStates;
output StateSets oStateSets;
algorithm
(outDummyStates,oStateSets) :=
match(isyst,ishared,inArg,hov,inDummyStates,iStateSets)
local
BackendDAE.EqSystem syst;
BackendDAE.Shared shared;
BackendDAE.StateOrder so;
BackendDAE.ConstraintEquations orgEqnsLst;
list<BackendDAE.Equation> eqnslst;
list<Integer> ilst;
list<BackendDAE.Var> varlst,dummvars,lov;
BackendDAE.Variables lov1;
list<DAE.ComponentRef> dummyStates;
array<list<Integer>> mapEqnIncRow;
array<Integer> mapIncRowEqn;
Integer noofeqns,freeStates,neqns;
StateSets stateSets;
DAE.FunctionTree funcs;
case (_,_,(_,{},_,_,_),_,_,_) then (inDummyStates,iStateSets);
case (_,_,(so,orgEqnsLst,mapEqnIncRow,mapIncRowEqn,noofeqns),_,_,_)
equation
// get orgequations of that level
(eqnslst,ilst,orgEqnsLst) = getFirstOrgEqns(orgEqnsLst,{},{},{});
// replace final parameter
(eqnslst,_) = BackendEquation.traverseBackendDAEExpsEqnList(eqnslst, replaceFinalVarsEqn,(BackendVariable.daeKnVars(ishared),false,BackendVarTransform.emptyReplacements()));
// replace all der(x) with dx
(eqnslst,_) = BackendEquation.traverseBackendDAEExpsEqnList(eqnslst, replaceDerStatesStates,so);
// force inline
funcs = BackendDAEUtil.getFunctions(ishared);
(eqnslst,_) = BackendEquation.traverseBackendDAEExpsEqnList(eqnslst, forceInlinEqn,funcs);
// try to make scalar
(eqnslst,_) = BackendDAEOptimize.getScalarArrayEqns(eqnslst,{},false);
// remove stateSelect=StateSelect.always vars
varlst = List.filter1(hov, notVarStateSelectAlways, 1);
neqns = BackendEquation.equationLstSize(eqnslst);
freeStates = listLength(varlst);
(dummvars,dummyStates,stateSets) = processComps2New(freeStates,varlst,neqns,eqnslst,isyst,ishared,so,hov,inDummyStates,iStateSets);
// get derivatives one order less
// print("DummyVars:\n");
// BackendDump.printVarList(dummvars);
//lov1 = lowerOrderDerivatives(BackendVariable.listVar1(dummvars),BackendVariable.daeVars(isyst),so);
lov1 = lowerOrderDerivatives(BackendVariable.listVar1(hov),BackendVariable.daeVars(isyst),so);
lov = BackendVariable.varList(lov1);
// next level
(dummyStates,stateSets) = processComps1New(isyst,ishared,(so,orgEqnsLst,mapEqnIncRow,mapIncRowEqn,noofeqns),lov,dummyStates,stateSets);
then
(dummyStates,stateSets);
end match;
end processComps1New;

protected function processComps2New
"author: Frenkel TUD 2012-11
process all strong connected components of the system and collect the
derived equations for dummy state selection"
input Integer freeStates;
input list<BackendDAE.Var> varlst;
input Integer neqns;
input list<BackendDAE.Equation> eqnslst;
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared ishared;
input BackendDAE.StateOrder so;
input list<BackendDAE.Var> hov;
input list<DAE.ComponentRef> inDummyStates;
input StateSets iStateSets;
output list<BackendDAE.Var> outDummyVars;
output list<DAE.ComponentRef> outDummyStates;
output StateSets oStateSets;
algorithm
(outDummyVars,outDummyStates,oStateSets) :=
matchcontinue(freeStates,varlst,neqns,eqnslst,isyst,ishared,so,hov,inDummyStates,iStateSets)
local
array<list<Integer>> mapEqnIncRow;
array<Integer> mapIncRowEqn;
Integer nv;
list<DAE.ComponentRef> dummyStates;
BackendDAE.Variables vars;
BackendDAE.EquationArray eqns;
BackendDAE.EqSystem syst;
BackendDAE.Shared shared;
BackendDAE.AdjacencyMatrixEnhanced me;
BackendDAE.AdjacencyMatrixTEnhanced meT;
StateSets stateSets;
String msg;
// number of free states equal to number of differentiated equations -> no state selection necessary, all dummy states
case (_,_,_,_,_,_,_,_,_,_)
equation
true = intEq(freeStates,neqns);
dummyStates = List.map(varlst,BackendVariable.varCref);
dummyStates = listAppend(dummyStates,inDummyStates);
then
(varlst,dummyStates,iStateSets);
// do state selection
case (_,_,_,_,_,_,_,_,_,_)
equation
// try to select dummy vars
true = intGt(freeStates,1);
false = intGt(neqns,freeStates);
Debug.fcall(Flags.BLT_DUMP, print, "try to select dummy vars with natural matching(new)\n");

// sort vars with heuristic
vars = BackendVariable.listVar1(varlst);
vars = sortStateCandidatesVars(vars,BackendVariable.daeVars(isyst),NONE());
(vars,_) = BackendVariable.traverseBackendDAEVarsWithUpdate(vars,setVarKind,BackendDAE.VARIABLE());

eqns = BackendEquation.listEquation(eqnslst);
syst = BackendDAE.EQSYSTEM(vars,eqns,NONE(),NONE(),BackendDAE.NO_MATCHING(),{});

//BackendDAE.DAE(eqs={syst}) = RemoveSimpleEquations.allAcausal(BackendDAE.DAE({syst},ishared,ei?));

(me,meT,mapEqnIncRow,mapIncRowEqn) = BackendDAEUtil.getAdjacencyMatrixEnhancedScalar(syst,ishared);
Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpAdjacencyMatrixEnhanced,me);
Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpAdjacencyMatrixTEnhanced,meT);

// (outDummyVars,dummyStates,stateSets) = processComps3New(arrayLength(meT),arrayLength(me),syst,me,meT,mapEqnIncRow1,mapIncRowEqn1,ishared,hov,inDummyStates,iStateSets);
(outDummyVars,dummyStates,stateSets) = processComps3New(freeStates,neqns,syst,me,meT,mapEqnIncRow,mapIncRowEqn,ishared,hov,inDummyStates,iStateSets);
then
(outDummyVars,dummyStates,stateSets);
// to much equations this is an error
case (_,_,_,_,_,_,_,_,_,_)
equation
true = intGt(neqns,freeStates);
// no chance, to much equations
msg = "It is not possible to select continues time states because Number of Equations " +& intString(neqns) +& " greater than number of States " +& intString(freeStates) +& " to select from.";
Error.addMessage(Error.INTERNAL_ERROR, {msg});
then
fail();
// number of differentiated equations exceeds number of free states, add StateSelect.always states and try again
case (_,_,_,_,_,_,_,_,_,_)
equation
true = intGt(neqns,freeStates);
// try again and add also stateSelect.always vars.
nv = listLength(hov);
true = intGe(nv,neqns);
(outDummyVars,dummyStates,stateSets) = processComps2New(nv,hov,neqns,eqnslst,isyst,ishared,so,hov,inDummyStates,iStateSets);
then
(outDummyVars,dummyStates,stateSets);
end matchcontinue;
end processComps2New;

//protected import RemoveSimpleEquations;

protected function processComps3New
"author: Frenkel TUD 2012-11
process all strong connected components of the system and collect the
derived equations for dummy state selection"
input Integer inVarSize;
input Integer inEqnsSize;
input BackendDAE.EqSystem inSubsyst;
input BackendDAE.AdjacencyMatrixEnhanced inMe;
input BackendDAE.AdjacencyMatrixTEnhanced inMeT;
input array<list<Integer>> inMapEqnIncRow1;
input array<Integer> inMapIncRowEqn1;
input BackendDAE.Shared iShared;
input list<BackendDAE.Var> inHov;
input list<DAE.ComponentRef> inDummyStates;
input StateSets iStateSets;
output list<BackendDAE.Var> outDummyVars;
output list<DAE.ComponentRef> outDummyStates;
output StateSets oStateSets;
algorithm
(outDummyVars,outDummyStates,oStateSets) :=
matchcontinue(inVarSize,inEqnsSize,inSubsyst,inMe,inMeT,inMapEqnIncRow1,inMapIncRowEqn1,iShared,inHov,inDummyStates,iStateSets)
local
BackendDAE.StateOrder so;
BackendDAE.ConstraintEquations orgEqnsLst;
array<list<Integer>> mapEqnIncRow,mapEqnIncRow1;
array<Integer> mapIncRowEqn,mapIncRowEqn1;
Integer noofeqns;
list<DAE.ComponentRef> dummyStates;
BackendDAE.Variables vars;
BackendDAE.EquationArray eqns;
BackendDAE.EqSystem syst;
BackendDAE.Shared shared;
BackendDAE.Variables hov1,lov;
list<DAE.ComponentRef> dummystates;
BackendDAE.IncidenceMatrix m;
BackendDAE.IncidenceMatrixT mT;
array<Integer> vec1,vec2;
list<tuple<DAE.ComponentRef, Integer>> states,dstates;
list<Integer> unassigned,assigned,set,usedstates,unusedstates;
list<BackendDAE.Var> vlst;
list<list<Integer>> sets;
StateSets stateSets;
DAE.FunctionTree funcs;
/*
case (_,_,BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns),_,_,_,_,_,_,_,_)
equation
// get the states with equations
usedstates = getUsedStates(arrayLength(inMeT),inMeT,{});
true = intEq(listLength(usedstates),inEqnsSize);
Debug.fcall(Flags.BLT_DUMP, BackendDump.printEqSystem, inSubsyst);
vlst = List.map1r(usedstates,BackendVariable.getVarAt,vars);
dummyStates = List.map(vlst,BackendVariable.varCref);
Debug.fcall(Flags.BLT_DUMP, print, ("Select as dummyStates(4):\n"));
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,((dummyStates,ComponentReference.printComponentRefStr,"\n","\n")));
dummyStates = listAppend(dummyStates,inDummyStates);
then
(vlst,dummyStates,iStateSets);
*/
// do matching to get the dummy states and the state candidates for dynamic state selection
case (_,_,BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns),_,_,_,_,_,_,_,_)
equation
// get indicenceMatrix from Enhanced
m = incidenceMatrixfromEnhanced2(inMe,vars);
mT = BackendDAEUtil.transposeMatrix(m,inVarSize);
Debug.fcall(Flags.BLT_DUMP, BackendDump.printEqSystem, BackendDAE.EQSYSTEM(vars,eqns,SOME(m),SOME(mT),BackendDAE.NO_MATCHING(),{}));

// match the variables not the equations, to have prevered states unmatched
vec1 = arrayCreate(inEqnsSize,-1);
vec2 = arrayCreate(inVarSize,-1);
Matching.matchingExternalsetIncidenceMatrix(inEqnsSize,inVarSize,mT);
BackendDAEEXT.matching(inEqnsSize,inVarSize,3,-1,1.0,1);
BackendDAEEXT.getAssignment(vec2,vec1);
Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpMatching, vec1);
Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpMatching, vec2);

(dstates,states) = checkAssignment(1,inVarSize,vec2,vars,{},{});
vlst = List.map1r(List.map(dstates,Util.tuple22),BackendVariable.getVarAt,vars);
dummyStates = List.map(vlst,BackendVariable.varCref);
dummyStates = listAppend(dummyStates,inDummyStates);

unassigned = Matching.getUnassigned(inEqnsSize, vec1, {});
assigned = Matching.getAssigned(inEqnsSize, vec1, {});

Debug.fcall(Flags.BLT_DUMP, print, ("dummyStates:\n"));
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,((dstates,dumpStates,"\n","\n")));
Debug.fcall(Flags.BLT_DUMP, print, ("States:\n"));
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,((states,dumpStates,"\n","\n")));
Debug.fcall(Flags.BLT_DUMP, print, ("Unassigned Eqns:\n"));
Debug.fcall(Flags.BLT_DUMP, BackendDump.debuglst,((unassigned,intString," ","\n")));

// splitt it into sets
syst = BackendDAE.EQSYSTEM(vars,eqns,NONE(),NONE(),BackendDAE.MATCHING(vec2,vec1,{}),{});
// dumpSystemGraphML(syst,iShared,NONE(),"StateSelection" +& intString(arrayLength(m)) +& ".graphml");
funcs = BackendDAEUtil.getFunctions(iShared);
(syst,m,mT,mapEqnIncRow1,mapIncRowEqn1) = BackendDAEUtil.getIncidenceMatrixScalar(syst,BackendDAE.NORMAL(), SOME(funcs));
// TODO: partition the system
sets = partitionSystem(m,mT);

// print("Sets:\n");
// BackendDump.dumpIncidenceMatrix(listArray(sets));
// BackendDump.printEqSystem(syst);
(vlst,dummyStates,stateSets) = processComps4New(sets,inVarSize,inEqnsSize,vars,eqns,m,mT,mapEqnIncRow1,mapIncRowEqn1,vec1,vec2,1,iShared,vlst,dummyStates,iStateSets);
then
(vlst,dummyStates,stateSets);
end matchcontinue;
end processComps3New;

protected function getUsedStates
input Integer n;
input BackendDAE.AdjacencyMatrixTEnhanced mt;
Expand Down

0 comments on commit a98130f

Please sign in to comment.