Skip to content

Commit

Permalink
- Compiler/BackEnd/Initialization.mo
Browse files Browse the repository at this point in the history
  - minor speedup
- Compiler/BackEnd/BackendDump.mo
  - make some dump-calls more clean


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14449 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Dec 18, 2012
1 parent 243cc2f commit f4e3dfc
Show file tree
Hide file tree
Showing 8 changed files with 417 additions and 443 deletions.
8 changes: 4 additions & 4 deletions Compiler/BackEnd/BackendDAECreate.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3645,7 +3645,7 @@ algorithm
{zc} = makeZeroCrossings({e_1}, {eq_count}, {wc_count});
zc_lst = List.select1(zeroCrossings, sameZeroCrossing, zc);
zeroCrossings = Util.if_(listLength(zc_lst)==0,listAppend(zeroCrossings,{zc}),zeroCrossings);
print(Debug.fcallret1(Flags.RELIDX, BackendDump.dumpZcStr1, zeroCrossings, ""));
print(Debug.fcallret1(Flags.RELIDX, BackendDump.zeroCrossingListString, zeroCrossings, ""));
then
((e_1,false,((zeroCrossings,relations,samples,numRelations1,numMathFunctions),(eq_count,wc_count,vars,knvars))));
// function with discrete expressions generate no zerocrossing
Expand Down Expand Up @@ -3812,7 +3812,7 @@ algorithm
{zc} = makeZeroCrossings({e_1}, {alg_indx}, {});
zc_lst = List.select1(zeroCrossings, sameZeroCrossing, zc);
zeroCrossings = Util.if_(listLength(zc_lst)==0,listAppend(zeroCrossings,{zc}),zeroCrossings);
print(Debug.fcallret1(Flags.RELIDX, BackendDump.dumpZcStr1, zeroCrossings, ""));
print(Debug.fcallret1(Flags.RELIDX, BackendDump.zeroCrossingListString, zeroCrossings, ""));
then
((e_1,false,(iterator,le,range,(zeroCrossings,relations,samples,numRelations1,numMathFunctions),(alg_indx,vars,knvars))));
// function with discrete expressions generate no zerocrossing
Expand Down Expand Up @@ -4001,7 +4001,7 @@ algorithm
zc_lst = mergeZeroCrossings(zc_lst);
itmp = (listLength(zc_lst)-listLength(zeroCrossings));
zeroCrossings = Util.if_(itmp>0,zc_lst,zeroCrossings);
print(Debug.fcallret1(Flags.RELIDX, BackendDump.dumpZcStr1, zeroCrossings, ""));
print(Debug.fcallret1(Flags.RELIDX, BackendDump.zeroCrossingListString, zeroCrossings, ""));
then
((e_1,false,(iterator,inExpLst,range,(zeroCrossings,relations,samples,numRelations1, numMathFunctions),(alg_indx,vars,knvars))));
case (((e as DAE.LBINARY(exp1 = e1,operator = op,exp2 = e2)),(iterator,inExpLst,range,(zeroCrossings,relations,samples,numRelations, numMathFunctions),(alg_indx,vars,knvars))))
Expand All @@ -4015,7 +4015,7 @@ algorithm
{zc} = makeZeroCrossings({e_1}, {alg_indx}, {});
zc_lst = List.select1(zeroCrossings, sameZeroCrossing, zc);
zeroCrossings = Util.if_(listLength(zc_lst)==0,listAppend(zeroCrossings,{zc}),zeroCrossings);
print(Debug.fcallret1(Flags.RELIDX, BackendDump.dumpZcStr1, zeroCrossings, ""));
print(Debug.fcallret1(Flags.RELIDX, BackendDump.zeroCrossingListString, zeroCrossings, ""));
then
((e_1,false,(iterator,inExpLst,range,(zeroCrossings,relations,samples,numRelations1,numMathFunctions),(alg_indx,vars,knvars))));
// function with discrete expressions generate no zerocrossing.
Expand Down
107 changes: 51 additions & 56 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2998,7 +2998,7 @@ algorithm
BackendDAE.MATCHING(v1_new,v2_new,_) = matching;
//(relaxedEqSystem,relaxedShared,_) = tearingSystemNew1(eqSystem,shared,{comps_Newton},false);
print("\nrelaxedEqSystem\n");
//BackendDump.dumpEqSystem(relaxedEqSystem);
//BackendDump.printEqSystem(relaxedEqSystem);
print("\n----end of linear system----\n");

