How to delete 10% percent of small particles?

Asked by zheng

Dear all,

I am very new in Yade. In my simulation, I have a polydisperse particle size distribution, from size 0.2~1.0mm. Thanks to this poster: https://answers.launchpad.net/yade/+question/211937, I now know how to delete all particles with a certain diameter or position.

Now I need to delete 10% of the smallest particles (d=0.2mm) every 100 steps, but I cannot figure out how to realize this function? Could anyone please give me any clues? Thanks so much!

Best regards,
Zheng

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Robert Caulk
Solved:
Last query:
Last reply:
Revision history for this message
Best Robert Caulk (rcaulk) said :
#1

I guess it's a python question.

import numpy as np

def delBelowPercentile(a, q):
    maxRad = np.percentile(a,q)
    for b in bodyRadius:
       if b[0].shape.radius <= maxRad:
           O.bodies.erase(b[0].id)

bodyRadius = []
for b in O.bodies:
    if isinstance(b.shape,Sphere):
        bodyRadius.append([b,b.shape.radius])

bodyRadius.sort(key=lambda x: x[1])
delBelowPercentile(bodyRadius,10)

Revision history for this message
Jan Stránský (honzik) said :
#2

Hello,

use PyRunner [1]:
###
def getSmallParticles():
   ret = []
   # fill ret with particles satisfying "10% percent of small particles"
   return ret

def deleteSmallParticles():
   for b in getSmallParticles():
      O.bodies.erase(b.id)

O.engines = [
   ...
   PyRunner(iterPeriod=100,command="deleteSmallParticles()"),
]
###

cheers
Jan

[1] https://yade-dem.org/doc/yade.wrapper.html#yade.wrapper.PyRunner

Revision history for this message
zheng (tigerhz) said :
#3

Thanks Caulk and Jan, this solved most of my question. However, deleting particles by sizes may not be suitable for all cases. For example, how to delete 10% of particles by number if I only have one particle size? This time the "percentile(a,q)” may not work. Could you please give me any clues? Thanks so much.

Best regards,
Zheng

Revision history for this message
Robert Caulk (rcaulk) said :
#4

Why don't you give that a shot and tell us where the difficulties lie?

Revision history for this message
zheng (tigerhz) said :
#5

Thanks Robert Caulk, that solved my question.