Skip to content

Commit

Permalink
added density information to backenddaeinfo of liner torn systems
Browse files Browse the repository at this point in the history
  • Loading branch information
Willi Braun authored and OpenModelica-Hudson committed Nov 13, 2015
1 parent be96874 commit 40390de
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -715,7 +715,8 @@ public
type SparsePattern = tuple<list<tuple< .DAE.ComponentRef, list< .DAE.ComponentRef>>>, // column-wise sparse pattern
list<tuple< .DAE.ComponentRef, list< .DAE.ComponentRef>>>, // row-wise sparse pattern
tuple<list< .DAE.ComponentRef>, // diff vars
list< .DAE.ComponentRef>>>; // diffed vars
list< .DAE.ComponentRef>>, // diffed vars
Integer>; // nonZeroElements

public
type SparseColoring = list<list< .DAE.ComponentRef>>; // colouring
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -134,7 +134,7 @@ algorithm
reqnarr := BackendEquation.listEquation(reqns);
ieqnarr := BackendEquation.listEquation(ieqns);
einfo := BackendDAE.EVENT_INFO(timeEvents, {}, {}, {}, 0);
symjacs := {(NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {})};
symjacs := {(NONE(), ({}, {}, ({}, {}), -1), {}), (NONE(), ({}, {}, ({}, {}), -1), {}), (NONE(), ({}, {}, ({}, {}), -1), {}), (NONE(), ({}, {}, ({}, {}), -1), {})};
outBackendDAE := BackendDAE.DAE(BackendDAEUtil.createEqSystem(vars_1, eqnarr, {}, BackendDAE.UNKNOWN_PARTITION(), reqnarr)::{},
BackendDAE.SHARED(knvars,
extVars,
Expand Down
48 changes: 36 additions & 12 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -717,10 +717,12 @@ public function dumpSparsityPattern "author lochel"
protected
list<tuple< .DAE.ComponentRef, list< .DAE.ComponentRef>>> pattern;
list< .DAE.ComponentRef> diffVars, diffedVars;
Integer nnz;
algorithm
(pattern, _, (diffVars, diffedVars)) := inPattern;
(pattern, _, (diffVars, diffedVars), nnz) := inPattern;

print("\n" + heading + "\n" + UNDERLINE + "\n");
print("Number of non zero elements: " + intString(nnz) + ")\n");
print("independents [or inputs] (" + intString(listLength(diffVars)) + ")\n");
ComponentReference.printComponentRefList(diffVars);

Expand Down Expand Up @@ -3208,14 +3210,15 @@ end tupleString;

protected type DumpCompShortSystemsTpl = tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>;
protected type DumpCompShortMixedTpl = tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>;
protected type DumpCompShortTornTpl = tuple<list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>;
protected type DumpCompShortTornTpl = tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>;

public function dumpCompShort
input BackendDAE.BackendDAE inDAE;
protected
Integer sys,inp,st,dvar,dst,seq,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys,strcomps;
list<Integer> e_jc,e_jn,e_nj;
list<tuple<Integer,Integer>> te_l,te_nl;
list<tuple<Integer,Integer,Integer>> te_l;
list<tuple<Integer,Integer>> te_nl;
list<Integer> m_se,m_salg,m_sarr,m_sec;
list<tuple<Integer,Integer>> me_jc,e_jt,me_jt,me_jn,me_nj,me_lt,me_nt;
list<DAE.ComponentRef> states,discvars,discstates;
Expand Down Expand Up @@ -3312,11 +3315,12 @@ end dumpCompSystems;
protected function dumpCompTorn
input DumpCompShortTornTpl systemsTpl;
protected
list<tuple<Integer,Integer>> te_l,te_nl;
list<tuple<Integer,Integer,Integer>> te_l;
list<tuple<Integer,Integer>> te_nl;
String s_l,s_nl;
algorithm
(te_l,te_nl) := systemsTpl;
s_l := equationSizesStr(te_l,intTplString);
s_l := equationSizesStr(te_l,sizeNumNonZeroTornTplString);
s_nl := equationSizesStr(te_nl,intTplString);
Error.addMessage(Error.BACKENDDAEINFO_TORN, {s_l,s_nl});
end dumpCompTorn;
Expand Down Expand Up @@ -3371,6 +3375,19 @@ algorithm
str := "(" + intString(sz) + "," + str + "%)";
end sizeNumNonZeroTplString;

protected function sizeNumNonZeroTornTplString
input tuple<Integer,Integer,Integer> inTpl;
output String str;
protected
Integer sz,nnz,others;
Real density;
algorithm
(sz,others,nnz) := inTpl;
density := realDiv(realMul(100.0,intReal(nnz)),realMul(intReal(sz),intReal(sz)));
str := System.snprintff("%.1f",20,density);
str := "(" + intString(sz) + "," + str + "%)" + " " + intString(others);
end sizeNumNonZeroTornTplString;

protected function intTplString
input tuple<Integer,Integer> inTpl;
output String outStr;
Expand All @@ -3384,7 +3401,7 @@ end intTplString;
protected function dumpCompShort1
input BackendDAE.EqSystem inSyst;
input BackendDAE.Shared inShared;
input tuple<Integer,Integer,Integer,list<DAE.ComponentRef>,Integer,list<DAE.ComponentRef>,Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>> inTpl;
input tuple<Integer,Integer,Integer,list<DAE.ComponentRef>,Integer,list<DAE.ComponentRef>,Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>> inTpl;
output tuple<
Integer,
Integer,
Expand All @@ -3407,7 +3424,7 @@ protected
Integer sys,inp,st,dvar,seq,salg,sarr,sce,swe,sie,inp1,st1,dvar1,seq1,salg1,sarr1,sce1,swe1,sie1;
tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>> eqsys,eqsys1;
tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>> meqsys,meqsys1;
tuple<list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>> teqsys,teqsys1;
tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>> teqsys,teqsys1;
list<DAE.ComponentRef> states,states1,discvars,discvars1;
algorithm
BackendDAE.EQSYSTEM(orderedVars=vars) := inSyst;
Expand Down Expand Up @@ -3453,21 +3470,23 @@ end traversingisStateTopInputVarFinder;

protected function dumpCompShort2
input BackendDAE.StrongComponent inComp;
input tuple<Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>> inTpl;
output tuple<Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>> outTpl;
input tuple<Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>> inTpl;
output tuple<Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>> outTpl;
algorithm
outTpl := match (inComp,inTpl)
local
Integer e,d,nnz;
list<Integer> ilst,ilst1;
Integer seq,salg,sarr,sce,swe,sie;
list<Integer> e_jc,e_jn,e_nj,m_se,m_salg,m_sarr,m_sec;
list<tuple<Integer,Integer>> e_jt,me_jc,me_jt,me_jn,me_nj,me_lt,me_nt,te_l,te_nl;
list<tuple<Integer,Integer,Integer>> te_l;
list<tuple<Integer,Integer>> e_jt,me_jc,me_jt,me_jn,me_nj,me_lt,me_nt,te_nl;
tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>> eqsys;
list<tuple<Integer, Integer, BackendDAE.Equation>> jac;
tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>> meqsys;
tuple<list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>> teqsys;
tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>> teqsys;
list<tuple<Integer,list<Integer>>> eqnvartpllst;
list<tuple< .DAE.ComponentRef, list< .DAE.ComponentRef>>> patternLst;

case (BackendDAE.SINGLEEQUATION(),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys))
then ((seq+1,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys));
Expand Down Expand Up @@ -3509,11 +3528,16 @@ algorithm
e = listLength(ilst);
then ((seq,salg,sarr,sce,swe,sie,(e_jc,e_jt,e_jn,e::e_nj),meqsys,teqsys));

case (BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(tearingvars=ilst,otherEqnVarTpl=eqnvartpllst,jac=BackendDAE.GENERIC_JACOBIAN(_,(_,_,_,nnz),_)),linear=true),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,(te_l,te_nl))) equation
d = listLength(ilst);
e = listLength(eqnvartpllst);
then ((seq,salg,sarr,sce,swe,sie,eqsys,meqsys,((d,e,nnz)::te_l,te_nl)));
/*
case (BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(tearingvars=ilst,otherEqnVarTpl=eqnvartpllst),linear=true),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,(te_l,te_nl))) equation
d = listLength(ilst);
e = listLength(eqnvartpllst);
then ((seq,salg,sarr,sce,swe,sie,eqsys,meqsys,((d,e)::te_l,te_nl)));

*/
case (BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(tearingvars=ilst,otherEqnVarTpl=eqnvartpllst),linear=false),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,(te_l,te_nl))) equation
d = listLength(ilst);
e = listLength(eqnvartpllst);
Expand Down
10 changes: 5 additions & 5 deletions Compiler/BackEnd/SymbolicJacobian.mo
Expand Up @@ -1044,8 +1044,8 @@ algorithm
list<list<DAE.ComponentRef>> translated;
list<tuple<DAE.ComponentRef,list<DAE.ComponentRef>>> sparsetuple, sparsetupleT;

