def unitCylinder(nDiv=24): """Returns GTS surface approximating cylinder (without caps), with 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])
def unitCylinder(nDiv=24): """Returns GTS surface approximating cylinder (without caps), with 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])
def Plane(v1, v2, v3, v4): pts = [[Vector3(v1), Vector3(v2), Vector3(v3), Vector3(v4)]] return pack.sweptPolylines2gtsSurface(pts, capStart=True, capEnd=True)
# default spheres material 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...
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(
#!/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,
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 + .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)
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([
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(
tc=0.001# collision time 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()],
en=.3 # normal restitution coefficient 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)
Running this script can take very long! """ 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 )
buldozerHeight=1.2 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,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
bumpRad=millRad-bumpHt 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])
radiusKnife = 1 lengthKnife = 2 buldozerHeight = 1.2 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,
def Plane(v1,v2,v3,v4): pts = [ [Vector3(v1),Vector3(v2),Vector3(v3),Vector3(v4)] ] return pack.sweptPolylines2gtsSurface(pts,capStart=True,capEnd=True)
#!/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()