File: simulation.py

package info (click to toggle)
yade 2026.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,448 kB
  • sloc: cpp: 97,645; python: 52,173; sh: 677; makefile: 162
file content (59 lines) | stat: -rw-r--r-- 2,076 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
# -*- encoding=utf-8 -*-
######################################################################
# Gravity deposition as a simple simulation illustrating creation of
# cohesive contacts and deleting the unwanted between different
# agglomerates
#
# Using CpmMat, but the same procedure can be used with any material
######################################################################
from yade import ymport

wall = O.bodies.append(wall((0, 0, 3), 2))

O.materials.append(CpmMat(neverDamage=True, frictionAngle=0))

# load spheres from file, including information of their agglomerates ids
attrs = []
print("\nPlease see README if you have errors when running this example.\n")
sp = ymport.textExt('/tmp/compressed.txt', format='x_y_z_r_attrs', attrs=attrs)
n = max(int(a[0]) for a in attrs) + 1
colors = [randomColor() for _ in range(n)]
for s, a in zip(sp, attrs):
	aa = int(a[0])
	s.agglomerate = aa
	s.shape.color = colors[aa]
O.bodies.append(sp)

factor = 1.5
O.engines = [
        ForceResetter(),
        InsertionSortCollider([Bo1_Sphere_Aabb(aabbEnlargeFactor=factor, label='bo1aabbs'),
                               Bo1_Wall_Aabb()]),
        InteractionLoop(
                [Ig2_Sphere_Sphere_ScGeom(interactionDetectionFactor=factor, label='ig2sss'),
                 Ig2_Wall_Sphere_ScGeom()],
                [Ip2_FrictMat_FrictMat_FrictPhys(), Ip2_CpmMat_CpmMat_CpmPhys(cohesiveThresholdIter=1)],
                [Law2_ScGeom_FrictPhys_CundallStrack(), Law2_ScGeom_CpmPhys_Cpm()]
        ),
        NewtonIntegrator(gravity=(0, 0, -30)),
]
O.dt = PWaveTimeStep()

# create cohesive interactions, possible also between different agglomerates
O.step()
ig2sss.interactionDetectionFactor = bo1aabbs.aabbEnlargeFactor = 1

# delete the inter-agglomerate interactions
for i in O.interactions:
	b1, b2 = [O.bodies[ii] for ii in (i.id1, i.id2)]
	if not (isinstance(b1.shape, Sphere) and isinstance(b2.shape, Sphere)):
		continue
	if b1.agglomerate != b2.agglomerate:
		O.interactions.erase(i.id1, i.id2)
O.step()

try:
	from yade import qt
	qt.View()
except:
	pass