← Back to team overview

yade-dev team mailing list archive

Fwd: python script with clumps

 

---------- Forwarded message ----------
From: Vincent Richefeu <richefeu@xxxxxxxxx>
Date: 2009/6/18
Subject: python script with clumps
To: eudoxos@xxxxxxxx


The attached file is a yade-python script that makes use of clumps.
(my python style should be funny for you!)
# Parameters ====================================================================================

lx = 10e-3
ly = 3e-3
lz = 10e-3
clumpType = 2
clumpRadius = 0.8e-3
clumpNumber = 50
clumpFilename = "clumps_test.spl"

Kn = 1.0e3
Ks = 0.8e3
en = 0.01
FrictionAngle = 0.5

Density = 2700.0
Gravity = [0.0,-9.81,0.0]
Damping = 0.0 # Cundall damping

import math
ln_en=math.log(en)
Cn = -ln_en/math.sqrt((math.pow(ln_en,2) + math.pi*math.pi))
print Cn
Cs = 0.0

#================================================================================================

if clumpType == 1:
  sphpos = [[0.0,0.0,0.0],]
  sphrad = 1.0
if clumpType == 2:
  sphpos = [[-0.5,0.0,0.0],[0.5,0.0,0.0]]
  sphrad = 0.5

  
#================================================================================================
# rq: il faut que les facets et les spheres aient le meme groupMask pour fonctionner

from yade import utils
import math,random

O=Omega()

O.initializers=[
  BoundingVolumeMetaEngine([InteractingSphere2AABB(),InteractingBox2AABB(),MetaInteractingGeometry2AABB()])
  ]

O.engines=[
  PhysicalActionContainerReseter(),
  BoundingVolumeMetaEngine([
	InteractingSphere2AABB(),
	InteractingBox2AABB(),
	MetaInteractingGeometry2AABB()
	]),
  PersistentSAPCollider(),
  InteractionGeometryMetaEngine([
  InteractingSphere2InteractingSphere4SpheresContactGeometry(),
  InteractingBox2InteractingSphere4SpheresContactGeometry()
  ]),
  InteractionPhysicsMetaEngine([BasicViscoelasticRelationships()]),
  ConstitutiveLawDispatcher([ef2_Spheres_Viscoelastic_SimpleViscoelasticContactLaw()]),
  GravityEngine(gravity=Gravity),
  NewtonsDampedLaw(damping=Damping),
  ]

midlx = 0.5 * lx
midly = 0.5 * ly
midlz = 0.5 * lz
thickness = clumpRadius*0.1
extention = 1.1
Color = [0.5,0.5,0.5]

s=utils.box([midlx,-thickness,midlz],[extention*midlx,-thickness,extention*midlz],frictionAngle=FrictionAngle,density=Density,dynamic=False,color=Color,physParamsClass='SimpleViscoelasticBodyParameters',physParamsAttr={'kn':Kn,'cn':Cn,'ks':Ks,'cs':Cs})
s['groupMask']=1
O.bodies.append(s)

s=utils.box([midlx,midly,-thickness],[extention*midlx,extention*midly,-thickness],frictionAngle=FrictionAngle,density=Density,dynamic=False,color=Color,physParamsClass='SimpleViscoelasticBodyParameters',physParamsAttr={'kn':Kn,'cn':Cn,'ks':Ks,'cs':Cs})
s['groupMask']=1
O.bodies.append(s)

s=utils.box([midlx,midly,lz+thickness],[extention*midlx,extention*midly,thickness],frictionAngle=FrictionAngle,density=Density,dynamic=False,color=Color,physParamsClass='SimpleViscoelasticBodyParameters',physParamsAttr={'kn':Kn,'cn':Cn,'ks':Ks,'cs':Cs})
s['groupMask']=1
O.bodies.append(s)

s=utils.box([-thickness,midly,midlz],[-thickness,extention*midly,extention*midlz],frictionAngle=FrictionAngle,density=Density,dynamic=False,color=Color,physParamsClass='SimpleViscoelasticBodyParameters',physParamsAttr={'kn':Kn,'cn':Cn,'ks':Ks,'cs':Cs})
s['groupMask']=1
O.bodies.append(s)

s=utils.box([lx+thickness,midly,midlz],[thickness,extention*midly,extention*midlz],frictionAngle=FrictionAngle,density=Density,dynamic=False,color=Color,physParamsClass='SimpleViscoelasticBodyParameters',physParamsAttr={'kn':Kn,'cn':Cn,'ks':Ks,'cs':Cs})
s['groupMask']=1
O.bodies.append(s)

n = 0
x = y = z = clumpRadius
while n < clumpNumber:
  Color = utils.randomColor()

  tmplist = []
  for i in range(0,len(sphpos)):
	rotAlea = random.random() * 0.5*math.pi
	c = math.cos(rotAlea)
	s = math.sin(rotAlea)

	Center = [x+(c*sphpos[i][0]-s*sphpos[i][2])*clumpRadius, y+sphpos[i][1]*clumpRadius, z+(s*sphpos[i][0]+c*sphpos[i][2])*clumpRadius]

	s=utils.sphere(center=Center,radius=clumpRadius*sphrad,color=Color,frictionAngle=FrictionAngle,dynamic=True,density=Density,physParamsClass='SimpleViscoelasticBodyParameters',physParamsAttr={'kn':Kn,'cn':Cn,'ks':Ks,'cs':Cs})
	s['groupMask']=1
	#print s.phys['inertia']
	tmplist.append(s)
  
  if clumpType > 1:
	O.bodies.appendClumped(tmplist)
  else: O.bodies.append(tmplist)
  
  n = n + 1	
  x = x + 2.0 * clumpRadius
  if x + clumpRadius > lx :
	x = clumpRadius
	z = z + 2.0 * clumpRadius
	if z + clumpRadius > lz :
	  z = clumpRadius
	  y = y + 2.0 * clumpRadius
	  
O.dt = 1.0e-6
O.saveTmp('init')

from yade import qt
qt.Controller()
qt.View()