case (_,{},_) then (({},{},({},{})),{});
case (_,_,{}) then (({},{},({},{})),{});
case (_,{},_) then (({},{},({},{}), -1),{});
case (_,_,{}) then (({},{},({},{}), -1),{});
case(BackendDAE.DAE(eqs = (syst as BackendDAE.EQSYSTEM(matching=bdaeMatching as BackendDAE.MATCHING(comps=comps, ass1=ass1)))::{}),indiffVars,indiffedVars)
equation
if Flags.isSet(Flags.DUMP_SPARSE_VERBOSE) then
Expand Down Expand Up @@ -1173,7 +1173,7 @@ algorithm
if Flags.isSet(Flags.DUMP_SPARSE_VERBOSE) then
print("analytical Jacobians[SPARSE] -> ready! " + realString(clock()) + "\n");
end if;
then ((sparsetupleT, sparsetuple, (diffCompRefs, diffedCompRefs)), coloring);
then ((sparsetupleT, sparsetuple, (diffCompRefs, diffedCompRefs), nonZeroElements), coloring);
else
equation
Error.addInternalError("function generateSparsePattern failed", sourceInfo());
Expand Down Expand Up @@ -3139,8 +3139,8 @@ protected
BackendDAE.SymbolicJacobians symjacs;
BackendDAE.ExtraInfo ei;
algorithm
symjacs := { (SOME(inSymJac), inSparsePattern, inSparseColoring), (NONE(), ({}, {}, ({}, {})), {}),
(NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {}) };
symjacs := { (SOME(inSymJac), inSparsePattern, inSparseColoring), (NONE(), ({}, {}, ({}, {}), -1), {}),
(NONE(), ({}, {}, ({}, {}), -1), {}), (NONE(), ({}, {}, ({}, {}), -1), {}) };
outShared := BackendDAEUtil.setSharedSymJacs(inShared, symjacs);
end addBackendDAESharedJacobian;

