← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2065: Reanimation of some examples; fix bug in ymport.stl

 

------------------------------------------------------------
revno: 2065
committer: Sergei D. <sega@think>
branch nick: trunk
timestamp: Sun 2010-03-07 22:53:42 +0300
message:
  Reanimation of some examples; fix bug in ymport.stl
modified:
  examples/buldozer.py
  examples/buldozerVTK.py
  examples/cyl.py
  examples/dynamic_simulation_tests/ringCundallDamping.py
  examples/dynamic_simulation_tests/ringSimpleViscoelastic.py
  examples/mill.py
  examples/rod_penetration/model.py
  py/ymport.py


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

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription.
=== modified file 'examples/buldozer.py'
--- examples/buldozer.py	2010-01-10 09:09:32 +0000
+++ examples/buldozer.py	2010-03-07 19:53:42 +0000
@@ -62,7 +62,7 @@
 	BoundDispatcher([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb(),]),
 	InsertionSortCollider(),
 	InteractionDispatchers(
-		[ef2_Sphere_Sphere_Dem3DofGeom(),ef2_Facet_Sphere_Dem3DofGeom()],
+		[Ig2_Sphere_Sphere_Dem3DofGeom(),Ig2_Facet_Sphere_Dem3DofGeom()],
 		[Ip2_FrictMat_FrictMat_FrictPhys()],
 		[Law2_Dem3DofGeom_FrictPhys_Basic()],
 	),

=== modified file 'examples/buldozerVTK.py'
--- examples/buldozerVTK.py	2009-12-25 14:46:48 +0000
+++ examples/buldozerVTK.py	2010-03-07 19:53:42 +0000
@@ -23,6 +23,11 @@
 en = 0.3
 es = 0.3
 
+## Materials
+params=utils.getViscoelasticFromSpheresInteraction(10e3,tc,en,es)
+facetMat=O.materials.append(SimpleViscoelasticMat(frictionAngle=frictionAngle,**params)) # **params sets kn, cn, ks, cs
+sphereMat=O.materials.append(SimpleViscoelasticMat(density=Density,frictionAngle=frictionAngle,**params))
+
 ### Creating the Buldozer Knife
 ### from facets, using GTS
 Knife=[]
@@ -31,8 +36,8 @@
 	
 KnifeP=[Knife,[p+Vector3(0,lengthKnife,0) for p in Knife]]
 KnifePoly=pack.sweptPolylines2gtsSurface(KnifeP,threshold=1e-4)
-KnifeIDs=O.bodies.append(pack.gtsSurface2Facets(KnifePoly,color=(1,0,0),wire=False,frictionAngle=frictionAngle,physParamsClass="SimpleViscoelasticBodyParameters",**utils.getViscoelasticFromSpheresInteraction(10e3,tc,en,es)))
-O.bodies.append(utils.facetBox((0,0,radiusKnife),(lengthKnife*3,lengthKnife*3,lengthKnife),wallMask=16,color=(1,1,1),wire=False,frictionAngle=frictionAngle,physParamsClass="SimpleViscoelasticBodyParameters",**utils.getViscoelasticFromSpheresInteraction(10e3,tc,en,es)))
+KnifeIDs=O.bodies.append(pack.gtsSurface2Facets(KnifePoly,color=(1,0,0),wire=False,material=facetMat))
+O.bodies.append(utils.facetBox((0,0,radiusKnife),(lengthKnife*3,lengthKnife*3,lengthKnife),wallMask=16,color=(1,1,1),wire=False,material=facetMat))
 
 
 ### Creating the material for buldozer
@@ -43,11 +48,11 @@
 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,density=Density,frictionAngle=frictionAngle, physParamsClass="SimpleViscoelasticBodyParameters"))
+	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))
 	for id in ids_spheres[1]:
 		s=O.bodies[id]
-		p=utils.getViscoelasticFromSpheresInteraction(s.phys['mass'],tc,en,es)
-		s.phys['kn'],s.phys['cn'],s.phys['ks'],s.phys['cs']=p['kn'],p['cn'],p['ks'],p['cs']
+		p=utils.getViscoelasticFromSpheresInteraction(s.state['mass'],tc,en,es)
+		s.mat['kn'],s.mat['cn'],s.mat['ks'],s.mat['cs']=p['kn'],p['cn'],p['ks'],p['cs']
 	if (colorSph==colorsph1):
 		colorSph=colorsph2
 	else:
@@ -63,8 +68,8 @@
 	InsertionSortCollider(),
 	InteractionDispatchers(
 		[Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom()],
-		[SimpleViscoelasticRelationships()],
-		[ef2_Spheres_Viscoelastic_SimpleViscoelasticContactLaw()],
+		[Ip2_SimleViscoelasticMat_SimpleViscoelasticMat_SimpleViscoelasticPhys()],
+		[Law2_Spheres_Viscoelastic_SimpleViscoelastic()],
 	),
 	GravityEngine(gravity=[0,0,-9.8]),
 	TranslationEngine(translationAxis=[1,0,0],velocity=2,subscribedBodies=KnifeIDs), # Buldozer motion

=== modified file 'examples/cyl.py'
--- examples/cyl.py	2010-01-10 09:09:32 +0000
+++ examples/cyl.py	2010-03-07 19:53:42 +0000
@@ -33,14 +33,14 @@
 print 'Generating cloud…'
 sp.makeCloud((-wd/2,-wd/2,-.5*cylHt),(wd/2,wd/2,.5*cylHt),rMean,0,int(nSpheres),False)
 sp.rotate((1,0,0),-pi/4)
