← Back to team overview

yade-users team mailing list archive

[Question #226112]: Packing Spheres Problem

 

New question #226112 on Yade:
https://answers.launchpad.net/yade/+question/226112

I just want to put a uge amount of sphers into an block with diefferent radius and amount.
The problem is i am only getting  approximately 30% percent of volume into the block. So if i want to have 90% of the volume consist of spheres i am just calculating spheres with the radius of 10 and 220 spheres in it, if the  block has the size of 100x100x100 or  spheres with the radius of 15 i just need to have only 65 spheres , how can i put more spheres in it and decrease the distances between the other spheres 

import yade 
import sys
import os
import inspect
import platform
import math
import re

print "Hello from Yade makegeo"
filepath=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))

#reading from file
if(len(sys.argv)) >1:
 file_name_in=sys.argv[1]
else:
 file_name_in='makegeo/sim0.txt'

if(len(sys.argv)) >2:
 dir_out=sys.argv[2]
else:
 dir_out="makegeo"

if(platform.uname()[0]=="Linux"):
 _char="/"
else:
 _char="\\"

l=len(file_name_in.split(_char))
dir_out=dir_out+_char+(file_name_in.split(_char)[l-1]).split(".")[0]

if(platform.uname()[0]=="Linux"):
 file_name_in=file_name_in.replace("\\","/")
 dir_out=dir_out.replace("\\","/")
else:
 file_name_in=file_name_in.replace("/","\\")
 dir_out=dir_out.replace("/","\\")

if not os.path.exists(dir_out):
	os.system("mkdir "+dir_out)

if not os.path.exists(filepath+_char+file_name_in):
 print "Input File not found"
 sys.exit("Error")
else:
 f_in=open(file_name_in,'r')
 f_h=f_in.readline()
 f_h=f_h.rstrip('\n\r')
 f_h=f_h.split(' ')

 for line in f_in:
   
    line=line.rstrip('\n\r')
    line_h=line.replace(".","_")
    line=line.split()
    line_h=line_h.split()

    #checking last line 
    if len(line_h)==0:
     continue
   
    #building filename
    file_name_out=''
    for i in range(len(line)):
      #checking total length of chars,limit to maximum of 7 chars
     #print i
     if len(f_h[i]) > 7:
       f_h[i]=f_h[i][0:5]
     if len(line_h[i]) > 7:
       line_h[i]=line_h[i][0:5]
     file_name_out=file_name_out+'__'+str(f_h[i])+'_'+str(line_h[i])
    print 'filename_out: ' + file_name_out

    #box
    boxsize= 1
 
    if (len(line)) > 1:
     scale =float(line[0])
    else:
     scale=100.0
  
    boxx=boxsize * scale 
    boxy=boxsize * scale
    boxz=boxsize * scale

    #sphere
    if (len(line)) > 1:
     r_numbers=int(line[1])
    else:
     r_numbers=1

    if (len(line)) > 2:
     r_mean=float(line[2])
    else:
     r_mean=10
    if (len(line)) > 3:
     r_relfuzz=float(line[3])
    else:
     r_relfuzz=0.0
    #wall thickne
    old_num=-1
    new_num=-1
    print r_relfuzz
    counter=0
    wall_th=r_mean/4.0
    sp_=pack.SpherePack()
    if r_numbers > 1:
      while(new_num != r_numbers):
       print r_relfuzz
       sp=pack.SpherePack()
       new_num=sp.makeCloud(
                  minCorner=(-boxx/2.0,-boxy/2.0,-boxz/2.0),
         	  maxCorner=(boxx/2.0,boxy/2.0,boxz/2.0),
	          rMean=r_mean,
	          rRelFuzz=r_relfuzz,
	          num=r_numbers,
                  periodic=1,
                  porosity=0.1)
       if(new_num > old_num):
	 old_num=new_num
         sp_=sp       
       if(counter > 5000):
        break
       counter = counter + 1
    else:
     sp_=pack.SpherePack()
     sp_.makeCloud((-r_mean,-r_mean,-r_mean),
          	 (r_mean,r_mean,r_mean),
		  rMean=r_mean,
	          rRelFuzz=r_relfuzz,
	          num=1)
    
    fullpath=filepath+_char+dir_out+_char+file_name_out+str(".txt")
    f_out=open(fullpath,'w+')
    #control line for salome
    f_out.write(str(math.fabs(old_num))+" "+str(r_mean)+" "+str(r_relfuzz)+"\n")

    #block geo data in salome
    f_out.write(str(boxx)+" "+str(boxy)+" "+str(boxz)+"\n")
    
    for center,radius in sp_:
      print center , radius
      f_out.write(str(center[0])+" "+
                  str(center[1])+" "+
                  str(center[2])+" "+
         	  str(radius)+"\n")
    f_out.close()
    del sp_
 f_in.close()



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