How to determine the maximum of a mixed time-continuous time-discrete signal in SimulationX?

333 Views Asked by At

There are questions how to determine the maximum of a mixed time-continuous and time-discrete signal x(t) over passed time with Modelica, i.e.,

y(t) = max{ x(s) with s in [startTime,t] }.

This is an open issue in the Modelica bug tracker (see https://trac.modelica.org/Modelica/ticket/109).

I will give a SimultionX-specific solution.

2

There are 2 best solutions below

5
On

I am not sure what exactly last() does. But, from your description it seems to do the same the same thing as pre() in standard modelica. And this gives the same results in OpenModelica:

model minTest
Real x;
Real y;
equation      
x = 2. * sin(2.0 * Modelica.Constants.pi * time) + sin(20.0 * Modelica.Constants.pi * time)+ (if time < 0.5 then 0. else 3.);
      y=max(x,pre(y))  ;
end minTest;
0
On

SimulationX extends Modelica by the last-operator which returns the last accepted value of the argument. At event-time points it returns the value at which the integration stopped before the event iteration. The last-operator can be used to calculate the maximum of the current x value and the last maximum. See the following working example.

model test "test.ism"
    extends SimModel;
    Real x=2*sin(2*pi*time)+sin(20*pi*time)+(if time < 0.5 then 0 else 3) "some input signal with jump";
    Real y=if noEvent( time > time.start ) then max(x,last(y)) else x  "Calculate the maximum with the help of the last-operator";
    Real z(start=0,fixed=true)=-der(z)+y "Just any dymanics.";
end test;

The input signal x and the corresponding output signal y are depicted in the following Figure.

enter image description here