Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use noEvent operator in Modelica language?

Tags:

modelica

The noEvent operator in Modelica doesn't use iteration to find the precise time instant in which the event was triggered.

enter image description here

It seems this would cause calculation error, here is an example I find on the following website https://mbe.modelica.university/behavior/discrete/decay/ So Do I have to ensure the function is smooth when using noEvent operator? What's the purpose of using noEvent operator if it can't ensure accuracy?

enter image description here

like image 602
Jack Avatar asked Feb 22 '20 09:02

Jack


1 Answers

Although the question is already answered I would like to add some points, as I think it could be useful for many.

There are some common reasons to use the noEvent() statement:

  1. Guarding expressions: This is used to prevent a function from being evaluated outside of their validity range. A typical example is der(x) = if x>=0 then sqrt(x) else 0; which would work perfectly in most common programming languages. This doesn't work always in Modelica for the following reason: When searching for the time when the condition x>=0 becomes false, it is possible that both branches are evaluated with values of x varying around 0. The same fact is mentioned in the screenshot posted by marvel This results in a crash if the square root of a negative x is evaluated. Therefore der(x) = if noEvent(x>=0) then -sqrt(x) else 0; Is used to suppress the iteration to search for the crossing time, leaving the handling of the discontinuity to the solver (often referred to as "expressions are taken literally instead of generating crossing functions"). In case of a variable step-size solver being used, this makes the solver reduce the step-size to meet it's relative error tolerance, which will likely result in degraded performance. Additionally this can be critical if the function described is not smooth enough resulting in non-precise or even instable simulations.

  2. Continuous Expressions: When a function is continuous there is actually no event necessary. This comes down to the fact, that events are used to describe discontinuities. So if there is none, usually the event is simply superfluous and can therefore be suppressed. This is actually covered by the smooth() operator in Modelica, but the specification says, that a tool is free to still generate events. To my experience, tools generate events if the change to the function is relatively big. Therefore it can make sense to have a noEvent() within a smooth().

  3. Avoid chattering: noEvent can help here but actually chattering is a more general problem. Therefore I'd recommend to solve issues related to chattering by re-building the model.

If none of the above is true the use of noEvent should be considered carefully.

like image 121
Markus A. Avatar answered Sep 30 '22 05:09

Markus A.