releaseFromClump-example.py 2.08 KB
Newer Older
1 2 3 4
#!/usr/bin/python
# -*- coding: utf-8 -*-

'''This example shows usage of releaseFromClump() and clump().'''
5
from __future__ import print_function
6 7

#define material for all bodies:
8 9
from builtins import input
from builtins import range
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
id_Mat=O.materials.append(FrictMat(young=1e6,poisson=0.3,density=1000,frictionAngle=1))
Mat=O.materials[id_Mat]

#define engines:
O.engines=[
	ForceResetter(),
	InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Box_Aabb()]),
	InteractionLoop(
		[Ig2_Sphere_Sphere_ScGeom(),Ig2_Box_Sphere_ScGeom()],
		[Ip2_FrictMat_FrictMat_FrictPhys()],
		[Law2_ScGeom_FrictPhys_CundallStrack()]
	),
	NewtonIntegrator(damping=0.7,gravity=[0,0,-10])
]

#create a box:
26
id_box = O.bodies.append(box((0,0,0),(5,5,.1),fixed=True,material=Mat))
27 28 29 30 31 32 33 34


#### show how to use clump():


#create spheres parallel to x-axis:
bodyList1 = []
for ii in range(-2,2):
35
	bodyList1.append(O.bodies.append(sphere((ii,0,1),radius=.5,material=Mat)))
36 37 38 39

#create spheres parallel to y-axis:
bodyList2 = []
for ii in range(-3,2):
40
	bodyList2.append(O.bodies.append(sphere((-1,ii,1.5),radius=.5,material=Mat)))
41 42 43 44 45

#create 2 clumps, and give each clump a different color
idClump1=O.bodies.clump(bodyList1)
idClump2=O.bodies.clump(bodyList2)
for ii in bodyList1:
46
	O.bodies[ii].shape.color=(.1,.5,.1)
47
for ii in bodyList2:
48
	O.bodies[ii].shape.color=(.2,.2,.7)
49 50 51 52 53

#definition for getting informations from all clumps:
def getClumpInfo():
	for b in O.bodies:
		if b.isClump:
54
			print('Clump ',b.id,' has following members:')
55
			keys = list(b.shape.members.keys())
56
			for ii in range(0,len(keys)):
57
				print('- Body ',keys[ii])
58 59 60 61 62 63 64

O.dt=1e-6


#### show how to use releaseFromClump():


65
print('\nSTATE before releasing spheres from clump ------------')
66 67
getClumpInfo()

68
input('\nPress Play button ... and look what happens.\n Then press Pause button and press ENTER on console!')
69 70 71 72 73

for ii in bodyList2:
	if ii > max(bodyList2)-2:
		clId = O.bodies[ii].clumpId
		O.bodies.releaseFromClump(ii,clId)
74
		print('Sphere ',ii,' released from clump ',clId)
75

76
print('\nSTATE after releasing spheres from clump ------------')
77 78
getClumpInfo()

79
print('\nPress Play button again ... ')