5def print_bool(arg, prefix = ""):
14def print_dbl(arg, prefix = ""):
16 str = prefix +
"%4.6e\n" % (arg)
19def print_int(arg, prefix = ""):
20 str = prefix +
"%d\n" % (arg)
23def print_dbl_list(arg, prefix = ""):
27 str +=
"%4.6e" % (arg[i])
35def print_int_list(arg, prefix = ""):
39 str +=
"%d" % (arg[i])
47def does_intersect(p, r, R, particles, padding):
51 pq = np.array([p[i] - q[i]
for i
in range(3)])
52 if np.linalg.norm(pq) <= r + R + padding:
59 return 3. * K * (1. - 2. * nu)
62 return E / (2. * (1. + nu))
66 return 2. * k1 * k2 / (k1 + k2)
69def particle_locations(inp_dir, pp_tag, R1, R2, offset):
70 """Generate particle location data"""
73 sim_particles.append([0., R1, R1, 0., R1])
74 sim_particles.append([1., R1, 2. * R1 + R2 + offset, 0., R2])
76 inpf = open(inp_dir +
'particle_locations_' + str(pp_tag) +
'.csv',
'w')
77 inpf.write(
"i, x, y, z, r\n")
78 for p
in sim_particles:
79 inpf.write(
"%d, %Lf, %Lf, %Lf, %Lf\n" % (int(p[0]), p[1], p[2], p[3], p[4]))
83def particle_locations_orient(inp_dir, pp_tag, R1, R2, offset):
84 """Generate particle location data"""
87 sim_particles.append([0., R1, R1, 0., R1, 0.5*np.pi])
88 sim_particles.append([1., R1, 2. * R1 + R2 + offset, 0., R2, 0.])
90 inpf = open(inp_dir +
'particle_locations_' + str(pp_tag) +
'.csv',
'w')
91 inpf.write(
"i, x, y, z, r, o\n")
92 for p
in sim_particles:
93 inpf.write(
"%d, %Lf, %Lf, %Lf, %Lf, %Lf\n" % (int(p[0]), p[1], p[2], p[3], p[4], p[5]))
97def rotate(p, theta, axis):
100 axis_np = np.array(axis)
106 p_dot_n = np.dot(p_np,axis_np)
109 n_cross_p = np.cross(axis_np, p_np)
111 return (1. - ct) * p_dot_n * axis_np + ct * p_np + st * n_cross_p
114def get_ref_hex_points(center, radius, add_center = False):
139 rotate_axis = [0., 0., 1.]
143 points.append(center)
146 xi = rotate(axis, i*np.pi/3., rotate_axis)
147 points.append([center[i] + radius * xi[i]
for i
in range(3)])
152def get_ref_drum_points(center, radius, width, add_center = False):
177 rotate_axis = [0., 0., 1.]
179 x1 = rotate(axis, np.pi/3., rotate_axis)
180 x2 = rotate(axis, -np.pi/3., rotate_axis)
184 points.append(center)
187 points.append([center[i] + width*0.5*axis[i]
for i
in range(3)])
189 points.append([center[i] + radius*x1[i]
for i
in range(3)])
191 points.append([center[i] + radius*x1[i] - radius*axis[i]
for i
in range(3)])
193 points.append([center[i] - width*0.5*axis[i]
for i
in range(3)])
195 v6 = [center[i] + radius*x2[i]
for i
in range(3)]
196 points.append([v6[i] - radius*axis[i]
for i
in range(3)])
203def generate_hex_particle_gmsh_input(inp_dir, filename, center, radius, mesh_size, pp_tag):
205 sim_inp_dir = str(inp_dir)
207 points = get_ref_hex_points(center, radius,
True)
212 geof = open(sim_inp_dir + filename +
'_' + str(pp_tag) +
'.geo',
'w')
213 geof.write(
"cl__1 = 1;\n")
214 geof.write(
"Mesh.MshFileVersion = 2.2;\n")
221 sts =
"Point({}) = ".format(i+1)
223 sts +=
"{}, {}, {}, {}".format(p[0], p[1], p[2], mesh_size)
230 geof.write(
"Line(1) = {2, 3};\n")
231 geof.write(
"Line(2) = {3, 4};\n")
232 geof.write(
"Line(3) = {4, 5};\n")
233 geof.write(
"Line(4) = {5, 6};\n")
234 geof.write(
"Line(5) = {6, 7};\n")
235 geof.write(
"Line(6) = {7, 2};\n")
240 geof.write(
"Line Loop(1) = {1, 2, 3, 4, 5, 6};\n")
245 geof.write(
"Plane Surface(1) = {1};\n")
254 geof.write(
"Point{1} In Surface {1};")
262 sim_inp_dir = str(inp_dir)
270 geof = open(sim_inp_dir + filename +
'_' + str(pp_tag) +
'.geo',
'w')
271 geof.write(
"cl__1 = 1;\n")
272 geof.write(
"Mesh.MshFileVersion = 2.2;\n")
279 sts =
"Point({}) = ".format(i+1)
281 sts +=
"{}, {}, {}, {}".format(p[0], p[1], p[2], mesh_size)
288 geof.write(
"Line(1) = {2, 3};\n")
289 geof.write(
"Line(2) = {3, 4};\n")
290 geof.write(
"Line(3) = {4, 5};\n")
291 geof.write(
"Line(4) = {5, 6};\n")
292 geof.write(
"Line(5) = {6, 7};\n")
293 geof.write(
"Line(6) = {7, 2};\n")
298 geof.write(
"Line Loop(1) = {1, 2, 3, 4, 5, 6};\n")
303 geof.write(
"Plane Surface(1) = {1};\n")
312 geof.write(
"Point{1} In Surface {1};")
320 """Generates input file for two-particle test"""
322 sim_inp_dir = str(inp_dir)
325 center = [0., 0., 0.]
332 horizon = 3. * mesh_size
333 particle_dist = 0.0004
341 dt_out_n = num_steps / num_outputs
348 E1 =
get_E(K1, poisson1)
349 G1 =
get_G(E1, poisson1)
355 E2 =
get_E(K2, poisson2)
356 G2 =
get_G(E2, poisson2)
362 R_contact_factor = 0.95
369 Kn_11 = 18. *
get_eff_k(K1, K1) / (np.pi * np.power(horizon, 5))
370 Kn_22 = 18. *
get_eff_k(K2, K2) / (np.pi * np.power(horizon, 5))
371 Kn_12 = 18. *
get_eff_k(K1, K2) / (np.pi * np.power(horizon, 5))
375 damping_active =
False
376 friction_active =
False
380 gravity_active =
True
381 gravity = [0., -10., 0.]
384 free_fall_dist = particle_dist - horizon
385 free_fall_vel = [0., 0., 0.]
387 free_fall_vel[1] = -1.
390 neigh_search_factor = 10.
391 neigh_search_interval = 40
392 neigh_search_criteria =
"simple_all"
399 inpf = open(sim_inp_dir +
'input_' + str(pp_tag) +
'.yaml',
'w')
400 inpf.write(
"Model:\n")
401 inpf.write(
" Dimension: 2\n")
402 inpf.write(
" Discretization_Type:\n")
403 inpf.write(
" Spatial: finite_difference\n")
404 inpf.write(
" Time: central_difference\n")
405 inpf.write(
" Final_Time: %4.6e\n" % (final_time))
406 inpf.write(
" Time_Steps: %d\n" % (num_steps))
408 inpf.write(
"Policy:\n")
409 inpf.write(
" Enable_PostProcessing: true\n")
414 inpf.write(
"Zone:\n")
415 inpf.write(
" Zones: 2\n")
418 inpf.write(
" Zone_1:\n")
419 inpf.write(
" Is_Wall: false\n")
422 inpf.write(
" Zone_2:\n")
423 inpf.write(
" Is_Wall: false\n")
428 inpf.write(
"Container:\n")
429 inpf.write(
" Geometry:\n")
430 inpf.write(
" Type: rectangle\n")
431 contain_params = [0., 0., 0., 2.*R1, 2.*R1 + 2.*R2 + particle_dist, 0.]
433 contain_params[3] = 2.*R2
439 inpf.write(
"Particle:\n")
440 inpf.write(
" Test_Name: two_particle\n")
441 inpf.write(
" Zone_1:\n")
442 inpf.write(
" Type: drum2d\n")
443 drum_axis = [1., 0., 0.]
444 drum1_neck_width = 0.5*R1
445 p1_geom = [R1, drum1_neck_width, center[0], center[1], center[2], drum_axis[0], drum_axis[1], drum_axis[2]]
447 inpf.write(
" Zone_2:\n")
448 inpf.write(
" Type: hexagon\n")
449 hex_axis = [1., 0., 0.]
450 p2_geom = [R2, center[0], center[1], center[2], hex_axis[0], hex_axis[1], hex_axis[2]]
456 inpf.write(
"Particle_Generation:\n")
457 inpf.write(
" From_File: particle_locations_" + str(pp_tag) +
".csv\n")
459 inpf.write(
" File_Data_Type: loc_rad_orient\n")
464 inpf.write(
"Mesh:\n")
467 inpf.write(
" Zone_1:\n")
468 inpf.write(
" File: mesh_particle_1_" + str(pp_tag) +
".msh \n")
471 inpf.write(
" Zone_2:\n")
472 inpf.write(
" File: mesh_particle_2_" + str(pp_tag) +
".msh \n")
477 inpf.write(
"Contact:\n")
480 inpf.write(
" Zone_11:\n")
482 inpf.write(
" Contact_Radius_Factor: %4.6e\n" % (R_contact_factor))
484 if damping_active ==
False:
485 inpf.write(
" Damping_On: false\n")
486 if friction_active ==
False:
487 inpf.write(
" Friction_On: false\n")
489 inpf.write(
" Kn: %4.6e\n" % (Kn_11))
490 inpf.write(
" Epsilon: %4.6e\n" % (beta_n_eps))
491 inpf.write(
" Friction_Coeff: %4.6e\n" % (friction_coeff))
492 inpf.write(
" Kn_Factor: 1.0\n")
493 inpf.write(
" Beta_n_Factor: %4.6e\n" % (beta_n_factor))
496 inpf.write(
" Zone_12:\n")
497 inpf.write(
" Contact_Radius_Factor: %4.6e\n" % (R_contact_factor))
499 if damping_active ==
False:
500 inpf.write(
" Damping_On: false\n")
501 if friction_active ==
False:
502 inpf.write(
" Friction_On: false\n")
504 inpf.write(
" Kn: %4.6e\n" % (Kn_12))
505 inpf.write(
" Epsilon: %4.6e\n" % (beta_n_eps))
506 inpf.write(
" Friction_Coeff: %4.6e\n" % (friction_coeff))
507 inpf.write(
" Kn_Factor: 1.0\n")
508 inpf.write(
" Beta_n_Factor: %4.6e\n" % (beta_n_factor))
511 inpf.write(
" Zone_22:\n")
512 inpf.write(
" Contact_Radius_Factor: %4.6e\n" % (R_contact_factor))
514 if damping_active ==
False:
515 inpf.write(
" Damping_On: false\n")
516 if friction_active ==
False:
517 inpf.write(
" Friction_On: false\n")
519 inpf.write(
" Kn: %4.6e\n" % (Kn_22))
520 inpf.write(
" Epsilon: %4.6e\n" % (beta_n_eps))
521 inpf.write(
" Friction_Coeff: %4.6e\n" % (friction_coeff))
522 inpf.write(
" Kn_Factor: 1.0\n")
523 inpf.write(
" Beta_n_Factor: %4.6e\n" % (beta_n_factor))
526 inpf.write(
"Neighbor:\n")
527 inpf.write(
" Update_Criteria: %s\n" % (neigh_search_criteria))
528 inpf.write(
" Search_Factor: %4.e\n" % (neigh_search_factor))
529 inpf.write(
" Search_Interval: %d\n" % (neigh_search_interval))
534 inpf.write(
"Material:\n")
537 inpf.write(
" Zone_1:\n")
538 inpf.write(
" Type: PDState\n")
539 inpf.write(
" Horizon: %4.6e\n" % (horizon))
540 inpf.write(
" Density: %4.6e\n" % (rho1))
541 inpf.write(
" Compute_From_Classical: true\n")
542 inpf.write(
" K: %4.6e\n" % (K1))
543 inpf.write(
" G: %4.6e\n" % (G1))
544 inpf.write(
" Gc: %4.6e\n" % (Gc1))
545 inpf.write(
" Influence_Function:\n")
546 inpf.write(
" Type: 1\n")
549 inpf.write(
" Zone_2:\n")
550 inpf.write(
" Type: PDState\n")
551 inpf.write(
" Horizon: %4.6e\n" % (horizon))
552 inpf.write(
" Density: %4.6e\n" % (rho2))
553 inpf.write(
" Compute_From_Classical: true\n")
554 inpf.write(
" K: %4.6e\n" % (K2))
555 inpf.write(
" G: %4.6e\n" % (G2))
556 inpf.write(
" Gc: %4.6e\n" % (Gc2))
557 inpf.write(
" Influence_Function:\n")
558 inpf.write(
" Type: 1\n")
563 if gravity_active ==
True:
564 inpf.write(
"Force_BC:\n")
571 inpf.write(
" Constant_Velocity:\n")
573 inpf.write(
" Particle_List: [1]\n")
578 inpf.write(
"Displacement_BC:\n")
579 inpf.write(
" Sets: 1\n")
581 inpf.write(
" Set_1:\n")
582 inpf.write(
" Particle_List: [0]\n")
583 inpf.write(
" Direction: [1,2]\n")
584 inpf.write(
" Time_Function:\n")
585 inpf.write(
" Type: constant\n")
586 inpf.write(
" Parameters:\n")
587 inpf.write(
" - 0.0\n")
588 inpf.write(
" Spatial_Function:\n")
589 inpf.write(
" Type: constant\n")
590 inpf.write(
" Zero_Displacement: true\n")
595 inpf.write(
"Output:\n")
596 inpf.write(
" Path: ../out/\n")
597 inpf.write(
" Tags:\n")
598 inpf.write(
" - Displacement\n")
599 inpf.write(
" - Velocity\n")
600 inpf.write(
" - Force\n")
601 inpf.write(
" - Force_Density\n")
602 inpf.write(
" - Damage_Z\n")
603 inpf.write(
" - Damage\n")
604 inpf.write(
" - Nodal_Volume\n")
605 inpf.write(
" - Zone_ID\n")
606 inpf.write(
" - Particle_ID\n")
607 inpf.write(
" - Fixity\n")
608 inpf.write(
" - Force_Fixity\n")
609 inpf.write(
" - Contact_Data\n")
610 inpf.write(
" - No_Fail_Node\n")
611 inpf.write(
" - Boundary_Node_Flag\n")
612 inpf.write(
" - Theta\n")
614 inpf.write(
" Output_Interval: %d\n" % (dt_out_n))
615 inpf.write(
" Compress_Type: zlib\n")
616 inpf.write(
" Perform_FE_Out: false\n")
618 inpf.write(
" Perform_Out: true\n")
620 inpf.write(
" Perform_Out: false\n")
621 inpf.write(
" Test_Output_Interval: %d\n" % (dt_out_n))
623 inpf.write(
" Debug: 1\n")
624 inpf.write(
" Tag_PP: %d\n" %(int(pp_tag)))
637 p_mesh_fname = [
'mesh_particle_1',
'mesh_particle_2']
642 os.system(
"mkdir -p ../out")
644 for s
in p_mesh_fname:
647 print(
"gmsh {}_{}.geo -2".format(s, pp_tag))
649 os.system(
"gmsh {}_{}.geo -2".format(s, pp_tag))
658 pp_tag = int(sys.argv[1])
generate_drum_particle_gmsh_input(inp_dir, filename, center, radius, width, mesh_size, pp_tag)
generate_hex_particle_gmsh_input(inp_dir, filename, center, radius, mesh_size, pp_tag)
create_input_file(inp_dir, pp_tag)
particle_locations_orient(inp_dir, pp_tag, R1, R2, offset)
print_dbl_list(arg, prefix="")
get_ref_drum_points(center, radius, width, add_center=False)