- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Time problems
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!
Code:
while h > 0 loop
t_dummy = time;
end while;
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.
- perost
- 114 Posts
Re: Time problems
If you want a delay function, why don't you use the builtin delay function in Modelica?
- sjoelund.se
- 1700 Posts
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)
- sjoelund.se
- 1700 Posts
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;
- sjoelund.se
- 1700 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Time problems