File: addToClump-example.py

package info (click to toggle)
yade 2025.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,308 kB
  • sloc: cpp: 93,298; python: 50,409; sh: 577; makefile: 162
file content (73 lines) | stat: -rw-r--r-- 2,233 bytes parent folder | download | duplicates (2)
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
# -*- encoding=utf-8 -*-
'''This example shows usage of addToClump() and appendClumped().'''

from yade import pack, export, qt

#define material for all bodies:
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:
id_box = O.bodies.append(box((0, 0, 0), (2, 2, .1), fixed=True, material=Mat))

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

#create 2 clumps:
clump1 = O.bodies.appendClumped([sphere([0, 0, 1], material=Mat, radius=0.5), sphere([0.2, 0, 1], material=Mat, radius=0.5)])
clump2 = O.bodies.appendClumped([sphere([3, 1, 2], material=Mat, radius=0.5), sphere([3.2, 1, 2], material=Mat, radius=0.5)])

#get clump ids:
id_clump1 = clump1[0]
id_clump2 = clump2[0]


#definition for getting informations from all clumps:
def getClumpInfo():
	for b in O.bodies:
		if b.isClump:
			print('Clump ', b.id, ' has following members:')
			keys = list(b.shape.members.keys())
			for ii in range(0, len(keys)):
				print('- Body ', keys[ii])
			print('inertia:', b.state.inertia)
			print('mass:', b.state.mass, '\n')


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

#create a new sphere:
id_new = O.bodies.append(sphere([0, 0.2, 1], material=Mat, radius=0.5))

print('\nSTATE before adding sphere to clump ------------')
getClumpInfo()

#add a sphere to the clump:
O.bodies.addToClump([id_new], id_clump1)

print('\nSTATE after adding sphere to clump ------------')
getClumpInfo()

#add a clump to a clump:
O.bodies.addToClump([id_clump2], id_clump1)

print('\nSTATE after adding the second clump to clump ------------')
getClumpInfo()

#try to add clump member to a clump (should give error message):
#O.bodies.addToClump(1,id_clump1)
#try to add clump to the same clump (should give error message):
#O.bodies.addToClump(id_clump1,id_clump1)

O.dt = 1e-6

print('\nPress Play button ... ')
renderer = qt.Renderer()
qt.View()