# How to delete 10% percent of small particles?

Asked by zheng on 2019-04-22

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:
2019-04-24
Last query:
2019-04-24
Last reply:
2019-04-23
 Robert Caulk (rcaulk) said on 2019-04-23: #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)

 Jan Stránský (honzik) said on 2019-04-23: #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

 zheng (tigerhz) said on 2019-04-23: #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

 Robert Caulk (rcaulk) said on 2019-04-23: #4

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

 zheng (tigerhz) said on 2019-04-24: #5

Thanks Robert Caulk, that solved my question.

To post a message you must log in.