This is an example of how to use the netdem library.
1from signal import pause
2import sys
3import os
4import math
5
6
7dir_path = os.path.dirname(os.path.realpath(__file__))
8sys.path.append(dir_path + "/../../build/lib/")
9from netdem import *
10
11
12sim = Simulation()
13sim.domain_manager.SetBound(-0.6, -0.6, -0.6, 0.6, 0.6, 1.2)
14sim.domain_manager.SetCellSpacing(0.02, 0.02, 0.02)
15
16
17sim.dem_solver.contact_solver_factory.settings.solver_type\
18 = ContactSolverSettings.SolverType.automatic
19sim.dem_solver.contact_solver_factory.settings.sdf_potential_type = 0
20
21
22cnt_model_1 = LinearSpring(2.0e6, 1.0e6, 0.0, 0.0)
23cnt_model_1.label = "cnt_model_1"
24cnt_model_1_prt = sim.scene.InsertContactModel(cnt_model_1)
25
26cnt_model_2 = LinearSpring(2.0e6, 1.0e6, 0.0, 0.0)
27cnt_model_2.label = "cnt_model_2"
28cnt_model_2_prt = sim.scene.InsertContactModel(cnt_model_2)
29
30sim.scene.SetNumberOfMaterials(2)
31sim.scene.SetCollisionModel(0, 0, cnt_model_1_prt)
32sim.scene.SetCollisionModel(0, 1, cnt_model_1_prt)
33sim.scene.SetCollisionModel(1, 1, cnt_model_2_prt)
34
35sim.dem_solver.timestep = 1.0e-5
36
37
38stl_bot = STLModel()
39stl_bot.InitFromSTL(dir_path + "/data/ring_bot.stl")
40stl_mid = STLModel()
41stl_mid.InitFromSTL(dir_path + "/data/ring_mid.stl")
42
43stl_top = STLModel()
44stl_top.InitFromSTL(dir_path + "/data/ring_mid.stl")
45tmp_vertices = stl_top.vertices
46for i in range(0, len(tmp_vertices)):
47 tmp_vertices[i] = [tmp_vertices[i][0],
48 tmp_vertices[i][1], tmp_vertices[i][2] * 4.0]
49stl_top.vertices = tmp_vertices
50
51
52bot_wall_ids = list([])
53for facet in stl_bot.facets:
54 triangle = Triangle(stl_bot.vertices[facet[0]],
55 stl_bot.vertices[facet[1]],
56 stl_bot.vertices[facet[2]])
57 shape_ptr = sim.scene.InsertShape(triangle)
58 wall = Wall(shape_ptr)
59 wall.material_type = 1
60 w_ptr = sim.scene.InsertWall(wall)
61 bot_wall_ids.append(w_ptr.id)
62
63num_mid_rings = 16
64
65stl_mid.Translate([0, 0, 0.02])
66stl_mid.Translate([0, 0, -0.00665])
67
68for i in range(0, num_mid_rings):
69 stl_mid.Translate([0, 0, 0.00665])
70
71 mid_wall_ids = list([])
72 for facet in stl_mid.facets:
73 triangle = Triangle(stl_mid.vertices[facet[0]],
74 stl_mid.vertices[facet[1]],
75 stl_mid.vertices[facet[2]])
76 shape_ptr = sim.scene.InsertShape(triangle)
77 wall = Wall(shape_ptr)
78 wall.material_type = 1
79 w_ptr = sim.scene.InsertWall(wall)
80 mid_wall_ids.append(w_ptr.id)
81
82 tmp_integrator = WallMotionIntegrator()
83 tmp_integrator.label = "wall_motion_integrator_" + str(i)
84 tmp_integrator.enable_translation = [True, False, False]
85 tmp_integrator.update_with_scene = False
86 tmp_integrator.mass = 0.0378
87 tmp_integrator.Init(sim)
88 tmp_integrator.Add(mid_wall_ids)
89 sim.modifier_manager.Insert(tmp_integrator)
90
91stl_top.Translate([0, 0, 0.02])
92stl_top.Translate([0, 0, 0.00665 * num_mid_rings])
93
94for facet in stl_top.facets:
95 triangle = Triangle(stl_top.vertices[facet[0]],
96 stl_top.vertices[facet[1]],
97 stl_top.vertices[facet[2]])
98 shape_ptr = sim.scene.InsertShape(triangle)
99 wall = Wall(shape_ptr)
100 wall.material_type = 1
101 w_ptr = sim.scene.InsertWall(wall)
102
103
104grav = Gravity()
105grav.Init(sim)
106sim.modifier_manager.Insert(grav)
107sim.modifier_manager.Enable(grav.label)
108
109
110unbal = UnbalancedForceRatioEvaluator()
111unbal.Init(sim)
112sim.modifier_manager.Insert(unbal)
113sim.modifier_manager.Enable(unbal.label)
114
115
116data_dumper = DataDumper()
117data_dumper.Init(sim)
118data_dumper.SetRootPath(dir_path + "/../../tmp/simple_shear/out/")
119data_dumper.SetSaveByTime(0.01)
120data_dumper.dump_wall_info = True
121data_dumper.dump_contact_info = True
122data_dumper.dump_mesh = True
123data_dumper.SaveShapeInfoAsSTL()
124sim.modifier_manager.Insert(data_dumper)
125sim.modifier_manager.Enable(data_dumper.label)
126
127
128sphere = Sphere(0.01)
129particle_shape_ptr = sim.scene.InsertShape(sphere)
130
131
132pack_generator = PackGenerator()
133particle_list = pack_generator.GetGridPack(
134 0.2, 0.2, 0.4, 0, 0, 0.22, 18, 18, 36, particle_shape_ptr)
135for p in particle_list:
136 p.SetDensity(7530)
137 p.damp_numerical = 0.7
138
139
140sim.scene.InsertParticle(particle_list)
141sim.Run(1.0)
142
143
144for p in sim.scene.particle_list:
145 if p.pos[2] < 0 or p.pos[2] > 0.12 \
146 or math.sqrt(p.pos[0] * p.pos[0] + p.pos[1] * p.pos[1]) > 0.154:
147 sim.scene.RemoveParticle(p)
148
149cnt_model_2_prt.SetProperty('mu', 0.1)
150
151
152plane = Plane(0, 0, 0.13, 0, 0, -1)
153plane.SetExtent(0.5)
154plane_ptr = sim.scene.InsertShape(plane)
155wall_top = Wall(plane_ptr)
156wall_top_ptr = sim.scene.InsertWall(wall_top)
157
158servo_top = WallServoControl(2e6, Math.PI * 0.308 * 0.308 / 4)
159servo_top.label = "servo_top"
160servo_top.Init(sim)
161servo_top.target_pressure = 4e5
162servo_top.SetWall([wall_top_ptr.id])
163tmp = sim.modifier_manager.Insert(servo_top)
164sim.modifier_manager.Enable(servo_top.label)
165servo_top_ptr = WallServoControl.Cast(tmp)
166
167
168while True:
169 sim.Run(0.01)
170 if servo_top_ptr.achieved:
171 break
172
173
174wall_motion_control = WallMotionControl()
175wall_motion_control.Init(sim)
176wall_motion_control.SetWall(bot_wall_ids)
177wall_motion_control.SetVelocity(0.005, 0, 0)
178sim.modifier_manager.Insert(wall_motion_control)
179sim.modifier_manager.Enable(wall_motion_control.label)
180
181
182for i in range(0, num_mid_rings):
183 tmp_label = "wall_motion_integrator_" + str(i)
184 sim.modifier_manager.Enable(tmp_label)
185
186
187sim.Run(3.0)