← 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

skonda2 gave more information on the question:
Hi!

I forgot to add script in my last comment, so the script am using is
below:

from yade import pack
pack.randomPeriPack(1,(10,10,10)).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/1_1_x_1.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/1_1_y_1.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/1_1_z_1.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()


So this program generates three files, for the periodic spheres in three directions. Is there anything wrong with script am using?

-SHailesh

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