""" from yade import pack,qt import gts, locale locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') #gts is locale-dependend. If, for example, german locale is used, gts.read()-function does not import floats normally ''' if you get "Error: unsupported locale setting" -> type as root: "dpkg-reconfigure locales" -> choose "en_US.UTF-8" (press space to choose) ''' s1=gts.read(open('horse.coarse.gts')) s2=gts.Surface(); s2.copy(s1); s2.translate(0.04,0,0) O.bodies.append(pack.gtsSurface2Facets(s1,color=(0,1,0))+pack.gtsSurface2Facets(s2,color=(1,0,0))) s12=gts.Surface(); s12.copy(s1.union(s2)); s12.translate(0,0,.1) radius=0.002 O.bodies.append(pack.gtsSurface2Facets(s12,color=(0,0,1))) qt.View() from time import time t0=time() O.bodies.append(pack.regularHexa(pack.inGtsSurface(s1) | pack.inGtsSurface(s2),radius,gap=0,color=(0,1,0))) t1=time() print 'Using predicate union: %gs'%(t1-t0) O.bodies.append(pack.regularHexa(pack.inGtsSurface(s12),radius,gap=0.,color=(1,0,0))) t2=time() print 'Using surface union: %gs'%(t2-t1)
pts=[]; thMin=0 for i in range(0,bumpNum): thMin+=interBumpAngle thMax=thMin+interBumpAngle-bumpAngle thTip=thMax+.5*bumpAngle # the circular parts spanning from thMin to thMax for th0 in linspace(thMin,thMax,interBumpAngle/dTheta,endpoint=True): pts.append(Vector3(-.5*millDp,millRad*cos(th0),millRad*sin(th0))) # tip of the bump pts.append(Vector3(-.5*millDp,bumpRad*cos(thTip),bumpRad*sin(thTip))) # close the curve pts+=[pts[0]] # make the second contour, just shifted by millDp; ppts contains both ppts=[pts,[p+Vector3(millDp,0,0) for p in pts]] mill=pack.sweptPolylines2gtsSurface(ppts,threshold=.01*min(dTheta*millRad,bumpHt))#,capStart=True,capEnd=True) millIds=O.bodies.append(pack.gtsSurface2Facets(mill,color=(1,0,1),wire=False)) # add triangles, save their ids # make the caps less comfortably, but looking better as two triangle couples over the mill mrs2=millRad*sqrt(2) cap1,cap2=[Vector3(0,0,mrs2),Vector3(0,-mrs2,0),Vector3(0,0,-mrs2)],[Vector3(0,0,mrs2),Vector3(0,0,-mrs2),Vector3(0,mrs2,0)] # 2 triangles at every side for xx in -.5*millDp,.5*millDp: millIds+=O.bodies.append([utils.facet([p+Vector3(xx,0,0) for p in cap1],color=(0,0,0)),utils.facet([p+Vector3(xx,0,0) for p in cap2],color=(0,0,0))]) # define domains for initial cloud of red and blue spheres packHt=.8*millRad # size of the area bboxes=[(Vector3(-.5*millDp,-.5*packHt,-.5*packHt),Vector3(.5*millDp,0,.5*packHt)),(Vector3(-.5*millDp,0,-.5*packHt),Vector3(.5*millDp,.5*packHt,.5*packHt))] colors=(1,0,0),(0,0,1) for i in (0,1): # red and blue spheres sp=pack.SpherePack(); bb=bboxes[i]; vol=(bb[1][0]-bb[0][0])*(bb[1][1]-bb[0][1])*(bb[1][2]-bb[0][2]) sp.makeCloud(bb[0],bb[1],sphRad,sphRadFuzz,int(.25*vol/((4./3)*pi*sphRad**3)),False) O.bodies.append([utils.sphere(s[0],s[1],color=colors[i]) for s in sp]) print "Numer of grains",len(O.bodies)-len(millIds)
if surface.is_closed(): pred=pack.inGtsSurface(surface) # get characteristic dimensions aabb=pred.aabb() dim=pred.dim() center=pred.center() minDim=min(dim[0],dim[1],dim[2]) # define discretisation radius=minDim/(2*sizeRatio) print(center, dim, ' | minDim=', minDim, ' | diameter=', 2*radius) ### regular packing #O.bodies.append(pack.regularHexa(pred,radius=radius,gap=0.,color=(0.9,0.8,0.6))) #O.bodies.append(pack.regularOrtho(pred,radius=radius,gap=0.,color=(0.9,0.8,0.6))) sp=SpherePack() # random packing sp=pack.randomDensePack(pred,radius=radius,rRelFuzz=0.3,useOBB=True,memoizeDb='/tmp/gts-triax-packings.sqlite',returnSpherePack=True) # cropLayers=5 (not to use) # periodic random packing #sp=pack.randomDensePack(pred,radius=radius,rRelFuzz=0.3,useOBB=True,spheresInCell=2000,memoizeDb='/tmp/gts-triax-packings.sqlite',returnSpherePack=True) # cropLayers=5 (not to use) sp.toSimulation(color=(0.9,0.8,0.6)) #### import mesh O.bodies.append(pack.gtsSurface2Facets(surface,color=(0.8,0.8,0.8),wire=True)) #### export packing export.text(mesh+'_'+str(int(sizeRatio))+'.spheres') #### VIEW from yade import qt qt.View()
from yade import pack thetas = numpy.linspace(0, 2 * pi, nDiv, endpoint=True) ptsBase = [Vector3(cos(th), sin(th), -1) for th in thetas] ptsTop = [p + Vector3(0, 0, 2) for p in ptsBase] return pack.sweptPolylines2gtsSurface([ptsBase, ptsTop]) from yade import pack, timing cyl = unitCylinder() sq = unitSquare() sq.translate(0, 0, -1) cyl.copy(sq) cyl.scale(cylRd, cylRd, .5 * cylHt) cyl.rotate(1, 0, 0, -pi / 4) # 45° anti-colckwise in the yz plane # calling gtsSurface2Facets with just "cyl" (without constructing the faces tuple) ignores 2 faces that were copy'd before; bug in pygts? cylIds = O.bodies.append(pack.gtsSurface2Facets(cyl)) sp = pack.SpherePack() wd = cylRd * sqrt(2) rMean = (.2 * wd * wd * cylHt / (nSpheres * (4 / 3.) * pi))**(1 / 3.) print 'Generating cloud…' sp.makeCloud((-wd / 2, -wd / 2, -.5 * cylHt), (wd / 2, wd / 2, .5 * cylHt), rMean, 0, int(nSpheres), False) sp.rotate((1, 0, 0), -pi / 4) O.bodies.append([sphere(s[0], s[1]) for s in sp]) O.engines = [ ForceResetter(), InsertionSortCollider([ Bo1_Sphere_Aabb(), Bo1_Facet_Aabb(), ]),
minDim = min(dim[0], dim[1], dim[2]) # define discretisation radius = minDim / (2 * sizeRatio) print center, dim, ' | minDim=', minDim, ' | diameter=', 2 * radius ### regular packing #O.bodies.append(pack.regularHexa(pred,radius=radius,gap=0.,color=(0.9,0.8,0.6))) #O.bodies.append(pack.regularOrtho(pred,radius=radius,gap=0.,color=(0.9,0.8,0.6))) sp = SpherePack() # random packing sp = pack.randomDensePack( pred, radius=radius, rRelFuzz=0.3, useOBB=True, memoizeDb='/tmp/gts-triax-packings.sqlite', returnSpherePack=True) # cropLayers=5 (not to use) # periodic random packing #sp=pack.randomDensePack(pred,radius=radius,rRelFuzz=0.3,useOBB=True,spheresInCell=2000,memoizeDb='/tmp/gts-triax-packings.sqlite',returnSpherePack=True) # cropLayers=5 (not to use) sp.toSimulation(color=(0.9, 0.8, 0.6)) #### import mesh O.bodies.append( pack.gtsSurface2Facets(surface, color=(0.8, 0.8, 0.8), wire=True)) #### export packing export.text(mesh + '_' + str(int(sizeRatio)) + '.spheres') #### VIEW from yade import qt qt.View()
# define the section shape as polygon in 2d; repeat first point at the end to close the polygon sq2 = sqrt(2) poly = ((3 + .1, 0), (3 + 0, .1), (3 + sq2, .1 + sq2), (3 + .1 + sq2, sq2), (3 + .1, 0)) #pylab.plot(*zip(*poly)); pylab.xlim(xmin=0); pylab.grid(); pylab.title('Meridian of the revolution surface\n(close to continue)'); pylab.gca().set_aspect(aspect='equal',adjustable='box'); pylab.show() thetas = arange(0, pi / 8, pi / 24) pts = pack.revolutionSurfaceMeridians([poly for theta in thetas], thetas, origin=Vector3(-4, 0, -1), orientation=Quaternion.Identity) surf = pack.sweptPolylines2gtsSurface(pts, capStart=True, capEnd=True, threshold=1e-4) O.bodies.append(pack.gtsSurface2Facets(surf, color=(1, 0, 1))) # fill this solid with triaxial packing; it will compute minimum-volume oriented bounding box # to minimize the number of throw-away spheres. # It does away with about 3k spheres for radius 3e-2 sp1 = SpherePack() sp1 = pack.randomDensePack(pack.inGtsSurface(surf), radius=3e-2, rRelFuzz=1e-1, memoizeDb='/tmp/gts-triax.sqlite', returnSpherePack=True) sp1.toSimulation() # translate the surface away and pack it again with sphere, but without the oriented bounding box (useOBB=False) # Here, we need 20k spheres (with more or less the same result) surf.translate(0, 0, 1) O.bodies.append(pack.gtsSurface2Facets(surf, color=(1, 0, 0))) sp2 = SpherePack()
O.dt = .01 * tc # time step Rs = 0.1 # particle radius # Create geometry plnSurf = pack.sweptPolylines2gtsSurface([[ Vector3(-.5, 0, 0), Vector3(.5, 0, 0), Vector3(.5, 0, -.5), Vector3(-.5, 0, -.5) ]], capStart=True, capEnd=True) plnIds = O.bodies.append( pack.gtsSurface2Facets(plnSurf, material=facetMat, color=(0, 1, 0))) plnSurf1 = pack.sweptPolylines2gtsSurface([[ Vector3(-.5, -.5, -.5), Vector3(.5, -.5, -.5), Vector3(.5, 1.5, -.5), Vector3(-.5, 1.5, -.5) ]], capStart=True, capEnd=True) plnIds1 = O.bodies.append( pack.gtsSurface2Facets(plnSurf1, material=facetMat, color=(0, 1, 0))) # Create clumps clpId, sphId = O.bodies.appendClumped([ sphere(Vector3(0, Rs * 2 * i, Rs * 2), Rs, material=dfltSpheresMat)
numBoxes = Vector3(15,5,2) gapBetweenBoxes = 0.05 sizeBox = (lengthKnife-(numBoxes[1]-1)*gapBetweenBoxes)/numBoxes[1] ### Creating the Buldozer Knife ### from facets, using GTS Knife=[] for i in linspace(pi, pi*3/2, num=numKnifeParts, endpoint=True): Knife.append(Vector3(radiusKnife*cos(i),0,radiusKnife*sin(i))) KnifeP=[Knife,[p+Vector3(0,lengthKnife,0) for p in Knife]] KnifePoly=pack.sweptPolylines2gtsSurface(KnifeP,threshold=1e-4) KnifeIDs=[] KnifeIDs=O.bodies.append(pack.gtsSurface2Facets(KnifePoly,color=(1,0,0),wire=False)) KnifeIDs+=O.bodies.append(geom.facetBox((-lengthKnife/2-radiusKnife,lengthKnife/2,-radiusKnife+buldozerHeight/2),(lengthKnife/2,lengthKnife/2,buldozerHeight/2.),wallMask=47,color=(0,1,0),wire=False)) KnifeIDs+=O.bodies.append(geom.facetBox((-lengthKnife/2-radiusKnife-lengthKnife/4.,lengthKnife/2,-radiusKnife+buldozerHeight*3./2.-buldozerHeight/4.),(lengthKnife/4.,lengthKnife/3.,buldozerHeight/4.),wallMask=47,color=(0,0,1),wire=False)) O.bodies.append(geom.facetBox((0,lengthKnife/2,radiusKnife),(lengthKnife*4,lengthKnife*4,lengthKnife),wallMask=16,color=(1,1,1),wire=False)) ### Creating the material for buldozer colorsph1=Vector3(120,234,150); colorsph2=Vector3(1,1,0);
locale.setlocale( locale.LC_ALL, 'en_US.UTF-8' ) #gts is locale-dependend. If, for example, german locale is used, gts.read()-function does not import floats normally ''' if you get "Error: unsupported locale setting" -> type as root: "dpkg-reconfigure locales" -> choose "en_US.UTF-8" (press space to choose) ''' s1 = gts.read(open('horse.coarse.gts')) s2 = gts.Surface() s2.copy(s1) s2.translate(0.04, 0, 0) O.bodies.append( pack.gtsSurface2Facets(s1, color=(0, 1, 0)) + pack.gtsSurface2Facets(s2, color=(1, 0, 0))) s12 = gts.Surface() s12.copy(s1.union(s2)) s12.translate(0, 0, .1) radius = 0.002 O.bodies.append(pack.gtsSurface2Facets(s12, color=(0, 0, 1))) qt.View() from time import time t0 = time() O.bodies.append( pack.regularHexa(pack.inGtsSurface(s1) | pack.inGtsSurface(s2), radius, gap=0,
of height 2 and radius 2, centered at origin, axis coincident with the z-axis. :param int nDiv: polyhedron approximating circle. """ import numpy; from yade import pack thetas=numpy.linspace(0,2*pi,nDiv,endpoint=True) ptsBase=[Vector3(cos(th),sin(th),-1) for th in thetas] ptsTop=[p+Vector3(0,0,2) for p in ptsBase] return pack.sweptPolylines2gtsSurface([ptsBase,ptsTop]) from yade import pack,timing cyl=unitCylinder(); sq=unitSquare(); sq.translate(0,0,-1); cyl.copy(sq) cyl.scale(cylRd,cylRd,.5*cylHt); cyl.rotate(1,0,0,-pi/4) # 45° anti-colckwise in the yz plane # calling gtsSurface2Facets with just "cyl" (without constructing the faces tuple) ignores 2 faces that were copy'd before; bug in pygts? cylIds=O.bodies.append(pack.gtsSurface2Facets(cyl)) sp=pack.SpherePack(); wd=cylRd*sqrt(2); rMean=(.2*wd*wd*cylHt/(nSpheres*(4/3.)*pi))**(1/3.) print('Generating cloud…') sp.makeCloud((-wd/2,-wd/2,-.5*cylHt),(wd/2,wd/2,.5*cylHt),rMean,0,int(nSpheres),False) sp.rotate((1,0,0),-pi/4) O.bodies.append([sphere(s[0],s[1]) for s in sp]) O.engines=[ ForceResetter(), InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb(),]), InteractionLoop( [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()], [Ip2_FrictMat_FrictMat_FrictPhys()], [Law2_ScGeom_FrictPhys_CundallStrack()], ), RotationEngine(rotateAroundZero=True,zeroPoint=(0,0,0),rotationAxis=(0,1,1),angularVelocity=30*(2*pi/60),ids=cylIds,label='rotor'),
en = 0.3 es = 0.3 ## Materials facetMat=O.materials.append(ViscElMat(frictionAngle=frictionAngle,tc=tc,en=en,et=es)) sphereMat=O.materials.append(ViscElMat(density=Density,frictionAngle=frictionAngle,tc=tc,en=en,et=es)) ### Creating the Buldozer Knife ### from facets, using GTS Knife=[] for i in linspace(pi, pi*3/2, num=numKnifeParts, endpoint=True): Knife.append(Vector3(radiusKnife*cos(i),0,radiusKnife*sin(i))) KnifeP=[Knife,[p+Vector3(0,lengthKnife,0) for p in Knife]] KnifePoly=pack.sweptPolylines2gtsSurface(KnifeP,threshold=1e-4) KnifeIDs=O.bodies.append(pack.gtsSurface2Facets(KnifePoly,color=(1,0,0),wire=False,material=facetMat)) KnifeIDs+=O.bodies.append(geom.facetBox((-lengthKnife/2-radiusKnife,lengthKnife/2,-radiusKnife+buldozerHeight/2),(lengthKnife/2,lengthKnife/2,buldozerHeight/2.),wallMask=47,color=(0,1,0),wire=False)) KnifeIDs+=O.bodies.append(geom.facetBox((-lengthKnife/2-radiusKnife-lengthKnife/4.,lengthKnife/2,-radiusKnife+buldozerHeight*3./2.-buldozerHeight/4.),(lengthKnife/4.,lengthKnife/3.,buldozerHeight/4.),wallMask=47,color=(0,0,1),wire=False)) O.bodies.append(geom.facetBox((0,0,radiusKnife),(lengthKnife*3,lengthKnife*3,lengthKnife),wallMask=16,color=(1,1,1),wire=False,material=facetMat)) ### Creating the material for buldozer colorsph1=Vector3(120,234,150); colorsph2=Vector3(0,0,1); colorsph1.normalize(); colorsph2.normalize(); colorSph=colorsph1
# the circular parts spanning from thMin to thMax for th0 in linspace(thMin, thMax, interBumpAngle / dTheta, endpoint=True): pts.append( Vector3(-.5 * millDp, millRad * cos(th0), millRad * sin(th0))) # tip of the bump pts.append( Vector3(-.5 * millDp, bumpRad * cos(thTip), bumpRad * sin(thTip))) # close the curve pts += [pts[0]] # make the second contour, just shifted by millDp; ppts contains both ppts = [pts, [p + Vector3(millDp, 0, 0) for p in pts]] mill = pack.sweptPolylines2gtsSurface( ppts, threshold=.01 * min(dTheta * millRad, bumpHt)) #,capStart=True,capEnd=True) millIds = O.bodies.append( pack.gtsSurface2Facets(mill, color=(1, 0, 1), wire=False)) # add triangles, save their ids # make the caps less comfortably, but looking better as two triangle couples over the mill mrs2 = millRad * sqrt(2) cap1, cap2 = [Vector3(0, 0, mrs2), Vector3(0, -mrs2, 0), Vector3(0, 0, -mrs2)], [ Vector3(0, 0, mrs2), Vector3(0, 0, -mrs2), Vector3(0, mrs2, 0) ] # 2 triangles at every side for xx in -.5 * millDp, .5 * millDp: millIds += O.bodies.append([ utils.facet([p + Vector3(xx, 0, 0) for p in cap1], color=(0, 0, 0)), utils.facet([p + Vector3(xx, 0, 0) for p in cap2], color=(0, 0, 0)) ])
#!/usr/bin/python # -*- coding: utf-8 -*- """This example demonstrates GTS (http://gts.sourceforge.net/) opportunities for creating surfaces VTU-files are created in /tmp directory after simulation. If you open those with paraview (or other VTK-based) program, you can create video, make screenshots etc.""" from numpy import linspace from yade import pack thetas=linspace(0,2*pi,num=16,endpoint=True) meridians=pack.revolutionSurfaceMeridians([[(3+rad*sin(th),10*rad+rad*cos(th)) for th in thetas] for rad in linspace(1,2,num=10)],linspace(0,pi,num=10)) surf=pack.sweptPolylines2gtsSurface(meridians+[[Vector3(5*sin(-th),-10+5*cos(-th),30) for th in thetas]]) O.bodies.append(pack.gtsSurface2Facets(surf)) sp=pack.SpherePack() sp.makeCloud(Vector3(-1,-9,30),Vector3(1,-13,32),.2,rRelFuzz=.3) O.bodies.append([sphere(c,r) for c,r in sp]) O.engines=[ ForceResetter(), InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]), InteractionLoop( [Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom()], [Ip2_FrictMat_FrictMat_FrictPhys()], [Law2_ScGeom_FrictPhys_CundallStrack()] ), NewtonIntegrator(gravity=(0,0,-9.81)), VTKRecorder(iterPeriod=100,recorders=['spheres','facets','colors'],fileName='/tmp/p1-') ] O.dt=PWaveTimeStep()
if surface.is_closed(): pred=pack.inGtsSurface(surface) # get characteristic dimensions aabb=pred.aabb() dim=pred.dim() center=pred.center() minDim=min(dim[0],dim[1],dim[2]) # define discretisation radius=minDim/(2*sizeRatio) print center, dim, ' | minDim=', minDim, ' | diameter=', 2*radius ### regular packing #O.bodies.append(pack.regularHexa(pred,radius=radius,gap=0.,color=(0.9,0.8,0.6))) #O.bodies.append(pack.regularOrtho(pred,radius=radius,gap=0.,color=(0.9,0.8,0.6))) sp=SpherePack() # random packing sp=pack.randomDensePack(pred,radius=radius,rRelFuzz=0.3,useOBB=True,memoizeDb='/tmp/gts-triax-packings.sqlite',returnSpherePack=True) # cropLayers=5 (not to use) # periodic random packing #sp=pack.randomDensePack(pred,radius=radius,rRelFuzz=0.3,useOBB=True,spheresInCell=2000,memoizeDb='/tmp/gts-triax-packings.sqlite',returnSpherePack=True) # cropLayers=5 (not to use) sp.toSimulation(color=(0.9,0.8,0.6)) #### import mesh O.bodies.append(pack.gtsSurface2Facets(surface,color=(0.8,0.8,0.8),wire=True)) #### export packing export.text(mesh+'_'+str(int(sizeRatio))+'.spheres') #### VIEW from yade import qt qt.View()
radiusSph = 0.05 numBoxes = Vector3(15, 5, 2) gapBetweenBoxes = 0.05 sizeBox = (lengthKnife - (numBoxes[1] - 1) * gapBetweenBoxes) / numBoxes[1] ### Creating the Buldozer Knife ### from facets, using GTS Knife = [] for i in linspace(pi, pi * 3 / 2, num=numKnifeParts, endpoint=True): Knife.append(Vector3(radiusKnife * cos(i), 0, radiusKnife * sin(i))) KnifeP = [Knife, [p + Vector3(0, lengthKnife, 0) for p in Knife]] KnifePoly = pack.sweptPolylines2gtsSurface(KnifeP, threshold=1e-4) KnifeIDs = [] KnifeIDs = O.bodies.append( pack.gtsSurface2Facets(KnifePoly, color=(1, 0, 0), wire=False)) KnifeIDs += O.bodies.append( geom.facetBox((-lengthKnife / 2 - radiusKnife, lengthKnife / 2, -radiusKnife + buldozerHeight / 2), (lengthKnife / 2, lengthKnife / 2, buldozerHeight / 2.), wallMask=47, color=(0, 1, 0), wire=False)) KnifeIDs += O.bodies.append( geom.facetBox( (-lengthKnife / 2 - radiusKnife - lengthKnife / 4., lengthKnife / 2, -radiusKnife + buldozerHeight * 3. / 2. - buldozerHeight / 4.), (lengthKnife / 4., lengthKnife / 3., buldozerHeight / 4.), wallMask=47,
""" from numpy import arange from yade import pack import pylab # define the section shape as polygon in 2d; repeat first point at the end to close the polygon sq2 = sqrt(2) poly = ((3 + 0.1, 0), (3 + 0, 0.1), (3 + sq2, 0.1 + sq2), (3 + 0.1 + sq2, sq2), (3 + 0.1, 0)) # pylab.plot(*zip(*poly)); pylab.xlim(xmin=0); pylab.grid(); pylab.title('Meridian of the revolution surface\n(close to continue)'); pylab.gca().set_aspect(aspect='equal',adjustable='box'); pylab.show() thetas = arange(0, pi / 8, pi / 24) pts = pack.revolutionSurfaceMeridians( [poly for theta in thetas], thetas, origin=Vector3(-4, 0, -1), orientation=Quaternion.Identity ) surf = pack.sweptPolylines2gtsSurface(pts, capStart=True, capEnd=True, threshold=1e-4) O.bodies.append(pack.gtsSurface2Facets(surf, color=(1, 0, 1))) # fill this solid with triaxial packing; it will compute minimum-volume oriented bounding box # to minimize the number of throw-away spheres. # It does away with about 3k spheres for radius 3e-2 O.bodies.append( pack.randomDensePack(pack.inGtsSurface(surf), radius=3e-2, rRelFuzz=1e-1, memoizeDb="/tmp/gts-triax.sqlite") ) # translate the surface away and pack it again with sphere, but without the oriented bounding box (useOBB=False) # Here, we need 20k spheres (with more or less the same result) surf.translate(0, 0, 1) O.bodies.append(pack.gtsSurface2Facets(surf, color=(1, 0, 0))) O.bodies.append( pack.randomDensePack( pack.inGtsSurface(surf), radius=3e-2, rRelFuzz=1e-1, memoizeDb="/tmp/gts-triax-packings.sqlite", useOBB=False ) )
gunzip horse.gts.gz """ quit() surf = gts.read(open('horse.coarse.gts')) if surf.is_closed(): pred = pack.inGtsSurface(surf) aabb = pred.aabb() dim0 = aabb[1][0] - aabb[0][0] radius = dim0 / 40. # get some characteristic dimension, use it for radius O.bodies.append(pack.regularHexa(pred, radius=radius, gap=radius / 4.)) surf.translate( 0, 0, -(aabb[1][2] - aabb[0][2]) ) # move surface down so that facets are underneath the falling spheres O.bodies.append(pack.gtsSurface2Facets(surf, wire=True)) O.engines = [ ForceResetter(), InsertionSortCollider( [Bo1_Sphere_Aabb(), Bo1_Facet_Aabb()], label='collider'), InteractionLoop( [Ig2_Sphere_Sphere_L3Geom(), Ig2_Facet_Sphere_L3Geom()], [Ip2_FrictMat_FrictMat_FrictPhys()], [Law2_L3Geom_FrictPhys_ElPerfPl()], ), NewtonIntegrator(damping=.1, gravity=[0, 0, -5000]), PyRunner(iterPeriod=1000, command='timing.stats(); O.pause();'), PyRunner(iterPeriod=10, command='addPlotData()') ]
kw=utils.getViscoelasticFromSpheresInteraction(tc,en,es) params=utils.getViscoelasticFromSpheresInteraction(tc,en,es) # facets material facetMat=O.materials.append(ViscElMat(frictionAngle=frictionAngle,**params)) # default spheres material dfltSpheresMat=O.materials.append(ViscElMat(density=density,frictionAngle=frictionAngle,**params)) O.dt=.2*tc # time step Rs=0.02 # mean particle radius Rf=0.01 # dispersion (Rs±Rf*Rs) nSpheres=1000# number of particles # Create geometry pln=Plane( (-.5, -.5, 0), (.5, -.5, -.05), (.5, .5, 0), (-.5, .5, -.05) ); plnIds=O.bodies.append(pack.gtsSurface2Facets(pln,material=facetMat,color=(0,1,0))) fct=Plane( (-.25, -.25, .5), (.25, -.25, .5), (.25, .25, .5), (-.25, .25, .5) ); fctIds=O.bodies.append(pack.gtsSurface2Facets(fct,material=facetMat,color=(1,0,0),noBound=True)) # Create spheres sp=pack.SpherePack(); sp.makeCloud(Vector3(-.5, -.5, 0),Vector3(.5, .5, .2), Rs, Rf, int(nSpheres), False) spheres=O.bodies.append([utils.sphere(s[0],s[1],color=(0.929,0.412,0.412),material=dfltSpheresMat) for s in sp]) # Create engines O.engines=[ ForceResetter(), InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]), InteractionLoop( [Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom()],
#!/usr/bin/python # -*- coding: utf-8 -*- """This example demonstrates GTS (http://gts.sourceforge.net/) opportunities for creating surfaces VTU-files are created in /tmp directory after simulation. If you open those with paraview (or other VTK-based) program, you can create video, make screenshots etc.""" from numpy import linspace from yade import pack thetas = linspace(0, 2 * pi, num=16, endpoint=True) meridians = pack.revolutionSurfaceMeridians( [[(3 + rad * sin(th), 10 * rad + rad * cos(th)) for th in thetas] for rad in linspace(1, 2, num=10)], linspace(0, pi, num=10)) surf = pack.sweptPolylines2gtsSurface( meridians + [[Vector3(5 * sin(-th), -10 + 5 * cos(-th), 30) for th in thetas]]) O.bodies.append(pack.gtsSurface2Facets(surf)) sp = pack.SpherePack() sp.makeCloud(Vector3(-1, -9, 30), Vector3(1, -13, 32), .2, rRelFuzz=.3) O.bodies.append([sphere(c, r) for c, r in sp]) O.engines = [ ForceResetter(), InsertionSortCollider([Bo1_Sphere_Aabb(), Bo1_Facet_Aabb()]), InteractionLoop([Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom()], [Ip2_FrictMat_FrictMat_FrictPhys()], [Law2_ScGeom_FrictPhys_CundallStrack()]), NewtonIntegrator(gravity=(0, 0, -9.81)), VTKRecorder(iterPeriod=100,
es=.3 # tangential restitution coefficient frictionAngle=radians(35)# density=2700 # facets material params=utils.getViscoelasticFromSpheresInteraction(10e3,tc,en,es) facetMat=O.materials.append(ViscElMat(frictionAngle=frictionAngle,**params)) # **params sets kn, cn, ks, cs # default spheres material dfltSpheresMat=O.materials.append(ViscElMat(density=density,frictionAngle=frictionAngle)) O.dt=.1*tc # time step Rs=0.1 # particle radius # Create geometry bottom = pack.sweptPolylines2gtsSurface([[Vector3(-1,-1,-1),Vector3(1,-1,-1),Vector3(1, 1, -1),Vector3(-1, 1, -1)]],capStart=True,capEnd=True) btmIds=O.bodies.append(pack.gtsSurface2Facets(bottom.faces(),material=facetMat,color=(0,1,0))) #top = pack.sweptPolylines2gtsSurface([[Vector3(-1,-1,1),Vector3(1,-1,1),Vector3(1, 1, 1),Vector3(-1, 1, 1)]],capStart=True,capEnd=True) #topIds=O.bodies.append(pack.gtsSurface2Facets(top.faces(),material=facetMat,color=(0,1,0))) left = pack.sweptPolylines2gtsSurface([[Vector3(-1,-1,-1),Vector3(1,-1,-1),Vector3(1, -1, 1),Vector3(-1, -1, 1)]],capStart=True,capEnd=True) lftIds=O.bodies.append(pack.gtsSurface2Facets(left.faces(),material=facetMat,color=(0,1,0))) right = pack.sweptPolylines2gtsSurface([[Vector3(-1,1,-1),Vector3(1,1,-1),Vector3(1, 1, 1),Vector3(-1, 1, 1)]],capStart=True,capEnd=True) rgtIds=O.bodies.append(pack.gtsSurface2Facets(right.faces(),material=facetMat,color=(0,1,0))) near = pack.sweptPolylines2gtsSurface([[Vector3(1,-1,-1),Vector3(1,1,-1),Vector3(1, 1, 1),Vector3(1, -1, 1)]],capStart=True,capEnd=True) nearIds=O.bodies.append(pack.gtsSurface2Facets(near.faces(),material=facetMat,color=(0,1,0))) far = pack.sweptPolylines2gtsSurface([[Vector3(-1,-1,-1),Vector3(-1,1,-1),Vector3(-1, 1, 1),Vector3(-1, -1, 1)]],capStart=True,capEnd=True) farIds=O.bodies.append(pack.gtsSurface2Facets(far.faces(),material=facetMat,color=(0,1,0)))
dfltSpheresMat=O.materials.append(ViscElMat(density=density,frictionAngle=frictionAngle,tc=tc,en=en,et=es)) O.dt=.05*tc # time step Rs=0.05 # particle radius # Create geometry x0=0.; y0=0.; z0=0.; ab=.7; at=2.; h=1.; hl=h; al=at*3 zb=z0; x0b=x0-ab/2.; y0b=y0-ab/2.; x1b=x0+ab/2.; y1b=y0+ab/2. zt=z0+h; x0t=x0-at/2.; y0t=y0-at/2.; x1t=x0+at/2.; y1t=y0+at/2. zl=z0-hl;x0l=x0-al/2.; y0l=y0-al/2.; x1l=x0+al/2.; y1l=y0+al/2. left = pack.sweptPolylines2gtsSurface([[Vector3(x0b,y0b,zb),Vector3(x0t,y0t,zt),Vector3(x0t,y1t,zt),Vector3(x0b,y1b,zb)]],capStart=True,capEnd=True) lftIds=O.bodies.append(pack.gtsSurface2Facets(left,material=facetMat,color=(0,1,0))) right = pack.sweptPolylines2gtsSurface([[Vector3(x1b,y0b,zb),Vector3(x1t,y0t,zt),Vector3(x1t,y1t,zt),Vector3(x1b,y1b,zb)]],capStart=True,capEnd=True) rgtIds=O.bodies.append(pack.gtsSurface2Facets(right,material=facetMat,color=(0,1,0))) near = pack.sweptPolylines2gtsSurface([[Vector3(x0b,y0b,zb),Vector3(x0t,y0t,zt),Vector3(x1t,y0t,zt),Vector3(x1b,y0b,zb)]],capStart=True,capEnd=True) nearIds=O.bodies.append(pack.gtsSurface2Facets(near,material=facetMat,color=(0,1,0))) far = pack.sweptPolylines2gtsSurface([[Vector3(x0b,y1b,zb),Vector3(x0t,y1t,zt),Vector3(x1t,y1t,zt),Vector3(x1b,y1b,zb)]],capStart=True,capEnd=True) farIds=O.bodies.append(pack.gtsSurface2Facets(far,material=facetMat,color=(0,1,0))) table = pack.sweptPolylines2gtsSurface([[Vector3(x0l,y0l,zl),Vector3(x0l,y1l,zl),Vector3(x1l,y1l,zl),Vector3(x1l,y0l,zl)]],capStart=True,capEnd=True) tblIds=O.bodies.append(pack.gtsSurface2Facets(table,material=facetMat,color=(0,1,0))) # Create clumps... clumpColor=(0.0, 0.5, 0.5)
facetMat = O.materials.append(ViscElMat( frictionAngle=frictionAngle, **params)) # **params sets kn, cn, ks, cs sphereMat = O.materials.append( ViscElMat(density=Density, frictionAngle=frictionAngle, **params)) ### Creating the Buldozer Knife ### from facets, using GTS Knife = [] for i in linspace(pi, pi * 3 / 2, num=numKnifeParts, endpoint=True): Knife.append(Vector3(radiusKnife * cos(i), 0, radiusKnife * sin(i))) KnifeP = [Knife, [p + Vector3(0, lengthKnife, 0) for p in Knife]] KnifePoly = pack.sweptPolylines2gtsSurface(KnifeP, threshold=1e-4) KnifeIDs = O.bodies.append( pack.gtsSurface2Facets(KnifePoly, color=(1, 0, 0), wire=False, material=facetMat)) KnifeIDs += O.bodies.append( geom.facetBox((-lengthKnife / 2 - radiusKnife, lengthKnife / 2, -radiusKnife + buldozerHeight / 2), (lengthKnife / 2, lengthKnife / 2, buldozerHeight / 2.), wallMask=47, color=(0, 1, 0), wire=False)) KnifeIDs += O.bodies.append( geom.facetBox( (-lengthKnife / 2 - radiusKnife - lengthKnife / 4., lengthKnife / 2, -radiusKnife + buldozerHeight * 3. / 2. - buldozerHeight / 4.), (lengthKnife / 4., lengthKnife / 3., buldozerHeight / 4.),
print """horse.gts not found, you need to download input data: wget http://gts.sourceforge.net/samples/horse.gts.gz gunzip horse.gts.gz """ quit() surf=gts.read(open('horse.coarse.gts')) if surf.is_closed(): pred=pack.inGtsSurface(surf) aabb=pred.aabb() dim0=aabb[1][0]-aabb[0][0]; radius=dim0/40. # get some characteristic dimension, use it for radius O.bodies.append(pack.regularHexa(pred,radius=radius,gap=radius/4.)) surf.translate(0,0,-(aabb[1][2]-aabb[0][2])) # move surface down so that facets are underneath the falling spheres O.bodies.append(pack.gtsSurface2Facets(surf,wire=True)) O.engines=[ ForceResetter(), InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()],label='collider'), InteractionLoop( [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()], [Ip2_FrictMat_FrictMat_FrictPhys()], [Law2_ScGeom_FrictPhys_CundallStrack()], ), NewtonIntegrator(damping=.1,gravity=[0,0,-5000]), PyRunner(iterPeriod=1000,command='timing.stats(); O.pause();'), PyRunner(iterPeriod=10,command='addPlotData()') ] O.dt=.7*PWaveTimeStep() O.saveTmp()
en=.3 # normal restitution coefficient es=.3 # tangential restitution coefficient frictionAngle=radians(35)# density=2700 # facets material facetMat=O.materials.append(ViscElMat(frictionAngle=frictionAngle,tc=tc,en=en,et=es)) # default spheres material dfltSpheresMat=O.materials.append(ViscElMat(density=density,frictionAngle=frictionAngle,tc=tc,en=en,et=es)) O.dt=.01*tc # time step Rs=0.1 # particle radius # Create geometry plnSurf = pack.sweptPolylines2gtsSurface([[Vector3(-.5,0,0),Vector3(.5,0,0),Vector3(.5, 0, -.5),Vector3(-.5, 0, -.5)]],capStart=True,capEnd=True) plnIds=O.bodies.append(pack.gtsSurface2Facets(plnSurf,material=facetMat,color=(0,1,0))) plnSurf1 = pack.sweptPolylines2gtsSurface([[Vector3(-.5,-.5,-.5),Vector3(.5,-.5,-.5),Vector3(.5, 1.5, -.5),Vector3(-.5, 1.5, -.5)]],capStart=True,capEnd=True) plnIds1=O.bodies.append(pack.gtsSurface2Facets(plnSurf1,material=facetMat,color=(0,1,0))) # Create clumps clpId,sphId=O.bodies.appendClumped([sphere(Vector3(0,Rs*2*i,Rs*2),Rs,material=dfltSpheresMat) for i in range(4)]) # Create engines O.engines=[ ForceResetter(), InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]), InteractionLoop( [Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom()], [Ip2_ViscElMat_ViscElMat_ViscElPhys()], [Law2_ScGeom_ViscElPhys_Basic()],
# facets material facetMat = O.materials.append(ViscElMat(frictionAngle=frictionAngle, **params)) # default spheres material dfltSpheresMat = O.materials.append( ViscElMat(density=density, frictionAngle=frictionAngle, **params)) O.dt = .2 * tc # time step Rs = 0.02 # mean particle radius Rf = 0.01 # dispersion (Rs±Rf*Rs) nSpheres = 1000 # number of particles # Create geometry pln = Plane((-.5, -.5, 0), (.5, -.5, -.05), (.5, .5, 0), (-.5, .5, -.05)) plnIds = O.bodies.append( pack.gtsSurface2Facets(pln, material=facetMat, color=(0, 1, 0))) fct = Plane((-.25, -.25, .5), (.25, -.25, .5), (.25, .25, .5), (-.25, .25, .5)) fctIds = O.bodies.append( pack.gtsSurface2Facets(fct, material=facetMat, color=(1, 0, 0), noBound=True)) # Create spheres sp = pack.SpherePack() sp.makeCloud(Vector3(-.5, -.5, 0), Vector3(.5, .5, .2), Rs, Rf, int(nSpheres), False) spheres = O.bodies.append([ sphere(s[0], s[1], color=(0.929, 0.412, 0.412), material=dfltSpheresMat) for s in sp
zl = z0 - hl x0l = x0 - al / 2. y0l = y0 - al / 2. x1l = x0 + al / 2. y1l = y0 + al / 2. left = pack.sweptPolylines2gtsSurface([[ Vector3(x0b, y0b, zb), Vector3(x0t, y0t, zt), Vector3(x0t, y1t, zt), Vector3(x0b, y1b, zb) ]], capStart=True, capEnd=True) lftIds = O.bodies.append( pack.gtsSurface2Facets(left, material=facetMat, color=(0, 1, 0))) right = pack.sweptPolylines2gtsSurface([[ Vector3(x1b, y0b, zb), Vector3(x1t, y0t, zt), Vector3(x1t, y1t, zt), Vector3(x1b, y1b, zb) ]], capStart=True, capEnd=True) rgtIds = O.bodies.append( pack.gtsSurface2Facets(right, material=facetMat, color=(0, 1, 0))) near = pack.sweptPolylines2gtsSurface([[ Vector3(x0b, y0b, zb), Vector3(x0t, y0t, zt),
kw=utils.getViscoelasticFromSpheresInteraction(10e3,tc,en,es) params=utils.getViscoelasticFromSpheresInteraction(10e3,tc,en,es) # facets material facetMat=O.materials.append(ViscElMat(frictionAngle=frictionAngle,**params)) # default spheres material dfltSpheresMat=O.materials.append(ViscElMat(density=density,frictionAngle=frictionAngle)) O.dt=.2*tc # time step Rs=0.02 # mean particle radius Rf=0.01 # dispersion (Rs±Rf*Rs) nSpheres=1000# number of particles # Create geometry pln=Plane( (-.5, -.5, 0), (.5, -.5, -.05), (.5, .5, 0), (-.5, .5, -.05) ); plnIds=O.bodies.append(pack.gtsSurface2Facets(pln.faces(),material=facetMat,color=(0,1,0))) fct=Plane( (-.25, -.25, .5), (.25, -.25, .5), (.25, .25, .5), (-.25, .25, .5) ); fctIds=O.bodies.append(pack.gtsSurface2Facets(fct.faces(),material=facetMat,color=(1,0,0),noBound=True)) # Create spheres sp=pack.SpherePack(); sp.makeCloud(Vector3(-.5, -.5, 0),Vector3(.5, .5, .2), Rs, Rf, int(nSpheres), False) spheres=O.bodies.append([utils.sphere(s[0],s[1],color=(0.929,0.412,0.412),material=dfltSpheresMat) for s in sp]) for id in spheres: s=O.bodies[id] p=utils.getViscoelasticFromSpheresInteraction(s.state['mass'],tc,en,es) s.mat['kn'],s.mat['cn'],s.mat['ks'],s.mat['cs']=p['kn'],p['cn'],p['ks'],p['cs'] # Create engines O.engines=[
en=.3 # normal restitution coefficient es=.3 # tangential restitution coefficient frictionAngle=radians(35)# density=2700 # facets material facetMat=O.materials.append(ViscElMat(frictionAngle=frictionAngle,tc=tc,en=en,et=es)) # default spheres material dfltSpheresMat=O.materials.append(ViscElMat(density=density,frictionAngle=frictionAngle,tc=tc,en=en,et=es)) O.dt=.01*tc # time step Rs=0.1 # particle radius # Create geometry plnSurf = pack.sweptPolylines2gtsSurface([[Vector3(-.5,0,0),Vector3(.5,0,0),Vector3(.5, 0, -.5),Vector3(-.5, 0, -.5)]],capStart=True,capEnd=True) plnIds=O.bodies.append(pack.gtsSurface2Facets(plnSurf,material=facetMat,color=(0,1,0))) plnSurf1 = pack.sweptPolylines2gtsSurface([[Vector3(-.5,-.5,-.5),Vector3(.5,-.5,-.5),Vector3(.5, 1.5, -.5),Vector3(-.5, 1.5, -.5)]],capStart=True,capEnd=True) plnIds1=O.bodies.append(pack.gtsSurface2Facets(plnSurf1,material=facetMat,color=(0,1,0))) # Create clumps clpId,sphId=O.bodies.appendClumped([sphere(Vector3(0,Rs*2*i,Rs*2),Rs,material=dfltSpheresMat) for i in xrange(4)]) # Create engines O.engines=[ ForceResetter(), InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]), InteractionLoop( [Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom()], [Ip2_ViscElMat_ViscElMat_ViscElPhys()], [Law2_ScGeom_ViscElPhys_Basic()],