Skip to content

Commit

Permalink
[BE] update non linear iteration var dump
Browse files Browse the repository at this point in the history
  • Loading branch information
kabdelhak authored and lochel committed Aug 29, 2019
1 parent 34e9358 commit 02516b2
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 68 deletions.
35 changes: 22 additions & 13 deletions OMCompiler/Compiler/BackEnd/BackendDump.mo
Expand Up @@ -2328,12 +2328,12 @@ algorithm
end match;
end jacobianTypeStr;

public function jacobianString"dumps a string representation of a jacobian.
public function dumpJacobianString
"dumps a string representation of a jacobian.
author: Waurich TUD 2014-10"
input BackendDAE.Jacobian jacIn;
output String sOut;
algorithm
sOut := match(jacIn)
_ := match(jacIn)
local
BackendDAE.BackendDAE dae;
BackendDAE.FullJacobian fJac;
Expand All @@ -2343,28 +2343,37 @@ algorithm
String s;
case(BackendDAE.FULL_JACOBIAN(jacobian=fJac))
equation
s = "FULL JACOBIAN:\n";
s = s + dumpJacobianStr(fJac);
then s;
s = "###############\n" +
" FULL_JACOBIAN \n" +
"###############\n\n" +
dumpJacobianStr(fJac);
print(s);
then "";
case(BackendDAE.GENERIC_JACOBIAN(jacobian=SOME(sJac),sparsePattern=sparsePattern))
equation
((dae,_,_,_,_, _)) = sJac;
s = "GENERIC JACOBIAN:\n";
print("##################\n" +
" GENERIC_JACOBIAN \n" +
"##################\n\n");
dumpBackendDAE(dae,"Directional Derivatives System");
dumpSparsityPattern(sparsePattern,"Sparse Pattern");
then s;
then "";
case(BackendDAE.GENERIC_JACOBIAN(jacobian=NONE(),sparsePattern=sparsePattern))
equation
s = "GENERIC JACOBIAN:\n";
print("##################\n" +
" GENERIC_JACOBIAN \n" +
"##################\n\n");
dumpSparsityPattern(sparsePattern,"Sparse Pattern");
then s;
then "";

case(BackendDAE.EMPTY_JACOBIAN())
equation
s = "EMPTY JACOBIAN:\n";
then s;
print("################\n" +
" EMPTY_JACOBIAN \n" +
"################\n\n");
then "";
end match;
end jacobianString;
end dumpJacobianString;

public function symJacString "dumps a string representation of a jacobian."
input tuple<Option<BackendDAE.SymbolicJacobian>, BackendDAE.SparsePattern, BackendDAE.SparseColoring> jacIn;
Expand Down
99 changes: 51 additions & 48 deletions OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo
Expand Up @@ -2751,10 +2751,9 @@ algorithm
// Check if all nonlinear iteration variables have start values
if BackendDAEUtil.isInitializationDAE(inShared) then
try
checkNonLinDependecies(outComp,inEqns);
checkNonLinDependecies(outComp,inEqns);
else
// ToDo Fix me! Like seriously!
Error.addInternalError("function calculateJacobianComponent failed to check all non-linear iteration variables for start values.", sourceInfo());
Error.addInternalError("function calculateJacobianComponent failed to check all non-linear iteration variables for start values.", sourceInfo());
end try;
end if;
end calculateJacobianComponent;
Expand All @@ -2778,7 +2777,7 @@ algorithm
BackendDAE.InnerEquations innerEquations;
Boolean linear;
String str;
// Case non-linear teared equation system
// Case non-linear torn equation system
case (BackendDAE.TORNSYSTEM(strictTearingSet=BackendDAE.TEARINGSET(jac=jac, residualequations=resIndices, innerEquations=innerEquations), linear=false))
algorithm
for eq in innerEquations loop
Expand All @@ -2794,7 +2793,7 @@ algorithm
printNonLinIterVarsAndEqs(jac,eqnIndices,inEqns);
then "";

// Case non-linear non-teared equation system
// Case non-linear non-torn equation system
case (BackendDAE.EQUATIONSYSTEM(eqns=eqnIndices, jac=jac, jacType=BackendDAE.JAC_NONLINEAR()))
algorithm
printNonLinIterVarsAndEqs(jac,eqnIndices,inEqns);
Expand Down Expand Up @@ -2874,53 +2873,57 @@ protected function printNonLinIterVarsAndEqs
input BackendDAE.Jacobian jacobian;
input list<Integer> eqnIndices;
input BackendDAE.EquationArray inEqns;
protected
BackendDAE.EqSystem syst;
BackendDAE.Shared shared;
Integer idx = 1;
list<BackendDAE.Var> diffVars, residualVars, allDiffedVars, nonLin = {}, nonLinStart = {}, lin = {};
list<DAE.ComponentRef> dependentVarsCref;
DAE.ComponentRef varCref;
BackendDAE.Var var;
String name;
algorithm
BackendDAE.GENERIC_JACOBIAN(SOME((BackendDAE.DAE({syst}, shared),name,diffVars,residualVars,allDiffedVars,dependentVarsCref))) := jacobian;

// Get non-linear variables without start value
for varCref in dependentVarsCref loop
for var in diffVars loop
if ComponentReference.crefEqual(varCref, var.varName) then
if (not BackendVariable.varHasStartValue(var)) then
nonLin := var::nonLin;
else
nonLinStart := var::nonLinStart;
_ := match jacobian
local
BackendDAE.EqSystem syst;
BackendDAE.Shared shared;
Integer idx = 1;
list<BackendDAE.Var> diffVars, residualVars, allDiffedVars, nonLin = {}, nonLinStart = {}, lin = {};
list<DAE.ComponentRef> dependentVarsCref;
DAE.ComponentRef varCref;
BackendDAE.Var var;
String name;
case BackendDAE.GENERIC_JACOBIAN(jacobian = SOME((BackendDAE.DAE({syst}, shared),name,diffVars,residualVars,allDiffedVars,dependentVarsCref)))
algorithm
// Get non-linear variables without start value
for varCref in dependentVarsCref loop
for var in diffVars loop
if ComponentReference.crefEqual(varCref, var.varName) then
if (not BackendVariable.varHasStartValue(var)) then
nonLin := var::nonLin;
else
nonLinStart := var::nonLinStart;
end if;
end if;
end for;
end for;
if not listEmpty(nonLin) then
BackendDump.dumpVarList(nonLin, "Nonlinear iteration variables with default zero start attribute in " + name + ".");
end if;
if not listEmpty(nonLinStart) then
BackendDump.dumpVarList(nonLinStart, "Nonlinear iteration variables with predefined start attribute in " + name + ".");
end if;
end if;
end for;
end for;
if not listEmpty(nonLin) then
BackendDump.dumpVarList(nonLin, "Nonlinear iteration variables with default zero start attribute in " + name + ".");
end if;
if not listEmpty(nonLinStart) then
BackendDump.dumpVarList(nonLinStart, "Nonlinear iteration variables with predefined start attribute in " + name + ".");
end if;

// Get linear variables with start value, but ignore discrete vars
for var in allDiffedVars loop
if (BackendVariable.varHasStartValue(var) and not BackendVariable.isVarDiscrete(var) ) then
lin := var::lin;
end if;
end for;
if not listEmpty(lin) then
BackendDump.dumpVarList(lin, "Linear iteration variables with predefined start attributes that are unrelevant in " + name + ".");
end if;
// Get linear variables with start value, but ignore discrete vars
for var in allDiffedVars loop
if (BackendVariable.varHasStartValue(var) and not BackendVariable.isVarDiscrete(var) ) then
lin := var::lin;
end if;
end for;
if not listEmpty(lin) then
BackendDump.dumpVarList(lin, "Linear iteration variables with predefined start attributes that are unrelevant in " + name + ".");
end if;

if not (listEmpty(nonLin) and listEmpty(nonLinStart) and listEmpty(lin)) then
print("Info: Only non-linear iteration variables in non-linear eqation systems require start values. " +
"All other start values have no influence on convergence and are ignored. " +
"Use \"-d=dumpLoops\" to show all loops. In OMEdit Tools->Options->Simulation->OMCFlags, in "+
"OMNotebook call setCommandLineOptions(\"-d=dumpLoops\")\n\n");
end if;
if not (listEmpty(nonLin) and listEmpty(nonLinStart) and listEmpty(lin)) then
print("Info: Only non-linear iteration variables in non-linear eqation systems require start values. " +
"All other start values have no influence on convergence and are ignored. " +
"Use \"-d=dumpLoops\" to show all loops. In OMEdit Tools->Options->Simulation->OMCFlags, in "+
"OMNotebook call setCommandLineOptions(\"-d=dumpLoops\")\n\n");
end if;
then "";
else "";
end match;
// ToDo
// BackendDAE.FULL_JACOBIAN()
end printNonLinIterVarsAndEqs;
Expand Down
10 changes: 10 additions & 0 deletions OMCompiler/Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -436,6 +436,16 @@ algorithm
outString := stringDelimitList(toStringList(inComponentRef), if Flags.getConfigBool(Flags.MODELICA_OUTPUT) then "__" else ".");
end crefStr;

public function crefListStr
"This function simply converts a list of ComponentReferences to a String."
input list<DAE.ComponentRef> crList;
output String outString = "";
algorithm
for cr in crList loop
outString := outString + crefStr(cr) + "\n";
end for;
end crefListStr;

