modelica / ModelicaSpecification

Specification of the Modelica Language
https://specification.modelica.org
Creative Commons Attribution Share Alike 4.0 International
98 stars 42 forks source link

Events, clocks and fixed-step solvers #2954

Open paultjevdh opened 3 years ago

paultjevdh commented 3 years ago

Hello, I'm trying to find out what the modelica language standard says about root finding at events. Section 8.5 states that "A root finding mechanism is needed which determines a small time interval in which the expression changes its value". Is this a hard requirement, and how is this supposed to co-operate with fixed-step integration? A related question is the definition of clocks: a clock with a regular tick is supposed to tick regularly, regardless of top-level simulation step choice, or not?

The above become issues when simulating with a fixed-step algorithm and the simulation grid does not align perfectly with the evens or clocks. Some simulator(s) will insert an additional sample to accommodate the event or clock tick. This violates a strict fixed-step operation. Other simulator(s) postpone the event to the next fixed-interval sample. This can lead to irregular clocks and introduce serious simulation errors.

What is the position of the standard on this matter? Or is this already documented, and can someone provide a link to documentation?

Best regards, Paul van der Hulst

HansOlsson commented 3 years ago

That's largely outside the scope of specification, or as stated in https://specification.modelica.org/master/introduction1.html#scope-of-the-specification "The Modelica specification does not define how to simulate a model."

At best the specification could define the ideal (simulation) result. (Or results.)

However, fixed-step size solvers are clearly not that ideal and there's a trade-off between accuracy and performance and different tools chose differently.

paultjevdh commented 3 years ago

Hello Hans,

I understand that the standard does not want to impose a specific implementation on programs, but it does to some extend describe what can be expected of a program. The section continues by saying: "However, it defines a set of equations that the simulation result should satisfy as well as possible." So the question is: how do you choose to define 'as well as possible'?

This makes me return to the question: what is the status of the sentence "[A root finding mechanism is needed which determines a small time interval in which the expression changes its value; the event occurs at the right side of this interval.]" in section 8.5. To me, this quote seems to describe some minimal expected complexity from the side of the program to be compliant with "as well as possible". Therefore I read it to be a hard requirement, not a polite request.

Modelica makes a point of advertising itself to be ideal for hybrid systems and treats state events generally well, but that requires a clear policy on interference between integration- and event intervals. At the moment this Modelica specification seems to be lacking just that, considering it is interpreted differently by different implementations.

Best regards, Paul