Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modelica events and hybrid modelling

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()?
like image 364
AssMero Avatar asked Mar 26 '17 09:03

AssMero


1 Answers

  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.

like image 115
Hans Olsson Avatar answered Oct 18 '22 10:10

Hans Olsson