modelica / ModelicaStandardLibrary

Free (standard conforming) library to model mechanical (1D/3D), electrical (analog, digital, machines), magnetic, thermal, fluid, control systems and hierarchical state machines. Also numerical functions and functions for strings, files and streams are included.
https://doc.modelica.org
BSD 3-Clause "New" or "Revised" License
472 stars 168 forks source link

ClockedWithDiscretizedContinuousController has clocked variable in initial equation #4458

Open henrikt-ma opened 1 month ago

henrikt-ma commented 1 month ago

The ClockedWithDiscretizedContinuousController contains a clocked instance of Modelica.Blocks.Continuous.PI: https://github.com/modelica/ModelicaStandardLibrary/blob/35ad28dd83fa36b5393fad54fa38c08e94ba6bb6/Modelica/Clocked/Examples/SimpleControlledDrive/ClockedWithDiscretizedContinuousController.mo#L30

However, this block contains an initial equation:

initial equation
  if initType == Init.SteadyState then
    der(x) = 0;
  elseif initType == Init.InitialState then
    x = x_start;
  elseif initType == Init.InitialOutput then
    y = y_start;
  end if;

This means that the clocked variable y violates one of the two very basic rules about synchronous variable initialization in https://specification.modelica.org/master/synchronous-language-elements.html#initialization-of-clocked-partitions:

Variables in clocked partitions cannot be used in initial equation or initial algorithm sections.

I know that the specification is considered more or less flawed when it comes to achieving the goal of being able to "sample any continuous-time model",

The goal is that every continuous-time Modelica model can be utilized in a sampled data control system. This is achieved by solving the continuous-time equations with a defined integration method between clock ticks. With this feature, it is for example possible to invert the nonlinear dynamic model of a plant, see Thümmel et al. (2005), and use it in a feedforward path of an advanced control system that is associated with a clock.

but while waiting for the specification to achieve this goal, the ClockedWithDiscretizedContinuousController should use a control block without initial equations.

casella commented 3 weeks ago

See MCP 0038 regarding how to solve this issue in general

casella commented 2 weeks ago

4465 fixes the issue on master for MSL 4.2.0. @Esther-Devakirubai we should back-port it to maint/4.1.x so we also get this in 4.1.0.