← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-pkg/yade/git-trunk] Rev 3755: move grid specific functions in separate module and add some more doc

 

------------------------------------------------------------
revno: 3755
committer: Klaus Thoeni <klaus.thoeni@xxxxxxxxx>
timestamp: Thu 2015-12-10 23:18:07 +1100
message:
  move grid specific functions in separate module and add some more doc
added:
  py/gridpfacet.py
modified:
  .gitignore
  doc/sphinx/yadeSphinx.py
  examples/chained-cylinders/CohesiveCylinderSphere.py
  examples/chained-cylinders/chained-cylinder-roots.py
  examples/chained-cylinders/chained-cylinder-spring.py
  examples/grids/Simple_Grid_Falling.py
  py/utils.py


--
lp:yade
https://code.launchpad.net/~yade-pkg/yade/git-trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-pkg/yade/git-trunk/+edit-subscription
=== modified file '.gitignore'
--- .gitignore	2015-04-24 15:54:07 +0000
+++ .gitignore	2015-12-10 12:18:07 +0000
@@ -26,6 +26,7 @@
 doc/sphinx/yade.wrapper.rst
 doc/sphinx/yade.ymport.rst
 doc/sphinx/yade.polyhedra_utils.rst
+doc/sphinx/yade.gridpfacet.rst
 .kdev4/
 *.kdev4
 *.pyc

=== modified file 'doc/sphinx/yadeSphinx.py'
--- doc/sphinx/yadeSphinx.py	2014-10-15 07:02:01 +0000
+++ doc/sphinx/yadeSphinx.py	2015-12-10 12:18:07 +0000
@@ -35,7 +35,7 @@
 #
 # don't forget to put the module in index.rst as well!
 #
-mods={'export':[],'post2d':[],'pack':['_packSpheres','_packPredicates','_packObb'],'plot':[],'timing':[],'utils':['_utils'],'polyhedra_utils':['_polyhedra_utils'],'ymport':[],'geom':[],'bodiesHandling':[],'qt':['qt._GLViewer'],'linterpolation':[]}
+mods={'export':[],'post2d':[],'pack':['_packSpheres','_packPredicates','_packObb'],'plot':[],'timing':[],'utils':['_utils'],'polyhedra_utils':['_polyhedra_utils'],'ymport':[],'geom':[],'bodiesHandling':[],'qt':['qt._GLViewer'],'linterpolation':[],'gridpfacet':[]}
 #
 # generate documentation, in alphabetical order
 mm=mods.keys(); mm.sort()

=== modified file 'examples/chained-cylinders/CohesiveCylinderSphere.py'
--- examples/chained-cylinders/CohesiveCylinderSphere.py	2015-12-09 00:17:37 +0000
+++ examples/chained-cylinders/CohesiveCylinderSphere.py	2015-12-10 12:18:07 +0000
@@ -1,5 +1,6 @@
 # encoding: utf-8
 from yade import qt
+from yade.gridpfacet import *
 
 qt.View()
 

=== modified file 'examples/chained-cylinders/chained-cylinder-roots.py'
--- examples/chained-cylinders/chained-cylinder-roots.py	2013-03-28 16:15:54 +0000
+++ examples/chained-cylinders/chained-cylinder-roots.py	2015-12-10 12:18:07 +0000
@@ -5,6 +5,7 @@
 # Experiment beam-like behaviour with chained cylinders + CohFrict connexions
 
 from yade import pack
+from yade.gridpfacet import *
 
 young=4.0e6
 poisson=3

=== modified file 'examples/chained-cylinders/chained-cylinder-spring.py'
--- examples/chained-cylinders/chained-cylinder-spring.py	2013-03-28 16:15:54 +0000
+++ examples/chained-cylinders/chained-cylinder-spring.py	2015-12-10 12:18:07 +0000
@@ -4,6 +4,8 @@
 
 # Experiment beam-like behaviour with chained cylinders + CohFrict connexions
 
+from yade.gridpfacet import *
+
 young=1.0e6
 poisson=4
 density=2.60e3 

=== modified file 'examples/grids/Simple_Grid_Falling.py'
--- examples/grids/Simple_Grid_Falling.py	2013-03-28 16:15:54 +0000
+++ examples/grids/Simple_Grid_Falling.py	2015-12-10 12:18:07 +0000
@@ -1,6 +1,7 @@
 # encoding: utf-8
 
 from yade import pack,geom,qt
+from yade.gridpfacet import *
 from pylab import *
 qt.View()
 

=== added file 'py/gridpfacet.py'
--- py/gridpfacet.py	1970-01-01 00:00:00 +0000
+++ py/gridpfacet.py	2015-12-10 12:18:07 +0000
@@ -0,0 +1,128 @@
+# encoding: utf-8
+#
+# 2015 © Bruno Chareyre <bruno.chareyre@xxxxxxxxxxx>
+# 2015 © Anna Effeindzourou <anna.effeindzourou@xxxxxxxxx>
+# 2015 © François Kneib <francois.kneib@xxxxxxxxx>
+# 2015 © Klaus Thoeni <klaus.thoeni@xxxxxxxxx>
+
+"""
+Helper functions for creating cylinders, grids and membranes.
+"""
+
+import math,random,doctest,geom,numpy
+from yade import *
+from yade.wrapper import *
+try: # use psyco if available
+	import psyco
+	psyco.full()
+except ImportError: pass
+
+from yade import utils
+from yade._utils import *
+
+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>`.
+	"""
+	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 overriden by the connection
+	V=0.
+	geomInert=(2./5.)*V*radius**2	# will be overriden 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: 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! 
+
+	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()
+	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
+

=== modified file 'py/utils.py'
--- py/utils.py	2015-06-10 08:07:09 +0000
+++ py/utils.py	2015-12-10 12:18:07 +0000
@@ -226,85 +226,6 @@
 	return b
 
 
-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>`.
-	"""
-	segment=end-begin
-	b=Body()
-	b.shape=ChainedCylinder(radius=radius,length=segment.norm(),color=color if color else 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))
-	_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):
-	b=Body()
-	b.shape=GridNode(radius=radius,color=color if color else randomColor(),wire=wire,highlight=highlight)
-	#V=(4./3)*math.pi*radius**3	# will be overriden by the connection
-	V=0.
-	geomInert=(2./5.)*V*radius**2	# will be overriden by the connection
-	_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):
-	b=Body()
-	b.shape=GridConnection(radius=radius,color=color if color else 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
-	_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
-	
-	
 def wall(position,axis,sense=0,color=None,material=-1,mask=1):
 	"""Return ready-made wall body.
 
@@ -323,6 +244,7 @@
 	b.mask=mask
 	return b
 
+
 def facet(vertices,dynamic=None,fixed=True,wire=True,color=None,highlight=False,noBound=False,material=-1,mask=1,chain=-1):
 	"""Create facet with given parameters.
 
@@ -342,6 +264,7 @@
 	b.chain=chain
 	return b
 
+
 def tetraPoly(vertices,dynamic=True,fixed=False,wire=True,color=None,highlight=False,noBound=False,material=-1,mask=1,chain=-1):
 	"""Create tetrahedron (actually simple Polyhedra) with given parameters.