Expand Down
16 changes: 8 additions & 8 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -3505,7 +3505,7 @@ algorithm
case (BackendDAE.GENERIC_JACOBIAN((BackendDAE.DAE(eqs={syst as BackendDAE.EQSYSTEM(matching=BackendDAE.MATCHING(comps=comps))},
shared=shared), name,
independentVarsLst, residualVarsLst, dependentVarsLst),
(sparsepatternComRefs, sparsepatternComRefsT, (_, _)),
(sparsepatternComRefs, sparsepatternComRefsT, (_, _), _),
sparseColoring), _, _)
equation
if Flags.isSet(Flags.JAC_DUMP2) then
Expand Down Expand Up @@ -3662,15 +3662,15 @@ algorithm

case ({}, _, _, _) then ({}, iuniqueEqIndex);
// if nothing is generated
case (((NONE(), ({}, {}, ({}, {})), {}))::rest, _, _, name::restnames)
case (((NONE(), ({}, {}, ({}, {}), _), {}))::rest, _, _, name::restnames)
equation
(linearModelMatrices, uniqueEqIndex) = createSymbolicJacobianssSimCode(rest, inSimVarHT, iuniqueEqIndex, restnames);
linearModelMatrices = (({}, {}, name, ({}, {}), {}, 0, -1))::linearModelMatrices;
then
(linearModelMatrices, uniqueEqIndex);

