Skip to content

Commit

Permalink
Tighten tolerance of continuous Cpp events
Browse files Browse the repository at this point in the history
This allows to remove a workaround for StateGraph from DASSL.cpp.

The effected examples ExecutionPaths and ShowCompositeStep were working
with 500 steps, but not with 2500 steps in daily library tests anymore.

The change is not applied to OMSI CodegenCpp.tpl, because the combination
cvode/kinsol performs better in msl32_cpp coverage for lose tolerances.
  • Loading branch information
rfranke committed Aug 14, 2021
1 parent c3c41ba commit 6384d1b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 25 deletions.
9 changes: 4 additions & 5 deletions OMCompiler/Compiler/Template/CodegenCpp.tpl
Expand Up @@ -12103,9 +12103,9 @@ template giveZeroFunc3(Integer index1, Exp relation, Text &varDecls /*BUFP*/,Tex
case LESS(__) then
<<
if(_conditions[<%zerocrossingIndex%>])
f[<%index1%>]=(<%e1%> - 1e-6 - <%e2%>);
f[<%index1%>]=(<%e1%> - 1e-6 - <%e2%>); // ToDo: tighter 1e-9 better for dassl
else
f[<%index1%>]=(<%e2%> - <%e1%> - 1e-6);
f[<%index1%>]=(<%e2%> - <%e1%> - 1e-6);
>>
case LESSEQ(__) then
<<
Expand All @@ -12128,10 +12128,9 @@ template giveZeroFunc3(Integer index1, Exp relation, Text &varDecls /*BUFP*/,Tex
else
f[<%index1%>] = (<%e1%> - 1e-6 - <%e2%>);
>>
else
else
<<
f[<%index1%>] = -1;
/*error(sourceInfo(), 'Unknown relation: <%ExpressionDumpTpl.dumpExp(rel,"\"")%> for <%index1%>')*/
error(sourceInfo(), 'Unknown relation: <%ExpressionDumpTpl.dumpExp(rel,"\"")%> for <%index1%>')
>>
end match
case CALL(path=IDENT(name="sample"), expLst={_, start, interval}) then
Expand Down
21 changes: 10 additions & 11 deletions OMCompiler/Compiler/Template/CodegenCppOld.tpl
Expand Up @@ -12308,35 +12308,34 @@ template giveZeroFunc3(Integer index1, Exp relation, Text &varDecls /*BUFP*/,Tex
case LESS(__) then
<<
if(_conditions[<%zerocrossingIndex%>])
f[<%index1%>]=(<%e1%> - 1e-6 - <%e2%>);
f[<%index1%>]=(<%e1%> - 1e-9 - <%e2%>);
else
f[<%index1%>]=(<%e2%> - <%e1%> - 1e-6);
f[<%index1%>]=(<%e2%> - <%e1%> - 1e-9);
>>
case LESSEQ(__) then
<<
if(_conditions[<%zerocrossingIndex%>])
f[<%index1%>] = (<%e1%> - 1e-6 - <%e2%>);
f[<%index1%>] = (<%e1%> - 1e-9 - <%e2%>);
else
f[<%index1%>] = (<%e2%> - <%e1%> - 1e-6);
f[<%index1%>] = (<%e2%> - <%e1%> - 1e-9);
>>
case GREATER(__) then
<<
if(_conditions[<%zerocrossingIndex%>])
f[<%index1%>] = (<%e2%> - <%e1%> - 1e-6);
f[<%index1%>] = (<%e2%> - <%e1%> - 1e-9);
else
f[<%index1%>] = (<%e1%> - 1e-6 - <%e2%>);
f[<%index1%>] = (<%e1%> - 1e-9 - <%e2%>);
>>
case GREATEREQ(__) then
<<
if(_conditions[<%zerocrossingIndex%>])
f[<%index1%>] = (<%e2%> - <%e1%> - 1e-6);
f[<%index1%>] = (<%e2%> - <%e1%> - 1e-9);
else
f[<%index1%>] = (<%e1%> - 1e-6 - <%e2%>);
f[<%index1%>] = (<%e1%> - 1e-9 - <%e2%>);
>>
else
else
<<
f[<%index1%>] = -1;
/*error(sourceInfo(), 'Unknown relation: <%ExpressionDumpTpl.dumpExp(rel,"\"")%> for <%index1%>')*/
error(sourceInfo(), 'Unknown relation: <%ExpressionDumpTpl.dumpExp(rel,"\"")%> for <%index1%>')
>>
end match
case CALL(path=IDENT(name="sample"), expLst={_, start, interval}) then
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/SimulationRuntime/cpp/Solver/DASSL/DASSL.cpp
Expand Up @@ -277,7 +277,7 @@ void DASSL::initialize()

// Initial step size
_info[7] = 1;
_rwork[2] = 1e-30; // start with very small value to not miss events later on -- see StateGraph!?
_rwork[2] = _settings->gethInit();

LOGGER_WRITE_END(LC_SOLVER, LL_DEBUG);
}
Expand Down
Expand Up @@ -9,7 +9,7 @@

runScript("../common/ModelTestingDefaults.mos"); getErrorString();

modelTestingType := OpenModelicaModelTesting.Kind.VerifiedSimulation;
modelTestingType := OpenModelicaModelTesting.Kind.SimpleSimulation;
modelName := $TypeName(Modelica.Electrical.Analog.Examples.AmplifierWithOpAmpDetailed);
compareVars :=
{
Expand All @@ -30,13 +30,12 @@ runScript(modelTesting);getErrorString();
// "true
// "
// ""
// OpenModelicaModelTesting.Kind.VerifiedSimulation
// OpenModelicaModelTesting.Kind.SimpleSimulation
// Modelica.Electrical.Analog.Examples.AmplifierWithOpAmpDetailed
// {"opAmp.v_in","opAmp.q_fr1","opAmp.q_fr2","opAmp.q_fr3","opAmp.q_fp1","opAmp.v_source","opAmp.x"}
// OpenModelicaModelTesting.SimulationRuntime.Cpp
// Simulation options: startTime = 0.0, stopTime = 0.003, numberOfIntervals = 2500, tolerance = 2e-07, method = 'dassl', fileNamePrefix = 'Modelica.Electrical.Analog.Examples.AmplifierWithOpAmpDetailed', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''
// Result file: Modelica.Electrical.Analog.Examples.AmplifierWithOpAmpDetailed_res.mat
// Files Equal!
// "true
// "
// ""
Expand Down
Expand Up @@ -9,7 +9,7 @@

runScript("../common/ModelTestingDefaults.mos"); getErrorString();

modelTestingType := OpenModelicaModelTesting.Kind.Compilation;
modelTestingType := OpenModelicaModelTesting.Kind.VerifiedSimulation;
modelName := $TypeName(Modelica.Electrical.Analog.Examples.DifferenceAmplifier);
compareVars :=
{
Expand All @@ -32,11 +32,22 @@ runScript(modelTesting);getErrorString();
// "true
// "
// ""
// OpenModelicaModelTesting.Kind.Compilation
// OpenModelicaModelTesting.Kind.VerifiedSimulation
// Modelica.Electrical.Analog.Examples.DifferenceAmplifier
// {"C1.v","C4.v","C5.v","C2.v","C3.v","Transistor1.Tr.vbc","Transistor1.Tr.vbe","Transistor2.Tr.vbc","Transistor2.Tr.vbe"}
// OpenModelicaModelTesting.SimulationRuntime.Cpp
// Compilation succeeded
// Simulation options: startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'Modelica.Electrical.Analog.Examples.DifferenceAmplifier', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''
// Result file: Modelica.Electrical.Analog.Examples.DifferenceAmplifier_res.mat
// Files Equal!
// Error: Could not read variable Transistor1.Tr.vbc in file Modelica.Electrical.Analog.Examples.DifferenceAmplifier_res.mat.
// Warning: Get data of variable Transistor1.Tr.vbc from file Modelica.Electrical.Analog.Examples.DifferenceAmplifier_res.mat failed!
// Error: Could not read variable Transistor1.Tr.vbe in file Modelica.Electrical.Analog.Examples.DifferenceAmplifier_res.mat.
// Warning: Get data of variable Transistor1.Tr.vbe from file Modelica.Electrical.Analog.Examples.DifferenceAmplifier_res.mat failed!
// Error: Could not read variable Transistor2.Tr.vbc in file Modelica.Electrical.Analog.Examples.DifferenceAmplifier_res.mat.
// Warning: Get data of variable Transistor2.Tr.vbc from file Modelica.Electrical.Analog.Examples.DifferenceAmplifier_res.mat failed!
// Error: Could not read variable Transistor2.Tr.vbe in file Modelica.Electrical.Analog.Examples.DifferenceAmplifier_res.mat.
// Warning: Get data of variable Transistor2.Tr.vbe from file Modelica.Electrical.Analog.Examples.DifferenceAmplifier_res.mat failed!
//
// "true
// "
// ""
Expand Down
Expand Up @@ -9,7 +9,7 @@

runScript("../common/ModelTestingDefaults.mos"); getErrorString();

modelTestingType := OpenModelicaModelTesting.Kind.SimpleSimulation;
modelTestingType := OpenModelicaModelTesting.Kind.VerifiedSimulation;
modelName := $TypeName(Modelica.Electrical.Digital.Examples.Counter);
compareVars :=
{
Expand All @@ -33,12 +33,13 @@ runScript(modelTesting);getErrorString();
// "true
// "
// ""
// OpenModelicaModelTesting.Kind.SimpleSimulation
// OpenModelicaModelTesting.Kind.VerifiedSimulation
// Modelica.Electrical.Digital.Examples.Counter
// {"Enable.y","Clock.y","Counter.q[1]","Counter.q[2]","Counter.q[3]","Counter.q[4]","Q0.y[1]","Q1.y[1]","Q2.y[1]","Q3.y[1]"}
// OpenModelicaModelTesting.SimulationRuntime.Cpp
// Simulation options: startTime = 0.0, stopTime = 100.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'Modelica.Electrical.Digital.Examples.Counter', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''
// Result file: Modelica.Electrical.Digital.Examples.Counter_res.mat
// Files Equal!
// "true
// "
// ""
Expand Down
Expand Up @@ -89,6 +89,13 @@ runScript(modelTesting);getErrorString();
// OpenModelicaModelTesting.SimulationRuntime.Cpp
// Simulation options: startTime = 0.0, stopTime = 200.0, numberOfIntervals = 500, tolerance = 1e-05, method = 'dassl', fileNamePrefix = 'Modelica.Fluid.Examples.HeatExchanger.HeatExchangerSimulation', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''
// Result file: Modelica.Fluid.Examples.HeatExchanger.HeatExchangerSimulation_res.mat
// Messages: ERROR : solver: DASSL: failed step at t = 54.987305: Nonlinear solver 4268 stopped at time 54.9873 with error in algloop solver:
// Nonlinear solver failed!
// ERROR : solver: SimManager: Simulation stopped with errors before t = 200.000000
// ERROR : solver: SimManager: DASSL: solve failed with idid = 1
// ERROR : solver: SimController: Simulation failed using nonlinear solver kinsol
// ERROR : solver: SimController: Recovering with nonlinear solver newton
//
// Files Equal!
// Warning: The model contains alias variables with redundant start and/or conflicting 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

0 comments on commit 6384d1b

Please sign in to comment.