Modelica events and hybrid modelling
Asked Answered
K

1

6

I would like to understand the general idea behind hybrid modelling (in particular state events) from a numerical point of view (although I am not a mathematician :)). Given the following Modelica model:

model BouncingBall
    constant Real g=9.81 
    Real h(start=1);
    Real v(start=0);
equation
    der(h)=v;
    der(v)=-g;
algorithm
    when h < 0 then
         reinit(v,-pre(v));
    end when;

end BouncingBall;

I understand the concept of when and reinit.

  1. The equation in the when statement are only active when the condition become true right?
  2. Let's assume that the ball would hit the floor at exactly 2sec. Since I am using multi-step solver does that mean that the solver "goes beyond 2 seconds", recognizes that h<0 (lets assume at simulation time = 2.5sec , h = -0.7). What does this mean "The time for the event is searched using a crossing function? Is there a simple explanation(example)?
  3. Is the solver now going back? Taking a smaller step-size?
  4. What does the pre() operation mean in that context?
  5. noEvent(): "Expressions are taken literally instead of generating crossing functions. Since there is no crossing function, there is no requirement tat the expression can be evaluated beyond the event limit": What does that mean? Given the same example with the bouncing ball: The solver detects at time 2.5 that h = 0.7. Whats the difference between with and without noEvent()?
Kat answered 26/3, 2017 at 9:57 Comment(1)
I suggest you read in the Modelica Book: book.xogeny.com/behavior/discrete In short: 1) yes 2) crossing function means when h crosses zero, the solver is using the derivatives of the signal to get a feeling when to make a smaller step size, but it depends on the solver 3) both, depending on solver 4) pre is the value of the discrete variable from previous step 5) basically no events are generated when the signal is crossing zero so the solver does not stop (no event) so basically the expression is evaluated only at the step boundaryCommingle
K
5
  1. Yes, the body of when is only executed at events.
  2. Simple view: The solver takes steps, and then uses a continuous extension to generate a (smooth) interpolation formula for the previous step. That interpolation formula can be used to generate a plot, and also for finding the first point where h has crossed zero (likely 2.000000001). An event iteration is then done at that interpolated point - and afterwards the solver is restarted.
  3. I wouldn't say that the solver goes back. It takes a partial step and then continues forward. Some solvers need to reduce the step-size a lot after the event - others don't.
  4. pre(x) is set to the value of x before the event.
  5. noEvent(h<0) basically means evaluate the expression as written without all the bells-and-whistles of crossing functions. You cannot use when noEvent(h<0) then

There are many additional point: If you are familiar with Sturm-sequences or control theory you might realize that it is not necessary to interpolate a formula to determine if it crossed zero or not in an interval (and some tools use that). The fact that the function is not necessarily smooth makes it a bit more complicated, and also means that derivative-tests cannot be used. How much the solver is reset depends on the kind of solver. One-step solvers (Runge-Kutta) can be restarted directly as if virtually nothing happened, whereas multi-step solvers (BDF/Adams - such as dassl/lsodar/cvode) need to start with lower order and smaller step-size.

Kano answered 28/3, 2017 at 8:35 Comment(3)
For 3.: isn't the large step that takes the solver behind the event rejected and then a new step is computed increasing the time to a value directly before the event? I guess that could be formulated as "going back"... for 4.: Would it help to add some more information? For an event two values are stored, one right before the event time, and one just after the event. During the event, pre(x) returns the value right before the event whereas referring to x returns the value after the event. In this case v after the event is set to the negative value before it which is pre(v)Charleencharlemagne
I would say the step is interpolated to just pass the event; and neither rejected nor fully taken. And, yes, might help to add more context for pre.Kano
Well, for pre(x) there are in general multiple iterations. At the first iteration pre(x) is the value from before the event, and in each iteration pre(x) is the value of x from the previous iteration. However, when-clauses are only active the first iteration - so in this context pre(x) is just the value before the event.Kano

© 2022 - 2024 — McMap. All rights reserved.