import gts 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)
frictionAngle = radians(35) density = 2300 params = utils.getViscoelasticFromSpheresInteraction(tc, en, es) defMat = O.materials.append( ViscElMat(density=density, frictionAngle=frictionAngle, **params)) # **params sets kn, cn, ks, cs O.dt = .1 * tc # time step rad = 0.5 # particle radius tolerance = 0.0001 SpheresID = [] SpheresID += O.bodies.append( pack.regularHexa(pack.inSphere((Vector3(0.0, 0.0, 0.0)), rad), radius=rad / rR, gap=rad / rR * 0.5, material=defMat)) geometryParameters = bodiesHandling.spheresPackDimensions(SpheresID) print(len(SpheresID)) floorId = [] floorId += O.bodies.append( geom.facetBox(geometryParameters['center'], geometryParameters['extends'] / 2.0 * 1.05, material=defMat)) #Floor #Calculate the mass of spheres sphMass = utils.getSpheresVolume() * density # Create engines
""" rad,gap=.15,.02 #Add material O.materials.append(FrictMat(young=10e9,poisson=.25,frictionAngle=0.5,density=1e3)) #Parameters, which will be passed into spheres and facets creators kw={'material':0} kwBoxes={'color':[1,0,0],'wire':False,'dynamic':False,'material':0} kwMeshes={'color':[1,1,0],'wire':True,'dynamic':False,'material':0} O.bodies.append( pack.regularHexa( (pack.inSphere((0,0,4),2)-pack.inSphere((0,-2,5),2)) & pack.notInNotch(centerPoint=(0,0,4),edge=(0,1,0),normal=(-1,1,-1),aperture=.2) ,radius=rad,gap=gap,color=(0,1,0),material=0) # head +[utils.sphere((.8,1.9,5),radius=.2,color=(.6,.6,.6),material=0),utils.sphere((-.8,1.9,5),radius=.2,color=(.6,.6,.6),material=0),utils.sphere((0,2.4,4),radius=.4,color=(1,0,0),material=0)] # eyes and nose +pack.regularHexa(pack.inCylinder((-1,2.2,3.3),(1,2.2,3.3),2*rad),radius=rad,gap=gap/3,color=(0.929,0.412,0.412),material=0) #mouth ) groundId=O.bodies.append(utils.facet([(12,0,-6),(0,12,-6,),(-12,-12,-6)],dynamic=False)) # ground for part in [ pack.regularHexa ( pack.inAlignedBox((-2,-2,-2),(2,2,2))-pack.inCylinder((0,-2,0),(0,2,0),1), radius=1.5*rad,gap=2*gap,color=(1,0,1),**kw), # body, pack.regularOrtho(pack.inEllipsoid((-1,0,-4),(1,1,2)),radius=rad,gap=0,color=(0,1,1),**kw), # left leg pack.regularHexa (pack.inCylinder((+1,1,-2.5),(0,3,-5),1),radius=rad,gap=gap,color=(0,1,1),**kw), # right leg pack.regularHexa (pack.inHyperboloid((+2,0,1),(+6,0,0),1,.5),radius=rad,gap=gap,color=(0,0,1),**kw), # right hand pack.regularOrtho(pack.inCylinder((-2,0,2),(-5,0,4),1),radius=rad,gap=gap,color=(0,0,1),**kw) # left hand ]: O.bodies.appendClumped(part)
tc=0.001 en=.003 es=.003 frictionAngle=radians(35) density=2300 params=utils.getViscoelasticFromSpheresInteraction(tc,en,es) defMat=O.materials.append(ViscElMat(density=density,frictionAngle=frictionAngle,**params)) # **params sets kn, cn, ks, cs O.dt=.1*tc # time step rad=0.5 # particle radius tolerance = 0.0001 SpheresID=[] SpheresID+=O.bodies.append(pack.regularHexa(pack.inSphere((Vector3(0.0,0.0,0.0)),rad),radius=rad/rR,gap=rad/rR*0.5,material=defMat)) geometryParameters = bodiesHandling.spheresPackDimensions(SpheresID) print(len(SpheresID)) floorId=[] floorId+=O.bodies.append(geom.facetBox(geometryParameters['center'],geometryParameters['extends']/2.0*1.05,material=defMat)) #Floor #Calculate the mass of spheres sphMass = utils.getSpheresVolume()*density # Create engines O.engines=[ ForceResetter(), InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]), InteractionLoop(
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 for xyz in itertools.product(arange(0,numBoxes[0]),arange(0,numBoxes[1]),arange(0,numBoxes[2])): ids_spheres=O.bodies.appendClumped(pack.regularHexa(pack.inEllipsoid((xyz[0]*(sizeBox+gapBetweenBoxes),xyz[1]*(sizeBox+gapBetweenBoxes)+sizeBox*0.5,xyz[2]*(sizeBox+gapBetweenBoxes)-radiusKnife+sizeBox*0.6),(sizeBox/2,sizeBox/2,sizeBox/2)),radius=radiusSph,gap=0,color=colorSph,material=sphereMat)) if (colorSph==colorsph1): colorSph=colorsph2 else: colorSph=colorsph1 O.dt=.2*tc 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()], ),
wire=False)) ### Creating the material for buldozer colorsph1 = Vector3(120, 234, 150) colorsph2 = Vector3(1, 1, 0) colorsph1.normalize() colorsph2.normalize() colorSph = colorsph1 for xyz in itertools.product(arange(0, numBoxes[0]), arange(0, numBoxes[1]), arange(0, numBoxes[2])): ids_spheres = O.bodies.appendClumped( pack.regularHexa(pack.inEllipsoid( (xyz[0] * (sizeBox + gapBetweenBoxes), xyz[1] * (sizeBox + gapBetweenBoxes) + sizeBox * 0.5, xyz[2] * (sizeBox + gapBetweenBoxes) - radiusKnife + sizeBox * 0.6), (sizeBox / 2, sizeBox / 2, sizeBox / 2)), radius=radiusSph, gap=0, color=colorSph)) if (colorSph == colorsph1): colorSph = colorsph2 else: colorSph = colorsph1 from woo import qt O.dt = 2 * utils.PWaveTimeStep() # We do not need now a high accuracy O.engines = [ ForceResetter(), InsertionSortCollider([ Bo1_Sphere_Aabb(),
tc=0.001 en=.003 es=.003 frictionAngle=radians(35) density=2300 params=utils.getViscoelasticFromSpheresInteraction(tc,en,es) defMat=O.materials.append(ViscElMat(density=density,frictionAngle=frictionAngle,**params)) # **params sets kn, cn, ks, cs O.dt=.1*tc # time step rad=0.5 # particle radius tolerance = 0.0001 SpheresID=[] SpheresID+=O.bodies.append(pack.regularHexa(pack.inSphere((Vector3(0.0,0.0,0.0)),rad),radius=rad/rR,gap=rad/rR*0.5,material=defMat)) geometryParameters = bodiesHandling.spheresPackDimensions(SpheresID) print len(SpheresID) floorId=[] floorId+=O.bodies.append(geom.facetBox(geometryParameters['center'],geometryParameters['extends']/2.0*1.05,material=defMat)) #Floor #Calculate the mass of spheres sphMass = utils.getSpheresVolume()*density # Create engines O.engines=[ ForceResetter(), InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]), InteractionLoop(
from woo import log, utils, pack, timing #log.setLevel('FlatGridCollider',log.TRACE) #O.bodies.append([ utils.sphere((0.2,0,0),.5,dynamic=False), utils.sphere((0.2,0.0,1.01),.5), ]) O.bodies.append( pack.regularHexa(pack.inAlignedBox((0, 0, 0), (10, 10, 1)), radius=.5, gap=0, dynamic=False)) O.bodies.append( pack.regularOrtho(pack.inAlignedBox((3, 3, 3), (7, 7, 4)), radius=.05, gap=0)) O.engines = [ ForceResetter(), FlatGridCollider(step=.2, aabbMin=(0, 0, 0), aabbMax=(10, 10, 5), verletDist=0.005), # InsertionSortCollider([Bo1_Sphere_Aabb()],sweepLength=0.005), InteractionLoop( [Ig2_Sphere_Sphere_Dem3DofGeom()], [Ip2_FrictMat_FrictMat_FrictPhys()], [Law2_Dem3DofGeom_FrictPhys_CundallStrack()], ), GravityEngine(gravity=[0, 0, -10]), NewtonIntegrator(damping=0.4), ] O.dt = .6 * utils.PWaveTimeStep() O.saveTmp() #O.step() #while True:
Note that GTS only moves references to surfaces around, therefore e.g. translating surface that is part of the union will move also the part of the united surface. Therefore, we use the copy() method for deep copy here. """ from __future__ import print_function from woo import pack, qt import gts 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, 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.0, color=(1, 0, 0))) t2 = time() print("Using surface union: %gs" % (t2 - t1))
from woo import pack,plot # the "if 0:" block will be never executed, therefore the "else:" block will be # to use cloud instead of regular packing, change to "if 1:" or something similar if 0: # create cloud of spheres and insert them into the simulation # we give corners, mean radius, radius variation sp=pack.SpherePack() sp.makeCloud((0,0,0),(2,2,2),rMean=.1,rRelFuzz=.6,periodic=True) # insert the packing into the simulation sp.toSimulation(color=(0,0,1)) # pure blue else: # in this case, add dense packing O.bodies.append( pack.regularHexa(pack.inAlignedBox((0,0,0),(2,2,2)),radius=.1,gap=0,color=(0,0,1)) ) # create "dense" packing by setting friction to zero initially O.materials[0].frictionAngle=0 # simulation loop (will be run at every step) O.engines=[ ForceResetter(), InsertionSortCollider([Bo1_Sphere_Aabb()]), InteractionLoop( [Ig2_Sphere_Sphere_L3Geom()], [Ip2_FrictMat_FrictMat_FrictPhys()], [Law2_L3Geom_FrictPhys_ElPerfPl()] ), NewtonIntegrator(damping=.4),
from woo import log,utils,pack,timing #log.setLevel('FlatGridCollider',log.TRACE) #O.bodies.append([ utils.sphere((0.2,0,0),.5,dynamic=False), utils.sphere((0.2,0.0,1.01),.5), ]) O.bodies.append(pack.regularHexa(pack.inAlignedBox((0,0,0),(10,10,1)),radius=.5,gap=0,dynamic=False)) O.bodies.append(pack.regularOrtho(pack.inAlignedBox((3,3,3),(7,7,4)),radius=.05,gap=0)) O.engines=[ ForceResetter(), FlatGridCollider(step=.2,aabbMin=(0,0,0),aabbMax=(10,10,5),verletDist=0.005), # InsertionSortCollider([Bo1_Sphere_Aabb()],sweepLength=0.005), InteractionLoop( [Ig2_Sphere_Sphere_Dem3DofGeom()], [Ip2_FrictMat_FrictMat_FrictPhys()], [Law2_Dem3DofGeom_FrictPhys_CundallStrack()], ), GravityEngine(gravity=[0,0,-10]), NewtonIntegrator(damping=0.4), ] O.dt=.6*utils.PWaveTimeStep() O.saveTmp() #O.step() #while True: # O.step() # if len(O.interactions)>0 or O.bodies[1].state.pos[2]<.97: break O.timingEnabled=True O.run(5000,True) timing.stats() import sys #sys.exit(0)
### Creating the material for buldozer colorsph1 = Vector3(120, 234, 150) colorsph2 = Vector3(1, 1, 0) colorsph1.normalize() colorsph2.normalize() colorSph = colorsph1 for xyz in itertools.product(arange(0, numBoxes[0]), arange(0, numBoxes[1]), arange(0, numBoxes[2])): ids_spheres = O.bodies.appendClumped( pack.regularHexa( pack.inEllipsoid( ( xyz[0] * (sizeBox + gapBetweenBoxes), xyz[1] * (sizeBox + gapBetweenBoxes) + sizeBox * 0.5, xyz[2] * (sizeBox + gapBetweenBoxes) - radiusKnife + sizeBox * 0.6, ), (sizeBox / 2, sizeBox / 2, sizeBox / 2), ), radius=radiusSph, gap=0, color=colorSph, ) ) if colorSph == colorsph1: colorSph = colorsph2 else: colorSph = colorsph1 from woo import qt