//-------------
Expand Down Expand Up @@ -8023,7 +8023,7 @@ algorithm
subsyst := BackendDAE.EQSYSTEM(vars,eqns,NONE(),NONE(),BackendDAE.NO_MATCHING(),{});
(subsyst,m,mt,_,_) := BackendDAEUtil.getIncidenceMatrixScalar(subsyst, BackendDAE.NORMAL());
// IndexReduction.dumpSystemGraphML(subsyst,ishared,NONE(),"System" +& intString(size) +& ".graphml");
Debug.fcall(Flags.TEARING_DUMP, BackendDump.dumpEqSystem,subsyst);
Debug.fcall(Flags.TEARING_DUMP, BackendDump.printEqSystem, subsyst);

(me,meT,mapEqnIncRow,mapIncRowEqn) := BackendDAEUtil.getAdjacencyMatrixEnhancedScalar(subsyst,ishared);
Debug.fcall(Flags.TEARING_DUMP, BackendDump.dumpAdjacencyMatrixEnhanced,me);
Expand Down Expand Up @@ -8069,7 +8069,7 @@ algorithm
m1 := getOtherEqSysIncidenceMatrix(m,size,1,ass2,ass1,m1);
mt1 := getOtherEqSysIncidenceMatrix(mt,size,1,ass1,ass2,mt1);
// subsyst := BackendDAE.EQSYSTEM(vars,eqns,SOME(m1),SOME(mt1),BackendDAE.MATCHING(ass1,ass2,{}));
// BackendDump.dumpEqSystem(subsyst);
// BackendDump.printEqSystem(subsyst);
number := arrayCreate(size,0);
lowlink := arrayCreate(size,0);
number := setIntArray(residual,number,size);
Expand All @@ -8078,9 +8078,9 @@ algorithm
Debug.fcall(Flags.TEARING_DUMP, BackendDump.dumpComponentsOLD,othercomps);
Debug.fcall(Flags.TEARING_DUMP, print, "\n");
// calculate influence of tearing vars in residual equations
mt1 := arrayCreate(size,{});
mark := getDependensOtherVars(othercomps,ass1,ass2,m,mt1,columark,mark);
(residual,mark) := sortResidualDepentOnTVars(residual,tvars,ass1,m,mt1,columark,mark);
mt1 := arrayCreate(size, {});
mark := getDependenciesOfVars(othercomps, ass1, ass2, m, mt1, columark, mark);
(residual, mark) := sortResidualDepentOnTVars(residual, tvars, ass1, m, mt1, columark, mark);
// handle system in case of liniear and other cases
//(osyst,oshared,outRunMatching) := tearingSystemNew4(jacType,isyst,ishared,subsyst,tvars,residual,ass1,ass2,othercomps,eindex,vindx,mapEqnIncRow,mapIncRowEqn);
(ocomp,outRunMatching) := tearingSystemNew4_1(jacType,isyst,ishared,subsyst,tvars,residual,ass1,ass2,othercomps,eindex,vindx,mapEqnIncRow,mapIncRowEqn,columark,mark);
Expand Down Expand Up @@ -8197,7 +8197,7 @@ algorithm
end match;
end tVarsofResidualEqns;

