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 - Feb 2, 2012 at 11:10PM
1 Posts


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 - Feb 03 2012 6:45AM
Francisco Esquembre
222 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:

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).



The OSP Network:
Open Source Physics - Tracker - EJS Modeling
Physlet Physics
Physlet Quantum Physics