Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Shattering (Zero Effect) problem? Another bouncing ball Example

Shattering (Zero Effect) problem? Another bouncing ball Example

Hi Guys,

I encountered an unpredictable behavior when running the simulation.

Let's start with the simple and successful example:

Code:


model BouncingBall
    constant Real g = 9.81;
    parameter Real c = 0.9;
    parameter Real radius = 0.1;
    Real height(start=1);
    Real velocity(start=0);
equation
    der(height) = velocity;
    der(velocity) = -g;
    when height <= radius then reinit(velocity, -c*pre(velocity)); end when;
end BouncingBall;

and following script:

Code:


loadFiles({"BouncingBall.mo"});
getErrorString();
simulate( BouncingBall,startTime=0,stopTime=5,outputFormat="plt"); getErrorString();
plot({height});
quit();

I can successfully get the plot I wanted.

However, if I use the same script but change the code to followings (all I did is to "abstract" the equation for re-use purpose), then the ball falls straightly into the ground, why is the code failed?

Code:


block derHeight
     Real height;
     Real velocity;
equation
    der(height)=velocity;
end derHeight;

block derVelocity
     Real velocity;
     Real g;
equation
    der(velocity)=-g;
end derVelocity;

block reinitVelocity
     Real height;
     Real radius;
     Real velocity;
     Real c;
equation
    when height <= radius then reinit(velocity, -c*pre(velocity)); end when;
end reinitVelocity;

model BouncingBall
    constant Real g = 9.81;
    parameter Real c = 0.9;
    parameter Real radius = 0.1;
    Real height(start=1);
    Real velocity(start=0);

    derHeight e1;
    derVelocity e2;
    reinitVelocity e3;   
equation
    velocity=e2.velocity;
    velocity=e1.velocity;
    velocity=e3.velocity;

    height = e1.height;
    height = e3.height;

    g = e2.g;
    radius=e3.radius;
    c = e3.c;
end BouncingBall;

Strange though, following code only abstract "e1" and it simulates successfully!

Code:


block derHeight
    Real height;
    Real velocity;
equation
    der(height)=velocity;
end derHeight;

model BouncingBall
    constant Real g = 9.81;
    parameter Real c = 0.9;
    parameter Real radius = 0.1;
    Real height(start=1);
    Real velocity(start=0);

    derHeight e1;
equation
    velocity=e1.velocity;
    height = e1.height;

    der(velocity)=-g;
    when height <= radius then reinit(velocity, -c*pre(velocity)); end when;
end BouncingBall;

Even more strange, following code only abstract "e2" but the simulation failed!

Code:


block derVelocity
    Real velocity;
    Real g;
equation
    der(velocity)=-g;
end derVelocity;

model BouncingBall
    constant Real g = 9.81;
    parameter Real c = 0.9;
    parameter Real radius = 0.1;
    Real height(start=1);
    Real velocity(start=0);

    derVelocity e2;
equation
    velocity=e2.velocity;
    g = e2.g;
    der(height)=velocity;
    when height <= radius then reinit(velocity, -c*pre(velocity)); end when;   
end BouncingBall;

Any helps? Thank you very much!
Miles

Edited by: milesma - Mar-16-16 02:27:01

Re: Shattering (Zero Effect) problem? Another bouncing ball Example

The ball will typically fall through the ground if the velocity does not bounce it high enough, so you need a condition to just let the ball remain to 0 velocity when the numbers get too small.

Re: Shattering (Zero Effect) problem? Another bouncing ball Example

if I remove "pre" function in my failed "abstract" version, so it looks like:

Code:



when height <= radius then reinit(velocity, -c*velocity); end when;

then the problem solved, I can get the exact plot as the the following code:

Code:


model BouncingBall
    constant Real g = 9.81;
    parameter Real c = 0.9;
    parameter Real radius = 0.1;
    Real height(start=1);
    Real velocity(start=0);
equation
    der(height) = velocity;
    der(velocity) = -g;
    when height <= radius then reinit(velocity, -c*pre(velocity)); end when;
end BouncingBall;

Now the questions:
1. what exactly role is the "pre" function playing in my example? Is it necessary?
2. why the version with "pre" on the "abstract" version does not work?

Re: Shattering (Zero Effect) problem? Another bouncing ball Example

removed duplicate reply

Edited by: milesma - Mar-16-16 05:46:57

Re: Shattering (Zero Effect) problem? Another bouncing ball Example

sjoelund.se wrote:

The ball will typically fall through the ground if the velocity does not bounce it high enough, so you need a condition to just let the ball remain to 0 velocity when the numbers get too small.

Thanks for your reply, from the book "Principles of Object-oriented modeling and simulation with modelica 3.3" second edition by Peter Fritzson, I understood the case you mentioned (Zero Effect). However, my problem is at the first bounce, it will falls into the ground (as if there is no ground). You can run the script and code to have a look.

I found "pre" is the cause of my problem. Remove it will just solve it. However, I don't know the side effect of removing "pre", there must be reason to have "pre" there?

Thanks
Miles

There are 0 guests and 0 other users also viewing this topic
You are here: