Skip to content

Commit

Permalink
[BE] added usage of flag -d=tearingdump and -d=tearingdumpV
Browse files Browse the repository at this point in the history
  - extends -d=optdaedump to print residual/inner equations and
    tearing/inner variables instead of only printing indices
  • Loading branch information
kabdelhak authored and adrpo committed Jun 14, 2019
1 parent 61b6e52 commit ef87d10
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 5 deletions.
18 changes: 18 additions & 0 deletions OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -5163,6 +5163,24 @@ algorithm
end match;
end getEqnAndVarsFromInnerEquation;

public function getEqnAndVarsFromInnerEquationLst
input BackendDAE.InnerEquations innerEquations;
output tuple<list<Integer>,list<list<Integer>>,list<BackendDAE.Constraints>> eqnVarConstTpl;
protected
Integer eqn;
list<Integer> eqns = {}, vars;
list<list<Integer>> allVars = {};
BackendDAE.Constraints constraints;
list<BackendDAE.Constraints> allConstraints = {};
algorithm
for innerEq in innerEquations loop
(eqn,vars,constraints) := getEqnAndVarsFromInnerEquation(innerEq);
eqns := eqn::eqns;
allVars := vars::allVars;
allConstraints := constraints::allConstraints;
end for;
eqnVarConstTpl := (eqns,allVars,allConstraints);
end getEqnAndVarsFromInnerEquationLst;

protected function transformSolvabilityForCasualTearingSet
input BackendDAE.Solvability inSolvab;
Expand Down
60 changes: 55 additions & 5 deletions OMCompiler/Compiler/BackEnd/BackendDump.mo
Expand Up @@ -130,7 +130,7 @@ algorithm
dumpOption(inSyst.mT, dumpIncidenceMatrixT);

print("\n");
dumpFullMatching(inSyst.matching);
dumpFullMatching(inSyst.matching,SOME(inSyst));
print("\n");
end printEqSystem;

Expand Down Expand Up @@ -1351,22 +1351,25 @@ end dumpComponentsAdvanced3;

public function dumpComponents
input BackendDAE.StrongComponents inComps;
input Option<BackendDAE.EqSystem> inSyst = NONE();
algorithm
print("StrongComponents\n");
print(UNDERLINE + "\n");
List.map_0(inComps,dumpComponent);
List.map1(inComps,dumpComponent,inSyst);
end dumpComponents;

public function dumpComponent
input BackendDAE.StrongComponent inComp;
input Option<BackendDAE.EqSystem> inSyst = NONE();

algorithm
print(printComponent(inComp));
print(printComponent(inComp,inSyst));

end dumpComponent;

public function printComponent
input BackendDAE.StrongComponent inComp;
input Option<BackendDAE.EqSystem> inSyst = NONE();
output String oString;

protected
Expand All @@ -1376,12 +1379,14 @@ algorithm
oString := match (inComp)
local
Integer i,v;
list<Integer> ilst,vlst,ilst2,vlst2;
list<Integer> ilst,vlst,ilst2,vlst2,innerEqLst;
list<list<Integer>> innerVarLst;
list<String> ls;
String s,s2,s3,s4;
BackendDAE.JacobianType jacType;
BackendDAE.StrongComponent comp;
BackendDAE.InnerEquations innerEquations,innerEquations2;
BackendDAE.EqSystem eSys;
Boolean b;
case BackendDAE.SINGLEEQUATION(eqn=i,var=v)
equation
Expand Down Expand Up @@ -1436,6 +1441,17 @@ algorithm
s3 = stringDelimitList(ls, ", ");
s4 = if b then "linear" else "nonlinear";
tmpStr = "{{" + s + "}\n,{" + s2 + ":" + s3 + "}} Size: " + intString(listLength(vlst)) + " " + s4 + "\n";
if (Flags.isSet(Flags.TEARING_DUMP) or Flags.isSet(Flags.TEARING_DUMPVERBOSE)) and isSome(inSyst) then
SOME(eSys) = inSyst;
(innerEqLst,innerVarLst,_) = BackendDAEUtil.getEqnAndVarsFromInnerEquationLst(innerEquations);
tmpStr = tmpStr
+ "\nTearing Variables:\n-------------------------------------\n" + dumpMarkedVars(eSys,vlst) + "\n"
+ "Residual Equations:\n-------------------------------------\n" + dumpMarkedEqns(eSys,ilst)
+ "Inner Variables:\n-------------------------------------\n" + dumpMarkedVarsLsts(eSys,innerVarLst) + "\n"
+ "InnerEquations:\n-------------------------------------\n" + dumpMarkedEqns(eSys,innerEqLst);
else
tmpStr = tmpStr + "For more information please use \"-d=tearingdump\".\n";
end if;
then tmpStr;
case BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(residualequations=ilst,tearingvars=vlst,innerEquations=innerEquations),SOME(BackendDAE.TEARINGSET(residualequations=ilst2,tearingvars=vlst2,innerEquations=innerEquations2)),linear=b)
equation
Expand All @@ -1447,6 +1463,18 @@ algorithm
s3 = stringDelimitList(ls, ", ");
s4 = if b then "linear" else "nonlinear";
tmpStr = "{{" + s + "}\n,{" + s2 + ":" + s3 + "}} Size: " + intString(listLength(vlst)) + " " + s4 + " (strict tearing set)\n";
if (Flags.isSet(Flags.TEARING_DUMP) or Flags.isSet(Flags.TEARING_DUMPVERBOSE)) and isSome(inSyst) then
SOME(eSys) = inSyst;
(innerEqLst,innerVarLst,_) = BackendDAEUtil.getEqnAndVarsFromInnerEquationLst(innerEquations);
tmpStr = tmpStr
+ "\nTearing Variables:\n-------------------------------------\n" + dumpMarkedVars(eSys,vlst) + "\n"
+ "Residual Equations:\n-------------------------------------\n" + dumpMarkedEqns(eSys,ilst)
+ "Inner Variables:\n-------------------------------------\n" + dumpMarkedVarsLsts(eSys,innerVarLst) + "\n"
+ "InnerEquations:\n-------------------------------------\n" + dumpMarkedEqns(eSys,innerEqLst);
else
tmpStr = tmpStr + "For more information please use \"-d=tearingdump\".\n";
end if;

