7def print_bool(arg, prefix = ""):
16def print_dbl(arg, prefix = ""):
18 str = prefix +
"%4.6e\n" % (arg)
21def print_int(arg, prefix = ""):
22 str = prefix +
"%d\n" % (arg)
25def print_dbl_list(arg, prefix = ""):
29 str +=
"%4.6e" % (arg[i])
37def print_int_list(arg, prefix = ""):
41 str +=
"%d" % (arg[i])
49def serialize_matrix_list(p):
58def write_point_geo(geof, p_id, x, h):
59 geof.write(
"Point(%d) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (p_id, x[0], x[1], x[2], h))
62def write_line_geo(geof, l_id, p1_id, p2_id):
63 geof.write(
"Line(%d) = {%d, %d};\n" % (l_id, p1_id, p2_id))
66def write_cir_line_geo(geof, l_id, p1_id, p2_id, p3_id):
67 geof.write(
"Circle(%d) = {%d, %d, %d};\n" % (l_id, p1_id, p2_id, p3_id))
70def write_contact_zone_part(inpf, R_contact_factor, damping_active, friction_active, beta_n_eps, friction_coeff, Kn_factor, beta_n_factor, zone_string, Kn):
71 inpf.write(
" Zone_%s:\n" % (zone_string))
72 inpf.write(
" Contact_Radius_Factor: %4.6e\n" % (R_contact_factor))
74 if damping_active ==
False:
75 inpf.write(
" Damping_On: false\n")
76 if friction_active ==
False:
77 inpf.write(
" Friction_On: false\n")
79 inpf.write(
" Kn: %4.6e\n" % (Kn))
80 inpf.write(
" Epsilon: %4.6e\n" % (beta_n_eps))
81 inpf.write(
" Friction_Coeff: %4.6e\n" % (friction_coeff))
82 inpf.write(
" Kn_Factor: %4.6e\n" % (Kn_factor))
83 inpf.write(
" Beta_n_Factor: %4.6e\n" % (beta_n_factor))
85def write_material_zone_part(inpf, zone_string, horizon, rho, K, G, Gc):
86 inpf.write(
" Zone_%s:\n" % (zone_string))
87 inpf.write(
" Type: PDState\n")
88 inpf.write(
" Horizon: %4.6e\n" % (horizon))
89 inpf.write(
" Density: %4.6e\n" % (rho))
90 inpf.write(
" Compute_From_Classical: true\n")
91 inpf.write(
" K: %4.6e\n" % (K))
92 inpf.write(
" G: %4.6e\n" % (G))
93 inpf.write(
" Gc: %4.6e\n" % (Gc))
94 inpf.write(
" Influence_Function:\n")
95 inpf.write(
" Type: 1\n")
97def copy_contact_zone(inpf, zone_numbers, zone_copy_from):
98 for s
in zone_numbers:
99 inpf.write(
" Zone_%d:\n" % (s))
100 inpf.write(
" Copy_Contact_Data: " + print_int_list(zone_copy_from))
103 return 3. * K * (1. - 2. * nu)
106 return E / (2. * (1. + nu))
109def get_eff_k(k1, k2):
110 return 2. * k1 * k2 / (k1 + k2)
117def get_center(p1, p2):
118 return [0.5*(p1[i] + p2[i])
for i
in range(3)]
120def rotate(p, theta, axis):
123 axis_np = np.array(axis)
129 p_dot_n = np.dot(p_np,axis_np)
132 n_cross_p = np.cross(axis_np, p_np)
134 return (1. - ct) * p_dot_n * axis_np + ct * p_np + st * n_cross_p
136def get_ref_rect_points(center, L, W, add_center = False):
140 points.append(center)
142 points.append([center[0] - 0.5*L, center[1] - 0.5*W, center[2]])
143 points.append([center[0] + 0.5*L, center[1] - 0.5*W, center[2]])
144 points.append([center[0] + 0.5*L, center[1] + 0.5*W, center[2]])
145 points.append([center[0] - 0.5*L, center[1] + 0.5*W, center[2]])
149def get_ref_triangle_points(center, radius, add_center = False):
168 cp = np.cos(np.pi/6.)
169 sp = np.sin(np.pi/6.)
173 points.append([sim_Cx, sim_Cy, sim_Cz])
174 points.append([sim_Cx, sim_Cy + sim_radius, sim_Cz])
175 points.append([sim_Cx - sim_radius*cp, sim_Cy - sim_radius*sp, sim_Cz])
176 points.append([sim_Cx + sim_radius*cp, sim_Cy - sim_radius*sp, sim_Cz])
180def get_ref_hex_points(center, radius, add_center = False):
205 rotate_axis = [0., 0., 1.]
209 points.append(center)
212 xi = rotate(axis, i*np.pi/3., rotate_axis)
213 points.append([center[i] + radius * xi[i]
for i
in range(3)])
217def get_ref_drum_points(center, radius, width, add_center = False):
242 rotate_axis = [0., 0., 1.]
244 x1 = rotate(axis, np.pi/3., rotate_axis)
245 x2 = rotate(axis, -np.pi/3., rotate_axis)
249 points.append(center)
252 points.append([center[i] + width*0.5*axis[i]
for i
in range(3)])
254 points.append([center[i] + radius*x1[i]
for i
in range(3)])
256 points.append([center[i] + radius*x1[i] - radius*axis[i]
for i
in range(3)])
258 points.append([center[i] - width*0.5*axis[i]
for i
in range(3)])
260 v6 = [center[i] + radius*x2[i]
for i
in range(3)]
261 points.append([v6[i] - radius*axis[i]
for i
in range(3)])
267def does_rect_intersect_rect(r1, r2, padding):
270 r1_padding = [r1[0] - padding, r1[1] - padding, r1[2], r1[3] + padding, r1[4] + padding, r1[5]]
272 return r1_padding[0] < r2[3]
and r1_padding[3] > r2[0]
and r1_padding[1] < r2[4]
and r1_padding[4] > r2[1]
274def does_rect_intersect_rect_use_pair_coord(r1, r2, padding):
277 p1_r1_padding = [r1[0][0] - padding, r1[0][1] - padding, r1[0][2]]
278 p2_r1_padding = [r1[1][0] + padding, r1[1][1] + padding, r1[0][2]]
283 return p1_r1_padding[0] < p2_r2[0]
and p2_r1_padding[0] > p1_r2[0]
and p1_r1_padding[1] < p2_r2[1]
and p2_r1_padding[1] > p1_r2[1]
286def does_particle_intersect_rect(p, r2, padding):
289 pc = [p[1], p[2], p[3]]
290 p_rect = [pc[0] - pr, pc[1] - pr, pc[2], pc[1] + pr, pc[2] + pr, pc[2]]
292 return does_rect_intersect_rect(p_rect, r2, padding)
294def does_particle_intersect(p, particles, rect, padding):
298 p_center = [p[i+1]
for i
in range(3)]
300 p_rect = [p_center[0] - p_r, p_center[1] - p_r, p_center[2], p_center[0] + p_r, p_center[1] + p_r, p_center[2]]
302 if p_rect[0] < rect[0] + padding
or p_rect[1] < rect[1] + padding
or p_rect[3] > rect[3] - padding
or p_rect[4] > rect[4] - padding:
306 pq = np.array([p[i+1] - q[i+1]
for i
in range(3)])
307 if np.linalg.norm(pq) <= p[-1] + q[-1] + padding:
313def particle_locations(inp_dir, pp_tag, center, padding, max_y, mesh_size, R1, R2, id_choices1, id_choices2, N1, N2, rect, z_coord, add_orient = True):
316 sim_inp_dir = str(inp_dir)
318 """Generate particle location data"""
325 rect_L = rect[3] - rect[0]
326 rect_W = rect[4] - rect[1]
328 if method_to_use == 0:
332 while pcount < N2
and count < 100*N2:
334 print(
'large particle iter = ', count)
337 r = R2 + np.random.uniform(-0.1 * R2, 0.1 * R2)
338 x = center[0] + np.random.uniform(-0.5*rect_L + R2 + padding, 0.5*rect_L - R2- padding)
339 y = np.random.uniform(-0.5*rect_W + R2+padding, max_y - R2-padding)
340 p_zone = id_choices2[select_count % len(id_choices2)]
341 p = [p_zone, x, y, center[2], r]
344 pintersect = does_particle_intersect(p, particles, rect_L, rect_W, center, padding)
346 if pintersect ==
False:
356 while pcount < N1
and count < 100*N1:
358 print(
'small particle iter = ', count)
361 r = R1 + np.random.uniform(-0.1 * R1, 0.1 * R1)
362 x = center[0] + np.random.uniform(-0.5*rect_L + R1 + padding, 0.5*rect_L - R1- padding)
363 y = np.random.uniform(-0.5*rect_W + R1 + padding, max_y - R1 - padding)
367 p_zone = id_choices1[select_count % len(id_choices1)]
368 p = [p_zone, x,y,center[2], r]
371 pintersect = does_particle_intersect(p, particles, rect_L, rect_W, center, padding)
373 if pintersect ==
False:
380 elif method_to_use == 1:
387 rows = int((max_y - rect[1]) / (2. * check_r))
388 cols = int(rect_L / (2. * check_r))
390 print(rows, cols, N1, N2)
398 x_old_right = rect[3]
408 cy_accptd.append(y_old)
414 for i
in range(rows):
415 print(
'row = {}'.format(i), flush=
True)
418 y_old = get_max(cy_accptd) + get_max(row_rads)
429 if y_old + padding + get_max(row_rads) < max_y:
433 if num_p_cols > cols - 1
or j > 100*(N1 + N2):
436 if counter1 >= N1
and counter2 >= N2:
442 x_old_right = rect[3]
445 p_type = np.random.choice([0,1], size=1)[0]
457 p_zone = id_choices1[counter1 % len(id_choices1)]
460 p_zone = id_choices2[counter2 % len(id_choices2)]
463 r = r0 + np.random.uniform(-0.1 * r0, 0.1 * r0)
468 rph = np.random.uniform(-0.1 * r0, 0.05 * r0)
469 rpv = np.random.uniform(-0.05 * r0, 0.05 * r0)
470 cx0 = x_old_right - padding - r
472 cy = y_old + padding + r + rpv
475 rph = np.random.uniform(-0.05 * r0, 0.1 * r0)
476 rpv = np.random.uniform(-0.05 * r0, 0.05 * r0)
477 cx0 = x_old + padding + r
479 cy = y_old + padding + r + rpv
482 p = [p_zone, cx, cy, cz, r]
487 pintersect = does_particle_intersect(p, particles, rect, padding)
489 if pintersect ==
False:
490 print(i, p, flush=
True)
492 row_rads.append(p[4])
496 x_old_right = cx - p[4]
511 inpf = open(inp_dir +
'particle_locations_' + str(pp_tag) +
'.csv',
'w')
513 inpf.write(
"i, x, y, z, r, o\n")
516 inpf.write(
"%d, %Lf, %Lf, %Lf, %Lf, %Lf\n" % (int(p[0]), p[1], p[2], p[3], p[4], np.random.uniform(0., 2.*np.pi)))
519 inpf.write(
"i, x, y, z, r\n")
521 inpf.write(
"%d, %Lf, %Lf, %Lf, %Lf\n" % (int(p[0]), p[1], p[2], p[3], p[4]))
533 points.append([p[1], p[2], p[3]])
535 zones.append(int(p[0]))
537 points = np.array(points)
538 rads = np.array(rads)
539 zones = np.array(zones)
540 mesh = pv.PolyData(points)
541 mesh[
"radius"] = rads
543 pv.save_meshio(sim_inp_dir +
'particle_locations_' + str(pp_tag) +
'.vtu', mesh)
545 print(
'number of particles created = {}'.format(len(particles)), flush=
True)
547 return len(particles), particles
549def particle_locations_old(inp_dir, pp_tag, center, padding, max_y, mesh_size, R1, R2, id_choices1, id_choices2, N1, N2, rect, z_coord, add_orient = True):
551 """Generate particle location data"""
554 def does_intersect_old(p, r, R, particles, padding):
558 pq = np.array([p[i] - q[i]
for i
in range(3)])
559 if np.linalg.norm(pq) <= r + R + padding:
565 def does_intersect_rect_old(p, r, particles, padding, rect):
568 pr = [p[0] - r, p[1] - r, p[2], p[0] + r, p[1] + r, p[2]]
570 if pr[0] < rect[0] + padding
or pr[1] < rect[1] + padding
or pr[3] > rect[3] - padding
or pr[4] > rect[4] - padding:
600 rows = int((rect[3] - rect[0])/ check_r)
601 cols = int((rect[4] - rect[1])/ check_r)
607 x_old_right = rect[3]
620 for i
in range(rows):
623 y_old = cy + get_max(row_rads)
632 while num_p_cols < cols - 1
and j < 500:
637 x_old_right = rect[3]
647 p_zone = np.random.choice(id_choices1, size=1)[0]
649 p_zone = np.random.choice(id_choices2, size=1)[0]
652 r = r0 + np.random.uniform(-0.1 * r0, 0.1 * r0)
657 rph = np.random.uniform(-0.1 * r0, 0.1 * r0)
659 cx0 = x_old + pad + r
663 cx0 = x_old_right - pad - r
669 inters = does_intersect_rect_old([cx, cy, cz], r, particles, pad, rect)
670 inters_parts = does_intersect_old
673 particles.append([float(p_zone), cx, cy, cz, r])
688 inpf = open(inp_dir +
'particle_locations_' + str(pp_tag) +
'.csv',
'w')
690 inpf.write(
"i, x, y, z, r, o\n")
693 inpf.write(
"%d, %Lf, %Lf, %Lf, %Lf, %Lf\n" % (int(p[0]), p[1], p[2], p[3], p[4], np.random.uniform(0., 2.*np.pi)))
696 inpf.write(
"i, x, y, z, r\n")
698 inpf.write(
"%d, %Lf, %Lf, %Lf, %Lf\n" % (int(p[0]), p[1], p[2], p[3], p[4]))
710 points.append([p[1], p[2], p[3]])
712 zones.append(int(p[0]))
714 points = np.array(points)
715 rads = np.array(rads)
716 zones = np.array(zones)
717 mesh = pv.PolyData(points)
718 mesh[
"radius"] = rads
720 pv.save_meshio(sim_inp_dir +
'particle_locations_' + str(pp_tag) +
'.vtu', mesh)
722 print(
'number of particles created = {}'.format(len(particles)))
724 return len(particles), particles
727def generate_cir_particle_gmsh_input(inp_dir, filename, center, radius, mesh_size, pp_tag):
729 sim_inp_dir = str(inp_dir)
743 geof = open(sim_inp_dir + filename +
'_' + str(pp_tag) +
'.geo',
'w')
744 geof.write(
"cl__1 = 1;\n")
745 geof.write(
"Mesh.MshFileVersion = 2.2;\n")
750 geof.write(
"Point(1) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Cx, sim_Cy, sim_Cz, sim_h));
751 geof.write(
"Point(2) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Cx + sim_radius, sim_Cy, sim_Cz, sim_h))
752 geof.write(
"Point(3) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Cx - sim_radius, sim_Cy, sim_Cz, sim_h))
753 geof.write(
"Point(4) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Cx, sim_Cy + sim_radius, sim_Cz, sim_h))
754 geof.write(
"Point(5) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Cx, sim_Cy - sim_radius, sim_Cz, sim_h))
759 geof.write(
"Circle(1) = {2, 1, 4};\n")
760 geof.write(
"Circle(2) = {4, 1, 3};\n")
761 geof.write(
"Circle(3) = {3, 1, 5};\n")
762 geof.write(
"Circle(4) = {5, 1, 2};\n")
767 geof.write(
"Line Loop(1) = {2, 3, 4, 1};\n")
772 geof.write(
"Plane Surface(1) = {1};\n")
781 geof.write(
"Point{1} In Surface {1};")
787def generate_hex_particle_gmsh_input(inp_dir, filename, center, radius, mesh_size, pp_tag):
789 sim_inp_dir = str(inp_dir)
791 points = get_ref_hex_points(center, radius,
True)
796 geof = open(sim_inp_dir + filename +
'_' + str(pp_tag) +
'.geo',
'w')
797 geof.write(
"cl__1 = 1;\n")
798 geof.write(
"Mesh.MshFileVersion = 2.2;\n")
805 sts =
"Point({}) = ".format(i+1)
807 sts +=
"{}, {}, {}, {}".format(p[0], p[1], p[2], mesh_size)
814 geof.write(
"Line(1) = {2, 3};\n")
815 geof.write(
"Line(2) = {3, 4};\n")
816 geof.write(
"Line(3) = {4, 5};\n")
817 geof.write(
"Line(4) = {5, 6};\n")
818 geof.write(
"Line(5) = {6, 7};\n")
819 geof.write(
"Line(6) = {7, 2};\n")
824 geof.write(
"Line Loop(1) = {1, 2, 3, 4, 5, 6};\n")
829 geof.write(
"Plane Surface(1) = {1};\n")
838 geof.write(
"Point{1} In Surface {1};")
844def generate_tri_particle_gmsh_input(inp_dir, filename, center, radius, mesh_size, pp_tag):
846 sim_inp_dir = str(inp_dir)
849 points = get_ref_triangle_points(center, radius,
True)
854 geof = open(sim_inp_dir + filename +
'_' + str(pp_tag) +
'.geo',
'w')
855 geof.write(
"cl__1 = 1;\n")
856 geof.write(
"Mesh.MshFileVersion = 2.2;\n")
863 sts =
"Point({}) = ".format(i+1)
865 sts +=
"{}, {}, {}, {}".format(p[0], p[1], p[2], mesh_size)
872 geof.write(
"Line(1) = {2, 3};\n")
873 geof.write(
"Line(2) = {3, 4};\n")
874 geof.write(
"Line(3) = {4, 2};\n")
879 geof.write(
"Line Loop(1) = {1, 2, 3};\n")
884 geof.write(
"Plane Surface(1) = {1};\n")
893 geof.write(
"Point{1} In Surface {1};")
899def generate_drum2d_particle_gmsh_input(inp_dir, filename, center, radius, width, mesh_size, pp_tag):
901 sim_inp_dir = str(inp_dir)
904 points = get_ref_drum_points(center, radius, width,
True)
909 geof = open(sim_inp_dir + filename +
'_' + str(pp_tag) +
'.geo',
'w')
910 geof.write(
"cl__1 = 1;\n")
911 geof.write(
"Mesh.MshFileVersion = 2.2;\n")
918 sts =
"Point({}) = ".format(i+1)
920 sts +=
"{}, {}, {}, {}".format(p[0], p[1], p[2], mesh_size)
927 geof.write(
"Line(1) = {2, 3};\n")
928 geof.write(
"Line(2) = {3, 4};\n")
929 geof.write(
"Line(3) = {4, 5};\n")
930 geof.write(
"Line(4) = {5, 6};\n")
931 geof.write(
"Line(5) = {6, 7};\n")
932 geof.write(
"Line(6) = {7, 2};\n")
937 geof.write(
"Line Loop(1) = {1, 2, 3, 4, 5, 6};\n")
942 geof.write(
"Plane Surface(1) = {1};\n")
951 geof.write(
"Point{1} In Surface {1};")
956def generate_rect_container_gmsh_input(inp_dir, filename, pi1, pi2, dx, dy, mesh_size, pp_tag):
958 sim_inp_dir = str(inp_dir)
960 innr_pts = get_ref_rect_points(get_center(pi1, pi2), pi2[0] - pi1[0], pi2[1] - pi1[1])
962 outr_pts = get_ref_rect_points(get_center(pi1, pi2), pi2[0] - pi1[0] + 2*dx, pi2[1] - pi1[1] + 2*dy)
970 geof = open(sim_inp_dir + filename +
'_' + str(pp_tag) +
'.geo',
'w')
971 geof.write(
"cl__1 = 1;\n")
972 geof.write(
"Mesh.MshFileVersion = 2.2;\n")
977 p_id = write_point_geo(geof, p_id, outr_pts[i], h)
980 p_id = write_point_geo(geof, p_id, innr_pts[i], h)
984 l_id = write_line_geo(geof, l_id, 1, 2)
985 l_id = write_line_geo(geof, l_id, 2, 3)
986 l_id = write_line_geo(geof, l_id, 3, 4)
987 l_id = write_line_geo(geof, l_id, 4, 1)
989 l_id = write_line_geo(geof, l_id, 5, 6)
990 l_id = write_line_geo(geof, l_id, 6, 7)
991 l_id = write_line_geo(geof, l_id, 7, 8)
992 l_id = write_line_geo(geof, l_id, 8, 5)
995 geof.write(
"Line Loop(9) = {1, 2, 3, 4};\n")
996 geof.write(
"Line Loop(10) = {5, 6, 7, 8};\n")
999 geof.write(
"Plane Surface(11) = {9, 10};\n")
1004def generate_rigid_rect_container_moving_wall_setup_gmsh_input(inp_dir, filename, outer_rect, inner_rect, mesh_size, pp_tag):
1006 sim_inp_dir = str(inp_dir)
1009 sim_Lx_out1 = outer_rect[0]
1010 sim_Ly_out1 = outer_rect[1]
1011 sim_Lz_out1 = outer_rect[2]
1012 sim_Lx_out2 = outer_rect[3]
1013 sim_Ly_out2 = outer_rect[4]
1014 sim_Lz_out2 = outer_rect[5]
1017 sim_Lx_in1 = inner_rect[0]
1018 sim_Ly_in1 = inner_rect[1]
1019 sim_Lz_in1 = inner_rect[2]
1020 sim_Lx_in2 = inner_rect[3]
1021 sim_Ly_in2 = inner_rect[4]
1022 sim_Lz_in2 = inner_rect[5]
1030 geof = open(sim_inp_dir + filename +
'_' + str(pp_tag) +
'.geo',
'w')
1031 geof.write(
"cl__1 = 1;\n")
1032 geof.write(
"Mesh.MshFileVersion = 2.2;\n")
1056 geof.write(
"Point(1) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Lx_out1, sim_Ly_out1, sim_Lz_out1, sim_h))
1057 geof.write(
"Point(2) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Lx_out2, sim_Ly_out1, sim_Lz_out1, sim_h))
1058 geof.write(
"Point(3) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Lx_out2, sim_Ly_out2, sim_Lz_out1, sim_h))
1059 geof.write(
"Point(4) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Lx_out1, sim_Ly_out2, sim_Lz_out1, sim_h))
1061 geof.write(
"Point(5) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Lx_in1, sim_Ly_in1, sim_Lz_in1, sim_h))
1062 geof.write(
"Point(6) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Lx_in2, sim_Ly_in1, sim_Lz_in1, sim_h))
1063 geof.write(
"Point(7) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Lx_in2, sim_Ly_out2, sim_Lz_in1, sim_h))
1064 geof.write(
"Point(8) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Lx_in1, sim_Ly_out2, sim_Lz_in1, sim_h))
1069 geof.write(
"Line(1) = {1, 2};\n")
1070 geof.write(
"Line(2) = {2, 3};\n")
1071 geof.write(
"Line(3) = {3, 7};\n")
1072 geof.write(
"Line(4) = {7, 6};\n")
1073 geof.write(
"Line(5) = {6, 5};\n")
1074 geof.write(
"Line(6) = {5, 8};\n")
1075 geof.write(
"Line(7) = {8, 4};\n")
1076 geof.write(
"Line(8) = {4, 1};\n")
1081 geof.write(
"Line Loop(1) = {1, 2, 3, 4, 5, 6, 7, 8};\n")
1086 geof.write(
"Plane Surface(1) = {1};\n")
1091 tag =
'"' +
"a" +
'"'
1092 geof.write(
"Physical Surface(%s) = {1};\n" % (tag))
1098def generate_moving_rect_wall_gmsh_input(inp_dir, filename, rectangle, mesh_size, pp_tag):
1100 sim_inp_dir = str(inp_dir)
1103 sim_Lx_out1 = rectangle[0]
1104 sim_Ly_out1 = rectangle[1]
1105 sim_Lz_out1 = rectangle[2]
1106 sim_Lx_out2 = rectangle[3]
1107 sim_Ly_out2 = rectangle[4]
1108 sim_Lz_out2 = rectangle[5]
1116 geof = open(sim_inp_dir + filename +
'_' + str(pp_tag) +
'.geo',
'w')
1117 geof.write(
"cl__1 = 1;\n")
1118 geof.write(
"Mesh.MshFileVersion = 2.2;\n")
1123 geof.write(
"Point(1) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Lx_out1, sim_Ly_out1, sim_Lz_out1, sim_h));
1124 geof.write(
"Point(2) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Lx_out2, sim_Ly_out1, sim_Lz_out1, sim_h))
1125 geof.write(
"Point(3) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Lx_out2, sim_Ly_out2, sim_Lz_out1, sim_h))
1126 geof.write(
"Point(4) = {%4.6e, %4.6e, %4.6e, %4.6e};\n" % (sim_Lx_out1, sim_Ly_out2, sim_Lz_out1, sim_h))
1131 geof.write(
"Line(1) = {1, 2};\n")
1132 geof.write(
"Line(2) = {2, 3};\n")
1133 geof.write(
"Line(3) = {3, 4};\n")
1134 geof.write(
"Line(4) = {4, 1};\n")
1139 geof.write(
"Line Loop(1) = {1, 2, 3, 4};\n")
1144 geof.write(
"Plane Surface(1) = {1};\n")
1149 tag =
'"' +
"a" +
'"'
1150 geof.write(
"Physical Surface(%s) = {1};\n" % (tag))
1155def create_input_file(inp_dir, pp_tag):
1156 """Generates input file for two-particle test"""
1158 sim_inp_dir = str(inp_dir)
1172 center = [0., 0., 0.]
1176 mesh_size = R_small / 5.
1177 horizon = 2 * mesh_size
1180 Lin, Win = 0.012, 0.008
1181 L, W = Lin + 1.5*horizon, Win + 1.5*horizon
1183 in_rect = [center[0] - 0.5*Lin, center[1] - 0.5*Win, center[2], center[0] + 0.5*Lin, center[1] + 0.5*Win, center[2]]
1184 out_rect = [center[0] - 0.5*L, center[1] - 0.5*W, center[2], center[0] + 0.5*L, center[1] + 0.5*W, center[2]]
1187 moving_wall_y = 0.5*Win - 1.5*horizon
1188 moving_rect = [center[0] - 0.5*Lin, center[1] + moving_wall_y, center[2], center[0] + 0.5*Lin, center[1] + moving_wall_y + 1.5*horizon, center[2]]
1192 remove_rect_from_out_rect = [in_rect[0], in_rect[1], in_rect[2], in_rect[3], out_rect[4], in_rect[5]]
1193 if moving_rect[4] > out_rect[4]:
1194 remove_rect_from_out_rect[4] = out_rect[4]
1196 fixed_container_params = []
1198 fixed_container_params.append(a)
1199 for a
in remove_rect_from_out_rect:
1200 fixed_container_params.append(a)
1203 contain_rect = out_rect
1206 small_circle = [R_small, center[0], center[1], center[2]]
1208 small_triangle = small_circle
1210 w_small_drum2d = R_small * 0.2
1211 small_drum2d = [R_small, w_small_drum2d, center[0], center[1], center[2]]
1213 small_hex = small_circle
1216 large_circle = [R_large, center[0], center[1], center[2]]
1218 large_triangle = large_circle
1220 w_large_drum2d = R_large* 0.2
1221 large_drum2d = [R_large, w_large_drum2d, center[0], center[1], center[2]]
1223 large_hex = large_circle
1232 dt_out_n = num_steps / num_outputs
1233 test_dt_out_n = dt_out_n / 10
1240 E_wall = get_E(K_wall, poisson_wall)
1241 G_wall = get_G(E_wall, poisson_wall)
1245 poisson_small = poisson_wall
1247 E_small = get_E(K_small, poisson_small)
1248 G_small = get_G(E_small, poisson_small)
1251 rho_large = rho_small
1252 poisson_large = poisson_small
1261 R_contact_factor = 0.95
1268 Kn_small_small = 18. * get_eff_k(K_small, K_small) / (np.pi * np.power(horizon, 5))
1269 Kn_large_large = 18. * get_eff_k(K_large, K_large) / (np.pi * np.power(horizon, 5))
1270 Kn_wall_wall = 18. * get_eff_k(K_wall, K_wall) / (np.pi * np.power(horizon, 5))
1271 Kn_small_large = 18. * get_eff_k(K_small, K_large) / (np.pi * np.power(horizon, 5))
1272 Kn_small_wall = 18. * get_eff_k(K_small, K_wall) / (np.pi * np.power(horizon, 5))
1273 Kn_large_wall = 18. * get_eff_k(K_large, K_wall) / (np.pi * np.power(horizon, 5))
1279 friction_coeff = 0.5
1280 damping_active =
False
1281 damping_active_floor =
True
1282 friction_active =
False
1283 beta_n_factor = 100.
1287 gravity_active =
True
1288 gravity = [0., -10., 0.]
1291 neigh_search_factor = 10.
1292 neigh_search_interval = 100
1293 neigh_search_criteria =
"simple_all"
1296 moving_wall_vert_velocity = -0.06
1303 padding = 1.1 * R_contact_factor * mesh_size
1304 max_y = moving_wall_y - 3*mesh_size
1307 id_choices1 = [0, 1, 2, 3]
1308 id_choices2 = [4, 5, 6, 7]
1309 num_particles_zones_1_to_8, particles_zones_1_to_8 = particle_locations(inp_dir, pp_tag, center, padding, max_y, mesh_size, R_small, R_large, id_choices1, id_choices2, N1, N2, in_rect, z_coord = 0., add_orient =
True)
1312 zones_mesh_fnames = [
"mesh_cir_small",
"mesh_tri_small",
"mesh_drum2d_small",
"mesh_hex_small",
"mesh_cir_large",
"mesh_tri_large",
"mesh_drum2d_large",
"mesh_hex_large",
"mesh_fixed_container",
"mesh_moving_container"]
1315 generate_cir_particle_gmsh_input(inp_dir, zones_mesh_fnames[0], center, R_small, mesh_size, pp_tag)
1316 generate_cir_particle_gmsh_input(inp_dir, zones_mesh_fnames[4], center, R_large, mesh_size, pp_tag)
1319 generate_tri_particle_gmsh_input(inp_dir, zones_mesh_fnames[1], center, R_small, mesh_size, pp_tag)
1320 generate_tri_particle_gmsh_input(inp_dir, zones_mesh_fnames[5], center, R_large, mesh_size, pp_tag)
1323 generate_drum2d_particle_gmsh_input(inp_dir, zones_mesh_fnames[2], center, R_small, 2.*w_small_drum2d, mesh_size, pp_tag)
1324 generate_drum2d_particle_gmsh_input(inp_dir, zones_mesh_fnames[6], center, R_large, 2.*w_large_drum2d, mesh_size, pp_tag)
1327 generate_hex_particle_gmsh_input(inp_dir, zones_mesh_fnames[3], center, R_small, mesh_size, pp_tag)
1328 generate_hex_particle_gmsh_input(inp_dir, zones_mesh_fnames[7], center, R_large, mesh_size, pp_tag)
1331 generate_rigid_rect_container_moving_wall_setup_gmsh_input(inp_dir, zones_mesh_fnames[8], out_rect, in_rect, mesh_size, pp_tag)
1333 generate_moving_rect_wall_gmsh_input(inp_dir, zones_mesh_fnames[9], moving_rect, mesh_size, pp_tag)
1335 os.system(
"mkdir -p ../out")
1337 for s
in zones_mesh_fnames:
1340 print(
"gmsh {}_{}.geo -2 &> /dev/null".format(s, pp_tag))
1343 os.system(
"gmsh {}_{}.geo -2".format(s, pp_tag))
1352 inpf = open(sim_inp_dir +
'input_' + str(pp_tag) +
'.yaml',
'w')
1353 inpf.write(
"Model:\n")
1354 inpf.write(
" Dimension: 2\n")
1355 inpf.write(
" Discretization_Type:\n")
1356 inpf.write(
" Spatial: finite_difference\n")
1357 inpf.write(
" Time: central_difference\n")
1358 inpf.write(
" Final_Time: %4.6e\n" % (final_time))
1359 inpf.write(
" Time_Steps: %d\n" % (num_steps))
1362 inpf.write(
"Container:\n")
1363 inpf.write(
" Geometry:\n")
1364 inpf.write(
" Type: rectangle\n")
1365 inpf.write(
" Parameters: " + print_dbl_list(contain_rect))
1368 inpf.write(
"Zone:\n")
1369 inpf.write(
" Zones: 10\n")
1372 inpf.write(
" Zone_%d:\n" % (i+1))
1374 inpf.write(
" Is_Wall: true\n")
1376 inpf.write(
" Is_Wall: false\n")
1379 inpf.write(
"Particle:\n")
1380 inpf.write(
" Test_Name: multi_particle_compressive_test\n")
1382 particle_data = [[
'circle', small_circle], [
'triangle', small_triangle], [
'drum2d', small_drum2d], [
'hexagon', small_hex], [
'circle', large_circle], [
'triangle', large_triangle], [
'drum2d', large_drum2d], [
'hexagon', large_hex]]
1383 for i
in range(len(particle_data)):
1384 inpf.write(
" Zone_%d:\n" % (i+1))
1385 inpf.write(
" Type: %s\n" % (particle_data[i][0]))
1386 inpf.write(
" Parameters: " + print_dbl_list((particle_data[i][1])))
1389 inpf.write(
" Zone_9:\n")
1390 inpf.write(
" Is_Wall: true\n")
1391 inpf.write(
" Type: rectangle_minus_rectangle\n")
1392 inpf.write(
" Parameters: " + print_dbl_list(fixed_container_params))
1393 inpf.write(
" All_Dofs_Constrained: true\n")
1394 inpf.write(
" Create_Particle_Using_ParticleZone_GeomObject: true\n")
1397 inpf.write(
" Zone_10:\n")
1398 inpf.write(
" Is_Wall: true\n")
1399 inpf.write(
" Type: rectangle\n")
1400 inpf.write(
" Parameters: " + print_dbl_list(moving_rect))
1401 inpf.write(
" All_Dofs_Constrained: true\n")
1402 inpf.write(
" Create_Particle_Using_ParticleZone_GeomObject: true\n")
1405 inpf.write(
"Particle_Generation:\n")
1406 inpf.write(
" From_File: particle_locations_" + str(pp_tag) +
".csv\n")
1407 inpf.write(
" File_Data_Type: loc_rad_orient\n")
1410 inpf.write(
"Mesh:\n")
1413 inpf.write(
" Zone_%d:\n" % (i+1))
1414 inpf.write(
" File: %s\n" % (zones_mesh_fnames[i] +
"_" + str(pp_tag) +
".msh"))
1417 inpf.write(
"Contact:\n")
1420 write_contact_zone_part(inpf, R_contact_factor, damping_active, friction_active, beta_n_eps, friction_coeff, Kn_factor, beta_n_factor,
"11", Kn_small_small)
1423 copy_contact_zone(inpf, [12, 13, 14], [1, 1])
1426 write_contact_zone_part(inpf, R_contact_factor, damping_active, friction_active, beta_n_eps, friction_coeff, Kn_factor, beta_n_factor,
"15", Kn_small_large)
1429 copy_contact_zone(inpf, [16, 17, 18], [1, 5])
1432 write_contact_zone_part(inpf, R_contact_factor, damping_active, friction_active, beta_n_eps, friction_coeff, Kn_factor, beta_n_factor,
"19", Kn_small_wall)
1435 write_contact_zone_part(inpf, R_contact_factor, damping_active, friction_active, beta_n_eps, friction_coeff, Kn_factor, beta_n_factor,
"110", Kn_small_wall)
1438 copy_contact_zone(inpf, [22, 23, 24], [1, 1])
1441 copy_contact_zone(inpf, [25, 26, 27, 28], [1, 5])
1444 copy_contact_zone(inpf, [29], [1, 9])
1447 copy_contact_zone(inpf, [210], [1, 10])
1450 copy_contact_zone(inpf, [33, 34], [1, 1])
1453 copy_contact_zone(inpf, [35, 36, 37, 38], [1, 5])
1456 copy_contact_zone(inpf, [39], [1, 9])
1459 copy_contact_zone(inpf, [310], [1, 10])
1462 copy_contact_zone(inpf, [44], [1, 1])
1465 copy_contact_zone(inpf, [45, 46, 47, 48], [1, 5])
1468 copy_contact_zone(inpf, [49], [1, 9])
1471 copy_contact_zone(inpf, [410], [1, 10])
1474 write_contact_zone_part(inpf, R_contact_factor, damping_active, friction_active, beta_n_eps, friction_coeff, Kn_factor, beta_n_factor,
"55", Kn_large_large)
1477 copy_contact_zone(inpf, [56, 57, 58], [5, 5])
1480 write_contact_zone_part(inpf, R_contact_factor, damping_active, friction_active, beta_n_eps, friction_coeff, Kn_factor, beta_n_factor,
"59", Kn_large_wall)
1483 write_contact_zone_part(inpf, R_contact_factor, damping_active, friction_active, beta_n_eps, friction_coeff, Kn_factor, beta_n_factor,
"510", Kn_large_wall)
1486 copy_contact_zone(inpf, [66, 67, 68], [5, 5])
1489 copy_contact_zone(inpf, [69], [5, 9])
1492 copy_contact_zone(inpf, [610], [5, 10])
1495 copy_contact_zone(inpf, [77, 78], [5, 5])
1498 copy_contact_zone(inpf, [79], [5, 9])
1501 copy_contact_zone(inpf, [710], [5, 10])
1504 copy_contact_zone(inpf, [88], [5, 5])
1507 copy_contact_zone(inpf, [89], [5, 9])
1510 copy_contact_zone(inpf, [810], [5, 10])
1513 write_contact_zone_part(inpf, R_contact_factor, damping_active, friction_active, beta_n_eps, friction_coeff, Kn_factor, beta_n_factor,
"99", Kn_wall_wall)
1516 copy_contact_zone(inpf, [910], [9, 9])
1519 copy_contact_zone(inpf, [1010], [9, 9])
1522 inpf.write(
"Neighbor:\n")
1523 inpf.write(
" Update_Criteria: %s\n" % (neigh_search_criteria))
1524 inpf.write(
" Search_Factor: %4.e\n" % (neigh_search_factor))
1525 inpf.write(
" Search_Interval: %d\n" % (neigh_search_interval))
1528 inpf.write(
"Material:\n")
1531 write_material_zone_part(inpf,
"1", horizon, rho_small, K_small, G_small, Gc_small)
1534 inpf.write(
" Zone_2:\n")
1535 inpf.write(
" Copy_Material_Data: 1\n")
1538 inpf.write(
" Zone_3:\n")
1539 inpf.write(
" Copy_Material_Data: 1\n")
1542 inpf.write(
" Zone_4:\n")
1543 inpf.write(
" Copy_Material_Data: 1\n")
1546 write_material_zone_part(inpf,
"5", horizon, rho_large, K_large, G_large, Gc_large)
1549 inpf.write(
" Zone_6:\n")
1550 inpf.write(
" Copy_Material_Data: 5\n")
1553 inpf.write(
" Zone_7:\n")
1554 inpf.write(
" Copy_Material_Data: 5\n")
1557 inpf.write(
" Zone_8:\n")
1558 inpf.write(
" Copy_Material_Data: 5\n")
1561 write_material_zone_part(inpf,
"9", horizon, rho_wall, K_wall, G_wall, Gc_wall)
1564 inpf.write(
" Zone_10:\n")
1565 inpf.write(
" Copy_Material_Data: 9\n")
1568 if gravity_active ==
True:
1569 inpf.write(
"Force_BC:\n")
1570 inpf.write(
" Gravity: " + print_dbl_list(gravity))
1573 inpf.write(
"Displacement_BC:\n")
1574 inpf.write(
" Sets: 2\n")
1576 inpf.write(
" Set_1:\n")
1578 inpf.write(
" Particle_List: [%d]\n" % (num_particles_zones_1_to_8))
1579 inpf.write(
" Direction: [1,2]\n")
1580 inpf.write(
" Zero_Displacement: true\n")
1582 inpf.write(
" Set_2:\n")
1584 inpf.write(
" Particle_List: [%d]\n" % (num_particles_zones_1_to_8 + 1))
1585 inpf.write(
" Direction: [2]\n")
1586 inpf.write(
" Time_Function:\n")
1587 inpf.write(
" Type: linear\n")
1588 inpf.write(
" Parameters:\n")
1589 inpf.write(
" - %4.6e\n" % (moving_wall_vert_velocity))
1590 inpf.write(
" Spatial_Function:\n")
1591 inpf.write(
" Type: constant\n")
1597 inpf.write(
"Output:\n")
1598 inpf.write(
" Path: ../out/\n")
1599 inpf.write(
" Tags:\n")
1600 inpf.write(
" - Displacement\n")
1601 inpf.write(
" - Velocity\n")
1602 inpf.write(
" - Force\n")
1603 inpf.write(
" - Force_Density\n")
1604 inpf.write(
" - Damage_Z\n")
1605 inpf.write(
" - Damage\n")
1606 inpf.write(
" - Nodal_Volume\n")
1607 inpf.write(
" - Zone_ID\n")
1608 inpf.write(
" - Particle_ID\n")
1609 inpf.write(
" - Fixity\n")
1610 inpf.write(
" - Force_Fixity\n")
1611 inpf.write(
" - Contact_Nodes\n")
1612 inpf.write(
" - No_Fail_Node\n")
1613 inpf.write(
" - Boundary_Node_Flag\n")
1614 inpf.write(
" Output_Interval: %d\n" % (dt_out_n))
1615 inpf.write(
" Compress_Type: zlib\n")
1616 inpf.write(
" Perform_FE_Out: false\n")
1618 inpf.write(
" Perform_Out: true\n")
1620 inpf.write(
" Perform_Out: false\n")
1621 inpf.write(
" Test_Output_Interval: %d\n" % (test_dt_out_n))
1623 inpf.write(
" Debug: 3\n")
1624 inpf.write(
" Tag_PP: %d\n" %(int(pp_tag)))
1634if len(sys.argv) > 1:
1635 pp_tag = int(sys.argv[1])
1637create_input_file(inp_dir, pp_tag)