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
12class WallMotionIntegrator(Modifier):
13 wall_id_list = set([])
14 wall_list = list([])
15 mass = 4.6
16
17 def __init__(self):
18 super().__init__()
19 self.label = "wall_motion_integrator"
20 self.cycle_point = DEMSolver.CyclePoint.mid_4
21 self.update_with_scene = False
22
23
24 def Clone(self):
25 tmp = self
26 return tmp
27
28 def Add(self, ids):
29 for id in ids:
30 self.wall_id_list.add(id)
31 self.Update()
32
33 def Execute(self):
34 dt = sim.dem_solver.timestep
35
36 fx = 0
37 for w_ptr in sim.scene.wall_list:
38 fx += w_ptr.force[0]
39
40 dv = fx / self.mass * dt
41 for w_ptr in self.wall_list:
42 w_ptr.SetVelocity(w_ptr.vel[0] + dv, 0, 0)
43
44 def Update(self):
45 self.wall_list.clear()
46 if not self.scene is None:
47 for id in self.wall_id_list:
48 w_ptr = self.scene.FindWall(id)
49 if not w_ptr is None:
50 self.wall_list.append(w_ptr)
51 else:
52 print("warning: null scene, please initialize: ")
53
54
55
56sim = Simulation()
57sim.domain_manager.SetBound(-0.6, -0.6, -0.6, 0.6, 0.6, 1.2)
58sim.domain_manager.SetCellSpacing(0.02, 0.02, 0.02)
59
60
61sim.dem_solver.contact_solver_factory.settings.solver_type = (
62 ContactSolverSettings.SolverType.automatic
63)
64sim.dem_solver.contact_solver_factory.settings.sdf_potential_type = 0
65
66
67cnt_model_1 = LinearSpring(2.0e4, 1.0e4, 0.5, 0.0)
68cnt_model_1.label = "cnt_model_1"
69cnt_model_1_prt = sim.scene.InsertContactModel(cnt_model_1)
70
71cnt_model_2 = LinearSpring(2.0e4, 1.0e4, 0.1, 0.0)
72cnt_model_2.label = "cnt_model_2"
73cnt_model_2_prt = sim.scene.InsertContactModel(cnt_model_2)
74
75sim.scene.SetNumberOfMaterials(2)
76sim.scene.SetCollisionModel(0, 0, cnt_model_1_prt)
77sim.scene.SetCollisionModel(0, 1, cnt_model_1_prt)
78sim.scene.SetCollisionModel(1, 1, cnt_model_2_prt)
79
80
81sphere = Sphere(0.01)
82sphere_ptr = sim.scene.InsertShape(sphere)
83
84stl_bot = STLModel()
85stl_bot.InitFromSTL(dir_path + "/data/ring_bot.stl")
86stl_mid = STLModel()
87stl_mid.InitFromSTL(dir_path + "/data/ring_mid.stl")
88
89
90bot_wall_ids = list([])
91for facet in stl_bot.facets:
92 triangle = Triangle(
93 stl_bot.vertices[facet[0]],
94 stl_bot.vertices[facet[1]],
95 stl_bot.vertices[facet[2]],
96 )
97 shape_ptr = sim.scene.InsertShape(triangle)
98 wall = Wall(shape_ptr)
99 wall.material_type = 1
100 w_ptr = sim.scene.InsertWall(wall)
101 bot_wall_ids.append(w_ptr.id)
102
103stl_mid.Translate([0, 0, 0.02])
104stl_mid.Translate([0, 0, -0.00665])
105
106wall_motion_integrator_list = [None] * 17
107for i in range(0, 17):
108 stl_mid.Translate([0, 0, 0.00665])
109
110 mid_wall_ids = list([])
111 for facet in stl_mid.facets:
112 triangle = Triangle(
113 stl_mid.vertices[facet[0]],
114 stl_mid.vertices[facet[1]],
115 stl_mid.vertices[facet[2]],
116 )
117 shape_ptr = sim.scene.InsertShape(triangle)
118 wall = Wall(shape_ptr)
119 wall.material_type = 1
120 w_ptr = sim.scene.InsertWall(wall)
121 mid_wall_ids.append(w_ptr.id)
122
123 wall_motion_integrator_list[i] = WallMotionIntegrator()
124 wall_motion_integrator_list[i].label = "wall_motion_integrator_" + str(i)
125 wall_motion_integrator_list[i].Init(sim)
126 wall_motion_integrator_list[i].Add(mid_wall_ids)
127 sim.modifier_manager.Insert(wall_motion_integrator_list[i])
128 sim.modifier_manager.Enable(wall_motion_integrator_list[i].label)
129
130
131grav = Gravity()
132grav.Init(sim)
133sim.modifier_manager.Insert(grav)
134sim.modifier_manager.Enable(grav.label)
135
136
137data_dumper = DataDumper()
138data_dumper.Init(sim)
139data_dumper.SetRootPath(dir_path + "/../../tmp/simple_shear/out/")
140data_dumper.SetSaveByCycles(100)
141data_dumper.dump_wall_info = True
142data_dumper.dump_contact_info = True
143data_dumper.dump_mesh = True
144data_dumper.SaveShapeInfoAsSTL()
145sim.modifier_manager.Insert(data_dumper)
146sim.modifier_manager.Enable(data_dumper.label)
147
148
149pack_generator = PackGenerator()
150particle_list = pack_generator.GetGridPack(
151 0.2, 0.2, 0.36, 0, 0, 0.2, 18, 18, 30, sphere_ptr
152)
153for p in particle_list:
154 p.SetDensity(7530)
155 p.damp_numerical = 0.7
156
157
158sim.scene.InsertParticle(particle_list)
159for i in range(0, 100):
160 sim.Run(0.01)
161 for p in sim.scene.particle_list:
162 p.SetVelocity(0, 0, 0)
163 p.SetSpin(0, 0, 0)
164
165
166for p in sim.scene.particle_list:
167 if (
168 p.pos[2] < 0
169 or p.pos[2] > 0.12
170 or math.sqrt(p.pos[0] * p.pos[0] + p.pos[1] * p.pos[1]) > 0.154
171 ):
172 sim.scene.RemoveParticle(p)
173
174
175plane = Plane(0, 0, 0.13, 0, 0, -1)
176plane.SetExtent(0.5)
177plane_ptr = sim.scene.InsertShape(plane)
178wall_top = Wall(plane_ptr)
179wall_top_ptr = sim.scene.InsertWall(wall_top)
180
181servo_top = WallServoControl(2e6, Math.PI * 0.304 * 0.304 / 4)
182servo_top.label = "servo_top"
183servo_top.Init(sim)
184servo_top.target_pressure = 4e5
185servo_top.SetWall([wall_top_ptr.id])
186tmp = sim.modifier_manager.Insert(servo_top)
187sim.modifier_manager.Enable(servo_top.label)
188servo_top_ptr = WallServoControl.Cast(tmp)
189
190
191while True:
192 sim.Run(0.01)
193 if servo_top_ptr.achieved:
194 break
195
196
197wall_motion_control = WallMotionControl()
198wall_motion_control.Init(sim)
199wall_motion_control.SetWall(bot_wall_ids)
200wall_motion_control.SetVelocity(0.005, 0, 0)
201sim.modifier_manager.Insert(wall_motion_control)
202sim.modifier_manager.Enable(wall_motion_control.label)
203
204sim.Run(3.0)