save in txt.file a packing of spheres

Asked by jacopo

hi, i m new in yade. I have to describe a land distribution. I m using all the command of gravity deposition. Now, what i want to do is to save in a txt file the final position of the sphere packings, so i will open it in a new file to change material , properrties and let collide with another body. How can i do ? i try to use export.textExt but is not working. How can i save then the positions and radii of all the spheres? this is my code, thanks for the help:

#####################################################

O.bodies.append(geom.facetBox((10,10,10),(10,10,10),wallMask=31))

# create empty sphere packing

sp=pack.SpherePack()
# generate randomly spheres with uniform radius distribution
sp.makeCloud((0,0,0),(10,10,2.6),rMean=.1,rRelFuzz=.1)

O.bodies.append(pack.regularHexa(pack.inAlignedBox((0,0,0),(20,20,20)),radius=.3,gap=0,color=(0.929,0.412,0.412),material="ghiaia"))

O.engines=[ForceResetter(),InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb(),Bo1_Box_Aabb(),Bo1_Wall_Aabb()]),InteractionLoop([Ig2_Sphere_Sphere_ScGeom(),Ig2_Box_Sphere_ScGeom(),Ig2_Wall_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],[Ip2_FrictMat_FrictMat_FrictPhys()],[Law2_ScGeom_MindlinPhys_HertzWithLinearShear()]),

NewtonIntegrator(gravity=(0,0,-9.81),damping=0.4
),
   # call the checkUnbalanced function (defined below) every 2 seconds
PyRunner(command='checkUnbalanced()',realPeriod=2),
   # call the addPlotData function every 200 steps
PyRunner(command='addPlotData()',iterPeriod=10)
]
O.dt=.5*PWaveTimeStep()

O.trackEnergy=True

# if the unbalanced forces goes below .05, the packing
# is considered stabilized, therefore we stop collected
# data history and stop
def checkUnbalanced():
   if unbalancedForce()<.05:
      O.pause()
      plot.saveDataTxt('bbb.txt.bz2')
export.textExt('/tmp/compressed.txt','x_y_z_r_attrs',attrs=[])

# collect history of data which will be plotted
def addPlotData():

plot.plots={'i':('unbalanced',None,O.energy.keys)}

plot.plot()

O.saveTmp()
export.textExt('/tmp/compressed.txt','x_y_z_r_attrs',attrs=[])

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Luc Scholtès
Solved:
Last query:
Last reply:
Revision history for this message
Jan Stránský (honzik) said :
#1

Hello,

> i m new in yade

welcome :-)

> but is not working.

please always specify what "is not working" mean (I got his and that error, the position saved is not the final one...).

Also please try to provide working examples. In this case I got "KeyError: "No material labeled `ghiaia'."" and some NameErrors afterwards..

Yade uses Python scripts to control simulation. Python reads and executes line by line. So in your case, it saves the positions before anything is run. You have several options:

1) run some time steps
O.run(2000,True) # note the True second parameter

2) do the save in a function:
def checkUnbalanced():
   if unbalancedForce()<.05:
      O.pause()
      plot.saveDataTxt('bbb.txt.bz2')
      export.textExt('/tmp/compressed.txt','x_y_z_r_attrs',attrs=[])
      # note the indentation, now it is part of checkUnbalanced function

cheers
Jan

Revision history for this message
jacopo (varrialeee) said :
#2

i was meaning that the code doesn't save me any positions, i see the simulation running. it ends and save the plots value inside 'bbb.txt.bz2, but any file txt for the positions and radii is created: i add the line code you suggest me but it still doesn't save nothing.

all the code is this now, it s really like deposition gravity, but i have to save the positions of the spheres in a txt file at the end of simulation:

from yade import pack, plot

# create rectangular box from facets
O.bodies.append(geom.facetBox((10,10,10),(10,10,10),wallMask=31))

sp=pack.SpherePack()

sp.makeCloud((0,0,0),(20,20,20),rMean=.3,rRelFuzz=.3)

sp.toSimulation()

O.engines=[
   ForceResetter(),
   InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
   InteractionLoop(
      # handle sphere+sphere and facet+sphere collisions
      [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],
      [Ip2_FrictMat_FrictMat_FrictPhys()],
      [Law2_ScGeom_FrictPhys_CundallStrack()]
   ),
   NewtonIntegrator(gravity=(0,0,-9.81),damping=0.4),
   # call the checkUnbalanced function (defined below) every 2 seconds
   PyRunner(command='checkUnbalanced()',realPeriod=2),
   # call the addPlotData function every 200 steps
   PyRunner(command='addPlotData()',iterPeriod=100)
]
O.dt=.5*PWaveTimeStep()

O.trackEnergy=True
O.run(2000,True)

def checkUnbalanced():
   if unbalancedForce()<.05:
      O.pause()
      plot.saveDataTxt('bbb.txt.bz2')
      export.textExt('/tmp/compressed.txt','x_y_z_r_attrs',attrs=[])

# collect history of data which will be plotted
def addPlotData():

   plot.addData(i=O.iter,unbalanced=unbalancedForce(),**O.energy)

plot.plots={'i':('unbalanced',None,O.energy.keys)}

plot.plot()

O.saveTmp()

Revision history for this message
Jan Stránský (honzik) said :
#3

I have tried your code and the data was saved.. you chose the file for saving to be /tmp/compressed.txt, maybe this confused you? After running the script, what is the output of terminal command
cat /tmp/compressed.txt
?
thanks
Jan

Revision history for this message
jacopo (varrialeee) said :
#4

Thanks jan for The answer, in The end i solved My problem , i created a functions that save the positions of The particles every 100 iter period. Now i m facing a new problem . I need To find And eventually change The Kn And Ks of The material. In The command FrictMat i can only choose young And poisson( i read that in realty that value aren t The real poisson And young Number) how can i do? Thanks

Revision history for this message
Best Luc Scholtès (luc) said :
#5

Hi Jacopo,

Changing the "young" and "poisson" in the material functor will change the stiffness of the newly created contacts only. If you want to change the stiffnesses of the existing ones, I believe that you have to loop over the interactions and modify the attributes of their Ip2_FrictMat_FrictMat_FrictPhys (for i in interactions: i.phys.kn=newValue). You should be able to do that but you should also consider opening a new question since this one is not related anymore to the initial one "save in txt.file a packing of spheres".

Luc

Revision history for this message
jacopo (varrialeee) said :
#6

Thanks Luc Scholtès, that solved my question.