/usr/lib/python2.7/dist-packages/yade/gridpfacet.py is in python-yade 2017.01a-8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | # encoding: utf-8
#
# 2015 © Bruno Chareyre <bruno.chareyre@hmg.inpg.fr>
# 2015 © Anna Effeindzourou <anna.effeindzourou@gmail.com>
# 2015 © François Kneib <francois.kneib@gmail.com>
# 2015 © Klaus Thoeni <klaus.thoeni@gmail.com>
"""
Helper functions for creating cylinders, grids and membranes. For more details on this type of elements see [Effeindzourou2016]_, [Effeindzourou2015a]_, [Bourrier2013]_,.
For examples using :yref:`GridConnections<GridConnection>`, see
* :ysrc:`examples/grids/CohesiveGridConnectionSphere.py`
* :ysrc:`examples/grids/GridConnection_Spring.py`
* :ysrc:`examples/grids/Simple_Grid_Falling.py`
* :ysrc:`examples/grids/Simple_GridConnection_Falling.py`
For examples using :yref:`PFacets<PFacet>`, see
* :ysrc:`examples/pfacet/gts-pfacet.py`
* :ysrc:`examples/pfacet/mesh-pfacet.py`
* :ysrc:`examples/pfacet/pfacetcreators.py`
"""
import math,random,doctest,geom,numpy
from yade.wrapper import *
try: # use psyco if available
import psyco
psyco.full()
except ImportError: pass
from yade import utils
from yade._utils import createInteraction
from minieigen import *
def chainedCylinder(begin=Vector3(0,0,0),end=Vector3(1.,0.,0.),radius=0.2,dynamic=None,fixed=False,wire=False,color=None,highlight=False,material=-1,mask=1):
"""
Create and connect a chainedCylinder with given parameters. The shape generated by repeted calls of this function is the Minkowski sum of polyline and sphere.
:param Real radius: radius of sphere in the Minkowski sum.
:param Vector3 begin: first point positioning the line in the Minkowski sum
:param Vector3 last: last point positioning the line in the Minkowski sum
In order to build a correct chain, last point of element of rank N must correspond to first point of element of rank N+1 in the same chain (with some tolerance, since bounding boxes will be used to create connections.
:return: Body object with the :yref:`ChainedCylinder` :yref:`shape<Body.shape>`.
.. note:: :yref:`ChainedCylinder` is deprecated and will be removed in the future, use :yref:`GridConnection` instead. See :yref:`yade.gridpfacet.cylinder` and :yref:`yade.gridpfacet.cylinderConnection`.
"""
import warnings
warnings.warn('\033[1;31mchainedCylinder is deprecated and will be removed in the future, use GridConnection instead.\033[1;0m',category=UserWarning)
segment=end-begin
b=Body()
b.shape=ChainedCylinder(radius=radius,length=segment.norm(),color=color if color else utils.randomColor(),wire=wire,highlight=highlight)
b.shape.segment=segment
V=2*(4./3)*math.pi*radius**3
geomInert=(2./5.)*V*radius**2+b.shape.length*b.shape.length*2*(4./3)*math.pi*radius**3
b.state=ChainedState()
b.state.addToChain(O.bodies.append(b))
utils._commonBodySetup(b,V,Vector3(geomInert,geomInert,geomInert),material,pos=begin,resetState=False,dynamic=dynamic,fixed=fixed)
b.mask=mask
b.bound=Aabb(color=[0,1,0])
b.state.ori.setFromTwoVectors(Vector3(0.,0.,1.),segment)
if (end == begin): b.state.ori = Quaternion((1,0,0),0)
return b
def gridNode(center,radius,dynamic=None,fixed=False,wire=False,color=None,highlight=False,material=-1):
"""
Create a :yref:`GridNode` which is needed to set up :yref:`GridConnections<GridConnection>`.
See documentation of :yref:`yade.utils.sphere` for meaning of parameters.
:return: Body object with the :yref:`gridNode` :yref:`shape<Body.shape>`.
"""
b=Body()
b.shape=GridNode(radius=radius,color=color if color else utils.randomColor(),wire=wire,highlight=highlight)
#V=(4./3)*math.pi*radius**3 # will be overwritten by the connection
V=0.
geomInert=(2./5.)*V*radius**2 # will be overwritten by the connection
utils._commonBodySetup(b,V,Vector3(geomInert,geomInert,geomInert),material,pos=center,dynamic=dynamic,fixed=fixed)
b.aspherical=False
b.bounded=False
b.mask=0 # avoid contact detection with the nodes. Manual interaction will be set for them in "gridConnection" below.
return b
def gridConnection(id1,id2,radius,wire=False,color=None,highlight=False,material=-1,mask=1,cellDist=None):
"""
Create a :yref:`GridConnection` by connecting two :yref:`GridNodes<GridNode>`.
:param id1,id2: the two :yref:`GridNodes<GridNode>` forming the cylinder.
:param float radius: radius of the cylinder. Note that the radius needs to be the same as the one for the :yref:`GridNodes<GridNode>`.
:param Vector3 cellDist: for periodic boundary conditions, see :yref:`Interaction.cellDist`. Note: periodic boundary conditions for gridConnections are not yet implemented!
See documentation of :yref:`yade.utils.sphere` for meaning of other parameters.
:return: Body object with the :yref:`GridConnection` :yref:`shape<Body.shape>`.
.. note:: The material of the :yref:`GridNodes<GridNode>` will be used to set the constitutive behaviour of the internal connection, i.e., the constitutive behaviour of the cylinder. The material of the :yref:`GridConnection` is used for interactions with other (external) bodies.
"""
b=Body()
b.shape=GridConnection(radius=radius,color=color if color else utils.randomColor(),wire=wire,highlight=highlight)
sph1=O.bodies[id1] ; sph2=O.bodies[id2]
i=createInteraction(id1,id2)
nodeMat=sph1.material
b.shape.node1=sph1 ; b.shape.node2=sph2
sph1.shape.addConnection(b) ; sph2.shape.addConnection(b)
if(O.periodic):
if(cellDist!=None):
i.cellDist=cellDist
segt=sph2.state.pos + O.cell.hSize*i.cellDist - sph1.state.pos
else: segt=sph2.state.pos - sph1.state.pos
L=segt.norm()
V=0.5*L*math.pi*radius**2
geomInert=(2./5.)*V*radius**2
utils._commonBodySetup(b,V,Vector3(geomInert,geomInert,geomInert),material,pos=sph1.state.pos,dynamic=False,fixed=True)
sph1.state.mass = sph1.state.mass + V*nodeMat.density
sph2.state.mass = sph2.state.mass + V*nodeMat.density
for k in [0,1,2]:
sph1.state.inertia[k] = sph1.state.inertia[k] + geomInert*nodeMat.density
sph2.state.inertia[k] = sph2.state.inertia[k] + geomInert*nodeMat.density
b.aspherical=False
if O.periodic:
i.phys.unp= -(sph2.state.pos + O.cell.hSize*i.cellDist - sph1.state.pos).norm() + sph1.shape.radius + sph2.shape.radius
b.shape.periodic=True
b.shape.cellDist=i.cellDist
else:
i.phys.unp= -(sph2.state.pos - sph1.state.pos).norm() + sph1.shape.radius + sph2.shape.radius
i.geom.connectionBody=b
I=math.pi*(2.*radius)**4/64.
E=nodeMat.young
i.phys.kn=E*math.pi*(radius**2)/L
i.phys.kr=E*I/L
i.phys.ks=12.*E*I/(L**3)
G=E/(2.*(1+nodeMat.poisson))
i.phys.ktw=2.*I*G/L
b.mask=mask
return b
#TODO: find a better way of handling the Id lists for checking duplicated gridNodes or gridConnections with the same coordinates etc. It would be better to handle this globally, maybe implement something like O.bodies.getGridNodes
def cylinder(begin=Vector3(0,0,0),end=Vector3(1.,0.,0.),radius=0.2,nodesIds=[],cylIds=[],dynamic=None,fixed=False,wire=False,color=None,highlight=False,intMaterial=-1,extMaterial=-1,mask=1):
"""
Create a cylinder with given parameters. The shape corresponds to the Minkowski sum of line-segment and sphere, hence, the cylinder has rounded vertices. The cylinder (:yref:`GridConnection<GridConnection>`) and its corresponding nodes (yref:`GridNodes<GridNode>`) are automatically added to the simulation. The lists with nodes and cylinder ids will be updated automatically.
:param Vector3 begin: first point of the Minkowski sum in the global coordinate system.
:param Vector3 end: last point of the Minkowski sum in the global coordinate system.
:param Real radius: radius of sphere in the Minkowski sum.
:param list nodesIds: list with ids of already existing :yref:`GridNodes<GridNode>`. New ids will be added.
:param list cylIds: list with ids of already existing :yref:`GridConnections<GridConnection>`. New id will be added.
:param intMaterial: :yref:`Body.material` used to create the interaction physics between the two GridNodes
:param extMaterial: :yref:`Body.material` used to create the interaction physics between the Cylinder (GridConnection) and other bodies (e.g., spheres interaction with the cylinder)
See :yref:`yade.utils.sphere`'s documentation for meaning of other parameters.
"""
id1 = O.bodies.append( gridNode(begin,radius,dynamic=dynamic,fixed=fixed,wire=wire,color=color,highlight=highlight,material=intMaterial) )
nodesIds.append(id1)
id2 = O.bodies.append( gridNode(end,radius,dynamic=dynamic,fixed=fixed,wire=wire,color=color,highlight=highlight,material=intMaterial) )
nodesIds.append(id2)
cylIds.append(O.bodies.append( gridConnection(id1,id2,radius=radius,wire=wire,color=color,highlight=highlight,material=extMaterial,mask=mask,cellDist=None) ))
def cylinderConnection(vertices,radius=0.2,nodesIds=[],cylIds=[],dynamic=None,fixed=False,wire=False,color=None,highlight=False,intMaterial=-1,extMaterial=-1,mask=1):
"""
Create a chain of cylinders with given parameters. The cylinders (:yref:`GridConnection<GridConnection>`) and its corresponding nodes (yref:`GridNodes<GridNode>`) are automatically added to the simulation. The lists with nodes and cylinder ids will be updated automatically.
:param [[Vector3]] vertices: coordinates of vertices to connect in the global coordinate system.
See :yref:`yade.gridpfacet.cylinder` documentation for meaning of other parameters.
"""
# create all gridNodes first
nodesIdsCC=[]
for i in vertices:
nodesIdsCC.append( O.bodies.append(gridNode(i,radius=radius,
dynamic=dynamic,fixed=fixed,wire=wire,color=color,highlight=highlight,material=intMaterial)) )
nodesIds.extend(nodesIdsCC)
# now create connection between the gridNodes
for i,j in zip( nodesIdsCC[:-1], nodesIdsCC[1:]):
cylIds.append( O.bodies.append( gridConnection(i,j,radius=radius,
wire=wire,color=color,highlight=highlight,material=intMaterial,mask=mask,cellDist=None)) )
def pfacet(id1,id2,id3,wire=True,color=None,highlight=False,material=-1,mask=1,cellDist=None):
"""
Create a :yref:`PFacet<PFacet>` element from 3 :yref:`GridNodes<GridNode>` which are already connected via 3 :yref:`GridConnections<GridConnection>`:
:param id1,id2,id3: already with :yref:`GridConnections<GridConnection>` connected :yref:`GridNodes<GridNode>`
:param bool wire: if ``True``, top and bottom facet are shown as skeleton; otherwise facets are filled.
:param Vector3-or-None color: color of the PFacet; random color will be assigned if ``None``.
:param Vector3 cellDist: for periodic boundary conditions, see :yref:`Interaction.cellDist`. Note: periodic boundary conditions are not yet implemented for PFacets!
See documentation of :yref:`yade.utils.sphere` for meaning of other parameters.
:return: Body object with the :yref:`PFacet<PFacet>` :yref:`shape<Body.shape>`.
.. note:: :yref:`GridNodes<GridNode>` and :yref:`GridConnections<GridConnection>` need to have the same radius. This is also the radius used to create the :yref:`PFacet<PFacet>`
"""
b=Body()
GridN1=O.bodies[id1]; GridN2=O.bodies[id2]; GridN3=O.bodies[id3]
b.shape=PFacet(color=color if color else randomColor(),wire=wire,highlight=highlight,node1=GridN1,node2=GridN2,node3=GridN3)
GridN1.bounded=False; GridN2.bounded=False; GridN3.bounded=False
GridC1=O.bodies[O.interactions[id1,id2].geom.connectionBody.id]
GridC2=O.bodies[O.interactions[id2,id3].geom.connectionBody.id]
GridC3=O.bodies[O.interactions[id1,id3].geom.connectionBody.id]
GridC1.bounded=False
GridC2.bounded=False
GridC3.bounded=False
b.shape.conn1=GridC1
b.shape.conn2=GridC2
b.shape.conn3=GridC3
b.shape.radius=GridN1.shape.radius
GridC1.shape.addPFacet(b)
GridC2.shape.addPFacet(b)
GridC3.shape.addPFacet(b)
GridN1.shape.addPFacet(b); GridN2.shape.addPFacet(b); GridN3.shape.addPFacet(b)
V=0
utils._commonBodySetup(b,V,Vector3(0,0,0),material,pos=GridN1.state.pos,dynamic=False,fixed=True)
b.aspherical=False # mass and inertia are lumped into the GridNodes
b.mask=mask
return b
#TODO: find a better way of handling the Id lists for checking duplicated gridNodes or gridConnections with the same coordinates etc. It would be better to handle this globally, maybe implement something like O.bodies.getGridNodes
def pfacetCreator1(vertices,radius,nodesIds=[],cylIds=[],pfIds=[],wire=False,fixed=True,materialNodes=-1,material=-1,color=None):
"""
Create a :yref:`PFacet<PFacet>` element from 3 vertices and automatically append to simulation. The function uses the vertices to create :yref:`GridNodes<GridNode>` and automatically checks for existing nodes.
:param [Vector3,Vector3,Vector3] vertices: coordinates of vertices in the global coordinate system.
:param float radius: radius used to create the :yref:`PFacets<PFacet>`.
:param list nodesIds: list with ids of already existing :yref:`GridNodes<GridNode>`. New ids will be added.
:param list cylIds: list with ids of already existing :yref:`GridConnections<GridConnection>`. New ids will be added.
:param list pfIds: list with ids of already existing :yref:`PFacets<PFacet>`. New ids will be added.
:param materialNodes: specify :yref:`Body.material` of :yref:`GridNodes<GridNode>`. This material is used to make the internal connections.
:param material: specify :yref:`Body.material` of :yref:`PFacets<PFacet>`. This material is used for interactions with external bodies.
See documentation of :yref:`yade.utils.sphere` for meaning of other parameters.
"""
n=len(nodesIds)
k=[0,0,0]
f=[0,0,0]
u=0
nod=0
for i in vertices:
u=0
for j in nodesIds:
if(i==O.bodies[j].state.pos):
f[nod]=j
k[nod]=1
u+=1
nod+=1
test=True
#if(u==0):
for GN in nodesIds:
if(i==O.bodies[GN].state.pos):
u=1
if(u==0):
nodesIds.append( O.bodies.append(gridNode(i,radius,wire=wire,fixed=fixed,material=materialNodes,color=color)) )
if(k==[0,0,0]):
pfacetCreator3(nodesIds[n],nodesIds[n+1],nodesIds[n+2],cylIds=cylIds,pfIds=pfIds,wire=wire,material=material,color=color,fixed=fixed )
if(k==[1,0,0]):
pfacetCreator3(f[0],nodesIds[n],nodesIds[n+1],cylIds=cylIds,pfIds=pfIds,wire=wire,material=material,color=color,fixed=fixed )
if(k==[0,1,0]):
pfacetCreator3(nodesIds[n],f[1],nodesIds[n+1],cylIds=cylIds,pfIds=pfIds,wire=wire,material=material,color=color,fixed=fixed )
if(k==[0,0,1]):
pfacetCreator3(nodesIds[n],nodesIds[n+1],f[2],cylIds=cylIds,pfIds=pfIds,wire=wire,material=material,color=color,fixed=fixed )
if(k==[1,1,0]):
pfacetCreator3(f[0],f[1],nodesIds[n],cylIds=cylIds,pfIds=pfIds,wire=wire,material=material,color=color,fixed=fixed )
if(k==[0,1,1]):
pfacetCreator3(nodesIds[n],f[1],f[2],cylIds=cylIds,pfIds=pfIds,wire=wire,material=material,color=color,fixed=fixed )
if(k==[1,0,1]):
pfacetCreator3(f[0],nodesIds[n],f[2],cylIds=cylIds,pfIds=pfIds,wire=wire,material=material,color=color,fixed=fixed )
if(k==[1,1,1]):
pfacetCreator3(f[0],f[1],f[2],cylIds=cylIds,pfIds=pfIds,wire=wire,material=material,color=color,fixed=fixed )
def pfacetCreator2(id1,id2,vertex,radius,nodesIds=[],wire=True,materialNodes=-1,material=-1,color=None,fixed=True):
"""
Create a :yref:`PFacet<PFacet>` element from 2 already existing and connected :yref:`GridNodes<GridNode>` and one vertex. The element is automatically appended to the simulation.
:param int id1,id2: ids of already with :yref:`GridConnection` connected :yref:`GridNodes<GridNode>`.
:param Vector3 vertex: coordinates of the vertex in the global coordinate system.
See documentation of :yref:`yade.gridpfacet.pfacetCreator1` for meaning of other parameters.
"""
n=len(nodesIds)
nodesIds.append( O.bodies.append(gridNode(vertex,radius,wire=wire,fixed=fixed,material=materialNodes,color=color)) )
O.bodies.append(gridConnection(id1,nodesIds[n],radius=radius,material=materialNodes,color=color,wire=wire))
O.bodies.append(gridConnection(id2,nodesIds[n],radius=radius,material=materialNodes,color=color,wire=wire))
O.bodies.append(pfacet(id1,id2,nodesIds[n],wire=wire,material=material,color=color))
def pfacetCreator3(id1,id2,id3,cylIds=[],pfIds=[],wire=True,material=-1,color=None,fixed=True,mask=-1):
"""
Create a :yref:`PFacet` element from 3 already existing :yref:`GridNodes<GridNode>` which are not yet connected. The element is automatically appended to the simulation.
:param int id1,id2,id3: id of the 3 :yref:`GridNodes<GridNode>` forming the :yref:`PFacet`.
See documentation of :yref:`yade.gridpfacet.pfacetCreator1` for meaning of other parameters.
"""
radius=O.bodies[id1].shape.radius
try:
cylIds.append(O.bodies.append(gridConnection(id1,id2,radius=radius,material=material,color=color,wire=wire,mask=mask)))
except:
pass
try:
cylIds.append(O.bodies.append(gridConnection(id2,id3,radius=radius,material=material,color=color,wire=wire,mask=mask)))
except:
pass
try:
cylIds.append(O.bodies.append(gridConnection(id3,id1,radius=radius,material=material,color=color,wire=wire,mask=mask)))
except:
pass
pfIds.append(O.bodies.append(pfacet(id1,id2,id3,wire=wire,material=material,color=color,mask=mask)))
def pfacetCreator4(id1,id2,id3,pfIds=[],wire=True,material=-1,color=None,fixed=True,mask=-1):
"""
Create a :yref:`PFacet<PFacet>` element from 3 already existing :yref:`GridConnections<GridConnection>`. The element is automatically appended to the simulation.
:param int id1,id2,id3: id of the 3 :yref:`GridConnections<GridConnection>` forming the :yref:`PFacet`.
See documentation of :yref:`yade.gridpfacet.pfacetCreator1` for meaning of other parameters.
"""
radius=O.bodies[id1].shape.radius
GridN=[]
GridN1=O.bodies[id1].shape.node1.id
GridN2=O.bodies[id1].shape.node2.id
GridN.append(GridN1)
GridN.append(GridN2)
GridN1=O.bodies[id2].shape.node1.id
if(GridN1 not in GridN):
GridN.append(GridN1)
GridN2=O.bodies[id2].shape.node2.id
if(GridN2 not in GridN):
GridN.append(GridN2)
GridN1=O.bodies[id3].shape.node1.id
if(GridN1 not in GridN):
GridN.append(GridN1)
GridN2=O.bodies[id3].shape.node2.id
if(GridN2 not in GridN):
GridN.append(GridN2)
pfIds.append(O.bodies.append(pfacet(GridN[0],GridN[1],GridN[2],wire=wire,material=material,color=color,mask=mask)))
def gtsPFacet(meshfile,shift=Vector3.Zero,scale=1.0,
radius=1,wire=True,fixed=True,materialNodes=-1,material=-1,color=None):
"""
Imports mesh geometry from .gts file and automatically creates connected :yref:`PFacet3<PFacet>` elements. For an example see :ysrc:`examples/pfacet/gts-pfacet.py`.
:param string filename: .gts file to read.
:param [float,float,float] shift: [X,Y,Z] parameter shifts the mesh.
:param float scale: factor scales the mesh.
:param float radius: radius used to create the :yref:`PFacets<PFacet>`.
:param materialNodes: specify :yref:`Body.material` of :yref:`GridNodes<GridNode>`. This material is used to make the internal connections.
:param material: specify :yref:`Body.material` of :yref:`PFacets<PFacet>`. This material is used for interactions with external bodies.
See documentation of :yref:`yade.utils.sphere` for meaning of other parameters.
:returns: lists of :yref:`GridNode<GridNode>` ids `nodesIds`, :yref:`GridConnection<GridConnection>` ids `cylIds`, and :yref:`PFacet<PFacet>` ids `pfIds`
"""
import gts,yade.pack
surf=gts.read(open(meshfile))
surf.scale(scale,scale,scale)
surf.translate(shift[0],shift[1],shift[2])
nodesIds=[]; cylIds=[]; pfIds=[]
for face in surf.faces():
a=face.vertices()[0].coords()
b=face.vertices()[1].coords()
c=face.vertices()[2].coords()
pfacetCreator1([a,b,c],radius=radius,nodesIds=nodesIds,cylIds=cylIds,pfIds=pfIds,wire=wire,fixed=fixed,materialNodes=materialNodes,material=material,color=color)
#print a,b,c
return nodesIds,cylIds,pfIds
def gmshPFacet(meshfile="file.mesh",shift=Vector3.Zero,scale=1.0,orientation=Quaternion.Identity,
radius=1.0,wire=True,fixed=True,materialNodes=-1,material=-1,color=None):
"""
Imports mesh geometry from .mesh file and automatically creates connected PFacet elements. For an example see :ysrc:`examples/pfacet/mesh-pfacet.py`.
:param string filename: .gts file to read.
:param [float,float,float] shift: [X,Y,Z] parameter shifts the mesh.
:param float scale: factor scales the mesh.
:param quaternion orientation: orientation of the imported geometry.
:param float radius: radius used to create the :yref:`PFacets<PFacet>`.
:param materialNodes: specify :yref:`Body.material` of :yref:`GridNodes<GridNode>`. This material is used to make the internal connections.
:param material: specify :yref:`Body.material` of :yref:`PFacets<PFacet>`. This material is used for interactions with external bodies.
See documentation of :yref:`yade.utils.sphere` for meaning of other parameters.
:returns: lists of :yref:`GridNode<GridNode>` ids `nodesIds`, :yref:`GridConnection<GridConnection>` ids `cylIds`, and :yref:`PFacet<PFacet>` ids `pfIds`
mesh files can easily be created with `GMSH <http://www.geuz.org/gmsh/>`_.
Additional examples of mesh-files can be downloaded from
http://www-roc.inria.fr/gamma/download/download.php
"""
infile = open(meshfile,"r")
lines = infile.readlines()
infile.close()
nodelistVector3=[]
findVerticesString=0
while (lines[findVerticesString].split()[0]<>'Vertices'): # find the string with the number of Vertices
findVerticesString+=1
findVerticesString+=1
numNodes = int(lines[findVerticesString].split()[0])
for i in range(numNodes):
nodelistVector3.append(Vector3(0.0,0.0,0.0))
id = 0
for line in lines[findVerticesString+1:numNodes+findVerticesString+1]:
data = line.split()
nodelistVector3[id] = orientation*Vector3(float(data[0])*scale,float(data[1])*scale,float(data[2])*scale)+shift
id += 1
findTriangleString=findVerticesString+numNodes
while (lines[findTriangleString].split()[0]<>'Triangles'): # find the string with the number of Triangles
findTriangleString+=1
findTriangleString+=1
numTriangles = int(lines[findTriangleString].split()[0])
triList = []
for i in range(numTriangles):
triList.append([0,0,0,0])
tid = 0
for line in lines[findTriangleString+1:findTriangleString+numTriangles+1]:
data = line.split()
id1 = int(data[0])-1
id2 = int(data[1])-1
id3 = int(data[2])-1
triList[tid][0] = tid
triList[tid][1] = id1
triList[tid][2] = id2
triList[tid][3] = id3
tid += 1
nodesIds=[]; cylIds=[]; pfIds=[]
for i in triList:
a=nodelistVector3[i[1]]
b=nodelistVector3[i[2]]
c=nodelistVector3[i[3]]
#print 'i',i
#print 'a',a
#print 'b',b
#print 'c',c
try:
pfacetCreator1([a,b,c],radius=radius,nodesIds=nodesIds,cylIds=cylIds,pfIds=pfIds,
wire=wire,fixed=fixed,materialNodes=materialNodes,material=material,color=color)
except:
pass
return nodesIds,cylIds,pfIds
|