-
Notifications
You must be signed in to change notification settings - Fork 0
/
continuous_generator_60s.py
244 lines (187 loc) · 9.38 KB
/
continuous_generator_60s.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
"""
@author: Jack Richard Grogan
___ ________ ________ ___ __ ________
|\ \|\ __ \|\ ____\|\ \|\ \ |\ ____\
\ \ \ \ \|\ \ \ \___|\ \ \/ /|_ \ \ \___|
__ \ \ \ \ __ \ \ \ \ \ ___ \ \ \ \ ___
|\ \\_\ \ \ \ \ \ \ \____\ \ \\ \ \ \ \ \|\ \
\ \________\ \__\ \__\ \_______\ \__\\ \__\ \ \_______\
\|________|\|__|\|__|\|_______|\|__| \|__| \|_______|
"""
#------------------------------------------------------------------------------------------
# Calling in Libraries
#------------------------------------------------------------------------------------------
import gmsh
if gmsh.isInitialized():
gmsh.finalize()
gmsh.initialize()
from jinja2 import Template
import numpy as np
import os
import sympy
import glob
from natsort import natsorted
#------------------------------------------------------------------------------------------
# Container Geometry Specifications
#------------------------------------------------------------------------------------------
particle_diameter = 10 #mm
# Square dimensions
z0_square = 0 #m
x0_square = 0 #m
y0_square = 0 #m
lc_square = 1e-2 #-
square_size = 0.122 #m
# inface dimensions
z0_inface = 0.2872579001 #m
x0_inface = 0 #m
y0_inface = 0 #m
lc_inface = 1e-2 #-
inface_size = 0.12 #m
# Mesh Configuration
base_mesh_max = 0.005 #-
base_mesh_min = 0.0 #-
inface_mesh_max = 1e22 #-
inface_mesh_min = 0.0 #-
#------------------------------------------------------------------------------------------
# Simulation Specifications
#------------------------------------------------------------------------------------------
timestep = 79e-7 #s
dumptime = 0.079 #s
ontime = 60 #s
filltime = 2 #s
settletime = 1 #s
w = 200 #rad/s
N = 3000 #-
density = 2500 #kg/m^3
youngs_modulus = 1e7 #Pa
poisson_ratio = 0.29 #-
sliding_pw = 0.3 #-
rolling_pw = 0.002 #-
restitution_pw = 0.922 #-
cohesion_pw = 0 #-
sliding_pp = 0.3 #-
rolling_pp = 0.002 #-
restitution_pp = 0.922 #-
cohesion_pp = 0 #-
number_of_seeds = 20 #-
#------------------------------------------------------------------------------------------
# Slurm Job Launch Specifications
#------------------------------------------------------------------------------------------
job_runtime = "10:00:00" # hr:min:sec
ntasks = int(8)
#------------------------------------------------------------------------------------------
# Preliminary Calculations
#------------------------------------------------------------------------------------------
input_ontime = np.round(np.ceil(ontime/timestep)*timestep,8)
input_filltime = np.round(np.ceil(filltime/timestep)*timestep,8)
input_settletime = np.round(np.ceil(settletime/timestep)*timestep,8)
oscillation_period = 2*np.pi/w
particle_radius = np.round(particle_diameter/2000, 8)
seeds = [0]*number_of_seeds
for k in range(number_of_seeds):
seeds[k] = sympy.prime(2000 + k)
#------------------------------------------------------------------------------------------
# Open Files
#------------------------------------------------------------------------------------------
with open(os.path.join("template_continuous", "base_template.geo"), 'r') as f:
base_template = f.read()
with open(os.path.join("template_continuous", "inface_template.geo"), 'r') as f:
inface_template = f.read()
with open(os.path.join("template_continuous", "shake_template.sim"), 'r') as f:
simulation_template = f.read()
with open(os.path.join("template_continuous", "batch_launch_template.sh"), 'r') as f:
batch_launch_template = f.read()
#------------------------------------------------------------------------------------------
# File Generation
#------------------------------------------------------------------------------------------
for seed in seeds:
# setting up jinja dictionaries for text replacement of tempalte files
base_mesh_data = { "square_size": square_size,
"z0_square": z0_square,
"y0_square": y0_square,
"x0_square": x0_square,
"lc_square": lc_square,
"mesh_max": base_mesh_max,
"mesh_min": base_mesh_max,
"Algor": 6
}
inface_mesh_data = { "inface_size": inface_size,
"z0_inface": z0_inface,
"y0_inface": y0_inface,
"x0_inface": x0_inface,
"lc_inface": lc_inface,
"mesh_max": inface_mesh_max,
"mesh_min": inface_mesh_min,
"Algor": 6
}
simulation_data = { "timestep": timestep,
"dumptime": dumptime,
"filltime": input_filltime,
"ontime": input_ontime,
"settletime": input_settletime,
"number_particles": N,
"particle_radius": particle_radius,
"density": density,
"youngs_modulus": youngs_modulus,
"poisson_ratio": poisson_ratio,
"sliding_pp": sliding_pp,
"sliding_pw": sliding_pw,
"rolling_pp": rolling_pp,
"rolling_pw": rolling_pw,
"restitution_pp": restitution_pp,
"restitution_pw": restitution_pw,
"cohesion_pp": cohesion_pp,
"cohesion_pw": cohesion_pw,
"seed": seed,
"period": oscillation_period
}
batch_launch_data = { "runtime": job_runtime,
"ntasks": ntasks
}
j2_base_template = Template(base_template)
j2_inface_template = Template(inface_template)
j2_simulation_template = Template(simulation_template)
j2_batch_launch_template = Template(batch_launch_template)
# Creating file paths
study_directory = os.path.join(f"{particle_diameter:.0f}_mm_diameter_particles", "continuous_60s", f"seed_{seed}")
if not os.path.exists(study_directory):
os.makedirs(study_directory)
simulation_newpath = os.path.join(study_directory)
if not os.path.exists(simulation_newpath):
os.makedirs(simulation_newpath)
batch_launch_newpath = os.path.join(study_directory)
if not os.path.exists(batch_launch_newpath):
os.makedirs(batch_launch_newpath)
mesh_newpath = os.path.join(study_directory, "mesh")
if not os.path.exists(mesh_newpath):
os.makedirs(mesh_newpath)
inface_newpath = os.path.join(study_directory, "mesh")
if not os.path.exists(inface_newpath):
os.makedirs(inface_newpath)
# Creating new simulation files
base_geo_file_new = os.path.join(mesh_newpath, "shake_base.geo")
inface_geo_file_new = os.path.join(inface_newpath, "inface.geo")
simulation_file_new = os.path.join(simulation_newpath, "shake.sim")
batch_launch_file_new = os.path.join(batch_launch_newpath, "batch_launch.sh")
# Writing parameters to new files
with open(base_geo_file_new, 'w') as f:
f.write(j2_base_template.render(base_mesh_data))
with open(inface_geo_file_new, 'w') as f:
f.write(j2_inface_template.render(inface_mesh_data))
with open(simulation_file_new, 'w') as f:
f.write(j2_simulation_template.render(simulation_data))
with open(batch_launch_file_new, 'w') as f:
f.write(j2_batch_launch_template.render(batch_launch_data))
# Creating stl files from the gmesh geo files
gmsh.open(base_geo_file_new)
gmsh.open(inface_geo_file_new)
#------------------------------------------------------------------------------------------
# Launch Slurm Jobs
#------------------------------------------------------------------------------------------
glob_input = os.path.join(f"{particle_diameter:.0f}_mm_diameter_particles", "continuous_60s", "seed_*")
directories = natsorted([k for k in glob.glob(glob_input)])
for directory in directories:
launch_file = os.path.join(directory, "batch_launch.sh")
cmd = f"sbatch --output={directory}/slurm-%j.out {launch_file} {directory}"
print(cmd)
os.system(cmd)