本文整理汇总了Python中yade.utils.sphere函数的典型用法代码示例。如果您正苦于以下问题:Python sphere函数的具体用法?Python sphere怎么用?Python sphere使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sphere函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testUserCreatedInteraction
def testUserCreatedInteraction(self):
O.engines=[
ForceResetter(),
InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb(),Bo1_Box_Aabb()],label="collider"),
InteractionLoop(
[Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom(),Ig2_Box_Sphere_ScGeom()],
[Ip2_FrictMat_FrictMat_FrictPhys()], #for linear model only
[Law2_ScGeom_FrictPhys_CundallStrack(label="law")], #for linear model only
label="interactionLoop"
),
GlobalStiffnessTimeStepper(timeStepUpdateInterval=10,label="timeStepper"),
NewtonIntegrator(label="newton")
]
O.bodies.append([utils.sphere((0,0,0),0.5),
utils.sphere((2,0,0),0.5), #(0,1) no overlap , no contacts
utils.sphere((0.9,0.9,0),0.5), #(0,2) overlapping bounds, no contacts
utils.sphere((-0.99,0,0),0.5)]) #(0,3) overlaping + contact
O.dt=0
O.dynDt=False
O.step()
i=utils.createInteraction(0,1)
self.assert_(i.iterBorn==1 and i.iterMadeReal==1)
j=utils.createInteraction(0,2)
self.assert_(j.iterBorn==1 and j.iterMadeReal==1)
self.assertRaises(RuntimeError,lambda: utils.createInteraction(0,3))
示例2: testErasedAndNewlyCreatedSphere
def testErasedAndNewlyCreatedSphere(self):
"Bodies: The bug is described in LP:1001194. If the new body was created after deletion of previous, it has no bounding box"
O.reset()
id1 = O.bodies.append(utils.sphere([0.0, 0.0, 0.0],0.5))
id2 = O.bodies.append(utils.sphere([0.0, 2.0, 0.0],0.5))
O.engines=[
ForceResetter(),
InsertionSortCollider([Bo1_Sphere_Aabb()]),
InteractionLoop(
[Ig2_Sphere_Sphere_L3Geom()],
[Ip2_FrictMat_FrictMat_FrictPhys()],
[Law2_L3Geom_FrictPhys_ElPerfPl()]
),
NewtonIntegrator(damping=0.1,gravity=(0,0,-9.81))
]
O.dt=.5e-4*utils.PWaveTimeStep()
#Before first step the bodies should not have bounds
self.assert_(O.bodies[id1].bound==None and O.bodies[id2].bound==None)
O.run(1, True)
#After first step the bodies should have bounds
self.assert_(O.bodies[id1].bound!=None and O.bodies[id2].bound!=None)
#Add 3rd body
id3 = O.bodies.append(utils.sphere([0.0, 4.0, 0.0],0.5))
O.run(1, True)
self.assert_(O.bodies[id1].bound!=None and O.bodies[id2].bound!=None and O.bodies[id3].bound!=None)
#Remove 3rd body
O.bodies.erase(id3)
O.run(1, True)
#Add 4th body
id4 = O.bodies.append(utils.sphere([0.0, 6.0, 0.0],0.5))
O.run(1, True)
self.assert_(O.bodies[id1].bound!=None and O.bodies[id2].bound!=None and O.bodies[id4].bound!=None)
示例3: SpherePack_toSimulation
def SpherePack_toSimulation(self,rot=Matrix3.Identity,**kw):
"""Append spheres directly to the simulation. In addition calling :yref:`O.bodies.append<BodyContainer.append>`,
this method also appropriately sets periodic cell information of the simulation.
>>> from yade import pack; from math import *
>>> sp=pack.SpherePack()
Create random periodic packing with 20 spheres:
>>> sp.makeCloud((0,0,0),(5,5,5),rMean=.5,rRelFuzz=.5,periodic=True,num=20)
20
Virgin simulation is aperiodic:
>>> O.reset()
>>> O.periodic
False
Add generated packing to the simulation, rotated by 45° along +z
>>> sp.toSimulation(rot=Quaternion((0,0,1),pi/4),color=(0,0,1))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
Periodic properties are transferred to the simulation correctly, including rotation (this could be avoided by explicitly passing "hSize=O.cell.hSize" as an argument):
>>> O.periodic
True
>>> O.cell.refSize
Vector3(5,5,5)
>>> O.cell.hSize
Matrix3(3.53553,-3.53553,0, 3.53553,3.53553,0, 0,0,5)
The current state (even if rotated) is taken as mechanically undeformed, i.e. with identity transformation:
>>> O.cell.trsf
Matrix3(1,0,0, 0,1,0, 0,0,1)
:param Quaternion/Matrix3 rot: rotation of the packing, which will be applied on spheres and will be used to set :yref:`Cell.trsf` as well.
:param \*\*kw: passed to :yref:`yade.utils.sphere`
:return: list of body ids added (like :yref:`O.bodies.append<BodyContainer.append>`)
"""
if isinstance(rot,Quaternion): rot=rot.toRotationMatrix()
assert(isinstance(rot,Matrix3))
if self.isPeriodic: O.periodic=True
if self.cellSize!=Vector3.Zero and self.isPeriodic:
O.cell.hSize=rot*Matrix3(self.cellSize[0],0,0, 0,self.cellSize[1],0, 0,0,self.cellSize[2])
O.cell.trsf=Matrix3.Identity
if not self.hasClumps():
return O.bodies.append([utils.sphere(rot*c,r,**kw) for c,r in self])
else:
standalone,clumps=self.getClumps()
ids=O.bodies.append([utils.sphere(rot*c,r,**kw) for c,r in self]) # append all spheres first
clumpIds=[]
userColor='color' in kw
for clump in clumps:
clumpIds.append(O.bodies.clump(clump)) # clump spheres with given ids together, creating the clump object as well
# make all spheres within one clump a single color, unless color was specified by the user
if not userColor:
for i in clump[1:]: O.bodies[i].shape.color=O.bodies[clump[0]].shape.color
return ids+clumpIds
示例4: setUp
def setUp(self):
O.reset()
r1,r2,p0,p1=1,.5,Vector3.Zero,Vector3(0,0,3)
self.idC,(self.id1,self.id2)=O.bodies.appendClumped([
utils.sphere(p0,r1),
utils.sphere(p1,r2)
])
示例5: setUp
def setUp(self):
# common setup for all tests in this class
O.reset()
O.materials.append([
FrictMat(young=1,label='materialZero'),
ElastMat(young=100,label='materialOne')
])
O.bodies.append([
utils.sphere([0,0,0],.5,material=0),
utils.sphere([1,1,1],.5,material=0),
utils.sphere([1,1,1],.5,material=1)
])
示例6: setUp
def setUp(self):
O.reset(); O.periodic=True;
O.cell.setBox(2.5,2.5,3)
self.cellDist=Vector3i(0,0,10) # how many cells away we go
self.relDist=Vector3(0,.999999999999999999,0) # rel position of the 2nd ball within the cell
self.initVel=Vector3(0,0,5)
O.bodies.append(utils.sphere((1,1,1),.5))
self.initPos=Vector3([O.bodies[0].state.pos[i]+self.relDist[i]+self.cellDist[i]*O.cell.refSize[i] for i in (0,1,2)])
O.bodies.append(utils.sphere(self.initPos,.5))
#print O.bodies[1].state.pos
O.bodies[1].state.vel=self.initVel
O.engines=[NewtonIntegrator(warnNoForceReset=False)]
O.cell.velGrad=Matrix3(0,0,0, 0,0,0, 0,0,-1)
O.dt=0 # do not change positions with dt=0 in NewtonIntegrator, but still update velocities from velGrad
示例7: gengeo
def gengeo(mntable,shift=Vector3.Zero,scale=1.0,**kw):
""" Imports geometry from LSMGenGeo library and creates spheres.
Since 2012 the package is available in Debian/Ubuntu and known as python-demgengeo
http://packages.qa.debian.org/p/python-demgengeo.html
:Parameters:
`mntable`: mntable
object, which creates by LSMGenGeo library, see example
`shift`: [float,float,float]
[X,Y,Z] parameter moves the specimen.
`scale`: float
factor scales the given data.
`**kw`: (unused keyword arguments)
is passed to :yref:`yade.utils.sphere`
LSMGenGeo library allows one to create pack of spheres
with given [Rmin:Rmax] with null stress inside the specimen.
Can be useful for Mining Rock simulation.
Example: :ysrc:`examples/packs/packs.py`, usage of LSMGenGeo library in :ysrc:`examples/test/genCylLSM.py`.
* https://answers.launchpad.net/esys-particle/+faq/877
* http://www.access.edu.au/lsmgengeo_python_doc/current/pythonapi/html/GenGeo-module.html
* https://svn.esscc.uq.edu.au/svn/esys3/lsm/contrib/LSMGenGeo/"""
try:
from GenGeo import MNTable3D,Sphere
except ImportError:
from gengeo import MNTable3D,Sphere
ret=[]
sphereList=mntable.getSphereListFromGroup(0)
for i in range(0, len(sphereList)):
r=sphereList[i].Radius()
c=sphereList[i].Centre()
ret.append(utils.sphere([shift[0]+scale*float(c.X()),shift[1]+scale*float(c.Y()),shift[2]+scale*float(c.Z())],scale*float(r),**kw))
return ret
示例8: filterSpherePack
def filterSpherePack(predicate, spherePack, returnSpherePack=None, **kw):
"""Using given SpherePack instance, return spheres the satisfy predicate.
The packing will be recentered to match the predicate and warning is given if the predicate
is larger than the packing."""
if returnSpherePack == None:
warnings.warn(
'The default behavior will change; specify returnSpherePack=True for the new behavior, and False to get rid of this warning (your code will break in the future, however). The returned SpherePack object can be added to the simulation using SpherePack.toSimulation()',
category=FutureWarning)
returnSpherePack = False
mn, mx = predicate.aabb()
dimP, centP = predicate.dim(), predicate.center()
dimS, centS = spherePack.dim(), spherePack.center()
if dimP[0] > dimS[0] or dimP[1] > dimS[1] or dimP[2] > dimS[2]:
warnings.warn(
"Packing's dimension (%s) doesn't fully contain dimension of the predicate (%s)."
% (dimS, dimP))
spherePack.translate(centP - centS)
if returnSpherePack:
ret = SpherePack()
for c, r in spherePack:
if predicate(c, r): ret.add(c, r)
return ret
else:
# return particles to be added to O.bodies
ret = []
for s in spherePack:
if predicate(s[0], s[1]):
ret += [utils.sphere(s[0], radius=s[1], **kw)]
return ret
示例9: regularHexa
def regularHexa(predicate, radius, gap, **kw):
"""Return set of spheres in regular hexagonal grid, clipped inside solid given by predicate.
Created spheres will have given radius and will be separated by gap space."""
ret = []
a = 2 * radius + gap
# thanks to Nasibeh Moradi for finding bug here:
# http://www.mail-archive.com/[email protected]/msg01424.html
hy, hz = a * sqrt(3) / 2., a * sqrt(6) / 3.
mn, mx = predicate.aabb()
dim = [mx[i] - mn[i] for i in 0, 1, 2]
if (max(dim) == float('inf')):
raise ValueError(
"Aabb of the predicate must not be infinite (didn't you use union | instead of intersection & for unbounded predicate such as notInNotch?"
)
ii, jj, kk = [
range(0,
int(dim[0] / a) + 1),
range(0,
int(dim[1] / hy) + 1),
range(0,
int(dim[2] / hz) + 1)
]
for i, j, k in itertools.product(ii, jj, kk):
x, y, z = mn[0] + radius + i * a, mn[1] + radius + j * hy, mn[
2] + radius + k * hz
if j % 2 == 0: x += a / 2. if k % 2 == 0 else -a / 2.
if k % 2 != 0:
x += a / 2.
y += hy / 2.
if predicate((x, y, z), radius):
ret += [utils.sphere((x, y, z), radius=radius, **kw)]
return ret
示例10: randomPeriPack
def randomPeriPack(radius,initSize,rRelFuzz=0.0,memoizeDb=None,noPrint=False):
"""Generate periodic dense packing.
A cell of initSize is stuffed with as many spheres as possible, then we run periodic compression with PeriIsoCompressor, just like with
randomDensePack.
:param radius: mean sphere radius
:param rRelFuzz: relative fuzz of sphere radius (equal distribution); see the same param for randomDensePack.
:param initSize: initial size of the periodic cell.
:return: SpherePack object, which also contains periodicity information.
"""
from math import pi
sp=_getMemoizedPacking(memoizeDb,radius,rRelFuzz,initSize[0],initSize[1],initSize[2],fullDim=Vector3(0,0,0),wantPeri=True,fillPeriodic=False,spheresInCell=-1,memoDbg=True,noPrint=noPrint)
if sp: return sp
O.switchScene(); O.resetThisScene()
sp=SpherePack()
O.periodic=True
#O.cell.refSize=initSize
O.cell.setBox(initSize)
sp.makeCloud(Vector3().Zero,O.cell.refSize,radius,rRelFuzz,-1,True)
O.engines=[ForceResetter(),InsertionSortCollider([Bo1_Sphere_Aabb()],nBins=2,verletDist=.05*radius),InteractionLoop([Ig2_Sphere_Sphere_ScGeom()],[Ip2_FrictMat_FrictMat_FrictPhys()],[Law2_ScGeom_FrictPhys_CundallStrack()]),PeriIsoCompressor(charLen=2*radius,stresses=[-100e9,-1e8],maxUnbalanced=1e-2,doneHook='O.pause();',globalUpdateInt=20,keepProportions=True),NewtonIntegrator(damping=.8)]
O.materials.append(FrictMat(young=30e9,frictionAngle=.1,poisson=.3,density=1e3))
for s in sp: O.bodies.append(utils.sphere(s[0],s[1]))
O.dt=utils.PWaveTimeStep()
O.timingEnabled=True
O.run(); O.wait()
ret=SpherePack()
ret.fromSimulation()
_memoizePacking(memoizeDb,ret,radius,rRelFuzz,wantPeri=True,fullDim=Vector3(0,0,0),noPrint=noPrint) # fullDim unused
O.switchScene()
return ret
示例11: testEraseBodiesInInteraction
def testEraseBodiesInInteraction(self):
O.reset()
id1 = O.bodies.append(utils.sphere([0.5,0.5,0.0+0.095],.1))
id2 = O.bodies.append(utils.sphere([0.5,0.5,0.0+0.250],.1))
O.engines=[
ForceResetter(),
InsertionSortCollider([Bo1_Sphere_Aabb()]),
InteractionLoop(
[Ig2_Sphere_Sphere_L3Geom()],
[Ip2_FrictMat_FrictMat_FrictPhys()],
[Law2_L3Geom_FrictPhys_ElPerfPl()]
),
NewtonIntegrator(damping=0.1,gravity=(0,0,-9.81))
]
O.dt=.5e-4*utils.PWaveTimeStep()
O.step()
O.bodies.erase(id1)
O.step()
示例12: textExt
def textExt(fileName,format='x_y_z_r',shift=Vector3.Zero,scale=1.0,attrs=[],**kw):
"""Load sphere coordinates from file in specific format, returns a list of corresponding bodies; that may be inserted to the simulation with O.bodies.append().
:param str filename: file name
:param str format: the name of output format. Supported `x_y_z_r`(default), `x_y_z_r_matId`, 'x_y_z_r_attrs'
:param [float,float,float] shift: [X,Y,Z] parameter moves the specimen.
:param float scale: factor scales the given data.
:param list attrs: attrs read from file if export.textExt(format='x_y_z_r_attrs') were used ('passed by refernece' style)
:param \*\*kw: (unused keyword arguments) is passed to :yref:`yade.utils.sphere`
:returns: list of spheres.
Lines starting with # are skipped
"""
infile = open(fileName,"r")
lines = infile.readlines()
infile.close()
ret=[]
for line in lines:
data = line.split()
if (data[0] == "#format"):
format=data[1]
continue
elif (data[0][0] == "#"): continue
if (format=='x_y_z_r'):
pos = Vector3(float(data[0]),float(data[1]),float(data[2]))
ret.append(utils.sphere(shift+scale*pos,scale*float(data[3]),**kw))
elif (format=='x_y_z_r_matId'):
pos = Vector3(float(data[0]),float(data[1]),float(data[2]))
ret.append(utils.sphere(shift+scale*pos,scale*float(data[3]),material=int(data[4]),**kw))
elif (format=='id_x_y_z_r_matId'):
pos = Vector3(float(data[1]),float(data[2]),float(data[3]))
ret.append(utils.sphere(shift+scale*pos,scale*float(data[4]),material=int(data[5]),**kw))
elif (format=='x_y_z_r_attrs'):
pos = Vector3(float(data[0]),float(data[1]),float(data[2]))
s = utils.sphere(shift+scale*pos,scale*float(data[3]),**kw)
ret.append(s)
attrs.append(data[4:])
else:
raise RuntimeError("Please, specify a correct format output!");
return ret
示例13: regularOrtho
def regularOrtho(predicate,radius,gap,**kw):
"""Return set of spheres in regular orthogonal grid, clipped inside solid given by predicate.
Created spheres will have given radius and will be separated by gap space."""
ret=[]
mn,mx=predicate.aabb()
if(max([mx[i]-mn[i] for i in 0,1,2])==float('inf')): raise ValueError("Aabb of the predicate must not be infinite (didn't you use union | instead of intersection & for unbounded predicate such as notInNotch?");
xx,yy,zz=[arange(mn[i]+radius,mx[i]-radius,2*radius+gap) for i in 0,1,2]
for xyz in itertools.product(xx,yy,zz):
if predicate(xyz,radius): ret+=[utils.sphere(xyz,radius=radius,**kw)]
return ret
示例14: textClumps
def textClumps(fileName,shift=Vector3.Zero,discretization=0,orientation=Quaternion((0,1,0),0.0),scale=1.0,**kw):
"""Load clumps-members from file, insert them to the simulation.
:param str filename: file name
:param str format: the name of output format. Supported `x_y_z_r`(default), `x_y_z_r_clumpId`
:param [float,float,float] shift: [X,Y,Z] parameter moves the specimen.
:param float scale: factor scales the given data.
:param \*\*kw: (unused keyword arguments) is passed to :yref:`yade.utils.sphere`
:returns: list of spheres.
Lines starting with # are skipped
"""
infile = open(fileName,"r")
lines = infile.readlines()
infile.close()
ret=[]
curClump=[]
newClumpId = -1
for line in lines:
data = line.split()
if (data[0][0] == "#"): continue
pos = orientation*Vector3(float(data[0]),float(data[1]),float(data[2]))
if (newClumpId<0 or newClumpId==int(data[4])):
idD = curClump.append(utils.sphere(shift+scale*pos,scale*float(data[3]),**kw))
newClumpId = int(data[4])
else:
newClumpId = int(data[4])
ret.append(O.bodies.appendClumped(curClump,discretization=discretization))
curClump=[]
idD = curClump.append(utils.sphere(shift+scale*pos,scale*float(data[3]),**kw))
if (len(curClump)<>0):
ret.append(O.bodies.appendClumped(curClump,discretization=discretization))
# Set the mask to a clump the same as the first member of it
for i in range(len(ret)):
O.bodies[ret[i][0]].mask = O.bodies[ret[i][1][0]].mask
return ret
示例15: textExt
def textExt(fileName,format='x_y_z_r',shift=Vector3.Zero,scale=1.0,**kw):
"""Load sphere coordinates from file in specific format, create spheres, insert them to the simulation.
:Parameters:
`filename`: string
`format`:
the name of output format. Supported `x_y_z_r`(default), `x_y_z_r_matId`
`shift`: [float,float,float]
[X,Y,Z] parameter moves the specimen.
`scale`: float
factor scales the given data.
`**kw`: (unused keyword arguments)
is passed to :yref:`yade.utils.sphere`
:Returns: list of spheres.
Lines starting with # are skipped
"""
infile = open(fileName,"r")
lines = infile.readlines()
infile.close()
ret=[]
for line in lines:
data = line.split()
if (data[0] == "#format"):
format=data[1]
continue
elif (data[0][0] == "#"): continue
if (format=='x_y_z_r'):
pos = Vector3(float(data[0]),float(data[1]),float(data[2]))
ret.append(utils.sphere(shift+scale*pos,scale*float(data[3]),**kw))
elif (format=='x_y_z_r_matId'):
pos = Vector3(float(data[0]),float(data[1]),float(data[2]))
ret.append(utils.sphere(shift+scale*pos,scale*float(data[3]),material=int(data[4]),**kw))
elif (format=='id_x_y_z_r_matId'):
pos = Vector3(float(data[1]),float(data[2]),float(data[3]))
ret.append(utils.sphere(shift+scale*pos,scale*float(data[4]),material=int(data[5]),**kw))
else:
raise RuntimeError("Please, specify a correct format output!");
return ret