I am trying to create a simulation within yade with different sphere radius to fall by gravity into a container

Asked by Huan

import random
import math
from yade import geom, pack, plot

# create cylindrical body with radius 6 cm and height 6.05 cm
cylinder = yade.geom.facetCylinder((0,0,0), radius=0.06, height=0.065, segmentsNumber=80, wallMask=6)
O.bodies.append(cylinder)

# create empty sphere packing
sp = pack.SpherePack()

# specify the radii and ratios
radii_ratios = [(0.000075, 0.04), (0.0006, 0.06), (0.00236, 0.05), (0.00475, 0.35), (0.0095, 0.20), (0.0125, 0.30)]

# generate spheres with specified radii and ratios
for r, ratio in radii_ratios:
   num_spheres = int(ratio * 1000)
   sp.makeCloud((-0.055,-0.055,0.20), (0.055,0.055,0.09), rMean=r, rRelFuzz=0, num=num_spheres)

# add the sphere pack to the simulation
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),
]
O.dt = 2 * PWaveTimeStep()

# run the simulation for 1000 steps
O.run(1000)

# calculate the volume of the packing
volume_packing = 0
num_spheres = 0
for b in O.bodies:
  if isinstance(b.shape, yade.wrapper.Sphere):
      volume_packing += 4/3 * math.pi * b.shape.radius**3
      num_spheres += 1

# calculate the volume of the cylinder
volume_cylinder = math.pi * 0.06**2 * 0.0605

# calculate the porosity and porosity percentage
porosity = (volume_cylinder - volume_packing) / volume_cylinder
porosity_percent = porosity * 100

print("Number of spheres:", "{:.2f}".format(num_spheres))
print("V Packing:", "{:.2f}".format(volume_packing))
print("V Cylinder:", "{:.2f}".format(volume_cylinder))
print("Porosity:", "{:.2f}".format(porosity))
print("Porosity:", "{:.2f}%".format(porosity_percent))

I was able to complete the simulation but the simulation doesn't fully packed and V packing and V cylinder are calculated as 0
Is there any guide on how to make the sphere pack better in the container?
Why does the calculation is calculated as 0?

Question information

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

Hello,

> V packing and V cylinder are calculated as 0
> Why does the calculation is calculated as 0?

it is not computed as 0, it is just printed as 0.00
Change "{:.2f}" e.g. to "{:e}" or even just "{}" to see the actual value [1,3]
:.2f rounds the number to two decimal numbers, but the actual value is much less, so 0.00 is printed, even if the number is not zero.

> Is there any guide on how to make the sphere pack better in the container?

See gravity deposition tutorial [2]

> the simulation doesn't fully packed
> O.run(1000)

because it runs too little time (?)

Also consider using
###
O.run(1000,wait=True)
###
or
###
O.run(1000)
O.wait()
###
If you have a python code after O.run(1000), it is executed "immediately", i.e. at a random time w.r.t. running simulation

Or go in the [3] style with checkUnbalanced-like stop condition.

A few not important notes:

> print("Number of spheres:", "{:.2f}".format(num_spheres))

"{:d}" makes much more sense for number (integer)
Also consider using f-strings [3]

> cylinder = yade.geom.facetCylinder(..., radius=0.06, ...)
> volume_cylinder = math.pi * 0.06**2 * 0.0605

you have repeated value 0.06
It is a good practice to make it a variable then
###
radius = 0.06
cylinder = yade.geom.facetCylinder(..., radius=radius, ...)
volume_cylinder = math.pi * radius**2 * 0.0605
###
This way, if you want to change the radius, you just change it in one place (reducing the possible error by forgetting some place in the case where the value is at multiple places).
Same for other repeated values (e.g. height)

Cheers
Jan

[1] https://docs.python.org/3/library/string.html#formatstrings
[2] https://yade-dem.org/doc/tutorial-examples.html#gravity-deposition
[3] https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals

Revision history for this message
Huan (huan-liu) said (last edit ):
#2

Thanks Jan Stránský, that solved my question.
But I ended up rewrite another one, but ultimately I was able to fix the old one. Unfortunately, I met another trouble in the rewrite version.

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

If you have a new problem, please open a new question
Cheers
Jan