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

The usage of StopTime.

The usage of StopTime.

I want to calculate the change in potential energy as a water droplet is falling towards the ground and I also want to be able to change the start heignt of the drop in an easy way. To know where the droplet is I have defined the position of the droplet as

Code:

x=time;

. But to calculate the potential energy I have to know the distance to the ground as well.

What I want to do, is something like this:

Code:

Distance=(StopTime-x);

I have tried to use the code

Code:

annotation(experiment(StartTime = 0.0, StopTime = 6.0, Tolerance = 1e-006)…);

and then use StopTime as both a variable and or parameter without success.
I could just type in the start height of the falling drop and then choose the same stop time before simulate.
Is there an easier way to solve this?
/Joakim

Re: The usage of StopTime.

Trust me, you never want to use "time" directly to model physical behaviour. Physics really is about relative time. You should probably do:

Code:

model M

  parameter Real startPos = 100;
  Real x(fixed=true,start=startPos);
  Real distance = startPos-x;
equation
  der(x) = -1.0;
  when x < 0 then
    terminate("drop hit the ground");
  end when;
end M;

You get something like:

Code:

stdout            | info    | Simulation call terminate() at time 100.000000

|                 | |       | Message : drop hit the ground

Re: The usage of StopTime.

Thanks! This solution works just fine.

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