How to save only the particles that contain in the box below ?

Asked by Bowonchanok Maneerat on 2020-04-14

Now I am creating a box that contains particles and in the box there are two box other box overlapping each other. So I compaction the particle til it should have maximum density . After that I use the order that remove the box on top so that I can use only the particles that contain in the box below.

Like the linked here :

After that I want to save the particles or sphere in the box below that are left by using an order export.text() to save the particles. But there was a problem in the order that it save the particles that contain in both boxes but I only want to save the particles that contain in the box below. Do you have a suggestion how to save only the particles that contain in the box below ?

this is my code :
from yade import pack,ymport
import matplotlib.pyplot as plt
import math



# create rectangular box from boxes (maybe there is some library function, but I did not find it quickly)
cx,cy,cz = 6.3,6.3,6.3 # center of the box
dx,dy,dz = 7.5,7.5,7.5 # half-dimensions of the box
t = 0.25 # half-thickness of walls
left = box((cx-dx-t+1.2,cy+1.2,cz),(t,dy+2*t,cz),fixed=True,wire=True,material="steel")
right = box((cx+dx+t+1.2,cy+1.2,cz),(t,dy+2*t,cz),fixed=True,wire=True,material="steel")
front = box((cx+1.2,cy-dy-t+1.2,cz),(dx,t,cz),fixed=True,wire=True,material="steel")
back = box((cx+1.2,cy+dy+t+1.2,cz),(dx,t,cz),fixed=True,wire=True,material="steel")
bottom = box((cx+1.2,cy+1.2,cz-dz-t+1.2),(dx+2*t,dy+2*t,t),fixed=True,wire=True,material="steel")

left2 = box((cx-dx-t+1.2,cy+1.2,cz*2+2.7),(t,dy+2*t,2.7),fixed=True,wire=True,material="steel")
right2 = box((cx+dx+t+1.2,cy+1.2,cz*2+2.7),(t,dy+2*t,2.7),fixed=True,wire=True,material="steel")
front2 = box((cx+1.2,cy-dy-t+1.2,cz*2+2.7),(dx,t,2.7),fixed=True,wire=True,material="steel")
back2 = box((cx+1.2,cy+dy+t+1.2,cz*2+2.7),(dx,t,2.7),fixed=True,wire=True,material="steel")

top2 = box((cx+1.2,cy+1.2,18+t),(dx,dy,t),fixed=True)




def check() :
 if O.bodies[7].state.pos[1]>20:
  for b in O.bodies:
   if isinstance(b.shape,Sphere):
    if b.state.pos[0]>=0 and b.state.pos[0]<=15:
     if b.state.pos[1]>=0 and b.state.pos[1]<=15:
      if b.state.pos[2]>=0 and b.state.pos[2]<=12.6:
  print('Densitymin =', Densitymin)
  print('Unitweightmin =', unitweightmin)
  print('Volume of soil =', vs)
  print('Mass of soil =', ms)
  print('Volume of specimen',V)
  print('Number of sphere in specimen', nb)

Question information

English Edit question
Yade Edit question
No assignee Edit question
Solved by:
Jan Stránský
Last query:
Last reply:
Best Jan Stránský (honzik) said : #1


please read [1], section "Please, no external links!".

> order

"command" is more suitable English word

> Do you have a suggestion how to save only the particles that contain in the box below ?

You have several options, e.g. save the packing "manually":
def particles_that_contain_in_the_box_below():
   ret = []
   for b in O.bodies:
      if not isinstance(b.shape,Sphere): continue # skip non-spherical, not clear if yes or not
      if b.state.pos[2] < 1: # for example, replace by your "contain in the box below" condition
   return ret

particles = particles_that_contain_in_the_box_below()
with open("particles_that_contain_in_the_box_below.dat","w") as f:
   for particle in particles:
      x,y,z = p.state.pos
      f.write("{} {} {} {}\n".format(x,y,z,particle.shape.radius))



thanks jan


Thanks Jan Stránský, that solved my question.