← Back to team overview

yade-users team mailing list archive

Re: [Question #676326]: Can I control the seed in randomdensepack?


Question #676326 on Yade changed:

    Status: Answered => Open

kalogeropoulos is still having a problem:
Thank you a lot Jan Stránský (honzik).

Well i need to make a parametric analysis of how random generation of
spherical elements influence the force during the rock cutting
simulatio, so i must rewrite the function.

i make that but it doesnt run.

The code with the seed:

def randomDensePack(predicate,radius,material=-1,dim=None,cropLayers=0,rRelFuzz=0.,spheresInCell=0,memoizeDb=None,useOBB=False,memoDbg=False,color=None,seed=0,returnSpherePack=None):
   """Generator of random dense packing with given geometry properties, using TriaxialTest (aperiodic)
   or PeriIsoCompressor (periodic). The periodicity depens on whether   the spheresInCell parameter is given.

   *O.switchScene()* magic is used to have clean simulation for TriaxialTest without deleting the original simulation.
   This function therefore should never run in parallel with some code accessing your simulation.

   :param predicate: solid-defining predicate for which we generate packing
   :param spheresInCell: if given, the packing will be periodic, with given number of spheres in the periodic cell.
   :param radius: mean radius of spheres
   :param rRelFuzz: relative fuzz of the radius -- e.g. radius=10, rRelFuzz=.2, then spheres will have radii 10 ± (10*.2)), with an uniform distribution.
      0 by default, meaning all spheres will have exactly the same radius.
   :param cropLayers: (aperiodic only) how many layers of spheres will be added to the computed dimension of the box so that there no
      (or not so much, at least) boundary effects at the boundaries of the predicate.
   :param dim: dimension of the packing, to override dimensions of the predicate (if it is infinite, for instance)
   :param memoizeDb: name of sqlite database (existent or nonexistent) to find an already generated packing or to store
      the packing that will be generated, if not found (the technique of caching results of expensive computations
      is known as memoization). Fuzzy matching is used to select suitable candidate -- packing will be scaled, rRelFuzz
      and dimensions compared. Packing that are too small are dictarded. From the remaining candidate, the one with the
      least number spheres will be loaded and returned.
   :param useOBB: effective only if a inGtsSurface predicate is given. If true (not default), oriented bounding box will be
      computed first; it can reduce substantially number of spheres for the triaxial compression (like 10× depending on
      how much asymmetric the body is), see examples/gts-horse/gts-random-pack-obb.py
   :param memoDbg: show packings that are considered and reasons why they are rejected/accepted
   :param returnSpherePack: see the corresponding argument in :yref:`yade.pack.filterSpherePack`

   :return: SpherePack object with spheres, filtered by the predicate.
   import sqlite3, os.path, cPickle, time, sys, _packPredicates, numpy
   from math import pi
   if 'inGtsSurface' in dir(_packPredicates) and type(predicate)==inGtsSurface and useOBB:
      print "Best-fit oriented-bounding-box computed for GTS surface, orientation is",orientation
      dim*=2 # gtsSurfaceBestFitOBB returns halfSize
      if not dim: dim=predicate.dim()
      if max(dim)==float('inf'): raise RuntimeError("Infinite predicate and no dimension of packing requested.")
   if not wantPeri: fullDim=tuple([dim[i]+4*cropLayers*radius for i in 0,1,2])
      # compute cell dimensions now, as they will be compared to ones stored in the db
      # they have to be adjusted to not make the cell to small WRT particle radius
      cloudPorosity=0.25 # assume this number for the initial cloud (can be underestimated)
      beta,gamma=fullDim[1]/fullDim[0],fullDim[2]/fullDim[0] # ratios β=y₀/x₀, γ=z₀/x₀
      N100=spheresInCell/cloudPorosity # number of spheres for cell being filled by spheres without porosity
      y1,z1=beta*x1,gamma*x1; vol0=x1*y1*z1
      x1=max(x1,8*maxR); y1=max(y1,8*maxR); z1=max(z1,8*maxR); vol1=x1*y1*z1
      N100*=vol1/vol0 # volume might have been increased, increase number of spheres to keep porosity the same
      if sp:
         if orientation:
            sp.cellSize=(0,0,0) # resetting cellSize avoids warning when rotating
         return filterSpherePack(predicate,sp,material=material,returnSpherePack=returnSpherePack)
      else: print "No suitable packing in database found, running",'PERIODIC compression' if wantPeri else 'triaxial'
   O.switchScene(); O.resetThisScene() ### !!
   if wantPeri:
      # x1,y1,z1 already computed above
      #print cloudPorosity,beta,gamma,N100,x1,y1,z1,O.cell.refSize
      #print x1,y1,z1,radius,rRelFuzz
      for s in sp: O.bodies.append(utils.sphere(s[0],s[1]))
      O.run(); O.wait()
      sp=SpherePack(); sp.fromSimulation()
      #print 'Resulting cellSize',sp.cellSize,'proportions',sp.cellSize[1]/sp.cellSize[0],sp.cellSize[2]/sp.cellSize[0]
      # repetition to the required cell size will be done below, after memoizing the result
      V=(4.0/3.0)*pi*radius**3.0; N=assumedFinalDensity*fullDim[0]*fullDim[1]*fullDim[2]/V;
         # upperCorner is just size ratio, if radiusMean is specified
         ## no need to touch any the following
      while ( numpy.isnan(utils.unbalancedForce()) or utils.unbalancedForce()>0.005 ) :
      sp=SpherePack(); sp.fromSimulation()
   O.switchScene() ### !!
   if wantPeri: sp.cellFill(Vector3(fullDim[0],fullDim[1],fullDim[2]))
   if orientation:
      sp.cellSize=(0,0,0); # reset periodicity to avoid warning when rotating periodic packing
   return filterSpherePack(predicate,sp,material=material,color=color,returnSpherePack=returnSpherePack)

You received this question notification because your team yade-users is
an answer contact for Yade.