-O.bodies.append([utils.sphere(s[0],s[1],density=3000) for s in sp])
+O.bodies.append([utils.sphere(s[0],s[1]) for s in sp])
 
 O.engines=[
 	ForceResetter(),
 	BoundDispatcher([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb(),]),
 	InsertionSortCollider(nBins=5,sweepLength=.1*rMean),
 	InteractionDispatchers(
-		[ef2_Sphere_Sphere_Dem3DofGeom(),ef2_Facet_Sphere_Dem3DofGeom()],
+		[Ig2_Sphere_Sphere_Dem3DofGeom(),Ig2_Facet_Sphere_Dem3DofGeom()],
 		[Ip2_FrictMat_FrictMat_FrictPhys()],
 		[Law2_Dem3DofGeom_FrictPhys_Basic()],
 	),

=== modified file 'examples/dynamic_simulation_tests/ringCundallDamping.py'
--- examples/dynamic_simulation_tests/ringCundallDamping.py	2009-12-25 14:46:48 +0000
+++ examples/dynamic_simulation_tests/ringCundallDamping.py	2010-03-07 19:53:42 +0000
@@ -1,19 +1,18 @@
 # -*- encoding=utf-8 -*-
 
 from yade import utils
+from yade import ymport
 
 ## Omega
 o=Omega() 
 
 ## PhysicalParameters 
-Young = 0.15e9
-Poisson = 0.3
-Density=500
-frictionAngle=radians(30)
+#Density=500
+#frictionAngle=radians(30)
 sphereRadius=0.05
 
 ## Import wall's geometry
-walls = utils.import_stl_geometry('ring.stl',young=Young,poisson=Poisson,frictionAngle=frictionAngle)
+walls = O.bodies.append(ymport.stl('ring.stl'))
 
 def fill_cylinder_with_spheres(sphereRadius,cylinderRadius,cylinderHeight,cylinderOrigin,cylinderSlope):
 	spheresCount=0
@@ -24,7 +23,7 @@
 					x = cylinderOrigin[0]+2*r*sphereRadius*cos(dfi*a)
 					y = cylinderOrigin[1]+2*r*sphereRadius*sin(dfi*a)
 					z = cylinderOrigin[2]+h*2*sphereRadius
-					o.bodies.append(utils.sphere([x,y*cos(cylinderSlope)+z*sin(cylinderSlope),z*cos(cylinderSlope)-y*sin(cylinderSlope)],sphereRadius,young=Young,poisson=Poisson,density=Density,frictionAngle=frictionAngle))
+					o.bodies.append(utils.sphere([x,y*cos(cylinderSlope)+z*sin(cylinderSlope),z*cos(cylinderSlope)-y*sin(cylinderSlope)],sphereRadius))
 					spheresCount+=1
 	return spheresCount
 
@@ -51,19 +50,11 @@
 
 	## Using bounding boxes find possible body collisions.
 	InsertionSortCollider(),
-
-	## Create geometry information about each potential collision.
-	InteractionGeometryDispatcher([
-		Ig2_Sphere_Sphere_ScGeom(),
-		Ig2_Facet_Sphere_ScGeom()
-	]),
-
-	## Create physical information about the interaction.
-	InteractionPhysicsDispatcher([MacroMicroElasticRelationships()]),
-
-    ## Constitutive law
-	ElasticContactLaw(),
-
+	InteractionDispatchers(
+		[Ig2_Sphere_Sphere_Dem3DofGeom(),Ig2_Facet_Sphere_Dem3DofGeom()],
+		[Ip2_FrictMat_FrictMat_FrictPhys()],
+		[Law2_Dem3DofGeom_FrictPhys_Basic()],
+	),
 	## Apply gravity
 	GravityEngine(gravity=[0,-9.81,0]),
 
@@ -77,7 +68,7 @@
 
 for b in o.bodies:
     if b.shape.name=='Sphere':
-        b.phys.blockedDOFs=['z'] # blocked movement along Z
+        b.state.blockedDOFs=['z'] # blocked movement along Z
 
 o.dt=0.2*utils.PWaveTimeStep()
 

=== modified file 'examples/dynamic_simulation_tests/ringSimpleViscoelastic.py'
--- examples/dynamic_simulation_tests/ringSimpleViscoelastic.py	2009-12-25 14:46:48 +0000
+++ examples/dynamic_simulation_tests/ringSimpleViscoelastic.py	2010-03-07 19:53:42 +0000
@@ -1,6 +1,7 @@
 # -*- encoding=utf-8 -*-
 
 from yade import utils
+from yade import ymport
 
 ## Omega
 o=Omega() 
@@ -15,7 +16,10 @@
 
 ## Import wall's geometry
 params=utils.getViscoelasticFromSpheresInteraction(10e3,tc,en,es)
-walls = utils.import_stl_geometry('ring.stl',frictionAngle=frictionAngle,physParamsClass="SimpleViscoelasticBodyParameters",**params)
+facetMat=O.materials.append(SimpleViscoelasticMat(frictionAngle=frictionAngle,**params)) # **params sets kn, cn, ks, cs
+sphereMat=O.materials.append(SimpleViscoelasticMat(density=Density,frictionAngle=frictionAngle,**params))
+
+walls = O.bodies.append(ymport.stl('ring.stl',material=facetMat))
 
 def fill_cylinder_with_spheres(sphereRadius,cylinderRadius,cylinderHeight,cylinderOrigin,cylinderSlope):
 	spheresCount=0
@@ -26,9 +30,9 @@
 					x = cylinderOrigin[0]+2*r*sphereRadius*cos(dfi*a)
 					y = cylinderOrigin[1]+2*r*sphereRadius*sin(dfi*a)
 					z = cylinderOrigin[2]+h*2*sphereRadius
-					s=utils.sphere([x,y*cos(cylinderSlope)+z*sin(cylinderSlope),z*cos(cylinderSlope)-y*sin(cylinderSlope)],sphereRadius,density=Density,frictionAngle=frictionAngle,physParamsClass="SimpleViscoelasticBodyParameters")
-					p=utils.getViscoelasticFromSpheresInteraction(s.phys['mass'],tc,en,es)
-					s.phys['kn'],s.phys['cn'],s.phys['ks'],s.phys['cs']=p['kn'],p['cn'],p['ks'],p['cs']
+					s=utils.sphere([x,y*cos(cylinderSlope)+z*sin(cylinderSlope),z*cos(cylinderSlope)-y*sin(cylinderSlope)],sphereRadius,material=sphereMat)
+					p=utils.getViscoelasticFromSpheresInteraction(s.state['mass'],tc,en,es)
+					s.mat['kn'],s.mat['cn'],s.mat['ks'],s.mat['cs']=p['kn'],p['cn'],p['ks'],p['cs']
 					o.bodies.append(s)
 					spheresCount+=1
 	return spheresCount
@@ -57,19 +61,15 @@
 
 	## Using bounding boxes find possible body collisions.
 	InsertionSortCollider(),
-
-	## Create geometry information about each potential collision.
-	InteractionGeometryDispatcher([
-		Ig2_Sphere_Sphere_ScGeom(),
-		Ig2_Facet_Sphere_ScGeom()
-	]),
-
-	## Create physical information about the interaction.
-	InteractionPhysicsDispatcher([SimpleViscoelasticRelationships()]),
-
-    ## Constitutive law
-	ConstitutiveLawDispatcher([ef2_Spheres_Viscoelastic_SimpleViscoelasticContactLaw()]),
-
+	# Interactions
+	InteractionDispatchers(
+		## Create geometry information about each potential collision.
+		[Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom()],
+		## Create physical information about the interaction.
+		[Ip2_SimleViscoelasticMat_SimpleViscoelasticMat_SimpleViscoelasticPhys()],
+		## Constitutive law
+		[Law2_Spheres_Viscoelastic_SimpleViscoelastic()],
+	),
 	## Apply gravity
 	GravityEngine(gravity=[0,-9.81,0]),
 	## Cundall damping must been disabled!
@@ -82,7 +82,7 @@
 
 for b in o.bodies:
     if b.shape.name=='Sphere':
-        b.phys.blockedDOFs=['z']
+        b.state.blockedDOFs=['z']
 
 o.dt=0.2*tc
 

=== modified file 'examples/mill.py'
--- examples/mill.py	2010-01-10 09:09:32 +0000
+++ examples/mill.py	2010-03-07 19:53:42 +0000
@@ -53,7 +53,7 @@
 for i in (0,1): # red and blue spheres
 	sp=pack.SpherePack(); bb=bboxes[i]; vol=(bb[1][0]-bb[0][0])*(bb[1][1]-bb[0][1])*(bb[1][2]-bb[0][2])
 	sp.makeCloud(bb[0],bb[1],sphRad,sphRadFuzz,int(.25*vol/((4./3)*pi*sphRad**3)),False)
-	O.bodies.append([utils.sphere(s[0],s[1],density=3000,color=colors[i]) for s in sp])
+	O.bodies.append([utils.sphere(s[0],s[1],color=colors[i]) for s in sp])
 
 print "Numer of grains",len(O.bodies)-len(millIds)
 
@@ -64,12 +64,12 @@
 	BoundDispatcher([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
 	InsertionSortCollider(),
 	InteractionDispatchers(
-		[ef2_Sphere_Sphere_Dem3DofGeom(),ef2_Facet_Sphere_Dem3DofGeom()],
+		[Ig2_Sphere_Sphere_Dem3DofGeom(),Ig2_Facet_Sphere_Dem3DofGeom()],
 		[Ip2_FrictMat_FrictMat_FrictPhys()],
 		[Law2_Dem3DofGeom_FrictPhys_Basic()],
 	),
-	GravityEngine(gravity=(0,0,-3e4)), # gravity artificially high, to make it faster going ;-)
-	RotationEngine(rotateAroundZero=True,zeroPoint=(0,0,0),rotationAxis=(1,0,0),angularVelocity=-120,subscribedBodies=millIds),
+	GravityEngine(gravity=(0,0,-50)), # gravity artificially high, to make it faster going ;-)
+	RotationEngine(rotateAroundZero=True,zeroPoint=(0,0,0),rotationAxis=(1,0,0),angularVelocity=-20,subscribedBodies=millIds),
 	SnapshotEngine(iterPeriod=30,fileBase='/tmp/mill-',viewNo=0,label='snapshooter'),
 	NewtonIntegrator(damping=.3),
 ]

=== modified file 'examples/rod_penetration/model.py'
--- examples/rod_penetration/model.py	2009-12-25 14:46:48 +0000
+++ examples/rod_penetration/model.py	2010-03-07 19:53:42 +0000
@@ -3,10 +3,9 @@
 
 from yade import utils
 import random
+from yade import ymport
 
 ## PhysicalParameters 
-Young = 15e6
-Poisson = 0.2
 
 ## Variant of mesh
 mesh = 'coarse'
@@ -17,8 +16,7 @@
 o=Omega() 
 
 ## Import geometry 
-rod = utils.import_stl_geometry('rod-'+mesh+'.stl',wire=True,young=Young,poisson=Poisson)
-shrinkFactor=0.005
+rod = O.bodies.append(ymport.stl('rod-'+mesh+'.stl',wire=True))
 
 # Spheres
 sphereRadius = 0.01
@@ -33,10 +31,10 @@
 			r = random.uniform(sphereRadius,sphereRadius*0.9)
 			dynamic = True
 			color=[0.51,0.52,0.4]
-			if (i==0 or i==nbSpheres[0]-1 or j==nbSpheres[1]-1 or k==0 or k==nbSpheres[2]-1): 
+			if (i==0 or i==nbSpheres[0]-1 or j==nbSpheres[1]-1 or k==0 or k==nbSpheres[2]-1):
 				dynamic = False
 				color=[0.21,0.22,0.1]
-			o.bodies.append(utils.sphere([x,y,z],r,young=Young,poisson=Poisson,density=2400,color=color,dynamic=dynamic))
+			o.bodies.append(utils.sphere([x,y,z],r,color=color,dynamic=dynamic))
 print "done\n"
 
 ## Estimate time step
@@ -60,15 +58,11 @@
 	]),
 	## Using bounding boxes find possible body collisions.
 	InsertionSortCollider(),
