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.

On using indexed variables on an ODE solver panel post and replies

Return to the On using indexed variables on an ODE solver panel thread
Login to post to this thread

On using indexed variables on an ODE solver panel
Cleon Teunissen
29 Posts

I want to expand an existing simulation, going from a single particle being tracked through time to multiple particles. (The particles won't influence each other; there is one force affecting the particles: gravity.)

As a template for achieving that with EJS I'm looking at the following simulation created by Juan M. Aguirregabiria:
http://www.compadre.org/OsP/items/detail.cfm?ID=7852

What I want to create is a simulation where the user can choose the amount of particles, up to a maximum. Let's say a maximum of 36 particles.
So in the variables panel the necessary variables are created as arrays of size 36.

Currently I'm using only linear motion, so I don't yet need a ODE panel. In the calculations a for loop calculates the array positions that are used. If the user has opted for four particles the for loop processes only the first four positions of the array.


I see in the N-body model that the ODE accepts array variables. I surmise that EJS detects the index notation, and proceeds to use a for loop to process _all_ the positions of the array variables.

Is that supposition correct?
The reason I ask: for my planned simulation, if the user has opted to use four particles then the simulation should run the calculations for those four particles only. However, if EJS ODE solving will always process _all_ the positions of the array variables then EJS will grind through far more calculation than necessary.

If my supposition is correct, is there a way to deal with this?
For instance, there is the model method: _setPageEnabled("pageName",true)
Let's say I want to give the user the options of 4, 8, 12, 24 or 36 particles. I could create a separate variable page for each of those numbers, using it to declare a number that on a subsequent page is used to set the length of the array variables. If only one page is enabled at a time, would that have the effect changing the length of the array at run time?


Cleon


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