// if only sparsity pattern is generated
case (((optionBDAE, (sparsepattern, sparsepatternT, (diffCompRefs, diffedCompRefs)), colsColors))::rest, _, _, name::restnames)
case (((optionBDAE, (sparsepattern, sparsepatternT, (diffCompRefs, diffedCompRefs), _), colsColors))::rest, _, _, name::restnames)
guard checkForEmptyBDAE(optionBDAE)
equation
if Flags.isSet(Flags.JAC_DUMP2) then
Expand Down Expand Up @@ -3727,7 +3727,7 @@ algorithm

case (((SOME((BackendDAE.DAE(eqs={syst as BackendDAE.EQSYSTEM(matching=BackendDAE.MATCHING(comps=comps))},
shared=shared), name,
_, diffedVars, alldiffedVars)), (sparsepattern, sparsepatternT, (diffCompRefs, diffedCompRefs)), colsColors))::rest,
_, diffedVars, alldiffedVars)), (sparsepattern, sparsepatternT, (diffCompRefs, diffedCompRefs), _), colsColors))::rest,
_, _, _::restnames)
equation
if Flags.isSet(Flags.JAC_DUMP2) then
Expand Down Expand Up @@ -11413,8 +11413,8 @@ algorithm
(crefSimVarHT,_) := createCrefToSimVarHT(inModelInfo);
// combine the transposed sparse pattern of matrix A and B
// to obtain dependencies for the derivatives
SOME((_, (_, spTA, (diffCrefsA, diffedCrefsA)), _)) := SymbolicJacobian.getJacobianMatrixbyName(inSymjacs, "A");
SOME((_, (_, spTB, (diffCrefsB, diffedCrefsB)), _)) := SymbolicJacobian.getJacobianMatrixbyName(inSymjacs, "B");
SOME((_, (_, spTA, (diffCrefsA, diffedCrefsA),_), _)) := SymbolicJacobian.getJacobianMatrixbyName(inSymjacs, "A");
SOME((_, (_, spTB, (diffCrefsB, diffedCrefsB),_), _)) := SymbolicJacobian.getJacobianMatrixbyName(inSymjacs, "B");

//print("-- Got matrixes\n");
spTA := mergeSparsePatter(spTA, spTB, {});
Expand All @@ -11440,8 +11440,8 @@ algorithm
//print("-- created derivatives \n");
// combine the transposed sparse pattern of matrix C and D
// to obtain dependencies for the outputs
SOME((_, (_, spTA, (diffCrefsA, diffedCrefsA)), _)) := SymbolicJacobian.getJacobianMatrixbyName(inSymjacs, "C");
SOME((_, (_, spTB, (diffCrefsB, diffedCrefsB)), _)) := SymbolicJacobian.getJacobianMatrixbyName(inSymjacs, "D");
SOME((_, (_, spTA, (diffCrefsA, diffedCrefsA),_), _)) := SymbolicJacobian.getJacobianMatrixbyName(inSymjacs, "C");
SOME((_, (_, spTB, (diffCrefsB, diffedCrefsB),_), _)) := SymbolicJacobian.getJacobianMatrixbyName(inSymjacs, "D");
//print("-- Got matrixes CD\n");
spTA := mergeSparsePatter(spTA, spTB, {});
//print("-- merged matrixes CD\n");
Expand Down

0 comments on commit 40390de

Please sign in to comment.