problems in

Asked by Chen Lifan on 2020-09-19

I have some problems in the example
1. I found the number (by the command 'print len(O.bodies)') in the cell isn't the same as the value appointed by sphereInCell. When I change the shape of the packing (i.e. the values in pack.inHyperboloid), the number of speres in the packing changes as well. I wonder the reason for it.
2. How to prepare a 2D packing using pack.randomDensePack? I tried to give the 'dim' in it a value as 2, but error occured.
Any kind of help is appreciated. Thanks.

Here is the scripts and error:


# -*- coding: utf-8 -*-
from __future__ import division

from yade import plot,pack,timing
import time, sys, os, copy
readParamsFromTable(noTableOk=True, # unknownOk=True,


 # 1=tension, 2=compression (ANDed; 3=both)


 # isotropic confinement (should be negative)

from yade.params.table import *

if 'description' in O.tags.keys(): O.tags['id']=O.tags['id']+O.tags['description']

# make geom; the dimensions are hard-coded here; could be in param table if desired
# z-oriented hyperboloid, length 20cm, diameter 10cm, skirt 8cm
# using spheres 7mm of diameter

print 'Timestep',O.dt

mm,mx=[pt[axis] for pt in aabbExtrema()]


# plot stresses in ¼, ½ and ¾ if desired as well; too crowded in the graph that includes confinement, though
plot.plots={'eps':('sigma',)} #,'sigma.50')},'t':('eps')} #'sigma.25','sigma.50','sigma.75')}



global mode
mode='tension' if doModes & 1 else 'compression'

def initTest():
 global mode
 print "init"
 if O.iter>0:
  print "Reversing plot data"; plot.reverseData()
 else: plot.plot(subPlots=False)
 strainer.strainRate=abs(strainRateTension) if mode=='tension' else -abs(strainRateCompression)
  from yade import qt
  renderer.dispScale=(1000,1000,1000) if mode=='tension' else (100,100,100)
 except ImportError: pass
 print "init done, will now run."
 O.step(); # to create initial contacts
 # now reset the interaction radius and go ahead

def stopIfDamaged():
 global mode
 if O.iter<2 or not'sigma'): return # do nothing at the very beginning
 extremum=max(sigma) if (strainer.strainRate>0) else min(sigma)
 minMaxRatio=0.5 if mode=='tension' else 0.5
 if extremum==0: return
 import sys; sys.stdout.flush()
 if abs(sigma[-1]/extremum)<minMaxRatio or abs(strainer.strain)>(5e-3 if isoPrestress==0 else 5e-2):
  if mode=='tension' and doModes & 2: # only if compression is enabled
   print "Saved /tmp/uniax-tension.yade.gz (for use with and"
   print "Damaged, switching to compression... "; O.pause()
   # important! initTest must be launched in a separate thread;
   # otherwise O.load would wait for the iteration to finish,
   # but it would wait for initTest to return and deadlock would result
   import thread; thread.start_new_thread(initTest,())
   print "Damaged, stopping."
   print 'Strengths fc=%g, ft=%g, |fc/ft|=%g'%(fc,ft,abs(fc/ft))
   title=O.tags['description'] if 'description' in O.tags.keys() else O.tags['params']
   print 'gnuplot',plot.saveGnuplot(O.tags['id'],title=title)
   print 'Bye.'
   #sys.exit(0) # results in some threading exception

def addPlotData():


Welcome to Yade 2018.02b
TCP python prompt on localhost:9000, auth cookie `uaekcd'
XMLRPC info provider on http://localhost:21000
Running script
Traceback (most recent call last):
  File "/usr/bin/yade", line 182, in runScript
  File "", line 78, in <module>
  File "/usr/lib/x86_64-linux-gnu/yade/py/yade/", line 491, in randomDensePack
    if max(dim)==float('inf'): raise RuntimeError("Infinite predicate and no dimension of packing requested.")
TypeError: 'int' object is not iterable

Question information

English Edit question
Yade Edit question
No assignee Edit question
Solved by:
Zhoufeng Shi
Last query:
Last reply:
Best Zhoufeng Shi (zhoufeng-s) said : #1

hi lifan,
for Q2, please check #660243 for 2d random dense pack. it provides some instruction on how to modify the randomDensePack code to make it 2d.
As for Q1, you can also try increasing the periodic cell size in the randomDensePack code and the spheresincell will increase to the value as requested.

Chen Lifan (chenlifan) said : #2

Thanks Zhoufeng Shi, that solved my question.

Jan Stránský (honzik) said : #3


if spheresInCell > 0, then periodic compaction is created, containing spheresInCell number of particles.
This periodic packing is then copied wherever needed and then cropped to form the desired packing.
So, spheresInCell is independent of number of particles in the resulting packing.
It is especially advantageous for large initial packing (but is usable universally), e.g. 1M particles, where randomDensePack with 1M particles would take much time. This way, you can generate a periodic cube with e.g. 1k particles and quickly copy it in the space.
With this approach, the packing generation has "almost" O(1) complexity.

**Personally** I do not use randomDensePack without spheresInCell parameter


Zhoufeng Shi (zhoufeng-s) said : #4

hi Jan
if the spheresInCell is not approximately equal to the number of particles in resulting packing(eg. sphereincel/final particles in packing =100), there seems to be clear pattern which is a kind of regularity that I don't desire. So what is the best ratio between sphereInCell and final particle number to make sure its randomness and save computation cost at the same time?

Jan Stránský (honzik) said : #5

> there seems to be clear pattern which is a kind of regularity

there **is** a regular pattern, by design (one periodic packing is copied wherever needed to fill the final packing)

> So what is the best ratio ...

You have to choose. According to your definition of "best", "randomness" etc.


Zhoufeng Shi (zhoufeng-s) said : #6

thanks Jan, that is very clear