Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#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 Francesco Casella, 6 years ago

BTW, I report the definition of type Real from the Modelica spec

type Real // Note: Defined with Modelica syntax although predefined
  RealType value; // Accessed without dot-notation
  parameter StringType quantity = "";
  parameter StringType unit = "" "Unit used in equations";
  parameter StringType displayUnit = "" "Default display unit";
  parameter RealType min=-Inf, max=+Inf; // Inf denotes a large value
  parameter RealType start = 0; // Initial value
  parameter BooleanType fixed = true, // default for parameter/constant;
                              = false; // default for other variables
  parameter RealType nominal; // Nominal value
  parameter BooleanType unbounded=false; // For error control
  parameter StateSelect stateSelect = StateSelect.default;
equation
  assert(value >= min and value <= max, "Variable value out of limit");
end Real;

The equation section has an assert statement, which, according to Section 8.3.7 means

assert(condition, message); // Uses level=AssertionLevel.error

comment:2 by Francesco Casella, 6 years ago

Component: *unknown*Run-time
Owner: changed from somebody to Willi Braun
Status: newassigned

comment:3 by Francesco Casella, 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 Willi Braun, 6 years ago

Resolution: fixed
Status: assignedclosed

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:5 by Francesco Casella, 6 years ago

Very good. I will experiment with it a bit and report if necessary

comment:6 by Francesco Casella, 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.

Last edited 6 years ago by Francesco Casella (previous) (diff)
Note: See TracTickets for help on using tickets.