Skip to content

Commit

Permalink
[C] Constrain nls iteration variables (#12201)
Browse files Browse the repository at this point in the history
  • Loading branch information
phannebohm committed Apr 5, 2024
1 parent 05e800f commit 1d26a1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Expand Up @@ -498,6 +498,10 @@ NLS_SOLVER_STATUS solveHybrd(DATA *data, threadData_t *threadData, NONLINEAR_SYS
/* start solving loop */
while(!giveUp && !success)
{
/* constrain x */
for(i=0; i<hybrdData->n; i++)
hybrdData->x[i] = fmax(nlsData->min[i], fmin(hybrdData->x[i], nlsData->max[i]));

for(i=0; i<hybrdData->n; i++)
hybrdData->xScalefactors[i] = fmax(fabs(hybrdData->x[i]), nlsData->nominal[i]);

Expand Down
Expand Up @@ -28,12 +28,15 @@ runScript(modelTesting);getErrorString();
// OpenModelicaModelTesting.Kind.SimpleSimulation
// Modelica.Fluid.Examples.Tanks.TanksWithOverflow
// {"upperTank.level","upperTank.medium.h","lowerTank.level","lowerTank.medium.h"}
// Simulation options: startTime = 0.0, stopTime = 25000.0, numberOfIntervals = 5000, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'Modelica.Fluid.Examples.Tanks.TanksWithOverflow', options = '', outputFormat = 'mat', variableFilter = 'time|upperTank.level|upperTank.medium.h|lowerTank.level|lowerTank.medium.h', cflags = '', simflags = ' -abortSlowSimulation -alarm=360 -emit_protected'
// Simulation options: startTime = 0.0, stopTime = 25000.0, numberOfIntervals = 5000, tolerance = 1e-6, method = 'dassl', fileNamePrefix = 'Modelica.Fluid.Examples.Tanks.TanksWithOverflow', options = '', outputFormat = 'mat', variableFilter = 'time|upperTank.level|upperTank.medium.h|lowerTank.level|lowerTank.medium.h', cflags = '', simflags = ' -abortSlowSimulation -alarm=360 -emit_protected'
// Result file: Modelica.Fluid.Examples.Tanks.TanksWithOverflow_res.mat
// Messages: LOG_ASSERT | warning | [Modelica 3.2.1+maint.om/Media/package.mo:5259:7-5259:55:writable]
// | | | | The following assertion has been violated at time 0.000000
// | | | | ((overflow.flowModel.states[1].p >= 0.0 and overflow.flowModel.states[1].p <= 100000000.0)) --> "Variable violating min/max constraint: 0.0 <= overflow.flowModel.states[1].p <= 100000000.0, has value: -93465.5"
// | | | | ((overflow.flowModel.states[1].p >= 0.0 and overflow.flowModel.states[1].p <= 1e8)) --> "Variable violating min/max constraint: 0.0 <= overflow.flowModel.states[1].p <= 1e8, has value: -93465.5"
// LOG_SUCCESS | info | The initialization finished successfully with 3 homotopy steps.
// LOG_ASSERT | info | [Modelica 3.2.1+maint.om/Fluid/Interfaces.mo:15:5-15:79:writable]
// | | | | The following assertion has been violated at time 0.325042
// | | | | ((lowerTank.ports[2].p >= 0.0 and lowerTank.ports[2].p <= 1e8)) --> "Variable violating min/max constraint: 0.0 <= lowerTank.ports[2].p <= 1e8, has value: -419515"
// LOG_SUCCESS | info | The simulation finished successfully.
//
// "true
Expand Down

0 comments on commit 1d26a1a

Please sign in to comment.