How to add/delete a particle from particles generated by the RandomPackerBox?

Asked by Shu-xiao Tsai

Hi everyone,
     I'm new here and has learned the example of the tutorial. Recently, I want to do a simulation with certain number of particles which need to be generated randomly.
    My problem : Is there any method to add/delete a particle from particles generated by the RandomPackerBox?

   best regards,
   Tsai

Question information

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

Hi Tsai,

One can manually add/remove particles from the list generated by RandomBoxPacker prior to calling sim.createParticles(). Here's an example of how to do this:

geoRandomBlock = RandomBoxPacker (
...
)
geoRandomBlock.generate()
geoRandomBlock_particles = geoRandomBlock.getSimpleSphereCollection()

#loop thru the particle list and find the particle(s) one wishes to remove:
myParticles = SimpleSphereCollection()
for pp in geoRandomBlock_particles:
   if (pp is not to be removed):
      myParticles.create(pp)

#one can then add more particles to the myParticles list:
myParticles.create(SimpleSphere(centre,radius,id,tag,mass))

#finally add the new list of particles to the simulation:
sim.createParticles(myParticles)

Cheers,

Dion

Revision history for this message
Shu-xiao Tsai (tsaitsai) said :
#2

Hi Dion,
    It's very nice of U to response so rapidly!
    I wonder whether the method to remove a particle from <myParticles> is myParticles.remove(pp)?
    The method U provided is easy to understand,I think I know how to do.

    Thanks again for your timely help,
    Tsai

Revision history for this message
Shu-xiao Tsai (tsaitsai) said :
#3

Oh,I see the method in the question #113242 https://answers.launchpad.net/esys-particle/+question/113242

I will enjoy the ESys-particle.
Thanks,Dion.

Tsai

Revision history for this message
Shu-xiao Tsai (tsaitsai) said :
#4

Thanks Dion Weatherley, that solved my question.