NetDEM v1.0
Loading...
Searching...
No Matches
simple_shear_sphere_v0.py

This is an example of how to use the netdem library.

1import sys
2import os
3import math
4
5# env
6dir_path = os.path.dirname(os.path.realpath(__file__))
7sys.path.append(dir_path + "/../../build/lib/")
8from netdem import *
9
10# sim settings
11sim = Simulation()
12sim.domain_manager.SetBound(-0.6, -0.6, -0.6, 0.6, 0.6, 0.6)
13sim.domain_manager.SetCellSpacing(0.02, 0.02, 0.02)
14
15# solver settings
16sim.dem_solver.contact_solver_factory.settings.solver_type \
17 = ContactSolverSettings.SolverType.automatic
18sim.dem_solver.contact_solver_factory.settings.sdf_potential_type = 0
19
20# contact model
21cnt_model_1 = LinearSpring(2.0e4, 1.0e4, 0.5, 0.0)
22cnt_model_1.label = "cnt_model_1"
23cnt_model_1_prt = sim.scene.InsertContactModel(cnt_model_1)
24
25cnt_model_2 = LinearSpring(2.0e4, 1.0e4, 0.0, 0.0)
26cnt_model_2.label = "cnt_model_2"
27cnt_model_2_prt = sim.scene.InsertContactModel(cnt_model_2)
28
29sim.scene.SetNumberOfMaterials(2)
30sim.scene.SetCollisionModel(0, 0, cnt_model_1_prt)
31sim.scene.SetCollisionModel(0, 1, cnt_model_1_prt)
32sim.scene.SetCollisionModel(1, 1, cnt_model_2_prt)
33
34# shape templates
35sphere = Sphere(0.01)
36sphere_ptr = sim.scene.InsertShape(sphere)
37
38ring_bot = TriMesh()
39ring_bot.InitFromSTL("data/ring_bot.stl")
40ring_bot.AlignAxes()
41ring_bot_ptr = sim.scene.InsertShape(ring_bot)
42
43ring_mid = TriMesh()
44ring_mid.InitFromSTL("data/ring_mid.stl")
45ring_mid.AlignAxes()
46ring_mid_ptr = sim.scene.InsertShape(ring_mid)
47
48# create particles as ring
49h_ref = 0.00749305 - 0.02 + 0.00665
50
51p_bot = Particle()
52p_bot.material_type = 1
53p_bot.SetShape(ring_bot_ptr)
54p_bot.SetPosition(0, 0, h_ref)
55p_bot.SetRodrigues(Math.PI, 1, 0, 0)
56p_bot.SetDensity(7530)
57p_bot.damp_viscous = 3
58p_bot_ptr = sim.scene.InsertParticle(p_bot)
59
60for i in range(1, 18):
61 p_mid = Particle()
62 p_mid.material_type = 1
63 p_mid.SetShape(ring_mid_ptr)
64 p_mid.SetPosition(0, 0, 0.003325 + i * 0.00665)
65 p_mid.SetDensity(7530)
66 p_mid.damp_viscous = 3
67 p_mid_ptr = sim.scene.InsertParticle(p_mid)
68
69# create a motion control for particles
70motion_control = ParticleMotionControl()
71motion_control.Init(sim)
72motion_control.SetFixed(p_bot_ptr.id)
73tmp = sim.modifier_manager.Insert(motion_control)
74sim.modifier_manager.Enable(motion_control.label)
75motion_control_ptr = ParticleMotionControl.Cast(tmp)
76
77# gravity
78grav = Gravity()
79grav.Init(sim)
80sim.modifier_manager.Insert(grav)
81sim.modifier_manager.Enable(grav.label)
82
83# output
84data_dumper = DataDumper()
85data_dumper.Init(sim)
86data_dumper.SetRootPath(dir_path + "/../../tmp/simple_shear/out/")
87data_dumper.SetSaveByCycles(100)
88data_dumper.dump_wall_info = True
89data_dumper.dump_contact_info = True
90data_dumper.dump_mesh = True
91data_dumper.SaveShapeInfoAsSTL()
92sim.modifier_manager.Insert(data_dumper)
93sim.modifier_manager.Enable(data_dumper.label)
94
95# relax the rings
96sim.Run(2.0)
97
98# fix the top two rings
99motion_control_ptr.SetFixed(16)
100motion_control_ptr.SetFixed(17)
101
102# generate particles
103cylinder = Cylinder(0.154, 0.2)
104cylinder_stl = cylinder.GetSTLModel(500)
105cylinder_stl.Translate([0, 0, 0.1])
106
107pack_generator = PackGenerator()
108particle_list = pack_generator.GetVoronoiPack(
109 cylinder_stl, 100, sphere_ptr)
110for p in particle_list:
111 p.SetDensity(7530)
112 p.damp_numerical = 0.7
113
114# insert particles and rest
115sim.scene.InsertParticle(particle_list)
116sim.Run(1.0)
117
118# remove extra particles
119for p in sim.scene.particle_list:
120 if p.pos[2] < 0 or p.pos[2] > 0.11 \
121 or math.sqrt(p.pos[0] * p.pos[0] + p.pos[1] * p.pos[1]) > 0.154:
122 if p.id >= 18:
123 sim.scene.RemoveParticle(p)
124
125# add top wall and apply servo-control
126plane = Plane(0, 0, 0.11, 0, 0, -1)
127plane.SetExtent(0.5)
128plane_ptr = sim.scene.InsertShape(plane)
129wall_top = Wall(plane_ptr)
130wall_top_ptr = sim.scene.InsertWall(wall_top)
131
132servo_top = WallServoControl(2e6, Math.PI * 0.304 * 0.304 / 4)
133servo_top.label = "servo_top"
134servo_top.Init(sim)
135servo_top.target_pressure = 4e5
136servo_top.SetWall([wall_top_ptr.id])
137tmp = sim.modifier_manager.Insert(servo_top)
138sim.modifier_manager.Enable(servo_top.label)
139servo_top_ptr = WallServoControl.Cast(tmp)
140
141# keep loading until target pressure is achieved
142while True:
143 sim.Run(0.01)
144 if servo_top_ptr.achieved:
145 break
146
147# moving the bot ring, v = a * t + b
148motion_control_ptr.SetLinearVelocity(0, 0, 0.005, 0, 0, 0, 0)
149
150sim.Run(3.0)