save and laod previously-generated 2d packing
Dear all,
I am trying to save the previously generated packing into file and load in the next simulation just like what was done in uniax.py (using memoizeDb). however, when I try to do the same for 2d randomDensePack, it always says that ' No suitable packing in database found, running PERIODIC compression' and 'Packing saved to the database /tmp/bending2DP
###############code begin##
from __future__ import print_function
from __future__ import division
from future import standard_library
standard_
from yade import pack,plot,timing,qt
import time, sys, os, copy
def _memoizePacking
import sys
if not memoizeDb: return
import pickle,
if os.path.
conn=
else:
conn=
c=conn.cursor()
c.execute('create table packings (radius real, rRelFuzz real, dimx real, dimy real, dimz real, N integer, timestamp real, periodic integer, pack blob)')
c=conn.cursor()
if(sys.
packBlob=
else:
packBlob=
packDim=
c.execute('insert into packings values (?,?,?,
c.close()
conn.commit()
if not noPrint: print("Packing saved to the database"
def _getMemoizedPac
"""Return suitable SpherePack read from *memoizeDb* if found, None otherwise.
:param fillPeriodic: whether to fill fullDim by repeating periodic packing
:param wantPeri: only consider periodic packings
"""
import os,os.path,
if memoDbg and not noPrint:
def memoDbgMsg(s): print(s)
else:
def memoDbgMsg(s): pass
if not memoizeDb or not os.path.
if memoizeDb: memoDbgMsg(
return None
# find suitable packing and return it directly
conn=sqlite3.
try:
c.execute('select radius,
except sqlite3.
raise RuntimeError(
for row in c:
R,rDev,
rDev*=scale; X*=scale; Y*=scale; Z*=scale
memoDbgMsg(
if not isPeri and wantPeri: memoDbgMsg("REJECT: is not periodic, which is requested."); continue
if wantPeri and (X/x1>0.9 or X/x1<0.6): memoDbgMsg("REJECT: initSize differs too much from scaled packing size."); continue
if (rRelFuzz==0 and rDev!=0) or (rRelFuzz!=0 and rDev==0) or (rRelFuzz!=0 and abs((rDev-
if isPeri and wantPeri:
if spheresInCell>NN and spheresInCell>0: memoDbgMsg("REJECT: Number of spheres in the packing too small"); continue
if abs((y1/
else:
if (X<fullDim[0] or Y<fullDim[1] or Z<fullDim[2]): memoDbgMsg("REJECT: not large enough"); continue # not large enough
memoDbgMsg(
if not noPrint: print("Found suitable packing in %s (radius=
c.execute('select pack from packings where timestamp=
sp=SpherePack
sp.scale(scale);
if isPeri and wantPeri:
sp.isPeriodic = True
sp.cellSize=
if fillPeriodic: sp.cellFill(
#sp.cellSize=
return sp
#if orientation: sp.rotate(
#return filterSpherePac
#print "No suitable packing in database found, running",'PERIODIC compression' if wantPeri else 'triaxial'
#sys.stdout.
def randomDensePack
import sqlite3, os.path, pickle, time, sys, numpy
from math import pi
from yade import _packPredicates
wantPeri=
if 'inGtsSurface' in dir(_packPredic
center,
print("Best-fit oriented-
dim*=2 # gtsSurfaceBestF
else:
if not dim: dim=predicate.dim()
if max(dim)
center=
orientation=None
if not wantPeri: fullDim=
else:
# 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
fullDim=dim
cloudPorosity
beta,
N100=
x1=radius*
y1,z1=
maxR=
x1=max(
N100*=vol1/vol0 # volume might have been increased, increase number of spheres to keep porosity the same
sp=_getMemoiz
if sp:
if orientation:
sp.
sp.
return filterSpherePac
else: print("No suitable packing in database found, running",'PERIODIC compression' if wantPeri else 'triaxial')
sys.stdout.
O.switchScene(); O.resetThisScene() ### !!
if wantPeri:
# x1,y1,z1 already computed above
sp=SpherePack()
O.periodic=True
#O.cell.
O.cell.
#print cloudPorosity,
#print x1,y1,z1,
O.materials.
vmin,
vmax[1]=0 ## diff
num=sp.
O.engines=
O.materials.
for s in sp:
b=utils.
b.state.
O.bodies.
O.dt=
O.run(); O.wait()
sp=SpherePack(); sp.fromSimulation()
#print 'Resulting cellSize'
# repetition to the required cell size will be done below, after memoizing the result
else:
assumedFinalD
V=(4.
TriaxialTest(
numberOfGrai
# upperCorner is just size ratio, if radiusMean is specified
upperCorner=
seed=seed,
## no need to touch any the following
noFiles=
while ( numpy.isnan(
O.run(500,True)
sp=SpherePack(); sp.fromSimulation()
O.switchScene() ### !!
_memoizePackin
if wantPeri: sp.cellFill(
if orientation:
sp.cellSize=
sp.rotate(
return filterSpherePac
###test
# tests
from yade import pack
#sp = randomDensePack
sp = randomDensePack
sp.toSimulation()
#######
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: