Commit b6645673 authored by Jan Stransky's avatar Jan Stransky
Browse files

Added examples for Ig2_Sphere_Polyhedra_ScGeom, added ymport.ele function

parent 79c8f2fb
def clumpPolyhedra(polyhedra):
clumpId,junk = O.bodies.appendClumped(polyhedra)
return
clump = O.bodies[clumpId]
clump.state.pos = sum((t.state.pos*t.state.mass for t in polyhedra),Vector3.Zero)/sum(t.state.mass for t in polyhedra)
print clump.state.pos
clump.state.mass = sum(t.state.mass for t in polyhedra)
clump.state.inertia = sum((t.state.inertia for t in polyhedra),Vector3.Zero)
m = PolyhedraMat()
m.density = 2600 #kg/m^3
m.Ks = 20000
m.Kn = 1E6 #Pa
m.frictionAngle = 0.6 #rad
O.materials.append(m)
t1 = polyhedron(((0,0,0),(0,0,1),(0,1,0),(0,1,1),(1,0,0),(1,0,1),(1,1,0),(1,1,1)))
t2 = polyhedron(((0,0,1),(0,0,2),(0,1,1),(0,1,2),(2,0,1),(2,0,2),(2,1,1),(2,1,2)))
t1.state.mass = 1e-12
t1.state.inertia = (1e-12,1e-12,1e-12)
t1.state.pos = (0,.5,0)
t2.state.ori = ((1,2,3),1)
t2.state.pos = (sqrt(2),.5,-sqrt(2))
clumpPolyhedra((t1,t2))
O.engines=[
ForceResetter(),
InsertionSortCollider([Bo1_Polyhedra_Aabb(),Bo1_Wall_Aabb(),Bo1_Facet_Aabb()]),
InteractionLoop(
[Ig2_Polyhedra_Polyhedra_PolyhedraGeom()],
[Ip2_PolyhedraMat_PolyhedraMat_PolyhedraPhys()],
[Law2_PolyhedraGeom_PolyhedraPhys_Volumetric()]
),
NewtonIntegrator()
]
O.dt=0.00025
#O.step()
try:
from yade import qt
qt.View()
except:
pass
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# modified script yade/examples/gts-horse/horse.py
from yade import pack,ymport
import gts
surf=gts.read(open('horse.coarse.gts'))
pred=pack.inGtsSurface(surf)
aabb=pred.aabb()
dim0=aabb[1][0]-aabb[0][0]; radius=dim0/40.
O.bodies.append(pack.regularHexa(pred,radius=radius,gap=radius/4.))
tetras = ymport.ele('horse.node','horse.ele',shift=(0,0,-1*(aabb[1][2]-aabb[0][2])),wire=False,color=(0,1,1),fixed=True)
O.bodies.append(tetras)
O.engines=[
ForceResetter(),
InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Polyhedra_Aabb()]),
InteractionLoop(
[Ig2_Sphere_Sphere_ScGeom(),Ig2_Sphere_Polyhedra_ScGeom(edgeCoeff=.1,vertexCoeff=.05)],
[Ip2_FrictMat_FrictMat_FrictPhys()],
[Law2_ScGeom_FrictPhys_CundallStrack()],
),
NewtonIntegrator(damping=.1,gravity=(0,0,-5000)),
PyRunner(iterPeriod=10,command='addPlotData()')
]
O.dt=.4*PWaveTimeStep()
O.saveTmp()
O.timingEnabled=True
O.trackEnergy=True
from yade import plot
plot.plots={'i':('total',O.energy.keys,)}
def addPlotData(): plot.addData(i=O.iter,total=O.energy.total(),**O.energy)
plot.plot(subPlots=False)
from yade import qt
qt.View()
from yade import polyhedra_utils
import random
polyMat = PolyhedraMat(young=1e10,poisson=.05)
frictMat = FrictMat(young=1e9,poisson=.2)
O.materials.append((polyMat,frictMat))
poly = polyhedra_utils.polyhedra(polyMat,(1,2,3)); poly.wire=False
sph1 = sphere((2,2,2),.5,material=frictMat)
sph2 = sphere((-2,0,0),.5,material=frictMat)
sph3 = sphere((0,-2,0),.5,material=frictMat)
O.bodies.append((
poly,
sph1,
sph2,
sph3
))
O.engines=[
ForceResetter(),
InsertionSortCollider([Bo1_Polyhedra_Aabb(),Bo1_Sphere_Aabb()]),
InteractionLoop(
[Ig2_Sphere_Polyhedra_ScGeom()],
[Ip2_FrictMat_PolyhedraMat_FrictPhys()],
[Law2_ScGeom_FrictPhys_CundallStrack()],
),
NewtonIntegrator(),
]
O.dt = 1e-7
O.step()
poly.state.blockedDOFs = 'xyzXYZ'
for s in (sph1,sph2,sph3):
r=random.random
s.state.vel = -10*(s.state.pos+Vector3(r(),r(),r()))
from yade import qt
qt.View()
......@@ -396,3 +396,48 @@ def iges(fileName,shift=(0,0,0),scale=1.0,returnConnectivityTable=False,**kw):
if returnConnectivityTable:
return facets, nodes, elems
return facets
def ele(nodeFileName,eleFileName,shift=(0,0,0),scale=1.0,**kw):
""" Import tetrahedral mesh from .ele file, return list of created tetrahedrons.
:param string nodeFileName: name of .node file
:param string eleFileName: name of .ele file
:param (float,float,float)|Vector3 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.polyhedron`
"""
f = open(nodeFileName)
line = f.readline()
while line.startswith('#'):
line = f.readline()
ls = line.split()
nVertices = int(ls[0])
if int(ls[1])!=3:
raise RuntimeError, "wrong .node file, number of dimensions should be 3"
vertices = [None for i in xrange(nVertices)]
shift = Vector3(shift)
for i in xrange(nVertices):
line = f.readline()
while line.startswith('#'):
line = f.readline()
ls = line.split()
if not ls:
continue
v = shift + scale*Vector3(tuple(float(ls[j]) for j in (1,2,3)))
vertices[int(ls[0])-1] = v
f.close()
#
f = open(eleFileName)
line = f.readline()
while line.startswith('#'):
line = f.readline()
ls = line.split()
if int(ls[1])!=4:
raise RuntimeError, "wrong .ele file, unsupported tetrahedra's number of nodes"
nTetras = int(ls[0])
tetras = [None for i in xrange(nTetras)]
for i in xrange(nTetras):
ls = f.readline().split()
tetras[int(ls[0])-1] = utils.polyhedron([vertices[int(ls[j])-1] for j in (1,2,3,4)],**kw)
f.close()
return tetras
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment