← Back to team overview

yade-users team mailing list archive

Re: [Question #678308]: save spheres coordinates to a file

 

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

hafsa posted a new comment:
thank Jan my problem is solved 
for the person who wont saved properties of spheres in cylinder there's my code  :


from yade import pack,plot,export,wrapper 

#material of cylinder
Mat1 = O.materials.append(ViscElMat(kn=10.0e4,ks=10.0e4,frictionAngle=0.455,density=2650.0))

# create sphere packing
sp=pack.SpherePack()
sp.makeCloud((-1.2,-1.2,1.5),(1.2,1.2,8.0),rMean=.2,rRelFuzz=.1,num=128)
sp.toSimulation(color=(0,1,0))

# create Cylinder 
Cylinder=O.bodies.append(geom.facetCylinder((0,0,1.5),2.0,height=3.0,wallMask=6,segmentsNumber=64,material=Mat1))

#time of simulation 
O.stopAtIter=5000

# interactions 
O.engines=[
    ForceResetter(),
    InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
    InteractionLoop(
      
        [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],
        [Ip2_FrictMat_FrictMat_FrictPhys()],
        [Law2_ScGeom_FrictPhys_CundallStrack()]
    ),
    NewtonIntegrator(gravity=(0,0,-9.81),damping=0.3),
    HarmonicMotionEngine(A=[0,0,0.5], f=[0,0,1.0], fi = [0.0,0.0,0.0],ids =Cylinder),# vertical vibration
    # HarmonicMotionEngine(A = (0,0.002,0),f = (0,50,0),fi = (0,-0.5*math.pi,0),ids =Cylinder), horizontal vibration
    PyRunner(command='myaddData()',iterPeriod=100,initRun=True), #call def fonction  
 ]

O.dt=utils.PWaveTimeStep() #to slow down the motion O.dt=.9*PWaveTimeStep()
O.resetTime()

#saving parameters of spheres in file
def myaddData():
   if (O.iter%8==0):
      # open file 
      fil=open("vibs_."+str(O.iter),"a+")
      fil.write ('id \t x \t y \t z \t vz \t radius \t force \n')
      for b in O.bodies:
         if (type(b.shape)==Sphere):
            number,rad=b.id,b.shape.radius
            x,y,z=b.state.pos[0],b.state.pos[1],b.state.pos[2]
            veloc,force=b.state.vel[2],O.forces.f(b.id)
            fil.write("{:d}\t{:.3g}\t{:.3g}\t{:.3g}\t{:.3g}\t{:.3g}\t{}\n".format(number,x,y,z,veloc,rad,force)) # ( .format = % )

  
O.saveTmp()

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.