APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

Modeling Tips & Help post and replies

Return to the Modeling Tips & Help thread
Login to post to this thread

automatically stop a simulation
mos
1 Posts

Hi,

Is there any way to define a final time for automatically stop a simulation when the simulation time reaches it?

Thank you in advance


Replies to automatically stop a simulation

Re: automatically stop a simulation -
Francisco Esquembre
237 Posts

Hi Mos,

If the model is based on an differential equation, then add an event with Zero condition:
return t - yourLimit;

where t is the time variable and yourLimit the maximum you want.

As action, enter:
_pause();

This will stop (_pause()) your simulation exactly at that time.

Notice that, if the event is of the "State event" type, you should not continue playing it. If you want to allow the user to continue playing, set the event type to be "Zero crossing".

If the model is not based on an ODE, then you need to add to your Evolution page the code
if (t>=yourLimit) _pause();

This will pause your simulation whenever t reaches or exceeds yourLimit. (numerical round errors permit).

Cheers,

Paco



OSP Projects:
Open Source Physics - EJS Modeling
Tracker
Physlet Physics
Physlet Quantum Physics
STP Book