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

Time problems

Time problems

Hi Guys!

Think of the bouncing ball. I have a ball, that's dropped from a certain height. It's accelerated by gravity and after a certain time the ball hits the floor. Everything runs!
Now i want to know the time, when the ball hits the floor, but I don't know how.

My intention was to use a while loop! A variable t_dummy runing with the time, and stopping, when the ball hits the floor!

 Spoiler Show Spoiler Hide Spoiler
 

Code:


while h > 0 loop
t_dummy = time;
end while;

But it seems, that while loops are not implemented yet...

Any other ideas, how this could be realised?????

Re: Time problems

Hi,

While-loops are only available in algorithm sections in Modelica, since they make no sense in equation sections. What you probably want is a when-equation, i.e.

Code:


when h > 0 then
  t_dummy = time;
end when;

I'm not a modeler though, so I don't know if this is the best way of doing this. Perhaps someone else has some better ideas.

Re: Time problems

Hi!

Thanks for your answer, but with the when-equation it did'nt work...
Has anyone any other any idea?

I want to use it for a delay function.

Regards

Re: Time problems

If you want a delay function, why don't you use the builtin delay function in Modelica?

Re: Time problems

I use the delay function. But the DelayTime I want to use depends on the hit time.

Unfortunately all my effords were not successful.
Has any other one ideas for a solution?

The problem for me seems to be the variable time.
If you set:

Code:

t_dummy = time;

it seems to be protected! You can't use reinite to set t_dummy to a different value or anything else.

Regards and thanks for your answers!

Re: Time problems

Have you tried making t_dummy a discrete variable? Then you can set it in the when-clause without reinit.

Only state variables can be used in a reinit, and t_dummy cannot be selected as a state variable. (But apparently OpenModelica silently accepts this and you get the unexpected behaviour)

Re: Time problems

Hello again!

Thanks for your help so far!
I tried to make t_dummy discrete but it didn't help me either...

But again I have an idea how it could work! I want to scan time in a variable.
So when you have the floating time, t_dummy would become [0,1,2,3,4,5] if you set the scan time to 1 second.
Is there any command to do this?

The smaller the sampling time the better results you would get and with the command pre() the time before a certain event could be read.

Hope you understand what I mean...

Do you have any suggestions again?

BIG THANKS and regards!

Re: Time problems

Do you mean the following?

Code:

when sample(0.0 /* startTime */, 1.0 /* interval */) then

   t_dummy = time;
end when;

Re: Time problems

Yes, that's what I've been looking for!

Thank you very much!!!

There are 0 guests and 0 other users also viewing this topic