From 1cb1c69e62808b086ac8d88ec6598835293b8faa Mon Sep 17 00:00:00 2001 From: phannebohm Date: Thu, 4 Apr 2024 18:34:47 +0200 Subject: [PATCH] Print true name of iteration variable when inf/nan (#12195) Fixes #12191 --- OMCompiler/Compiler/Template/CodegenC.tpl | 3 ++- testsuite/openmodelica/dataReconciliation/TSP_Pipe3.mos | 2 +- testsuite/simulation/modelica/tearing/dynamicTearing3.mos | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/OMCompiler/Compiler/Template/CodegenC.tpl b/OMCompiler/Compiler/Template/CodegenC.tpl index f0ccab42111..86bda496bd0 100644 --- a/OMCompiler/Compiler/Template/CodegenC.tpl +++ b/OMCompiler/Compiler/Template/CodegenC.tpl @@ -3160,7 +3160,8 @@ match system /* iteration variables */ for (i=0; i<<%listLength(nls.crefs)%>; i++) { if (isinf(xloc[i]) || isnan(xloc[i])) { - errorStreamPrint(LOG_NLS, 0, "residualFunc<%nls.index%>: Iteration variable xloc[%i] is nan.", i); + errorStreamPrint(LOG_NLS, 0, "residualFunc<%nls.index%>: Iteration variable `%s` is inf or nan.", + modelInfoGetEquation(&data->modelData->modelDataXml, <%nls.index%>).vars[i]); for (j=0; j<<%listLength(nls.crefs)%>; j++) { res[j] = NAN; } diff --git a/testsuite/openmodelica/dataReconciliation/TSP_Pipe3.mos b/testsuite/openmodelica/dataReconciliation/TSP_Pipe3.mos index 999b34e21d7..3e54db62c4d 100644 --- a/testsuite/openmodelica/dataReconciliation/TSP_Pipe3.mos +++ b/testsuite/openmodelica/dataReconciliation/TSP_Pipe3.mos @@ -2258,7 +2258,7 @@ getErrorString(); // LOG_STDOUT | info | DataReconciliation Starting! // LOG_STDOUT | info | NewDataReconciliationSimpleTests.TSP_Pipe3 // LOG_STDOUT | warning | The default linear solver fails, the fallback solver with total pivoting is started at time 1.000000. That might raise performance issues, for more information use -lv LOG_LS. -// LOG_NLS | error | residualFunc76: Iteration variable xloc[0] is nan. +// LOG_NLS | error | residualFunc76: Iteration variable `singularPressureLoss3.Pm` is inf or nan. // LOG_ASSERT | debug | residualFunc76 failed at time=1. // | | | | For more information please use -lv LOG_NLS. // LOG_ASSERT | debug | Solving non-linear system 76 failed at time=1. diff --git a/testsuite/simulation/modelica/tearing/dynamicTearing3.mos b/testsuite/simulation/modelica/tearing/dynamicTearing3.mos index 4f04e31a58f..dfb67c99645 100644 --- a/testsuite/simulation/modelica/tearing/dynamicTearing3.mos +++ b/testsuite/simulation/modelica/tearing/dynamicTearing3.mos @@ -130,7 +130,7 @@ simulate(dynamicTearing3,startTime=0,stopTime=2,numberOfIntervals=500,simflags=" // Forced selection of Tearing Variables: // ======================================== // Unsolvables as tVars: 3 -// Variables with annotation attribute 'always' as tVars: +// Variables with annotation attribute 'always' as tVars: // // Matching // ======================================== @@ -265,7 +265,7 @@ simulate(dynamicTearing3,startTime=0,stopTime=2,numberOfIntervals=500,simflags=" // Forced selection of Tearing Variables: // ======================================== // Unsolvables as tVars: 4 -// Variables with annotation attribute 'always' as tVars: +// Variables with annotation attribute 'always' as tVars: // // Matching // ======================================== @@ -369,13 +369,13 @@ simulate(dynamicTearing3,startTime=0,stopTime=2,numberOfIntervals=500,simflags=" // // record SimulationResult // resultFile = "dynamicTearing3_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 2.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'dynamicTearing3', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv=LOG_DT_CONS'", +// simulationOptions = "startTime = 0.0, stopTime = 2.0, numberOfIntervals = 500, tolerance = 1e-6, method = 'dassl', fileNamePrefix = 'dynamicTearing3', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv=LOG_DT_CONS'", // messages = "LOG_DT_CONS | info | The following local constraint is violated: // | | | | abs(x) > 1e-12 // LOG_SUCCESS | info | The initialization finished successfully without homotopy method. // LOG_DT_CONS | info | The following local constraint is violated: // | | | | abs(x) > 1e-12 -// LOG_NLS | error | residualFunc10: Iteration variable xloc[0] is nan. +// LOG_NLS | error | residualFunc10: Iteration variable `z` is inf or nan. // LOG_ASSERT | debug | residualFunc10 failed at time=0.004. // | | | | For more information please use -lv LOG_NLS. // LOG_DT_CONS | info | The following local constraint is violated: