ModelicaSpecification icon indicating copy to clipboard operation
ModelicaSpecification copied to clipboard

Integration in state-machines

Open HansOlsson opened this issue 3 years ago • 2 comments

Trying to clean up integration of clocked discretized equations and investigating MCP-0038 https://github.com/modelica/ModelicaSpecification/tree/MCP/0038/RationaleMCP/0038 I stumbled upon an issue by combining the following:

  • State machines are defined by a mapping to normal synchronous equations.
  • Higher order Runge-Kutta methods are defined as interpolating inputs for some of the stages. (Different interpolation for continuous and discrete-valued input.)
  • Integration should only be done in the active state, #2735 (working on it).

But combined that gives that there could be a switch between state-machine states during one step (e.g. between stage 2 and 3), which seems problematic for me. (This could happen both if the derivative is within one state or if it is one level above and using the output from the state-machine.) If used it would not work well, since this will naturally define a discontinuous integrand breaking the underlying assumptions. (And also be weird in my opinion.)

Note that inputs are a bit complicated, as it's not necessarily the transition conditions themselves but could be the variables appearing in them that are inputs as currently defined (afaik).

Thus I would as a minimum propose to state that there is no switching of state-machine states during these integration stages. However, it might be that we need more - e.g., restrict input more; and/or always use delayed transitions; or possibly reconsider the entire idea of modifying discrete variables during integration.

HansOlsson avatar Jan 19 '21 16:01 HansOlsson

This turned out to be more impacting and complicated that I thought.

I see three possibilities:

  • Completely redesign the handling of discrete-valued variables in clocked discretized equations.
  • Require that all transitions having conditions directly depending on integrated values use delayed transitions.
  • Actually allow reset during the step!

My plan is: include the latter part in MCP-0038 which I believe will be fairly straightforward. The other possibilities can then be considered later, and the second possibly as a style-guide.

HansOlsson avatar Feb 11 '21 16:02 HansOlsson

Actually the "simple" latter part had non-simple consequences.

Basically it's trivial to make the normal chattering differential equation (der(x)=-sign(x)) as a state-machine. Discretized with ExplicitEuler that would work, with higher order explicit methods we get transitions and reset during step, and with ImplicitEuler it will create an unsolvable mixed system of equations (that Dymola reject since it mixes different states from a state-machine).

To me it seems that the simple solution doesn't satisfy these natural requirements:

  • The validity of a discretized continuous model should be independent of the discretization method.
  • The discretized continuous models should not require solving mixed systems of equations, as that may take an unknown amount of time

HansOlsson avatar Feb 15 '21 09:02 HansOlsson

Design meeting: Should add example models

HansOlsson avatar Mar 14 '23 09:03 HansOlsson