.ModelicaReference.Operators.'assert()'

Information

Trigger error and print error message if assertion condition is not fulfilled

Syntax

assert(condition, message, level = AssertionLevel.error)

Description

The Boolean expression condition shall be true for successful model evaluations. Otherwise, an error occurs using the string expression message as error message.

If the condition of an assert statement is true, message is not evaluated and the procedure call is ignored. If the condition evaluates to false different actions are taken depending on the level input:

The AssertionLevel.error case can be used to avoid evaluating a model outside its limits of validity; for instance, a function to compute the saturated liquid temperature cannot be called with a pressure lower than the triple point value. The AssertionLevel.warning case can be used when the boundary of validity is not hard: for instance, a fluid property model based on a polynomial interpolation curve might give accurate results between temperatures of 250 K and 400 K, but still give reasonable results in the range 200 K and 500 K. When the temperature gets out of the smaller interval, but still stays in the largest one, the user should be warned, but the simulation should continue without any further action. The corresponding code would be

  assert(T > 250 and T < 400, "Medium model outside full accuracy range",
         AssertionLevel.warning);
  assert(T > 200 and T < 500, "Medium model outside feasible region");

Examples

  parameter Real upperLimit=2;
  parameter Real lowerLimit=-2;
equation
  assert(upperLimit > lowerLimit, "upperLimit must be greater than lowerLimit.");

Generated at 2024-04-24T18:15:52Z by OpenModelicaOpenModelica 1.22.3 using GenerateDoc.mos