particles exiting the bounding box

Asked by JOHN on 2017-10-26

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 "bingle.py", 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

Language:
English Edit question
Status:
Solved
For:
ESyS-Particle Edit question
Assignee:
No assignee Edit question
Solved by:
Dion Weatherley
Solved:
2017-10-27
Last query:
2017-10-27
Last reply:
2017-10-27
Best Dion Weatherley (d-weatherley) said : #1

Hi John,

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

Let me explain:

Initially the bingle.py 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!

Cheers,

Dion

JOHN (washingmachine) said : #2

Thanks Dion Weatherley, that solved my question.