particles exiting the bounding box

Asked by JOHN

Good evening,
I recently started playing around with the tutorial. I noticed that if a particle exits the bounding box through its movement
i get this error

  File "", line 45, in <module>
    p2 = particles[1].getPosn()
IndexError: list index out of range

is there a way substract the particle from the simulation instead of throwing this error?

Thank you very much for your help, i realise this might be a beginners question

Question information

English Edit question
ESyS-Particle Edit question
No assignee Edit question
Solved by:
Dion Weatherley
Last query:
Last reply:
Revision history for this message
Best Dion Weatherley (d-weatherley) said :

Hi John,

As it happens, this error is thrown *because* the particle has already been subtracted from the simulation.

Let me explain:

Initially the simulation contains two particles, both entirely within the simulation domain. Thus a call to sim.getParticleList(..) will return a Python list containing two NRotSpheres (one for each particle); the length of this list is 2. From within Python, we can examine the properties (position, velocity, etc.) of the two particles via list indexes 0 or 1; for a list of size 2.

When one/other particle leaves the simulation domain (defined by the bounding box), ESyS-Particle internally subtracts/deletes that particle. A subsequent call to sim.getParticleList(..) will return a list containing only a single NRotSphere (or an empty list if both particles have left the simulation domain).

The error thrown above is because you are attempting to access an element with index=1, from a list of length=1. In this case (as the error message indicates) the "list index is out of range". To prevent this error messaage occurring, you will need to explicitly check the length of the list returned by sim.getParticleList(..) and ensure you do not try to obtain information about non-existent particles.

I hope this helps and have fun!



Revision history for this message
JOHN (washingmachine) said :

Thanks Dion Weatherley, that solved my question.