File: replaceByClumps-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 (77 lines) | stat: -rw-r--r-- 2,485 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
74
75
76
77
# -*- encoding=utf-8 -*-
'''This example shows usage of clumpTemplate(), replaceByClumps() and getRoundness().'''

#define material for all bodies:
id_Mat = O.materials.append(FrictMat(young=1e7, 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])
]

from yade import qt

qt.Controller()
qt.View()

#create a box:
id_box = O.bodies.append(box((0, 0, 0), (2, 2, .1), fixed=True, material=Mat))

#create assembly of spheres:
sp = pack.SpherePack()
sp.makeCloud(minCorner=(-1.5, -1.5, .1), maxCorner=(1.5, 1.5, 2), rMean=.2, rRelFuzz=.5, num=100, periodic=False)
O.bodies.append([sphere(c, r, material=Mat) for c, r in sp])

print(len(sp), ' particles generated.')
print('Roundness coefficient without clumps is: ', O.bodies.getRoundness())

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

#dyad:
relRadList1 = [1, 1]
relPosList1 = [[1, 0, 0], [-1, 0, 0]]

#peanut:
relRadList2 = [.5, 1, .5]
relPosList2 = [[1, 0, 0], [0, 0, 0], [-1, 0, 0]]

#stick:
relRadList3 = [1, 1, 1, 1, 1]
relPosList3 = [[0, 1, 0], [0, 2, 0], [0, 3, 0], [0, 4, 0], [0, 5, 0]]

templates = []
templates.append(clumpTemplate(relRadii=relRadList1, relPositions=relPosList1))
templates.append(clumpTemplate(relRadii=relRadList2, relPositions=relPosList2))
templates.append(clumpTemplate(relRadii=relRadList3, relPositions=relPosList3))

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

#replace by 50% dyads, 30% peanuts and 10% sticks:
O.bodies.replaceByClumps(templates, [.5, .3, .1])

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

#create a list of all standalone spheres:
standaloneList = []
for b in O.bodies:
	if b.isStandalone:
		standaloneList.append(b.id)

print('Roundness coefficient for spheres and clumps is: ', O.bodies.getRoundness())
print('Roundness coefficient just for clumps is: ', O.bodies.getRoundness(standaloneList))

O.dt = 1e-6

#NOTE, that after replacing some overlaps may occur.
#So after replacing calm() function may be helpful:
if 0:
	print('\nPlease wait a minute ...\n')
	O.engines = O.engines + [PyRunner(iterPeriod=10000, command='calm()', label='calmRunner')]
	O.run(1000000, True)
	calmRunner.dead = True

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