creat many polyhedra in a box

Asked by lip

hello

i want to creat many polyhedra in a box with same size and i tried the code below, to replace the sphere with polyhedra i created:

from yade import pack, qt
from yade import polyhedra_utils,pack
import random

#creat a polyhedra
polyMat = PolyhedraMat(density=3000,young=1e10,poisson=.5,frictionAngle=atan(0.8))
O.materials.append(polyMat)
t=polyhedra_utils.polyhedra(polyMat,(.6,.6,.6),v=[(0,0,0),(0,0,1),(0,1,0),(1,0,0)])

sp=pack.SpherePack()
list=sp.makeCloud((0,0,0),(2,2,2),rMean=.1,rRelFuzz=.6,periodic=True)

#replace the sphere with polyhedra
for s in list
    O.bodies.append(t)

but it didn't work, the list turn out to be an int type, not a list, i would appreciate it if you can help me

Question information

Language:
English Edit question
Status:
Expired
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

  • by lip
Revision history for this message
Jan Stránský (honzik) said :
#1

Hello,

> list = ...

although might work, I suggest not to use python built-in types (list, tuple, set, int...) as variable names

1)
sp.makeCloud(...) modifies the 'sp' object. It returns number of created spheres, but the sp variable (SpherePack instance) is important for you.

2)
you create t=polyhedra only once, so O.bodies.append the same body object would be an error anyway

3)
> i want to creat many polyhedra in a box with same size
then do not use rRelFuzz for makeCloud (controls size distribution of created spheres)

4)
ployhedra_utils.polyhedra: if v parameter is used, size is ignored

a MWE:
###
from yade import pack, polyhedra_utils

polyMat = PolyhedraMat()
O.materials.append(polyMat)

sp=pack.SpherePack()
nSpheres=sp.makeCloud((0,0,0),(2,2,2),rMean=.1,periodic=True)

#replace the sphere with polyhedra
for center,radius in sp:
    # note: new polyhedron for each cycle
    t = polyhedra_utils.polyhedra(polyMat,(radius,radius,radius))
    t.state.pos = center # sets polyhedron position according to sphere position
    O.bodies.append(t)
###

cheers
Jan

Revision history for this message
lip (mr.xie) said :
#2

Thanks Jan Stránský, that solved my question.

Revision history for this message
lip (mr.xie) said :
#3

Dear Jan,
Thank you for your advice, it do solve my problem. But i still have some questions.
first, what does the param ratio refer to in function fillBox?It gives very little information in the doc.
seccond, if i want to creat many polyhedra of different shape and size with fixed proportion and distribution in a box, for example, in the flow simulation of concrete, i want to fine aggregate accounts for 10% and evenly distributed, the rest is coarse aggregate, is there any function can help me solve this problem?
i would appreciate if you can help me.

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

> what does the param ratio refer to in function fillBox?

according to source code [1] (after a quick look), for nonzero values it scales the sizemin and sizemax values. You can experiment a bit :-)

> ... of different shape and size with fixed proportion and distribution ...

you can use makeCloud with psdCumm and psdSizes parameters [2]. I am not very familiar with it, so please see examples or ask a new question concerning this.

cheers
Jan

[1] https://gitlab.com/yade-dev/trunk/blob/master/py/_polyhedra_utils.cpp#L260
[2] https://yade-dem.org/doc/yade.pack.html#yade._packSpheres.SpherePack.makeCloud

Revision history for this message
lip (mr.xie) said :
#5

hello
i was tried to simulation polyhedra collison by many polyhedra in a box, my code is as below:

from yade import pack, polyhedra_utils,plot

polyMat = PolyhedraMat()
O.materials.append(polyMat)

sp=pack.SpherePack()
nSpheres=sp.makeCloud((0,0,0),(2,2,2),rMean=.1,periodic=True)

#replace the sphere with polyhedra
for center,radius in sp:
    # note: new polyhedron for each cycle
    t = polyhedra_utils.polyhedra(polyMat,(radius,radius,radius))
    t.state.pos = center # sets polyhedron position according to sphere position
    O.bodies.append(t)

O.engines=[
   ForceResetter(),
   InsertionSortCollider([Bo1_Polyhedra_Aabb(),Bo1_Facet_Aabb()]),
   InteractionLoop(
      [Ig2_Polyhedra_Polyhedra_PolyhedraGeom(),Ig2_Facet_Polyhedra_PolyhedraGeom()],
      [Ip2_PolyhedraMat_PolyhedraMat_PolyhedraPhys()],
      [Law2_PolyhedraGeom_PolyhedraPhys_Volumetric()]
   ),
   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()

# enable energy tracking; any simulation parts supporting it
# can create and update arbitrary energy types, which can be
# accessed as O.energy['energyName'] subsequently
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')

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

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

# show the plot on the screen, and update while the simulation runs
plot.plot()

O.saveTmp()
##end
but when i click the start button, everything dissappear and send me a warn: WARN /usr/local/myYade/trunk/pkg/common/InsertionSortCollider.cpp:242 action: verletDist is set to 0 because no spheres were found. It will result in suboptimal performances, consider setting a positive verletDist in your script.
i don't where is wrong in my code. i would appreciate it if you can help me

Revision history for this message
Jan Stránský (honzik) said :
#6
Revision history for this message
Launchpad Janitor (janitor) said :
#7

This question was expired because it remained in the 'Open' state without activity for the last 15 days.