-	## Create geometry information about each potential collision.
-	InteractionGeometryDispatcher([
-		Ig2_Sphere_Sphere_ScGeom(),
-		Ig2_Facet_Sphere_ScGeom()
-	]),
-	## Create physical information about the interaction.
-	InteractionPhysicsDispatcher([MacroMicroElasticRelationships()]),
-    ## Constitutive law
-	ElasticContactLaw(),
+	InteractionDispatchers(
+		[Ig2_Sphere_Sphere_Dem3DofGeom(),Ig2_Facet_Sphere_Dem3DofGeom()],
+		[Ip2_FrictMat_FrictMat_FrictPhys()],
+		[Law2_Dem3DofGeom_FrictPhys_Basic()],
+	),
 	## Apply gravity
 	GravityEngine(gravity=[0,-9.81,0]),
 	## Motion equation
@@ -76,13 +70,9 @@
 	## Apply kinematics to rod
 	TranslationEngine(subscribedBodies=rod,translationAxis=[0,-1,0],velocity=0.075),
 	## Save force on rod
-	ForceRecorder(startId=0,endId=len(rod)-1,outputFile='force-'+mesh+'.dat',interval=50),	
-	## Save positions
-	SQLiteRecorder(recorders=['se3'],dbFile='positions-'+mesh+'.sqlite',iterPeriod=100)
-
+	ForceRecorder(subscribedBodies=rod,file='force-'+mesh+'.dat',iterPeriod=50),	
 ]
 
-o.save('/tmp/scene.xml.bz2');
 
 import sys,time
 

=== modified file 'py/ymport.py'
--- py/ymport.py	2010-02-21 09:29:06 +0000
+++ py/ymport.py	2010-03-07 19:53:42 +0000
@@ -23,7 +23,7 @@
 		ret.append(utils.sphere([shift[0]+scale*float(data[0]),shift[1]+scale*float(data[1]),shift[2]+scale*float(data[2])],scale*float(data[3]),**kw))
 	return ret
 
-def stl(file, dynamic=False,wire=True,color=None,highlight=False,noBound=False,material=0):
+def stl(file, dynamic=False,wire=True,color=None,highlight=False,noBound=False,material=-1):
 	""" Import geometry from stl file, create facets and return list of their ids."""
 	imp = STLImporter()
 	facets=imp.ymport(file)