0

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.

Community
  • 1
  • 1
Tobias
  • 5,038
  • 1
  • 18
  • 39
  • possible duplicate of [modelica: compute minimum/maximum of continuous variable over time](http://stackoverflow.com/questions/30732774/modelica-compute-minimum-maximum-of-continuous-variable-over-time) – matth Jun 30 '15 at 09:46
  • @matth This is not a duplicate of [modelica: compute minimum/maximum of continuous variable over time](http://stackoverflow.com/questions/30732774/modelica-compute-minimum-maximum-of-continuous-variable-over-time) since it works on the base of the `last`-operator which is a SimulationX-specific extension (as stated in the question). That is the reason why I did not post it as an answer there. Also: this problem is not solved in the framework of pure Modelica because there is no clean solution within this framework yet. – Tobias Jun 30 '15 at 09:59
  • @matth If I had posted it as an answer to [modelica: compute minimum/maximum of continuous variable over time](http://stackoverflow.com/questions/30732774/modelica-compute-minimum-maximum-of-continuous-variable-over-time) it had caused complains about the code not running in other Modelica tools. – Tobias Jun 30 '15 at 10:07
  • The duplicate flag refers to the question only. It seems you are asking the identical questions only to give a different answer (actually you are not even asking anything). Your answer is good and helpful and I upvoted it, but I still think it should be given as a new alternative answer to the existing question. – matth Jun 30 '15 at 11:08
  • @matth The question which differs from that one of PeterE is in the headline. The difference is that it askes for a solution in SimulationX not a Modelica solution per se. The given solution cannot be used in other Modelica environments. As I already stated the question of PeterE is actually unsolved in the framework of pure Modelica allone. – Tobias Jun 30 '15 at 12:06

2 Answers2

3

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

Tobias
  • 5,038
  • 1
  • 18
  • 39
1

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;
Adam
  • 742
  • 1
  • 6
  • 23
  • 1
    According to the Modelica Specification 3.3 r1, Section 3.7.3, the `pre`-operator can only be applied to variables that are discrete expressions. Either the variable is discrete or the `pre` is applied within a `when`-block (where all expressions are discrete). – Tobias Jun 30 '15 at 12:45
  • It might be that this works in OpenModelica. If so, it works outside the Modelica Specification (version 3.3 r1). – Tobias Jun 30 '15 at 13:14
  • You *should* clarify your answer. I assume that `x` and `y` are of type `Real` and they are not assigned within a `when`. Your answer might work in OpenModelica but it is not valid according to 'standard modelica'. – Tobias Jun 30 '15 at 16:05
  • I had not looked at the spec on this. So, perhaps it is a bug in OM? – Adam Jun 30 '15 at 16:44
  • 1
    I wouldn't call it a bug if everything works fine for `pre` on discrete expressions. Yes, from the perspective of the Modelica specification the application of `pre` on a non-discrete expression is an error. But, maybe OM deals with this by extending the functionality of `pre`. Then it should be noted somewhere in the documentation of OM and it would be nice to have a `pedandic mode` where deviations from the standard are rejected to ensure compatibility with other Modelica tools. Furthermore, one should be wary when striding from the standard path;-). – Tobias Jun 30 '15 at 16:58