#4985 closed defect (fixed)
OMC accepts invalid nonlinear system solutions
Reported by: | Francesco Casella | Owned by: | Willi Braun |
---|---|---|---|
Priority: | blocker | Milestone: | 1.13.0 |
Component: | Run-time | Version: | |
Keywords: | Cc: |
Description
Please run the following simple test
model Test Real x(min = 0); Real y(start = 0, fixed = true); equation 0 = 1e-6*x + sin(x+0.5); der(y) = x; end Test;
This equation has (among others) two solutions: x = -0.5 and x = pi-0.5. The first is found easily by Newton's algorithm, give the initial guess of zero, but it is invalid because it violates the min constraint.
OMC responds with:
LOG_SUCCESS | info | The initialization finished successfully without homotopy method.
which is wrong, because the initialization violates the constraint. Then, it reports
assert | warning | The following assertion has been violated at time -4.995000 x >= 0.0 assert | warning | Variable violating min constraint: 0.0 <= x, has value: -0.5
Then the simulation starts anyway and eventually OMC reports
LOG_SUCCESS | info | The simulation finished successfully.
IMHO the violation of a min/max attribute should generate an error, not a warning, e.g.
Error: Variable violating min constraint: 0.0 <= x, has value: -0.5 To disable this check, set the simulation flag -ignoreMinMax
One could then set a flage to make this a warning, if some old code has wrong min/max attributes, *as an interim solution before the min/max attribute in the model is fixed*
I would also use this assertions as a guide to the solver. For example, consider this revised test case
model Test Real x(min = 0); Real y(start = 0, fixed = true); equation 0 = homotopy(1e-6*x + sin(x+0.5), x-2.65); der(y) = x; end Test;
in this case, the Newton solver would find the solution x = -0.5, but as it is invalid, the solver should fail. Then, the homotopy-based solver would be invoked, and the right solution would be found. Currently, the wrong one is produced with the default settings.
Change History (6)
comment:1 by , 6 years ago
comment:2 by , 6 years ago
Component: | *unknown* → Run-time |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:3 by , 6 years ago
Proposal: add optional simulation flag if possible (default false) to enforce min/max attributes on initial solution.
If not possible, then add -d flag with the same effect
comment:4 by , 6 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
In the current it's not possible to do that in the simulation. So an omc debug flag has been added "warnMinMax" with is set to true, and can be disabled for error asserts.
Done in in PR2676.
comment:6 by , 6 years ago
This issue is fixed, in the sense that if I set -d=nowarnMinMax
, the model with homotopy does not produce the x = -0.5
solution.
However, the homotopy solver is not triggered, which would eventually allow to find the desired positive solution to the equation. I just opened #5139 on this topic.
BTW, I report the definition of type Real from the Modelica spec
The equation section has an assert statement, which, according to Section 8.3.7 means