protected function getDependensOtherVars
protected function getDependenciesOfVars
input list<list<Integer>> iComps;
input array<Integer> ass1;
input array<Integer> ass2;
Expand All @@ -8207,35 +8207,35 @@ protected function getDependensOtherVars
input Integer iMark;
output Integer oMark;
algorithm
oMark := match(iComps,ass1,ass2,m,mT,visited,iMark)
oMark := match(iComps, ass1, ass2, m, mT, visited, iMark)
local
Integer c,v;
list<Integer> comp,tvars,vars;
Integer c, v;
list<Integer> comp, tvars, vars;
list<list<Integer>> comps;
case ({},_,_,_,_,_,_) then iMark;
case ({c}::comps,_,_,_,_,_,_)
equation
// get var of eqn
v = ass2[c];
// get TVars of Eqn
vars = List.select(m[c], Util.intPositive);
tvars = tVarsofEqn(vars,ass1,mT,visited,iMark,{});
// update map
_ = arrayUpdate(mT,v,tvars);
then
getDependensOtherVars(comps,ass1,ass2,m,mT,visited,iMark+1);
case (comp::comps,_,_,_,_,_,_)
equation
// get var of eqns
vars = List.map1r(comp,arrayGet,ass2);
// get TVars of Eqns
tvars = tVarsofEqns(comp,m,ass1,mT,visited,iMark,{});
// update map
_ = List.fold1r(vars,arrayUpdate,tvars,mT);
then
getDependensOtherVars(comps,ass1,ass2,m,mT,visited,iMark+1);

case ({}, _, _, _, _, _, _)
then iMark;

case ({c}::comps, _, _, _, _, _, _) equation
// get var of eqn
v = ass2[c];
// get TVars of Eqn
vars = List.select(m[c], Util.intPositive);
tvars = tVarsofEqn(vars, ass1, mT, visited, iMark, {});
// update map
_ = arrayUpdate(mT, v, tvars);
then getDependenciesOfVars(comps, ass1, ass2, m, mT, visited, iMark+1);

case (comp::comps, _, _, _, _, _, _) equation
// get var of eqns
vars = List.map1r(comp,arrayGet,ass2);
// get TVars of Eqns
tvars = tVarsofEqns(comp, m, ass1, mT, visited, iMark, {});
// update map
_ = List.fold1r(vars, arrayUpdate, tvars, mT);
then getDependenciesOfVars(comps, ass1, ass2, m, mT, visited, iMark+1);
end match;
end getDependensOtherVars;
end getDependenciesOfVars;

protected function tVarsofEqns
input list<Integer> iEqns;
Expand All @@ -8247,17 +8247,18 @@ protected function tVarsofEqns
input list<Integer> iAcc;
output list<Integer> oAcc;
algorithm
oAcc := match(iEqns,m,ass1,mT,visited,iMark,iAcc)
oAcc := match(iEqns, m, ass1, mT, visited, iMark, iAcc)
local
Integer e;
list<Integer> eqns,vars,tvars;
case ({},_,_,_,_,_,_) then iAcc;
case (e::eqns,_,_,_,_,_,_)
equation
vars = List.select(m[e], Util.intPositive);
tvars = tVarsofEqn(vars,ass1,mT,visited,iMark,iAcc);
then
tVarsofEqns(eqns,m,ass1,mT,visited,iMark,tvars);
list<Integer> eqns, vars, tvars;

case ({}, _, _, _, _, _, _)
then iAcc;

case (e::eqns, _, _, _, _, _, _) equation
vars = List.select(m[e], Util.intPositive);
tvars = tVarsofEqn(vars, ass1, mT, visited, iMark, iAcc);
then tVarsofEqns(eqns, m, ass1, mT, visited, iMark, tvars);
end match;
end tVarsofEqns;

Expand All @@ -8281,11 +8282,9 @@ algorithm
tvars = uniqueIntLst(v,iMark,visited,iAcc);
then
tVarsofEqn(vars,ass1,mT,visited,iMark,tvars);
case (v::vars,_,_,_,_,_)
equation
tvars = List.fold2(mT[v],uniqueIntLst,iMark,visited,iAcc);
then
tVarsofEqn(vars,ass1,mT,visited,iMark,tvars);
case (v::vars,_,_,_,_,_) equation
tvars = List.fold2(mT[v],uniqueIntLst,iMark,visited,iAcc);
then tVarsofEqn(vars, ass1, mT, visited, iMark, tvars);
end matchcontinue;
end tVarsofEqn;

Expand Down Expand Up @@ -9496,8 +9495,7 @@ algorithm
true = intEq(listLength(tvars),numvars);
// replace new residual equations in original system
syseqns = BackendEquation.daeEqns(isyst);
Debug.fcall(Flags.TEARING_DUMP, print,"dump original system\n");
Debug.fcall(Flags.TEARING_DUMP, BackendDump.dumpEqSystem,isyst);
Debug.fcall2(Flags.TEARING_DUMP, BackendDump.dumpEqSystem, isyst, "dump original system");
// all additional vars and equations
sysvars = BackendVariable.addVars(k0,sysvars);
sysvars = BackendVariable.addVars(pdvarlst,sysvars);
Expand All @@ -9507,9 +9505,8 @@ algorithm
ores = List.map1r(residual1,arrayGet,listArray(eindex));
syseqns = replaceHEquationsinSystem(ores,h,syseqns);
syst = BackendDAE.EQSYSTEM(sysvars,syseqns,NONE(),NONE(),BackendDAE.NO_MATCHING(),statSets);
// BackendDump.dumpEqSystem(syst);
Debug.fcall(Flags.TEARING_DUMP, print,"dump original replaced system\n");
Debug.fcall(Flags.TEARING_DUMP, BackendDump.dumpEqSystem,syst);
// BackendDump.printEqSystem(syst);
Debug.fcall2(Flags.TEARING_DUMP, BackendDump.dumpEqSystem, syst, "dump original replaced system");
then
(syst,ishared,true);

Expand Down Expand Up @@ -9550,11 +9547,9 @@ algorithm
Debug.fcall(Flags.TEARING_DUMP, BackendDump.debugStrIntStr,("Found ",numvars," Tearing Vars in the Residual Equations\n"));
true = intEq(listLength(tvars),numvars);
// replace new residual equations in original system
Debug.fcall(Flags.TEARING_DUMP, print,"dump original system\n");
Debug.fcall(Flags.TEARING_DUMP, BackendDump.dumpEqSystem,isyst);
Debug.fcall2(Flags.TEARING_DUMP, BackendDump.dumpEqSystem, isyst, "dump original system");
syst = replaceTornEquationsinSystem(residual1,listArray(eindex),eqns,isyst);
Debug.fcall(Flags.TEARING_DUMP, print,"dump original replaced system\n");
Debug.fcall(Flags.TEARING_DUMP, BackendDump.dumpEqSystem,syst);
Debug.fcall2(Flags.TEARING_DUMP, BackendDump.dumpEqSystem, syst, "dump original replaced system");
then
(syst,ishared,true);
case (_,_,_,_,_,_,_,_,_,_,_,_,_)
Expand Down
5 changes: 2 additions & 3 deletions Compiler/BackEnd/BackendDAETransform.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2731,8 +2731,7 @@ algorithm
"We need to change variables in the differentiated equations and in the equations having the dummy derivative" ;
syst = makeAlgebraic(syst, state);
(syst,mapEqnIncRow,mapIncRowEqn) = BackendDAEUtil.updateIncidenceMatrixScalar(syst,BackendDAE.SOLVABLE(), changedeqns,mapEqnIncRow,mapIncRowEqn);
// print("new DAE:");
// BackendDump.dumpEqSystem(syst);
// BackendDump.dumpEqSystem(systm, "new DAE:");
// BackendDump.dump(BackendDAE.DAE({syst},shared));
// print("new IM:");
// (_,m,_) = BackendDAEUtil.getIncidenceMatrixfromOption(syst,BackendDAE.SOLVABLE());
Expand Down Expand Up @@ -3635,7 +3634,7 @@ algorithm
case ({},_,_,_,_)
equation
Error.addMessage(Error.INTERNAL_ERROR, {"BackendDAETransform.selectDummyState: no state to select"});
BackendDump.dumpEqSystem(syst);
BackendDump.printEqSystem(syst);
then
fail();

Expand Down

0 comments on commit f4e3dfc

Please sign in to comment.