← Back to team overview

yade-users team mailing list archive

Re: [Question #255437]: Periodic random packing of spheres in a cube

 

Question #255437 on Yade changed:
https://answers.launchpad.net/yade/+question/255437

    Status: Answered => Open

skonda2 is still having a problem:
Hi Jan,

I guess exporting "normal" spheres did the trick. So, i will post the
final script that am using for periodic packing, which can be useful for
any future yade users in this forum.

from yade import pack
pack.randomPeriPack(3.5,(45,45,45), rRelFuzz = 0.5).toSimulation()
O.step() # to initialize bounding boxes
xImages = [] # list of "edge" particles

for b in O.bodies:
	xmin,xmax = O.cell.wrap(b.bound.min)[0], O.cell.wrap(b.bound.max)[0] # wrap is important as physically the particles can be anywhere

	if xmin > xmax: # this means that bounding box crosses periodic cell. You can define various different conditions..
		xImages.append(b)

pr = [[O.cell.wrap(b.state.pos),b.shape.radius] for b in xImages] # list
or [pos,radius] of "edge" particles. Now pos is always inside the cell

for i,(pos,r) in enumerate(pr):
	shift = Vector3(O.cell.size[0],0,0) * (1 if pos[0]<0.5*O.cell.size[0] else -1) # determine shift to create a periodic image +x... direction if particles is near -x face and vice versa
	pr[i][0] += shift

# saves images into a file
f = open("/home/konda/imp/Extra_imp/one_packing/1_1_x.dat","w")
f.write("x y z r\n")
f.writelines("%g %g %g %g\n"%(pos[0],pos[1],pos[2],r) for pos,r in pr)
f.close()

yImages = []

for b in O.bodies:
	ymin,ymax = O.cell.wrap(b.bound.min)[1], O.cell.wrap(b.bound.max)[1]
	if ymin > ymax:
		yImages.append(b)

pr1 = [[O.cell.wrap(b.state.pos),b.shape.radius] for b in yImages]

for i,(pos,r) in enumerate(pr1):
	shift = Vector3(0,O.cell.size[1],0) * (1 if pos[1]<0.5*O.cell.size[1] else -1)
	pr1[i][0] += shift

# saves images into a file
f = open("/home/konda/imp/Extra_imp/one_packing/1_1_y.dat","w")
f.write("x y z r\n")
f.writelines("%g %g %g %g\n"%(pos[0],pos[1],pos[2],r) for pos,r in pr1)
f.close()

zImages = []

for b in O.bodies:
	zmin,zmax = O.cell.wrap(b.bound.min)[2], O.cell.wrap(b.bound.max)[2]
	if zmin > zmax:
		zImages.append(b)

pr2 = [[O.cell.wrap(b.state.pos),b.shape.radius] for b in zImages]

for i,(pos,r) in enumerate(pr2):
	shift = Vector3(0,0,O.cell.size[2]) * (1 if pos[2]<0.5*O.cell.size[2] else -1)
	pr2[i][0] += shift

# saves images into a file
f = open("/home/konda/imp/Extra_imp/one_packing/1_1_z.dat","w")
f.write("x y z r\n")
f.writelines("%g %g %g %g\n"%(pos[0],pos[1],pos[2],r) for pos,r in pr2)
f.close()


# saving normal spheres
f = open("/home/konda/imp/Extra_imp/one_packing/normal.dat", "w")
f.write('x y z r\n')
for b in O.bodies:
	p,r = O.cell.wrap(b.state.pos),b.shape.radius
	f.write('%g %g %g %g\n' %(p[0],p[1],p[2],r))
f.close()

So, this script produces periodic packing of spheres in x,y,z
directions. I tested the visualization, it is very much similar to what
we observe in yade after exporting the position. There is something
wrong with the corner spheres. I am not sure how to export positions of
corner spheres and there periodic images? It is very hard to understand,
how to incorporate those in my script?

-- 
You received this question notification because you are a member of
yade-users, which is an answer contact for Yade.