← 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

    Status: Answered => Open

hafsa is still having a problem:
hi Robert ,
thank you for answer me , i changed O.bodies like you said and it's work so thank you a obtain file (vibration.txt) contains properties 
but the problem that ( id ) start with 192 not by zero . and i used  VTKRecorder  but i don't know how to add this properties .
Any idea ?

Thanks in advance.

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 Cylinder 
Cylinder=O.bodies.append(geom.facetCylinder((0,0,1.5),2.0,height=3.0,wallMask=6,segmentsNumber=64,material=Mat1))

# 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))

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,pi],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()',realPeriod=1,initRun=True), #call def fonction every second 
    VTKRecorder(iterPeriod=100,recorders=['myaddData()'],fileName='vibrations.txt-') # add iteration number to basename
 ]

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

# open file 
fil=open("vibrations.txt.bz","a+")
fil.write ('id \t x \t y \t z \t velocity \t radius \t force \n')


#saving parameters of spheres in file
def myaddData():
   for b in O.bodies:
      if isinstance(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.