public function crefModelicaStr
"Same as crefStr, but uses _ instead of . "
input DAE.ComponentRef inComponentRef;
Expand Down
Expand Up @@ -23,7 +23,6 @@ simulate(OverdeterminedInitialization.Fluid.DynamicPipeInitialValues); getErrorS
// "
// end SimulationResult;
// "Warning: The model contains alias variables with conflicting start and/or nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
// [BackEnd/SymbolicJacobian.mo:0:0-0:0:writable] Error: Internal error function calculateJacobianComponent failed to check all non-linear iteration variables for start values.
// Warning: Assuming fixed start value for the following 1 variables:
// m_flow_initial:DISCRETE(unit = "kg/s" fixed = false ) type: Real
// Warning: The initial conditions are over specified. The following 1 initial equations are redundant, so they are removed from the initialization sytem:
Expand Down
Expand Up @@ -17,7 +17,6 @@ buildModel(OverdeterminedInitialization.Fluid.DynamicPipeLumpedPressureInitializ
// ""
// {"OverdeterminedInitialization.Fluid.DynamicPipeLumpedPressureInitialization","OverdeterminedInitialization.Fluid.DynamicPipeLumpedPressureInitialization_init.xml"}
// "Warning: The model contains alias variables with conflicting start and/or nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
// [BackEnd/SymbolicJacobian.mo:0:0-0:0:writable] Error: Internal error function calculateJacobianComponent failed to check all non-linear iteration variables for start values.
// Warning: Assuming fixed start value for the following 1 variables:
// m_flow_initial:DISCRETE(unit = "kg/s" fixed = false ) type: Real
// Warning: The initial conditions are over specified. The following 4 initial equations are redundant, so they are removed from the initialization sytem:
Expand Down
Expand Up @@ -18,7 +18,6 @@ buildModel(OverdeterminedInitialization.Fluid.DynamicPipesSeriesLargeNSteadyStat
// {"OverdeterminedInitialization.Fluid.DynamicPipesSeriesLargeNSteadyStateInitial","OverdeterminedInitialization.Fluid.DynamicPipesSeriesLargeNSteadyStateInitial_init.xml"}
// "Warning: The model contains alias variables with conflicting start and/or nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
// Notification: The following initial equation is redundant and consistent due to simplifications in RemoveSimpleEquations and therefore removed from the initialization problem: der(pipe1.mediums[1].p) = 0.0 -> 0.0 = 0.0
// [BackEnd/SymbolicJacobian.mo:0:0-0:0:writable] Error: Internal error function calculateJacobianComponent failed to check all non-linear iteration variables for start values.
// Warning: The initial conditions are over specified. The following 1 initial equations are redundant, so they are removed from the initialization sytem:
// $DER.pipe1.mediums[50].p = 0.0.
// "
Expand Down
Expand Up @@ -18,7 +18,6 @@ buildModel(OverdeterminedInitialization.Fluid.DynamicPipesSeriesSteadyStateIniti
// {"OverdeterminedInitialization.Fluid.DynamicPipesSeriesSteadyStateInitial","OverdeterminedInitialization.Fluid.DynamicPipesSeriesSteadyStateInitial_init.xml"}
// "Warning: The model contains alias variables with conflicting start and/or nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
// Notification: The following initial equation is redundant and consistent due to simplifications in RemoveSimpleEquations and therefore removed from the initialization problem: der(pipe1.mediums[1].p) = 0.0 -> 0.0 = 0.0
// [BackEnd/SymbolicJacobian.mo:0:0-0:0:writable] Error: Internal error function calculateJacobianComponent failed to check all non-linear iteration variables for start values.
// Warning: The initial conditions are over specified. The following 1 initial equations are redundant, so they are removed from the initialization sytem:
// $DER.pipe1.mediums[5].p = 0.0.
// "
Expand Down
Expand Up @@ -18,7 +18,6 @@ buildModel(OverdeterminedInitialization.Fluid.TwoVolumesFullInitial); getErrorSt
// {"OverdeterminedInitialization.Fluid.TwoVolumesFullInitial","OverdeterminedInitialization.Fluid.TwoVolumesFullInitial_init.xml"}
// "Warning: The model contains alias variables with conflicting start and/or nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
// Warning: It was not possible to determine if the initialization problem is consistent, because of not evaluable parameters/start values during compile time: V1.medium.p = V1.p_start (V2.p_start = V1.p_start)
// [BackEnd/SymbolicJacobian.mo:0:0-0:0:writable] Error: Internal error function calculateJacobianComponent failed to check all non-linear iteration variables for start values.
// Warning: The initial conditions are over specified. The following 1 initial equations are redundant, so they are removed from the initialization sytem:
// V1.medium.p = V1.p_start.
// "
Expand Down
Expand Up @@ -26,7 +26,6 @@ simulate(OverdeterminedInitialization.Fluid.TwoVolumesFullInitialInconsistent);
// end SimulationResult;
// "Warning: The model contains alias variables with conflicting start and/or nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
// Warning: It was not possible to determine if the initialization problem is consistent, because of not evaluable parameters/start values during compile time: V1.medium.p = V1.p_start (V2.p_start = V1.p_start)
// [BackEnd/SymbolicJacobian.mo:0:0-0:0:writable] Error: Internal error function calculateJacobianComponent failed to check all non-linear iteration variables for start values.
// Warning: The initial conditions are over specified. The following 1 initial equations are redundant, so they are removed from the initialization sytem:
// V1.medium.p = V1.p_start.
// Warning: The model contains alias variables with conflicting start and/or nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
Expand Down
Expand Up @@ -17,7 +17,6 @@ buildModel(OverdeterminedInitialization.Fluid.TwoVolumesFullSteadyStatePressureA
// ""
// {"OverdeterminedInitialization.Fluid.TwoVolumesFullSteadyStatePressureAndTemperature","OverdeterminedInitialization.Fluid.TwoVolumesFullSteadyStatePressureAndTemperature_init.xml"}
// "Warning: The model contains alias variables with conflicting start and/or nominal values. It is recommended to resolve the conflicts, because otherwise the system could be hard to solve. To print the conflicting alias sets and the chosen candidates please use -d=aliasConflicts.
// [BackEnd/SymbolicJacobian.mo:0:0-0:0:writable] Error: Internal error function calculateJacobianComponent failed to check all non-linear iteration variables for start values.
// Warning: The initial conditions are over specified. The following 1 initial equations are redundant, so they are removed from the initialization sytem:
// $DER.V1.medium.p = 0.0.
// "
Expand Down

0 comments on commit 02516b2

Please sign in to comment.