ls = List.map(innerEquations2, innerEquationString);
s = stringDelimitList(ls, ", ");
ls = List.map(ilst2, intString);
Expand All @@ -1455,6 +1483,17 @@ algorithm
s3 = stringDelimitList(ls, ", ");
s4 = if b then "linear" else "nonlinear";
tmpStr2 = "{{" + s + "}\n,{" + s2 + ":" + s3 + "}} Size: " + intString(listLength(vlst2)) + " " + s4 + " (casual tearing set)\n";
if (Flags.isSet(Flags.TEARING_DUMP) or Flags.isSet(Flags.TEARING_DUMPVERBOSE)) and isSome(inSyst) then
SOME(eSys) = inSyst;
(innerEqLst,innerVarLst,_) = BackendDAEUtil.getEqnAndVarsFromInnerEquationLst(innerEquations2);
tmpStr2 = tmpStr2
+ "\nTearing Variables:\n-------------------------------------\n" + dumpMarkedVars(eSys,vlst2) + "\n"
+ "Residual Equations:\n-------------------------------------\n" + dumpMarkedEqns(eSys,ilst2)
+ "Inner Variables:\n-------------------------------------\n" + dumpMarkedVarsLsts(eSys,innerVarLst) + "\n"
+ "InnerEquations:\n-------------------------------------\n" + dumpMarkedEqns(eSys,innerEqLst);
else
tmpStr2 = tmpStr2 + "For more information please use \"-d=tearingdump\".\n";
end if;
then tmpStr + tmpStr2;
end match;
end printComponent;
Expand Down Expand Up @@ -3052,6 +3091,7 @@ end dumpSolvability;

public function dumpFullMatching
input BackendDAE.Matching inMatch;
input Option<BackendDAE.EqSystem> inSyst = NONE();
algorithm
_:= match(inMatch)
local
Expand All @@ -3065,7 +3105,7 @@ algorithm
case (BackendDAE.MATCHING(ass1, _, comps)) equation
dumpMatching(ass1);
print("\n\n");
dumpComponents(comps);
dumpComponents(comps,inSyst);
then ();
end match;
end dumpFullMatching;
Expand Down Expand Up @@ -3168,6 +3208,16 @@ algorithm
outS := stringAppendList({inS,s3,": ",s2,";\n"});
end dumpMarkedEqns1;

public function dumpMarkedVarsLsts
input BackendDAE.EqSystem syst;
input list<list<Integer>> inIntegerLstLst;
output String outString = "";
algorithm
for inIntegerLst in inIntegerLstLst loop
outString := outString + dumpMarkedVars(syst,inIntegerLst) + ",";
end for;
end dumpMarkedVarsLsts;

