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

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

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