public function dumpMarkedVars
"Dumps only the variable names given as list of indexes to a string."
input BackendDAE.EqSystem syst;
Expand Down
15 changes: 15 additions & 0 deletions testsuite/openmodelica/debugDumps/optdaedump.mos
Expand Up @@ -1307,6 +1307,7 @@ buildModel(testOptdaedump); getErrorString();
// {1:7}
// {{{6:4}, {7:9}, {8:5}}
// ,{2:8}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {5:2}
// {3:6}
//
Expand Down Expand Up @@ -1408,6 +1409,7 @@ buildModel(testOptdaedump); getErrorString();
// {1:7}
// {{{6:4}, {7:9}, {8:5}}
// ,{2:8}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {5:2}
// {3:6}
//
Expand Down Expand Up @@ -2126,6 +2128,7 @@ buildModel(testOptdaedump); getErrorString();
// {1:7}
// {{{6:4}, {7:9}, {8:5}}
// ,{2:8}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {5:2}
// {3:6}
//
Expand Down Expand Up @@ -2227,6 +2230,7 @@ buildModel(testOptdaedump); getErrorString();
// {1:7}
// {{{6:4}, {7:9}, {8:5}}
// ,{2:8}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {5:2}
// {3:6}
//
Expand Down Expand Up @@ -2328,6 +2332,7 @@ buildModel(testOptdaedump); getErrorString();
// {1:7}
// {{{6:4}, {7:9}, {8:5}}
// ,{2:8}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {5:2}
// {3:6}
//
Expand Down Expand Up @@ -3071,6 +3076,7 @@ buildModel(testOptdaedump); getErrorString();
// {2:6}
// {{{5:3}, {6:8}, {3:4}}
// ,{4:7}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {7:2}
// {1:9}
// {8:1}
Expand Down Expand Up @@ -3156,6 +3162,7 @@ buildModel(testOptdaedump); getErrorString();
// {2:6}
// {{{5:3}, {6:8}, {3:4}}
// ,{4:7}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {7:2}
// {1:9}
// {8:1}
Expand Down Expand Up @@ -3858,6 +3865,7 @@ buildModel(testOptdaedump); getErrorString();
// {2:6}
// {{{5:3}, {6:8}, {3:4}}
// ,{4:7}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {7:2}
// {1:9}
// {8:1}
Expand Down Expand Up @@ -3943,6 +3951,7 @@ buildModel(testOptdaedump); getErrorString();
// {2:6}
// {{{5:3}, {6:8}, {3:4}}
// ,{4:7}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {7:2}
// {1:9}
// {8:1}
Expand Down Expand Up @@ -4028,6 +4037,7 @@ buildModel(testOptdaedump); getErrorString();
// {2:6}
// {{{5:3}, {6:8}, {3:4}}
// ,{4:7}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {7:2}
// {1:9}
// {8:1}
Expand Down Expand Up @@ -4113,6 +4123,7 @@ buildModel(testOptdaedump); getErrorString();
// {2:6}
// {{{5:3}, {6:8}, {3:4}}
// ,{4:7}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {7:2}
// {1:9}
// {8:1}
Expand Down Expand Up @@ -4198,6 +4209,7 @@ buildModel(testOptdaedump); getErrorString();
// {2:6}
// {{{5:3}, {6:8}, {3:4}}
// ,{4:7}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {7:2}
// {1:9}
// {8:1}
Expand Down Expand Up @@ -4283,6 +4295,7 @@ buildModel(testOptdaedump); getErrorString();
// {2:6}
// {{{5:3}, {6:8}, {3:4}}
// ,{4:7}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {7:2}
// {1:9}
// {8:1}
Expand Down Expand Up @@ -4368,6 +4381,7 @@ buildModel(testOptdaedump); getErrorString();
// {2:6}
// {{{5:3}, {6:8}, {3:4}}
// ,{4:7}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {7:2}
// {1:9}
// {8:1}
Expand Down Expand Up @@ -4453,6 +4467,7 @@ buildModel(testOptdaedump); getErrorString();
// {2:6}
// {{{5:3}, {6:8}, {3:4}}
// ,{4:7}} Size: 1 linear
// For more information please use "-d=tearingdump".
// {7:2}
// {1:9}
// {8:1}
Expand Down
Expand Up @@ -1172,6 +1172,7 @@ val(aimc.inertiaRotor.flange_b.tau, 0);
// {8:34}
// {{{22:3}, {21:25}, {20:1}, {18:2}}
// ,{17, 19:26, 27}} Size: 2 linear
// For more information please use "-d=tearingdump".
// {37:45}
// {39:42}
// {85:85}
Expand Down Expand Up @@ -1206,6 +1207,7 @@ val(aimc.inertiaRotor.flange_b.tau, 0);
// {31:68}
// {{{74:30}, {73:29}, {72:28}, {56:32}, {71:33}, {55:31}, {54:81}, {69:37}, {70:76}, {59:14}, {58:13}, {60:49}, {65:48}, {64:69}, {61:70}, {68:71}, {67:72}, {57:36}, {63:77}, {75:73}, {51:80}, {76:74}, {50:75}}
// ,{62, 53, 49, 52, 66:79, 78, 15, 16, 47}} Size: 5 linear
// For more information please use "-d=tearingdump".
// {91:91}
// {93:93}
// {90:90}
Expand Down

0 comments on commit ef87d10

Please sign in to comment.