MFC
Exascale flow solver
Loading...
Searching...
No Matches
m_start_up.fpp.f90
Go to the documentation of this file.
1# 1 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2!>
3!! @file
4!! @brief Contains module m_start_up
5
6# 1 "/home/runner/work/MFC/MFC/src/common/include/case.fpp" 1
7! This file exists so that Fypp can be run without generating case.fpp files for
8! each target. This is useful when generating documentation, for example. This
9! should also let MFC be built with CMake directly, without invoking mfc.sh.
10
11! For pre-process.
12# 8 "/home/runner/work/MFC/MFC/src/common/include/case.fpp"
13
14! For moving immersed boundaries in simulation
15# 12 "/home/runner/work/MFC/MFC/src/common/include/case.fpp"
16# 6 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp" 2
17# 1 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp" 1
18# 1 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp" 1
19# 1 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp" 1
20# 2 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
21# 3 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
22# 4 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
23# 5 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
24# 6 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
25
26# 8 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
27# 9 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
28# 10 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
29
30# 12 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
31# 1 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp" 1
32! Default for Fypp runs outside the toolchain (e.g. documentation). Searched last, so the
33! build/include/<target>/thermochem.fpp the toolchain writes from m_thermochem takes precedence.
34# 4 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp"
35# 5 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp"
36# 13 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp" 2
37
38# 16 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
39# 17 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
40
41# 24 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
42
43# 53 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
44
45# 65 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
46
47# 75 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
48
49# 105 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
50
51# 117 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
52
53# 127 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
54
55# 174 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
56! New line at end of file is required for FYPP
57# 2 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp" 2
58# 1 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp" 1
59# 1 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp" 1
60# 2 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
61# 3 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
62# 4 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
63# 5 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
64# 6 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
65
66# 8 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
67# 9 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
68# 10 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
69
70# 12 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
71# 1 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp" 1
72! Default for Fypp runs outside the toolchain (e.g. documentation). Searched last, so the
73! build/include/<target>/thermochem.fpp the toolchain writes from m_thermochem takes precedence.
74# 4 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp"
75# 5 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp"
76# 13 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp" 2
77
78# 16 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
79# 17 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
80
81# 24 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
82
83# 53 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
84
85# 65 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
86
87# 75 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
88
89# 105 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
90
91# 117 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
92
93# 127 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
94
95# 174 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
96! New line at end of file is required for FYPP
97# 2 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp" 2
98
99# 4 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
100# 5 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
101# 6 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
102# 7 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
103# 8 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
104
105# 20 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
106
107# 49 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
108
109# 54 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
110
111# 59 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
112
113# 64 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
114
115# 69 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
116
117# 74 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
118
119# 87 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
120
121# 101 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
122
123# 106 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
124
125# 111 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
126
127# 116 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
128
129# 121 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
130
131# 126 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
132
133# 131 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
134
135# 136 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
136
137# 141 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
138
139# 171 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
140
141# 231 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
142
143# 245 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
144
145# 270 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
146
147# 281 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
148
149# 283 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
150# 294 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
151
152# 343 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
153
154# 353 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
155
156# 363 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
157
158# 372 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
159
160# 389 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
161
162# 399 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
163
164# 406 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
165
166# 412 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
167
168# 418 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
169
170# 424 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
171
172# 430 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
173
174# 436 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
175! New line at end of file is required for FYPP
176# 3 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp" 2
177# 1 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp" 1
178# 1 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp" 1
179# 2 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
180# 3 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
181# 4 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
182# 5 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
183# 6 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
184
185# 8 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
186# 9 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
187# 10 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
188
189# 12 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
190# 1 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp" 1
191! Default for Fypp runs outside the toolchain (e.g. documentation). Searched last, so the
192! build/include/<target>/thermochem.fpp the toolchain writes from m_thermochem takes precedence.
193# 4 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp"
194# 5 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp"
195# 13 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp" 2
196
197# 16 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
198# 17 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
199
200# 24 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
201
202# 53 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
203
204# 65 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
205
206# 75 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
207
208# 105 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
209
210# 117 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
211
212# 127 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
213
214# 174 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
215! New line at end of file is required for FYPP
216# 2 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp" 2
217
218# 7 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
219
220# 17 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
221
222# 22 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
223
224# 27 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
225
226# 32 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
227
228# 37 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
229
230# 42 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
231
232# 47 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
233
234# 52 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
235
236# 57 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
237
238# 62 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
239
240# 73 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
241
242# 78 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
243
244# 83 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
245
246# 88 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
247
248# 103 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
249
250# 131 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
251
252# 161 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
253
254# 176 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
255
256# 194 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
257
258# 216 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
259
260# 245 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
261
262# 260 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
263
264# 270 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
265
266# 279 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
267
268# 295 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
269
270# 305 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
271
272# 312 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
273! New line at end of file is required for FYPP
274# 4 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp" 2
275
276! GPU parallel region (scalar reductions, maxval/minval)
277# 23 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
278
279! GPU parallel loop over threads (most common GPU macro)
280# 44 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
281
282! Required closing for GPU_PARALLEL_LOOP
283# 56 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
284
285! Mark routine for device compilation
286# 113 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
287
288! Declare device-resident data
289# 131 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
290
291! Inner loop within a GPU parallel region
292# 146 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
293
294! Scoped GPU data region
295# 165 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
296
297! Host code with device pointers (for MPI with GPU buffers)
298# 191 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
299
300! Allocate device memory (unscoped)
301# 205 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
302
303! Free device memory
304# 217 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
305
306! Atomic operation on device
307# 229 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
308
309! End atomic capture block
310# 240 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
311
312! Copy data between host and device
313# 252 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
314
315! Synchronization barrier
316# 264 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
317
318! Import GPU library module (openacc or omp_lib)
319# 273 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
320
321! Emit code only for AMD compiler
322# 280 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
323
324! Emit code for non-Cray compilers
325# 287 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
326
327! Emit code only for Cray compiler
328# 294 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
329
330! Cray compiler directive, emitted from Fypp so the formatter cannot turn it into a comment
331# 301 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
332
333! Emit code for non-NVIDIA compilers
334# 308 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
335
336# 310 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
337# 311 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
338! New line at end of file is required for FYPP
339# 2 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp" 2
340
341# 14 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
342
343! Caution: This macro requires the use of a binding script to set CUDA_VISIBLE_DEVICES, such that we have one GPU device per MPI
344! rank. That's because for both cudaMemAdvise (preferred location) and cudaMemPrefetchAsync we use location = device_id = 0. For an
345! example see misc/nvidia_uvm/bind.sh.
346# 52 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
347
348! Allocate and create GPU device memory
349# 72 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
350
351! Free GPU device memory and deallocate
352# 80 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
353
354! Cray-specific GPU pointer setup for vector fields
355# 104 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
356
357! Cray-specific GPU pointer setup for scalar fields
358# 120 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
359
360! Cray-specific GPU pointer teardown for scalar fields - exact inverse of ACC_SETUP_SFs. Removes the
361! present-table entries ACC_SETUP_SFs added (the scalar_field descriptor and its %sf copyin). REQUIRED when
362! an ACC_SETUP'd field is freed MID-RUN (e.g. AMR slot free on regrid/restart): Cray 'exit data delete'
363! decrements the reference counter, so the lone @:DEALLOCATE(arg%sf) only undoes the @:ALLOCATE create ref
364! and leaves the descriptor + the ACC_SETUP %sf copyin dangling. Call BEFORE @:DEALLOCATE(arg%sf).
365# 140 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
366
367! Cray-specific GPU pointer setup for acoustic source spatials
368# 165 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
369
370! Whether stress index idx is a shear component. Spelled out because NVHPC 26.9 at -O2 vectorizes any(idx == shear_indices)
371! inside a loop to always true, which doubled the normal-stress elastic energy.
372# 171 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
373
374# 177 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
375
376# 184 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
377! New line at end of file is required for FYPP
378# 7 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp" 2
379
380!> @brief Reads input files, loads initial conditions and grid data, and orchestrates solver initialization and finalization
382
386 use m_mpi_proxy
387 use m_mpi_common
389 use m_eos
390 use m_weno
391 use m_muscl
392 use m_thinc
394 use m_cbc
396 use m_boundary_io
398 use m_rhs
400 use m_chemistry
401 use m_data_output
403 use m_qbmm
405 use m_hypoelastic
407 use m_viscous
408 use m_bubbles_ee
409 use m_bubbles_el
412 use ieee_arithmetic
414 use m_helper
415
416#if defined(MFC_OpenACC)
417# 44 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
418 use openacc
419# 44 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
420#elif defined(MFC_OpenMP)
421# 44 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
422 use omp_lib
423# 44 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
424#endif
425# 45 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
426
427 use m_nvtx
428 use m_ibm
429 use m_ib_patches
430 use m_model
431 use m_collisions
434 use m_checker
436 use m_body_forces
437 use m_sim_helpers
438 use m_igr
439 use m_amr, only: amr_maxc_fit, s_initialize_amr_module, s_populate_amr_fine, s_finalize_amr_module, s_amr_setup_ib
440 use m_amr_regrid, only: s_amr_regrid
446
447 implicit none
448
453
454 type(scalar_field), allocatable, dimension(:) :: q_cons_temp
455 real(wp) :: dt_init
456
457 !> AMR: the fine level was prolonged from level 0 at start-up (no restart file), so the first step regrids onto the initial
458 !! features
459 logical :: amr_fresh_start = .false.
460
461contains
462
463 !> Read data files. Dispatch subroutine that replaces procedure pointer.
464 impure subroutine s_read_data_files(q_cons_vf)
465
466 type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
467
468 if (.not. parallel_io) then
470 else
472 end if
473
474 end subroutine s_read_data_files
475
476 !> Verify the input file exists and read it
477 impure subroutine s_read_input_file
478
479 character(LEN=name_len), parameter :: file_path = './simulation.inp'
480 logical :: file_exist !< Logical used to check the existence of the input file
481 integer :: iostatus
482 ! Integer to check iostat of file read
483
484 character(len=1000) :: line
485
486# 1 "/home/runner/work/MFC/MFC/build/include/simulation/generated_namelist.fpp" 1
487! AUTO-GENERATED - do not edit directly. Regenerate: cmake reconfigure
488!
489# 29 "/home/runner/work/MFC/MFC/build/include/simulation/generated_namelist.fpp"
490namelist /user_inputs/ adc_kappa, bx0, ca, r0ref, re_inv, web, acoustic, acoustic_source, adap_dt, adap_dt_max_iters, &
491 & adap_dt_tol, adv_n, alf_factor, alpha_bar, alt_soundspeed, amr, amr_block_beg, amr_block_end, amr_blocking_factor, &
492 & amr_buf, amr_cluster_eff, amr_device_pack, amr_max_blocks, amr_max_grid_size, amr_max_level, amr_place_owner, amr_prolong, &
493 & amr_ref_ratio, amr_regrid_int, amr_snap, amr_subcycle, amr_tag_abs, amr_tag_eps, amr_tag_species, amr_tag_var, avg_state, &
494 & bc_x, bc_y, bc_z, bf_spatial_support, bf_x, bf_y, bf_z, bub_pp, bubble_model, bubbles_euler, bubbles_lagrange, case_dir, &
495 & cfl_adap_dt, cfl_const_dt, cfl_target, chem_params, coefficient_of_restitution, collision_model, &
496 & collision_temporal_resolution, collision_time, cont_damage, cont_damage_s, cyl_coord, dist_type, down_sample, dt, &
497 & face_bound, fd_order, fft_wrt, file_extension, file_per_process, files_dir, fluid_pp, g_x, g_y, g_z, hll_u_interface, &
498 & hyper_cleaning, hyper_cleaning_speed, hyper_cleaning_tau, hypo_hll_interface_rhs, hypoelasticity, ib, ib_airfoil, &
499 & ib_coefficient_of_friction, ib_flux_wall, ib_force_stride, ib_force_wrt, ib_friction_slip_eps, ib_heat_wrt, ib_ip_interp, &
500 & ib_ip_min_dist, ib_mass_relax, ib_neighborhood_radius, ib_second_order_vel, ib_slip_ccst, ib_smooth_contact, ib_state_wrt, &
501 & ib_surface_wrt, ib_uncover_fill, ib_visc_compact, ib_wall_order, ic_beta, ic_eps, int_comp, k_x, k_y, k_z, lag_params, &
502 & low_mach, m, many_ib_patch_parallelism, mean_dpdx, mean_dpdx_gain, mean_mflux, mean_qdot, mean_temp, mean_temp_gain, &
503 & mean_temp_wall, mixlayer_vel_coef, mixlayer_vel_profile, mixture_err, model_eqns, mp_weno, mpp_lim, muscl_eps, n, n_start, &
504 & null_weights, num_bc_patches, num_ibs, num_igr_iters, num_igr_warm_start_iters, num_particle_clouds, num_patches, &
505 & num_probes, num_source, num_stl_models, num_turbulent_sources, nv_uvm_igr_temps_on_gpu, nv_uvm_out_of_core, &
506 & nv_uvm_pref_gpu, p, p_x, p_y, p_z, palpha_eps, parallel_io, particle_cloud, particle_params, particle_pp, &
507 & particles_lagrange, patch_ib, patch_icpp, pi_fac, poly_sigma, polydisperse, polytropic, precision, prim_vars_wrt, probe, &
508 & probe_wrt, ptgalpha_eps, qbmm, ramp_ratio, rank_time_wrt, rburn, rdma_mpi, reactive_burn, relax, relax_model, rhorv, &
509 & riemann_hypo_adc, riemann_solver, run_time_info, sigv, sigma, spatial_bf, stl_models, surface_tension, synth_l, &
510 & synth_u_inf, synth_amp_shell, synth_k_shell, synth_n_shells, synth_n_waves_per_shell, synth_seed, synthetic_turbulence, &
511 & t_save, t_step_old, t_step_print, t_step_save, t_step_start, t_step_stop, t_stop, tau_star, teno_ct, thermal, &
512 & time_stepper, turb_pos, w_x, w_y, w_z, wall_column_dt_frac, wave_speeds, weno_re_flux, weno_re_flux_compact, weno_avg, &
513 & weno_eps, &
514 & igr, igr_iter_solver, igr_order, igr_pres_lim, mapped_weno, mhd, muscl_lim, muscl_order, nb, num_fluids, recon_type, &
515 & relativity, teno, viscous, weno_order, wenoz, wenoz_q
516# 56 "/home/runner/work/MFC/MFC/build/include/simulation/generated_namelist.fpp"
517# 106 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp" 2
518
519 inquire (file=trim(file_path), exist=file_exist)
520
521 if (file_exist) then
522 open (1, file=trim(file_path), form='formatted', action='read', status='old')
523 read (1, nml=user_inputs, iostat=iostatus)
524
525 if (iostatus /= 0) then
526 backspace(1)
527 read (1, fmt='(A)') line
528 print *, 'Invalid line in namelist: ' // trim(line)
529 call s_mpi_abort('Invalid line in simulation.inp. It is ' // 'likely due to a datatype mismatch. Exiting.')
530 end if
531
532 close (1)
533
534 if (bf_x .or. bf_y .or. bf_z .or. bf_spatial_support .or. any(mean_dpdx /= 0._wp) &
535 & .or. any(.not. f_is_default(mean_mflux)) .or. mean_qdot /= 0._wp .or. .not. f_is_default(mean_temp)) then
536 bodyforces = .true.
537 end if
538
539 m_glb = m
540 n_glb = n
541 p_glb = p
542
544
545 if (cfl_adap_dt .or. cfl_const_dt) cfl_dt = .true.
546
547 if (any((/bc_x%beg, bc_x%end, bc_y%beg, bc_y%end, bc_z%beg, bc_z%end/) == -17) .or. num_bc_patches > 0) then
548 bc_io = .true.
549 end if
550
551 if (bc_x%beg == bc_periodic .and. bc_x%end == bc_periodic) periodic_bc(1) = .true.
552 if (bc_y%beg == bc_periodic .and. bc_y%end == bc_periodic) periodic_bc(2) = .true.
553 if (bc_z%beg == bc_periodic .and. bc_z%end == bc_periodic) periodic_bc(3) = .true.
554 else
555 call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
556 end if
557
558 end subroutine s_read_input_file
559
560 !> Validate that all user-provided inputs form a consistent simulation configuration
561 impure subroutine s_check_input_file
562
563 character(LEN=path_len) :: file_path
564 logical :: file_exist
565
566 file_path = trim(case_dir) // '/.'
567
568 call my_inquire(file_path, file_exist)
569
570 if (file_exist .neqv. .true.) then
571 call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
572 end if
573
574 call s_check_inputs_common(check_total_cells=.false., n_global=0_8)
575 call s_check_inputs()
576
577 end subroutine s_check_input_file
578
579 !> Read serial initial condition and grid data files and compute cell-width distributions
580 impure subroutine s_read_serial_data_files(q_cons_vf)
581
582 type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
583 character(LEN=path_len + 2*name_len) :: t_step_dir !< Relative path to the starting time-step directory
584 character(LEN=path_len + 3*name_len) :: file_path !< Relative path to the grid and conservative variables data files
585 logical :: file_exist !< Logical used to check the existence of the input file
586 integer :: i, r
587
588 if (cfl_dt) then
589 write (t_step_dir, '(A,I0,A,I0)') trim(case_dir) // '/p_all/p', proc_rank, '/', n_start
590 else
591 write (t_step_dir, '(A,I0,A,I0)') trim(case_dir) // '/p_all/p', proc_rank, '/', t_step_start
592 end if
593
594 file_path = trim(t_step_dir) // '/.'
595 call my_inquire(file_path, file_exist)
596
597 if (file_exist .neqv. .true.) then
598 call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
599 end if
600
601 if (bc_io) then
603 else
605 end if
606
607 file_path = trim(t_step_dir) // '/x_cb.dat'
608
609 inquire (file=trim(file_path), exist=file_exist)
610
611 if (file_exist) then
612 open (2, file=trim(file_path), form='unformatted', action='read', status='old')
613 read (2) x_cb(-1:m); close (2)
614 else
615 call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
616 end if
617
618 dx(0:m) = x_cb(0:m) - x_cb(-1:m - 1)
619 x_cc(0:m) = x_cb(-1:m - 1) + dx(0:m)/2._wp
620
621 if (n > 0) then
622 file_path = trim(t_step_dir) // '/y_cb.dat'
623
624 inquire (file=trim(file_path), exist=file_exist)
625
626 if (file_exist) then
627 open (2, file=trim(file_path), form='unformatted', action='read', status='old')
628 read (2) y_cb(-1:n); close (2)
629 else
630 call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
631 end if
632
633 dy(0:n) = y_cb(0:n) - y_cb(-1:n - 1)
634 y_cc(0:n) = y_cb(-1:n - 1) + dy(0:n)/2._wp
635 end if
636
637 if (p > 0) then
638 file_path = trim(t_step_dir) // '/z_cb.dat'
639
640 inquire (file=trim(file_path), exist=file_exist)
641
642 if (file_exist) then
643 open (2, file=trim(file_path), form='unformatted', action='read', status='old')
644 read (2) z_cb(-1:p); close (2)
645 else
646 call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
647 end if
648
649 dz(0:p) = z_cb(0:p) - z_cb(-1:p - 1)
650 z_cc(0:p) = z_cb(-1:p - 1) + dz(0:p)/2._wp
651 end if
652
653 do i = 1, sys_size
654 write (file_path, '(A,I0,A)') trim(t_step_dir) // '/q_cons_vf', i, '.dat'
655 inquire (file=trim(file_path), exist=file_exist)
656 if (file_exist) then
657 open (2, file=trim(file_path), form='unformatted', action='read', status='old')
658 read (2) q_cons_vf(i)%sf(0:m,0:n,0:p); close (2)
659 else
660 call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
661 end if
662 end do
663
664 if (bubbles_euler .or. hypoelasticity) then
665 ! Read pb and mv for non-polytropic qbmm
666 if (qbmm .and. .not. polytropic) then
667 do i = 1, nb
668 do r = 1, nnode
669 write (file_path, '(A,I0,A)') trim(t_step_dir) // '/pb', sys_size + (i - 1)*nnode + r, '.dat'
670 inquire (file=trim(file_path), exist=file_exist)
671 if (file_exist) then
672 open (2, file=trim(file_path), form='unformatted', action='read', status='old')
673 read (2) pb_ts(1)%sf(0:m,0:n,0:p,r, i); close (2)
674 else
675 call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
676 end if
677 end do
678 end do
679 do i = 1, nb
680 do r = 1, nnode
681 write (file_path, '(A,I0,A)') trim(t_step_dir) // '/mv', sys_size + (i - 1)*nnode + r, '.dat'
682 inquire (file=trim(file_path), exist=file_exist)
683 if (file_exist) then
684 open (2, file=trim(file_path), form='unformatted', action='read', status='old')
685 read (2) mv_ts(1)%sf(0:m,0:n,0:p,r, i); close (2)
686 else
687 call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
688 end if
689 end do
690 end do
691 end if
692 end if
693
694 end subroutine s_read_serial_data_files
695
696 !> Read parallel initial condition and grid data files via MPI I/O
697 impure subroutine s_read_parallel_data_files(q_cons_vf)
698
699 type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
700
701#ifdef MFC_MPI
702 real(wp), allocatable, dimension(:) :: x_cb_glb, y_cb_glb, z_cb_glb
703 integer :: ifile, ierr, data_size
704 integer, dimension(MPI_STATUS_SIZE) :: status
705 integer(KIND=MPI_OFFSET_KIND) :: disp
706 integer(KIND=MPI_OFFSET_KIND) :: m_mok, n_mok, p_mok
707 integer(KIND=MPI_OFFSET_KIND) :: wp_mok, var_mok
708 integer(KIND=MPI_OFFSET_KIND) :: mok
709 character(LEN=path_len + 2*name_len) :: file_loc
710 logical :: file_exist
711 character(len=10) :: t_step_start_string
712 integer :: i, j
713 integer(KIND=MPI_OFFSET_KIND) :: nvars_mok !< variables read per cell
714
715 ! Downsampled data variables
716 integer :: m_ds, n_ds, p_ds
717 integer :: m_glb_ds, n_glb_ds, p_glb_ds
718 integer :: m_glb_read, n_glb_read, p_glb_read !< data size of read
719
720 allocate (x_cb_glb(-1:m_glb))
721 allocate (y_cb_glb(-1:n_glb))
722 allocate (z_cb_glb(-1:p_glb))
723
724 file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // 'x_cb.dat'
725 inquire (file=trim(file_loc), exist=file_exist)
726
727 if (down_sample) then
728 m_ds = int((m + 1)/3) - 1
729 n_ds = int((n + 1)/3) - 1
730 p_ds = int((p + 1)/3) - 1
731
732 m_glb_ds = int((m_glb + 1)/3) - 1
733 n_glb_ds = int((n_glb + 1)/3) - 1
734 p_glb_ds = int((p_glb + 1)/3) - 1
735 end if
736
737 if (file_exist) then
738 data_size = m_glb + 2
739 call mpi_file_open(mpi_comm_world, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
740 call s_check_mpi_file_open(ierr, file_loc)
741 call mpi_file_read(ifile, x_cb_glb, data_size, mpi_p, status, ierr)
742 call mpi_file_close(ifile, ierr)
743 else
744 call s_mpi_abort('File ' // trim(file_loc) // ' is missing. Exiting.')
745 end if
746
747 call s_apply_grid_from_global_dim(x_cb_glb, m_glb, m, start_idx(1), bc_x%beg, bc_x%end, buff_size, buff_size, buff_size, &
748 & buff_size, x_cb, x_cc, dx)
749
750 if (n > 0) then
751 file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // 'y_cb.dat'
752 inquire (file=trim(file_loc), exist=file_exist)
753
754 if (file_exist) then
755 data_size = n_glb + 2
756 call mpi_file_open(mpi_comm_world, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
757 call s_check_mpi_file_open(ierr, file_loc)
758 call mpi_file_read(ifile, y_cb_glb, data_size, mpi_p, status, ierr)
759 call mpi_file_close(ifile, ierr)
760 else
761 call s_mpi_abort('File ' // trim(file_loc) // ' is missing. Exiting.')
762 end if
763
764 call s_apply_grid_from_global_dim(y_cb_glb, n_glb, n, start_idx(2), bc_y%beg, bc_y%end, buff_size, buff_size, &
766
767 if (p > 0) then
768 file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // 'z_cb.dat'
769 inquire (file=trim(file_loc), exist=file_exist)
770
771 if (file_exist) then
772 data_size = p_glb + 2
773 call mpi_file_open(mpi_comm_world, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
774 call s_check_mpi_file_open(ierr, file_loc)
775 call mpi_file_read(ifile, z_cb_glb, data_size, mpi_p, status, ierr)
776 call mpi_file_close(ifile, ierr)
777 else
778 call s_mpi_abort('File ' // trim(file_loc) // 'is missing. Exiting.')
779 end if
780
781 call s_apply_grid_from_global_dim(z_cb_glb, p_glb, p, start_idx(3), bc_z%beg, bc_z%end, buff_size, buff_size, &
783 end if
784 end if
785
786 nvars_mok = int(sys_size, mpi_offset_kind)
787 if ((bubbles_euler .or. hypoelasticity) .and. qbmm .and. .not. polytropic) nvars_mok = nvars_mok + 2*nb*nnode
788
789 if (file_per_process) then
790 if (cfl_dt) then
791 call s_int_to_str(n_start, t_step_start_string)
792 write (file_loc, '(I0,A1,I7.7,A)') n_start, '_', proc_rank, '.dat'
793 else
794 call s_int_to_str(t_step_start, t_step_start_string)
795 write (file_loc, '(I0,A1,I7.7,A)') t_step_start, '_', proc_rank, '.dat'
796 end if
797 file_loc = trim(case_dir) // '/restart_data/lustre_' // trim(t_step_start_string) // trim(mpiiofs) // trim(file_loc)
798 inquire (file=trim(file_loc), exist=file_exist)
799
800 if (file_exist) then
801 call mpi_file_open(mpi_comm_self, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
802 call s_check_mpi_file_open(ierr, file_loc)
803
804 if (down_sample) then
805 call s_initialize_mpi_data_ds(m_ds, n_ds, p_ds)
806 else
807 if (ib) then
809 & qbmm_pb=pb_ts(1), qbmm_mv=mv_ts(1))
810 else
811 call s_initialize_mpi_data(q_cons_vf, qbmm_pb=pb_ts(1), qbmm_mv=mv_ts(1))
812 end if
813 end if
814
815 if (down_sample) then
816 data_size = (m_ds + 3)*(n_ds + 3)*(p_ds + 3)
817 m_glb_read = m_glb_ds + 1
818 n_glb_read = n_glb_ds + 1
819 p_glb_read = p_glb_ds + 1
820 else
821 data_size = (m + 1)*(n + 1)*(p + 1)
822 m_glb_read = m_glb + 1
823 n_glb_read = n_glb + 1
824 p_glb_read = p_glb + 1
825 end if
826 call s_check_restart_file_size(ifile, file_loc, int(data_size, mpi_offset_kind)*int(storage_size(0._stp)/8, &
827 & mpi_offset_kind)*nvars_mok)
828
829 m_mok = int(m_glb_read + 1, mpi_offset_kind)
830 n_mok = int(m_glb_read + 1, mpi_offset_kind)
831 p_mok = int(m_glb_read + 1, mpi_offset_kind)
832 wp_mok = int(storage_size(0._stp)/8, mpi_offset_kind)
833 mok = int(1._wp, mpi_offset_kind)
834
835 if (bubbles_euler .or. hypoelasticity) then
836 do i = 1, sys_size
837 var_mok = int(i, mpi_offset_kind)
838
839 call mpi_file_read(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
840 end do
841 ! Read pb and mv for non-polytropic qbmm
842 if (qbmm .and. .not. polytropic) then
843 do i = sys_size + 1, sys_size + 2*nb*nnode
844 var_mok = int(i, mpi_offset_kind)
845
846 call mpi_file_read(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
847 end do
848 end if
849 else
850 if (down_sample) then
851 do i = 1, sys_size
852 var_mok = int(i, mpi_offset_kind)
853
854 call mpi_file_read(ifile, q_cons_temp(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
855 end do
856 else
857 do i = 1, sys_size
858 var_mok = int(i, mpi_offset_kind)
859
860 call mpi_file_read(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
861 end do
862 end if
863 end if
864
865 call s_mpi_barrier()
866
867 call mpi_file_close(ifile, ierr)
868 else
869 call s_mpi_abort('File ' // trim(file_loc) // ' is missing. Exiting.')
870 end if
871 else
872 if (cfl_dt) then
873 write (file_loc, '(I0,A)') n_start, '.dat'
874 else
875 write (file_loc, '(I0,A)') t_step_start, '.dat'
876 end if
877 file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // trim(file_loc)
878 inquire (file=trim(file_loc), exist=file_exist)
879
880 if (file_exist) then
881 call mpi_file_open(mpi_comm_world, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
882 call s_check_mpi_file_open(ierr, file_loc)
883
884 if (ib) then
886 & qbmm_mv=mv_ts(1))
887 else
888 call s_initialize_mpi_data(q_cons_vf, qbmm_pb=pb_ts(1), qbmm_mv=mv_ts(1))
889 end if
890
891 data_size = (m + 1)*(n + 1)*(p + 1)
892
893 m_mok = int(m_glb + 1, mpi_offset_kind)
894 n_mok = int(n_glb + 1, mpi_offset_kind)
895 p_mok = int(p_glb + 1, mpi_offset_kind)
896 wp_mok = int(storage_size(0._stp)/8, mpi_offset_kind)
897 mok = int(1._wp, mpi_offset_kind)
898 call s_check_restart_file_size(ifile, file_loc, m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*nvars_mok)
899
900 if (bubbles_euler .or. hypoelasticity) then
901 do i = 1, sys_size
902 var_mok = int(i, mpi_offset_kind)
903 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1)
904
905 call mpi_file_set_view(ifile, disp, mpi_io_p, mpi_io_data%view(i), 'native', mpi_info_int, ierr)
906 call mpi_file_read(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
907 end do
908 ! Read pb and mv for non-polytropic qbmm
909 if (qbmm .and. .not. polytropic) then
910 do i = sys_size + 1, sys_size + 2*nb*nnode
911 var_mok = int(i, mpi_offset_kind)
912 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1)
913
914 call mpi_file_set_view(ifile, disp, mpi_io_p, mpi_io_data%view(i), 'native', mpi_info_int, ierr)
915 call mpi_file_read(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
916 end do
917 end if
918 else
919 do i = 1, sys_size
920 var_mok = int(i, mpi_offset_kind)
921
922 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1)
923
924 call mpi_file_set_view(ifile, disp, mpi_io_p, mpi_io_data%view(i), 'native', mpi_info_int, ierr)
925 call mpi_file_read_all(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
926 end do
927 end if
928
929 call s_mpi_barrier()
930
931 call mpi_file_close(ifile, ierr)
932 else
933 call s_mpi_abort('File ' // trim(file_loc) // ' is missing. Exiting.')
934 end if
935 end if
936
937 deallocate (x_cb_glb, y_cb_glb, z_cb_glb)
938
939 if (bc_io) then
941 else
943 end if
944#endif
945
946 end subroutine s_read_parallel_data_files
947
948#ifdef MFC_MPI
949 !> Abort if an open restart file holds fewer bytes than are about to be read from it, as a job killed while writing it leaves.
950 !! MPI reads past the end return short without an error, so the missing tail would come back as garbage.
951 impure subroutine s_check_restart_file_size(ifile, file_loc, expected_bytes)
952
953 integer, intent(in) :: ifile
954 character(len=*), intent(in) :: file_loc
955 integer(KIND=MPI_OFFSET_KIND), intent(in) :: expected_bytes
956 integer(KIND=MPI_OFFSET_KIND) :: file_bytes
957 integer :: ierr
958 character(len=64) :: sizes
959
960 call mpi_file_get_size(ifile, file_bytes, ierr)
961 if (ierr /= mpi_success) call s_mpi_abort('MPI_FILE_GET_SIZE failed on ' // trim(file_loc) // '. Exiting.')
962 if (file_bytes < expected_bytes) then
963 write (sizes, '(I0," bytes but ",I0)') file_bytes, expected_bytes
964 call s_mpi_abort('Restart file ' // trim(file_loc) // ' holds ' // trim(sizes) // ' are expected. It is ' &
965 & // 'truncated, e.g. by a job killed while writing it; restart from an earlier step.')
966 end if
967
968 end subroutine s_check_restart_file_size
969#endif
970
971 !> Initialize internal-energy equations from phase mass, mixture momentum, and total energy
973
974 type(scalar_field), dimension(sys_size), intent(inout) :: v_vf
975 real(wp) :: rho
976 real(wp) :: dyn_pres
977 real(wp) :: gamma
978 real(wp) :: pi_inf
979 real(wp) :: qv
980 real(wp), dimension(2) :: re
981 real(wp) :: pres, t
982 real(wp) :: alpha_i, alpha_rho_i, e_i
983 integer :: i, j, k, l, c
984 real(wp), dimension(num_species) :: rhoyks
985 real(wp) :: pres_mag
986
987 pres_mag = 0._wp
988
989 t = dflt_t_guess
990
991 do j = 0, m
992 do k = 0, n
993 do l = 0, p
994 call s_convert_to_mixture_variables(v_vf, j, k, l, rho, gamma, pi_inf, qv, re)
995
996 dyn_pres = 0._wp
997 do i = eqn_idx%mom%beg, eqn_idx%mom%end
998 dyn_pres = dyn_pres + 5.e-1_wp*v_vf(i)%sf(j, k, l)*v_vf(i)%sf(j, k, l)/max(rho, sgm_eps)
999 end do
1000
1001 if (chemistry) then
1002 do c = 1, num_species
1003 rhoyks(c) = v_vf(eqn_idx%species%beg + c - 1)%sf(j, k, l)
1004 end do
1005 end if
1006
1007 if (mhd) then
1008 if (n == 0) then
1009 pres_mag = 0.5_wp*(bx0**2 + v_vf(eqn_idx%B%beg)%sf(j, k, l)**2 + v_vf(eqn_idx%B%beg + 1)%sf(j, k, l)**2)
1010 else
1011 pres_mag = 0.5_wp*(v_vf(eqn_idx%B%beg)%sf(j, k, l)**2 + v_vf(eqn_idx%B%beg + 1)%sf(j, k, &
1012 & l)**2 + v_vf(eqn_idx%B%beg + 2)%sf(j, k, l)**2)
1013 end if
1014 end if
1015
1016 call s_compute_pressure(v_vf(eqn_idx%E)%sf(j, k, l), 0._stp, dyn_pres, pi_inf, gamma, rho, qv, rhoyks, pres, &
1017 & t, pres_mag=pres_mag)
1018
1019 do i = 1, num_fluids
1020 alpha_i = v_vf(i + eqn_idx%adv%beg - 1)%sf(j, k, l)
1021 alpha_rho_i = v_vf(i + eqn_idx%cont%beg - 1)%sf(j, k, l)
1022 call s_phase_internal_energy(pres, alpha_i, alpha_rho_i, i, e_i)
1023 v_vf(i + eqn_idx%int_en%beg - 1)%sf(j, k, l) = e_i
1024 end do
1025 end do
1026 end do
1027 end do
1028
1030
1031 !> Advance the simulation by one time step, handling CFL-based dt and time-stepper dispatch
1032 impure subroutine s_perform_time_step(t_step, time_avg)
1033
1034 integer, intent(inout) :: t_step
1035 real(wp), intent(inout) :: time_avg
1036 integer :: i, eta_hh, eta_mm, eta_ss
1037 real(wp) :: eta_sec
1038 real(wp) :: dt_floor
1039 character(len=8) :: lim_str !< Time-step limiter tag, e.g. ' (ICFL)'
1040
1041 call s_phase_step_tic()
1042 if (t_step == t_step_start) then
1044 if (amr_regrid_int > 0) call s_amr_check_fixed_dt(reach=.true.)
1045 end if
1046 if (cfl_dt) then
1047 if (cfl_const_dt .and. t_step == 0) call s_compute_dt()
1048
1049 if (cfl_adap_dt) call s_compute_dt()
1050
1051 if (t_step == 0) dt_init = dt
1052
1053 ! the collision restriction deliberately drops dt to collision_time/collision_temporal_resolution, so lower the
1054 ! runaway-dt abort threshold below that cap when it is enabled
1055 dt_floor = 1.e-3_wp*dt_init
1056 if (collision_model > 0 .and. collision_temporal_resolution > 0) then
1057 dt_floor = min(dt_floor, 1.e-3_wp*collision_time/real(collision_temporal_resolution, wp))
1058 end if
1059
1060 if (dt < dt_floor .and. cfl_adap_dt .and. proc_rank == 0) then
1061 print *, "Delta t = ", dt, " limited by ", dt_limiter
1062 call s_mpi_abort("Delta t has become too small")
1063 end if
1064 end if
1065
1066 ! Land exactly on t_stop. A fixed dt already lands on t_step_stop by step count; trimming it to t_step_stop*dt - mytime
1067 ! would only change the run's last dt by round-off, which a run continuing past that step does not see
1068 if (cfl_dt) then
1069 if ((mytime + dt) >= t_stop) then
1070 dt = t_stop - mytime
1071
1072# 659 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1073#if defined(MFC_OpenACC)
1074# 659 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1075!$acc update device(dt)
1076# 659 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1077#elif defined(MFC_OpenMP)
1078# 659 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1079!$omp target update to(dt)
1080# 659 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1081#endif
1082# 660 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1083 end if
1084 end if
1085
1086 if (cfl_dt) then
1087 if (proc_rank == 0 .and. mod(t_step - t_step_start, t_step_print) == 0) then
1088 eta_sec = wall_time_avg*(t_stop - mytime)/max(dt, tiny(dt))
1089 eta_hh = int(eta_sec)/3600
1090 eta_mm = mod(int(eta_sec), 3600)/60
1091 eta_ss = mod(int(eta_sec), 60)
1092 lim_str = ''
1093 if (cfl_adap_dt) lim_str = ' (' // dt_limiter // ')'
1094 print '(" [", I3, "%] t = ", ES11.4, " dt = ", ES11.4, A, " @ step ", I0, " t/step ", ES9.2, "s (avg ", ES9.2, "s) ETA ", I0, ":", I2.2, ":", I2.2)', &
1095 & int(ceiling(100._wp*(mytime/t_stop))), mytime, dt, trim(lim_str), t_step, wall_time, wall_time_avg, eta_hh, &
1096 & eta_mm, eta_ss
1097 end if
1098 else
1099 if (proc_rank == 0 .and. mod(t_step - t_step_start, t_step_print) == 0) then
1100 eta_sec = wall_time_avg*real(t_step_stop - t_step, wp)
1101 eta_hh = int(eta_sec)/3600
1102 eta_mm = mod(int(eta_sec), 3600)/60
1103 eta_ss = mod(int(eta_sec), 60)
1104 print '(" [", I3, "%] step ", I0, " of ", I0, " (t_step ", I0, ") t/step ", ES9.2, "s (avg ", ES9.2, "s) ETA ", I0, ":", I2.2, ":", I2.2)', &
1105 & int(ceiling(100._wp*(real(t_step - t_step_start)/(t_step_stop - t_step_start + 1)))), &
1106 & t_step - t_step_start + 1, t_step_stop - t_step_start + 1, t_step, wall_time, wall_time_avg, eta_hh, &
1107 & eta_mm, eta_ss
1108 end if
1109 end if
1110
1111 if (probe_wrt) then
1112 do i = 1, sys_size
1113
1114# 690 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1115#if defined(MFC_OpenACC)
1116# 690 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1117!$acc update host(q_cons_ts(1)%vf(i)%sf)
1118# 690 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1119#elif defined(MFC_OpenMP)
1120# 690 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1121!$omp target update from(q_cons_ts(1)%vf(i)%sf)
1122# 690 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1123#endif
1124# 691 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1125 end do
1126 if (bubbles_euler) then
1127
1128# 693 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1129#if defined(MFC_OpenACC)
1130# 693 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1131!$acc update host(ptil)
1132# 693 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1133#elif defined(MFC_OpenMP)
1134# 693 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1135!$omp target update from(ptil)
1136# 693 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1137#endif
1138# 694 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1139 end if
1140 end if
1141
1142 ! Total-variation-diminishing (TVD) Runge-Kutta (RK) time-steppers
1143 if (any(time_stepper == (/time_stepper_rk1, time_stepper_rk2, time_stepper_rk3/))) then
1144 call s_tvd_rk(t_step, time_avg, time_stepper)
1145 end if
1146
1147 ! Advance time after RK so source terms see current-step time. With a fixed dt, use the same t_step*dt a restart
1148 ! starts from (p_main): a running sum drifts from it (1290 ulps by step 27000), so a restarted run would see the
1149 ! prescribed IB kinematics, inflow ramps and forcing at slightly different times than the run it continues
1150 if (cfl_dt) then
1151 mytime = mytime + dt
1152 else
1153 mytime = (t_step + 1)*dt
1154 end if
1155
1156 if (relax) then
1158 if (amr) call s_amr_relax_fine(q_cons_ts(1)%vf)
1159 end if
1160
1161 ! Time-stepping loop controls
1162 t_step = t_step + 1
1163
1164 if (amr .and. amr_regrid_int > 0) then
1165 if (mod(t_step, amr_regrid_int) == 0) then
1167 call s_amr_regrid(q_cons_ts(1)%vf)
1170 end if
1171 end if
1172
1173 call s_phase_step_toc()
1174
1175 end subroutine s_perform_time_step
1176
1177 !> Collect per-process wall-clock times and write aggregate performance metrics to file
1178 impure subroutine s_save_performance_metrics(time_avg, time_final, io_time_avg, io_time_final, proc_time, io_proc_time, &
1179 & file_exists)
1180
1181 real(wp), intent(inout) :: time_avg, time_final
1182 real(wp), intent(inout) :: io_time_avg, io_time_final
1183 real(wp), dimension(:), intent(inout) :: proc_time
1184 real(wp), dimension(:), intent(inout) :: io_proc_time
1185 logical, intent(inout) :: file_exists
1186 real(wp) :: grind_time
1187
1188 call s_mpi_barrier()
1189
1190 if (num_procs > 1) then
1191 call mpi_bcast_time_step_values(proc_time, time_avg)
1192
1193 call mpi_bcast_time_step_values(io_proc_time, io_time_avg)
1194 end if
1195
1196 if (proc_rank == 0) then
1197 time_final = 0._wp
1198 io_time_final = 0._wp
1199 if (num_procs == 1) then
1200 time_final = time_avg
1201 io_time_final = io_time_avg
1202 else
1203 time_final = maxval(proc_time)
1204 io_time_final = maxval(io_proc_time)
1205 end if
1206
1207 grind_time = time_final*1.0e9_wp/(real(sys_size, wp)*real(maxval((/1, m_glb/)), wp)*real(maxval((/1, n_glb/)), &
1208 & wp)*real(maxval((/1, p_glb/)), wp))
1209
1210 print *, "Performance:", grind_time, "ns/gp/eq/rhs"
1211 inquire (file='time_data.dat', exist=file_exists)
1212 if (file_exists) then
1213 open (1, file='time_data.dat', position='append', status='old')
1214 else
1215 open (1, file='time_data.dat', status='new')
1216 ! time_final is the fastest single RK stage (one RHS evaluation), not a whole step; see s_tvd_rk
1217 write (1, '(A10, A15, A15)') "Ranks", "s/rhs", "ns/gp/eq/rhs"
1218 end if
1219
1220 write (1, '(I10, 2(F15.8))') num_procs, time_final, grind_time
1221
1222 close (1)
1223
1224 inquire (file='io_time_data.dat', exist=file_exists)
1225 if (file_exists) then
1226 open (1, file='io_time_data.dat', position='append', status='old')
1227 else
1228 open (1, file='io_time_data.dat', status='new')
1229 ! io_time_final is the mean time of one s_save_data call
1230 write (1, '(A10, A15)') "Ranks", "s/save"
1231 end if
1232
1233 write (1, '(I10, F15.8)') num_procs, io_time_final
1234 close (1)
1235 end if
1236
1237 end subroutine s_save_performance_metrics
1238
1239 !> Save conservative variable data to disk at the current time step
1240 impure subroutine s_save_data(t_step, start, finish, io_time_avg, nt)
1241
1242 integer, intent(inout) :: t_step
1243 real(wp), intent(inout) :: start, finish, io_time_avg
1244 integer, intent(inout) :: nt
1245 integer(kind=8) :: i, j, k, l
1246 integer :: stor
1247 integer :: save_count
1248
1249 if (down_sample) then
1251 end if
1252
1253 stor = 1
1254
1255 if (time_stepper /= time_stepper_rk1) then
1256
1257# 811 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1258
1259# 811 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1260#if defined(MFC_OpenACC)
1261# 811 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1262!$acc parallel loop collapse(4) gang vector default(present) copyin(idwbuff)
1263# 811 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1264#elif defined(MFC_OpenMP)
1265# 811 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1266
1267# 811 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1268
1269# 811 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1270
1271# 811 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1272!$omp target teams loop defaultmap(firstprivate:scalar) bind(teams,parallel) collapse(4) defaultmap(tofrom:aggregate) defaultmap(tofrom:allocatable) defaultmap(tofrom:pointer) map(to:idwbuff)
1273# 811 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1274#endif
1275# 812 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1276 do i = 1, sys_size
1277 do l = idwbuff(3)%beg, idwbuff(3)%end
1278 do k = idwbuff(2)%beg, idwbuff(2)%end
1279 do j = idwbuff(1)%beg, idwbuff(1)%end
1280 q_cons_ts(2)%vf(i)%sf(j, k, l) = q_cons_ts(1)%vf(i)%sf(j, k, l)
1281 end do
1282 end do
1283 end do
1284 end do
1285
1286# 821 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1287#if defined(MFC_OpenACC)
1288# 821 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1289!$acc end parallel loop
1290# 821 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1291#elif defined(MFC_OpenMP)
1292# 821 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1293
1294# 821 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1295!$omp end target teams loop
1296# 821 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1297#endif
1298# 822 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1299 stor = 2
1300 end if
1301
1302 call cpu_time(start)
1303 call nvtxstartrange("SAVE-DATA")
1304 do i = 1, sys_size
1305#ifndef FRONTIER_UNIFIED
1306
1307# 829 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1308#if defined(MFC_OpenACC)
1309# 829 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1310!$acc update host(q_cons_ts(stor)%vf(i)%sf)
1311# 829 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1312#elif defined(MFC_OpenMP)
1313# 829 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1314!$omp target update from(q_cons_ts(stor)%vf(i)%sf)
1315# 829 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1316#endif
1317# 830 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1318#endif
1319 do l = 0, p
1320 do k = 0, n
1321 do j = 0, m
1322 if (ieee_is_nan(real(q_cons_ts(stor)%vf(i)%sf(j, k, l), kind=wp))) then
1323 print *, "NaN(s) in timestep output.", j, k, l, i, proc_rank, t_step, m, n, p
1324 call s_mpi_abort("NaN(s) in timestep output.")
1325 end if
1326 end do
1327 end do
1328 end do
1329 end do
1330
1331 if (qbmm .and. .not. polytropic) then
1332
1333# 844 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1334#if defined(MFC_OpenACC)
1335# 844 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1336!$acc update host(pb_ts(1)%sf)
1337# 844 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1338#elif defined(MFC_OpenMP)
1339# 844 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1340!$omp target update from(pb_ts(1)%sf)
1341# 844 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1342#endif
1343# 845 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1344
1345# 845 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1346#if defined(MFC_OpenACC)
1347# 845 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1348!$acc update host(mv_ts(1)%sf)
1349# 845 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1350#elif defined(MFC_OpenMP)
1351# 845 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1352!$omp target update from(mv_ts(1)%sf)
1353# 845 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1354#endif
1355# 846 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1356 end if
1357
1358 if (cfl_dt) then
1359 save_count = int(mytime/t_save)
1360 else
1361 save_count = t_step
1362 end if
1363
1364 if (bubbles_lagrange) then
1366 call s_write_data_files(q_cons_ts(stor)%vf, q_t_sf, q_prim_vf, save_count, bc_type, q_beta(bub_q_idx%alphaf))
1367 call s_write_lag_save_data(save_count)
1368 else if (particles_lagrange) then
1371 call s_write_lag_save_data(save_count)
1372 else
1373 call s_write_data_files(q_cons_ts(stor)%vf, q_t_sf, q_prim_vf, save_count, bc_type)
1374 end if
1375
1376 ! Write IB kinematic state for restart
1377 if (ib) call s_write_ib_state_file(save_count)
1378 if (ib .and. ib_surface_wrt) call s_write_ib_surface(save_count)
1379 ! Fine-level AMR restart file (current box + intersection-local fine state) alongside the level-0 restart
1380 if (amr) call s_write_amr_restart(save_count)
1381
1382 call nvtxendrange
1383 call cpu_time(finish)
1384 if (cfl_dt) then
1385 nt = mytime/t_save
1386 else
1387 nt = int((t_step - t_step_start)/(t_step_save))
1388 end if
1389
1390 if (nt <= 1) then ! nt = 0 for the initial save of Lagrangian particle runs
1391 io_time_avg = abs(finish - start)
1392 else
1393 io_time_avg = (abs(finish - start) + io_time_avg*(nt - 1))/nt
1394 end if
1395
1396 end subroutine s_save_data
1397
1398 !> Initialize all simulation sub-modules in the required dependency order
1399 impure subroutine s_initialize_modules
1400
1401 integer :: m_ds, n_ds, p_ds
1402 integer :: i
1403 integer :: save_count, n_lag_loc
1404 real(wp) :: qtime
1405 real(wp), allocatable, dimension(:,:) :: lag_rows !< Lagrangian input-file or restart rows
1406 integer, allocatable, dimension(:) :: lag_ids !< Their global IDs on a fresh start
1407 logical :: amr_restored
1408
1410 ! Start time; a CFL-mode restart replaces the nominal t_save*n_start with the saved time (s_read_ib_restart_data)
1411 if (cfl_dt) then
1412 mytime = t_save*n_start
1413 else
1414 mytime = t_step_start*dt
1415 end if
1416# 916 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1417 if (bubbles_euler .or. bubbles_lagrange) then
1419 end if
1420 ! AMR needs the temperature ghost as the cons->prim Newton guess when a fine block's conversion widens over the ghost shell
1421 call s_initialize_mpi_common_module(exchange_all_chemistry_temperatures_in=amr, use_rdma_transport_in=rdma_mpi, &
1422 & num_beta_vars_in=max(merge(bub_q_idx%num, 0, bubbles_lagrange), &
1423 & merge(part_q_idx%num, 0, particles_lagrange)))
1426 call s_initialize_variables_conversion_module(enforce_density_floor=.true., preserve_qbmm_number=.true.)
1427 if (grid_geometry == 3) call s_initialize_fftw_module()
1428
1429 if (bubbles_euler) call s_initialize_bubbles_ee_module()
1430 if (ib) then
1432 end if
1433 if (qbmm) call s_initialize_qbmm_module()
1434
1435 if (acoustic_source) then
1437 end if
1438
1439 if (viscous .and. (.not. igr)) then
1441 end if
1442
1444
1445 if (surface_tension) call s_initialize_surface_tension_module()
1446
1447 if (relax) call s_initialize_phasechange_module()
1448
1452
1453 call s_initialize_boundary_common_module(use_dirichlet_buffers=.true.)
1454
1455 if (down_sample) then
1456 m_ds = int((m + 1)/3) - 1
1457 n_ds = int((n + 1)/3) - 1
1458 p_ds = int((p + 1)/3) - 1
1459
1460 allocate (q_cons_temp(1:sys_size))
1461 do i = 1, sys_size
1462 allocate (q_cons_temp(i)%sf(-1:m_ds + 1,-1:n_ds + 1,-1:p_ds + 1))
1463 end do
1464 end if
1465
1466 if (down_sample) then
1469 do i = 1, sys_size
1470
1471# 969 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1472#if defined(MFC_OpenACC)
1473# 969 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1474!$acc update device(q_cons_ts(1)%vf(i)%sf)
1475# 969 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1476#elif defined(MFC_OpenMP)
1477# 969 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1478!$omp target update to(q_cons_ts(1)%vf(i)%sf)
1479# 969 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1480#endif
1481# 970 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1482 end do
1483 do i = 1, sys_size
1484 deallocate (q_cons_temp(i)%sf)
1485 end do
1486 deallocate (q_cons_temp)
1487 else
1488 call s_read_data_files(q_cons_ts(1)%vf)
1489 end if
1490
1491 block
1492 type(int_bounds_info), dimension(3) :: grid_offsets
1493
1494 grid_offsets(:)%beg = buff_size
1495 grid_offsets(:)%end = buff_size
1496 if (n == 0) then
1497 call s_populate_grid_variables_buffers(x_cb, x_cc, dx, grid_offsets(1), grid_offsets(2), grid_offsets(3), &
1498 & global_bounds=glb_bounds)
1499 else if (p == 0) then
1500 call s_populate_grid_variables_buffers(x_cb, x_cc, dx, grid_offsets(1), grid_offsets(2), grid_offsets(3), y_cb, &
1501 & y_cc, dy, global_bounds=glb_bounds)
1502 else
1503 call s_populate_grid_variables_buffers(x_cb, x_cc, dx, grid_offsets(1), grid_offsets(2), grid_offsets(3), y_cb, &
1504 & y_cc, dy, z_cb, z_cc, dz, glb_bounds)
1505 end if
1506 end block
1507
1508# 995 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1509#if defined(MFC_OpenACC)
1510# 995 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1511!$acc update device(glb_bounds)
1512# 995 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1513#elif defined(MFC_OpenMP)
1514# 995 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1515!$omp target update to(glb_bounds)
1516# 995 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1517#endif
1518# 996 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1519 ! the grid arrays are allocated to the _alloc extents (a pinned block cap can exceed the subdomain) but filled only over
1520 ! the buffered range: take the minima there
1521 dx_min = minval(dx(-buff_size:m + buff_size))
1522 if (n > 0) dy_min = minval(dy(-buff_size:n + buff_size))
1523 if (p > 0) dz_min = minval(dz(-buff_size:p + buff_size))
1524
1526 call s_initialize_amr_registers(amr_maxc_fit)
1527 ! restarts restore the saved fine state; otherwise prolong from coarse
1528 call s_read_amr_restart(amr_restored)
1529 if (.not. amr_restored) call s_populate_amr_fine(q_cons_ts(1)%vf)
1530 amr_fresh_start = amr .and. .not. amr_restored
1531
1533 if (ib) then
1537 if (cfl_dt .and. n_start > 0) then
1538 call s_read_ib_restart_data(n_start)
1539 else if (t_step_start > 0) then
1540 call s_read_ib_restart_data(t_step_start)
1541 else
1543 end if
1545 call s_ibm_setup()
1546 ! the wall conduction temperature of the last stage, which the saved state cannot reproduce
1547 if (chemistry .and. chem_params%diffusion .and. merge(n_start, t_step_start, &
1548 & cfl_dt) > 0) call s_read_ib_conduction_temperature(merge(n_start, t_step_start, cfl_dt))
1549 ! resolve the body on each fine block from the geometry
1550 if (amr) call s_amr_setup_ib()
1551 ! a CFL-mode run keeps t_step_start = 0, so only n_start tells a restart apart
1552 if (merge(n_start, t_step_start, cfl_dt) == 0) call s_write_ib_data_file(0)
1553 end if
1554 if (bodyforces .or. synthetic_turbulence) call s_initialize_body_forces_module()
1555 if (acoustic_source) call s_precalculate_acoustic_spatial_sources()
1556
1557 ! Initialize the Temperature cache.
1558 if (chemistry) call s_compute_q_t_sf(q_t_sf, q_cons_ts(1)%vf, idwint)
1559
1560 ! Computation of parameters, allocation of memory, association of pointers, and/or execution of any other tasks that are
1561 ! needed to properly configure the modules. The preparations below DO DEPEND on the grid being complete.
1562 if (igr) then
1564 end if
1565 if (.not. igr) then
1566 if (recon_type == recon_type_weno) then
1568 else if (recon_type == recon_type_muscl) then
1570 end if
1573 end if
1574 if (int_comp > 0) call s_initialize_thinc_module()
1576 if (bubbles_lagrange .or. particles_lagrange) then
1577 ! qtime is taken before a restart read resets dt
1578 call s_get_lag_restart_point(save_count, qtime)
1579 call s_read_lag_entities(save_count, lag_rows, lag_ids, n_lag_loc)
1580 if (bubbles_lagrange) call s_initialize_bubbles_el_module(q_cons_ts(1)%vf, bc_type, lag_rows, lag_ids, n_lag_loc)
1581 if (particles_lagrange) call s_initialize_particles_el_module(bc_type, lag_rows, lag_ids, n_lag_loc)
1582 call s_initialize_lag_output(save_count, qtime)
1583 end if
1584
1585 if (hypoelasticity) call s_initialize_hypoelastic_module()
1586
1587 end subroutine s_initialize_modules
1588
1589 !> Set up the MPI execution environment, bind GPUs, and decompose the computational domain
1590 impure subroutine s_initialize_mpi_domain
1591
1592 integer :: ierr
1593
1594#ifdef MFC_GPU
1595 real(wp) :: starttime, endtime
1596 integer :: num_devices, local_size, num_nodes, ppn, my_device_num
1597 integer :: dev, devnum, local_rank
1598#ifdef MFC_MPI
1599 integer :: local_comm
1600#endif
1601#if defined(MFC_OpenACC)
1602 integer(acc_device_kind) :: devtype
1603#endif
1604#endif
1605
1606 call s_mpi_initialize()
1607
1608#ifdef MFC_GPU
1609#ifndef MFC_MPI
1610 local_size = 1
1611 local_rank = 0
1612#else
1613 call mpi_comm_split_type(mpi_comm_world, mpi_comm_type_shared, 0, mpi_info_null, local_comm, ierr)
1614 call mpi_comm_size(local_comm, local_size, ierr)
1615 call mpi_comm_rank(local_comm, local_rank, ierr)
1616#endif
1617#if defined(MFC_OpenACC)
1618 devtype = acc_get_device_type()
1619 devnum = acc_get_num_devices(devtype)
1620 dev = mod(local_rank, devnum)
1621
1622 call acc_set_device_num(dev, devtype)
1623#elif defined(MFC_OpenMP)
1624 devnum = omp_get_num_devices()
1625 dev = mod(local_rank, devnum)
1626 call omp_set_default_device(dev)
1627#endif
1628#endif
1629
1630 ! After the device is bound: the update in s_mpi_initialize went to the default device
1631
1632# 1108 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1633#if defined(MFC_OpenACC)
1634# 1108 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1635!$acc update device(num_procs, proc_rank)
1636# 1108 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1637#elif defined(MFC_OpenMP)
1638# 1108 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1639!$omp target update to(num_procs, proc_rank)
1640# 1108 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1641#endif
1642# 1109 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1643
1644 if (proc_rank == 0) then
1645 call s_assign_default_values_to_user_inputs()
1646 call s_read_input_file()
1647 call s_check_input_file()
1648
1649 print '(" Simulating a ", A, " ", I0, "x", I0, "x", I0, " case on ", I0, " rank(s) ", A, ".")', &
1650# 1117 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1651 "regular", &
1652# 1121 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1653 m, n, p, num_procs, &
1654#if defined(MFC_OpenACC)
1655 "with OpenACC offloading"
1656#elif defined(MFC_OpenMP)
1657 "with OpenMP offloading"
1658#else
1659 "on CPUs"
1660#endif
1661 end if
1662
1663 call s_mpi_bcast_user_inputs()
1664
1665 ! Save original BCs before decomposition overwrites them with MPI neighbor ranks
1666 ib_bc_x = bc_x
1667 ib_bc_y = bc_y
1668 ib_bc_z = bc_z
1669
1670 call s_initialize_parallel_io()
1671
1672 call s_mpi_decompose_computational_domain(write_silo_ghost_offsets=.false., adjust_local_domains=.false.)
1673
1674 bc = bc_xyz_info(bc_x, bc_y, bc_z)
1675
1676 end subroutine s_initialize_mpi_domain
1677
1678 !> Transfer initial conservative variable and model parameter data to the GPU device
1680
1681 integer :: i
1682
1683 if (.not. down_sample) then
1684 do i = 1, sys_size
1685
1686# 1153 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1687#if defined(MFC_OpenACC)
1688# 1153 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1689!$acc update device(q_cons_ts(1)%vf(i)%sf)
1690# 1153 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1691#elif defined(MFC_OpenMP)
1692# 1153 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1693!$omp target update to(q_cons_ts(1)%vf(i)%sf)
1694# 1153 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1695#endif
1696# 1154 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1697 end do
1698 end if
1699
1700 if (qbmm .and. .not. polytropic) then
1701
1702# 1158 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1703#if defined(MFC_OpenACC)
1704# 1158 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1705!$acc update device(pb_ts(1)%sf, mv_ts(1)%sf)
1706# 1158 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1707#elif defined(MFC_OpenMP)
1708# 1158 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1709!$omp target update to(pb_ts(1)%sf, mv_ts(1)%sf)
1710# 1158 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1711#endif
1712# 1159 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1713 end if
1714 if (chemistry) then
1715
1716# 1161 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1717#if defined(MFC_OpenACC)
1718# 1161 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1719!$acc update device(q_T_sf%sf)
1720# 1161 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1721#elif defined(MFC_OpenMP)
1722# 1161 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1723!$omp target update to(q_T_sf%sf)
1724# 1161 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1725#endif
1726# 1162 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1727 end if
1728
1729
1730# 1164 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1731#if defined(MFC_OpenACC)
1732# 1164 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1733!$acc update device(chem_params)
1734# 1164 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1735#elif defined(MFC_OpenMP)
1736# 1164 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1737!$omp target update to(chem_params)
1738# 1164 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1739#endif
1740# 1165 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1741
1742
1743# 1166 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1744#if defined(MFC_OpenACC)
1745# 1166 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1746!$acc update device(rburn)
1747# 1166 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1748#elif defined(MFC_OpenMP)
1749# 1166 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1750!$omp target update to(rburn)
1751# 1166 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1752#endif
1753# 1167 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1754
1755
1756# 1168 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1757#if defined(MFC_OpenACC)
1758# 1168 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1759!$acc update device(R0ref, p0ref, rho0ref, ss, pv, vd, mu_l, mu_v, mu_g, gam_v, gam_g, M_v, M_g, R_v, R_g, Tw, cp_v, cp_g, k_vl, k_gl, gam, gam_m, Eu, Ca, Web, Re_inv, Pe_c, phi_vg, phi_gv, omegaN, bubbles_euler, polytropic, polydisperse, qbmm, ptil, bubble_model, thermal, poly_sigma, adv_n, adap_dt, adap_dt_tol, adap_dt_max_iters, eqn_idx%n, pi_fac, low_Mach)
1760# 1168 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1761#elif defined(MFC_OpenMP)
1762# 1168 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1763!$omp target update to(R0ref, p0ref, rho0ref, ss, pv, vd, mu_l, mu_v, mu_g, gam_v, gam_g, M_v, M_g, R_v, R_g, Tw, cp_v, cp_g, k_vl, k_gl, gam, gam_m, Eu, Ca, Web, Re_inv, Pe_c, phi_vg, phi_gv, omegaN, bubbles_euler, polytropic, polydisperse, qbmm, ptil, bubble_model, thermal, poly_sigma, adv_n, adap_dt, adap_dt_tol, adap_dt_max_iters, eqn_idx%n, pi_fac, low_Mach)
1764# 1168 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1765#endif
1766# 1172 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1767
1768 if (bubbles_euler) then
1769
1770# 1174 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1771#if defined(MFC_OpenACC)
1772# 1174 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1773!$acc update device(weight, R0)
1774# 1174 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1775#elif defined(MFC_OpenMP)
1776# 1174 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1777!$omp target update to(weight, R0)
1778# 1174 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1779#endif
1780# 1175 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1781 if (.not. polytropic) then
1782
1783# 1176 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1784#if defined(MFC_OpenACC)
1785# 1176 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1786!$acc update device(pb0, Pe_T, k_g, k_v, mass_g0, mass_v0, Re_trans_T, Re_trans_c, Im_trans_T, Im_trans_c)
1787# 1176 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1788#elif defined(MFC_OpenMP)
1789# 1176 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1790!$omp target update to(pb0, Pe_T, k_g, k_v, mass_g0, mass_v0, Re_trans_T, Re_trans_c, Im_trans_T, Im_trans_c)
1791# 1176 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1792#endif
1793# 1177 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1794 else if (qbmm) then
1795
1796# 1178 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1797#if defined(MFC_OpenACC)
1798# 1178 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1799!$acc update device(pb0)
1800# 1178 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1801#elif defined(MFC_OpenMP)
1802# 1178 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1803!$omp target update to(pb0)
1804# 1178 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1805#endif
1806# 1179 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1807 end if
1808 end if
1809
1810
1811# 1182 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1812#if defined(MFC_OpenACC)
1813# 1182 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1814!$acc update device(adv_n, adap_dt, adap_dt_tol, adap_dt_max_iters, pi_fac, low_Mach, ib_flux_wall)
1815# 1182 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1816#elif defined(MFC_OpenMP)
1817# 1182 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1818!$omp target update to(adv_n, adap_dt, adap_dt_tol, adap_dt_max_iters, pi_fac, low_Mach, ib_flux_wall)
1819# 1182 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1820#endif
1821# 1183 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1822
1823
1824# 1184 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1825#if defined(MFC_OpenACC)
1826# 1184 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1827!$acc update device(acoustic_source, num_source)
1828# 1184 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1829#elif defined(MFC_OpenMP)
1830# 1184 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1831!$omp target update to(acoustic_source, num_source)
1832# 1184 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1833#endif
1834# 1185 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1835
1836# 1185 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1837#if defined(MFC_OpenACC)
1838# 1185 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1839!$acc update device(sigma, surface_tension)
1840# 1185 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1841#elif defined(MFC_OpenMP)
1842# 1185 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1843!$omp target update to(sigma, surface_tension)
1844# 1185 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1845#endif
1846# 1186 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1847
1848
1849# 1187 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1850#if defined(MFC_OpenACC)
1851# 1187 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1852!$acc update device(dx, dy, dz, x_cb, x_cc, y_cb, y_cc, z_cb, z_cc)
1853# 1187 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1854#elif defined(MFC_OpenMP)
1855# 1187 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1856!$omp target update to(dx, dy, dz, x_cb, x_cc, y_cb, y_cc, z_cb, z_cc)
1857# 1187 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1858#endif
1859# 1188 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1860
1861# 1188 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1862#if defined(MFC_OpenACC)
1863# 1188 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1864!$acc update device(bc_x%beg, bc_x%end, bc_y%beg, bc_y%end, bc_z%beg, bc_z%end)
1865# 1188 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1866#elif defined(MFC_OpenMP)
1867# 1188 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1868!$omp target update to(bc_x%beg, bc_x%end, bc_y%beg, bc_y%end, bc_z%beg, bc_z%end)
1869# 1188 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1870#endif
1871# 1189 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1872
1873# 1189 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1874#if defined(MFC_OpenACC)
1875# 1189 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1876!$acc update device(bc_x%vb1, bc_x%vb2, bc_x%vb3, bc_x%ve1, bc_x%ve2, bc_x%ve3)
1877# 1189 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1878#elif defined(MFC_OpenMP)
1879# 1189 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1880!$omp target update to(bc_x%vb1, bc_x%vb2, bc_x%vb3, bc_x%ve1, bc_x%ve2, bc_x%ve3)
1881# 1189 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1882#endif
1883# 1190 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1884
1885# 1190 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1886#if defined(MFC_OpenACC)
1887# 1190 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1888!$acc update device(bc_y%vb1, bc_y%vb2, bc_y%vb3, bc_y%ve1, bc_y%ve2, bc_y%ve3)
1889# 1190 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1890#elif defined(MFC_OpenMP)
1891# 1190 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1892!$omp target update to(bc_y%vb1, bc_y%vb2, bc_y%vb3, bc_y%ve1, bc_y%ve2, bc_y%ve3)
1893# 1190 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1894#endif
1895# 1191 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1896
1897# 1191 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1898#if defined(MFC_OpenACC)
1899# 1191 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1900!$acc update device(bc_z%vb1, bc_z%vb2, bc_z%vb3, bc_z%ve1, bc_z%ve2, bc_z%ve3)
1901# 1191 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1902#elif defined(MFC_OpenMP)
1903# 1191 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1904!$omp target update to(bc_z%vb1, bc_z%vb2, bc_z%vb3, bc_z%ve1, bc_z%ve2, bc_z%ve3)
1905# 1191 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1906#endif
1907# 1192 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1908
1909
1910# 1193 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1911#if defined(MFC_OpenACC)
1912# 1193 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1913!$acc update device(bc_x%grcbc_in, bc_x%grcbc_out, bc_x%grcbc_vel_out)
1914# 1193 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1915#elif defined(MFC_OpenMP)
1916# 1193 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1917!$omp target update to(bc_x%grcbc_in, bc_x%grcbc_out, bc_x%grcbc_vel_out)
1918# 1193 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1919#endif
1920# 1194 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1921
1922# 1194 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1923#if defined(MFC_OpenACC)
1924# 1194 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1925!$acc update device(bc_y%grcbc_in, bc_y%grcbc_out, bc_y%grcbc_vel_out)
1926# 1194 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1927#elif defined(MFC_OpenMP)
1928# 1194 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1929!$omp target update to(bc_y%grcbc_in, bc_y%grcbc_out, bc_y%grcbc_vel_out)
1930# 1194 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1931#endif
1932# 1195 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1933
1934# 1195 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1935#if defined(MFC_OpenACC)
1936# 1195 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1937!$acc update device(bc_z%grcbc_in, bc_z%grcbc_out, bc_z%grcbc_vel_out)
1938# 1195 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1939#elif defined(MFC_OpenMP)
1940# 1195 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1941!$omp target update to(bc_z%grcbc_in, bc_z%grcbc_out, bc_z%grcbc_vel_out)
1942# 1195 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1943#endif
1944# 1196 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1945
1946
1947# 1197 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1948#if defined(MFC_OpenACC)
1949# 1197 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1950!$acc update device(bc_x%vel_in_ramp, bc_x%vel_in_t0, bc_x%vel_in_frac0)
1951# 1197 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1952#elif defined(MFC_OpenMP)
1953# 1197 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1954!$omp target update to(bc_x%vel_in_ramp, bc_x%vel_in_t0, bc_x%vel_in_frac0)
1955# 1197 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1956#endif
1957# 1198 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1958
1959# 1198 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1960#if defined(MFC_OpenACC)
1961# 1198 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1962!$acc update device(bc_y%vel_in_ramp, bc_y%vel_in_t0, bc_y%vel_in_frac0)
1963# 1198 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1964#elif defined(MFC_OpenMP)
1965# 1198 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1966!$omp target update to(bc_y%vel_in_ramp, bc_y%vel_in_t0, bc_y%vel_in_frac0)
1967# 1198 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1968#endif
1969# 1199 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1970
1971# 1199 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1972#if defined(MFC_OpenACC)
1973# 1199 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1974!$acc update device(bc_z%vel_in_ramp, bc_z%vel_in_t0, bc_z%vel_in_frac0)
1975# 1199 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1976#elif defined(MFC_OpenMP)
1977# 1199 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1978!$omp target update to(bc_z%vel_in_ramp, bc_z%vel_in_t0, bc_z%vel_in_frac0)
1979# 1199 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1980#endif
1981# 1200 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1982
1983
1984# 1201 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1985#if defined(MFC_OpenACC)
1986# 1201 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1987!$acc update device(bc_x%isothermal_in, bc_x%isothermal_out)
1988# 1201 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1989#elif defined(MFC_OpenMP)
1990# 1201 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1991!$omp target update to(bc_x%isothermal_in, bc_x%isothermal_out)
1992# 1201 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1993#endif
1994# 1202 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1995
1996# 1202 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1997#if defined(MFC_OpenACC)
1998# 1202 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
1999!$acc update device(bc_y%isothermal_in, bc_y%isothermal_out)
2000# 1202 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2001#elif defined(MFC_OpenMP)
2002# 1202 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2003!$omp target update to(bc_y%isothermal_in, bc_y%isothermal_out)
2004# 1202 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2005#endif
2006# 1203 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2007
2008# 1203 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2009#if defined(MFC_OpenACC)
2010# 1203 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2011!$acc update device(bc_z%isothermal_in, bc_z%isothermal_out)
2012# 1203 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2013#elif defined(MFC_OpenMP)
2014# 1203 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2015!$omp target update to(bc_z%isothermal_in, bc_z%isothermal_out)
2016# 1203 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2017#endif
2018# 1204 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2019
2020# 1204 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2021#if defined(MFC_OpenACC)
2022# 1204 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2023!$acc update device(bc_x%Twall_in, bc_x%Twall_out, bc_y%Twall_in, bc_y%Twall_out, bc_z%Twall_in, bc_z%Twall_out)
2024# 1204 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2025#elif defined(MFC_OpenMP)
2026# 1204 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2027!$omp target update to(bc_x%Twall_in, bc_x%Twall_out, bc_y%Twall_in, bc_y%Twall_out, bc_z%Twall_in, bc_z%Twall_out)
2028# 1204 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2029#endif
2030# 1205 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2031
2032
2033# 1206 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2034#if defined(MFC_OpenACC)
2035# 1206 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2036!$acc update device(bc)
2037# 1206 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2038#elif defined(MFC_OpenMP)
2039# 1206 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2040!$omp target update to(bc)
2041# 1206 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2042#endif
2043# 1207 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2044
2045
2046# 1208 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2047#if defined(MFC_OpenACC)
2048# 1208 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2049!$acc update device(relax, relax_model)
2050# 1208 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2051#elif defined(MFC_OpenMP)
2052# 1208 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2053!$omp target update to(relax, relax_model)
2054# 1208 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2055#endif
2056# 1209 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2057 if (relax) then
2058
2059# 1210 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2060#if defined(MFC_OpenACC)
2061# 1210 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2062!$acc update device(palpha_eps, ptgalpha_eps)
2063# 1210 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2064#elif defined(MFC_OpenMP)
2065# 1210 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2066!$omp target update to(palpha_eps, ptgalpha_eps)
2067# 1210 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2068#endif
2069# 1211 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2070 end if
2071
2072 if (ib) then
2073
2074# 1214 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2075#if defined(MFC_OpenACC)
2076# 1214 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2077!$acc update device(ib_markers%sf)
2078# 1214 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2079#elif defined(MFC_OpenMP)
2080# 1214 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2081!$omp target update to(ib_markers%sf)
2082# 1214 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2083#endif
2084# 1215 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2085 end if
2086# 1217 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2087
2088# 1217 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2089#if defined(MFC_OpenACC)
2090# 1217 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2091!$acc update device(igr, nb, igr_order)
2092# 1217 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2093#elif defined(MFC_OpenMP)
2094# 1217 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2095!$omp target update to(igr, nb, igr_order)
2096# 1217 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2097#endif
2098# 1218 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2099# 1219 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2100
2101 end subroutine s_initialize_gpu_vars
2102
2103 !> Fresh AMR run, before the first save: put the initial condition patches on the blocks and, under dynamic regrid, regrid once
2104 !! per level, so each level is tagged on the one above it.
2106
2107 integer :: i
2108
2109 if (.not. amr_fresh_start) return
2110 call s_amr_apply_ic_patches(q_cons_ts(1)%vf)
2111 if (amr_regrid_int > 0) then
2112 do i = 1, amr_max_level
2113 call s_amr_regrid(q_cons_ts(1)%vf)
2114 call s_amr_apply_ic_patches(q_cons_ts(1)%vf)
2115 end do
2116 end if
2117
2118 end subroutine s_amr_start_fresh_blocks
2119
2120 !> Read the Lagrangian bubbles or particles this rank starts with: the input-file rows (and their global IDs) on a fresh start,
2121 !! otherwise the restart-file rows, which also reset mytime and dt.
2122 impure subroutine s_read_lag_entities(save_count, rows, ids, n_loc)
2123
2124 integer, intent(in) :: save_count
2125 real(wp), allocatable, dimension(:,:), intent(out) :: rows
2126 integer, allocatable, dimension(:), intent(out) :: ids
2127 integer, intent(out) :: n_loc
2128 character(LEN=pathlen_max) :: path
2129 character(len=9) :: lag_kind
2130 integer :: ncols, n_glb, n_read
2131
2132 if (bubbles_lagrange) then
2133 lag_kind = 'bubbles'; path = lag_params%input_path; ncols = 8; n_glb = lag_params%nBubs_glb
2134 else
2135 lag_kind = 'particles'; path = particle_params%input_path; ncols = 7; n_glb = particle_params%nParticles_glb
2136 end if
2137
2138 n_read = 0
2139 if (save_count == 0) then
2140 if (proc_rank == 0) print *, 'Reading lagrange ' // trim(lag_kind) // ' input file.'
2141 call s_read_lag_input(path, ncols, n_glb, rows, ids, n_loc, n_read)
2142 else
2143 if (proc_rank == 0) print *, 'Restarting lagrange ' // trim(lag_kind) // ' at save_count: ', save_count
2144 call s_read_lag_restart(trim(lag_kind), save_count, rows, n_loc)
2145 if (.not. allocated(rows)) allocate (rows(1, lag_io_vars))
2146 allocate (ids(0))
2147 end if
2148
2149 if (bubbles_lagrange) print *, " Lagrange bubbles running, in proc", proc_rank, "number:", n_loc, "/", n_read
2150
2151 end subroutine s_read_lag_entities
2152
2153 !> Read the initial Lagrangian entities from path, one per line with ncols values, and return those in this rank's physical
2154 !! domain: rows(1:n_loc, :) and their global IDs ids(1:n_loc), which are the line numbers among the n_read lines read.
2155 impure subroutine s_read_lag_input(path, ncols, n_glb, rows, ids, n_loc, n_read)
2156
2157 character(len=*), intent(in) :: path
2158 integer, intent(in) :: ncols, n_glb
2159 real(wp), allocatable, dimension(:,:), intent(out) :: rows
2160 integer, allocatable, dimension(:), intent(out) :: ids
2161 integer, intent(out) :: n_loc, n_read
2162 real(wp), dimension(ncols) :: vals
2163 character(LEN=1024) :: line
2164 character(LEN=200) :: abort_msg
2165 integer :: ios, ios_line, iunit
2166 logical :: file_exist
2167
2168 call my_inquire(trim(path), file_exist)
2169 if (.not. file_exist) call s_mpi_abort('Lagrangian input file ' // trim(path) // ' does not exist')
2170
2171 allocate (rows(max(1, n_glb), ncols), ids(max(1, n_glb)))
2172 n_loc = 0
2173 n_read = 0
2174 open (newunit=iunit, file=trim(path), form='formatted', status='old', iostat=ios)
2175 if (ios /= 0) call s_mpi_abort('Cannot open the Lagrangian input file ' // trim(path))
2176 do while (ios == 0)
2177 ! Read line by line so a line with extra columns cannot shift the lines after it
2178 read (iunit, '(A)', iostat=ios) line
2179 if (ios /= 0 .or. len_trim(line) == 0) cycle
2180 read (line, *, iostat=ios_line) vals
2181 if (ios_line /= 0) then
2182 write (abort_msg, '(A,I0,A)') 'Each line of ' // trim(path) // ' needs ', ncols, ' columns'
2183 call s_mpi_abort(trim(abort_msg))
2184 end if
2185 n_read = n_read + 1
2186 if (n_read > n_glb) call s_mpi_abort('More entries in ' // trim(path) // ' than the global count (nBubs_glb or ' &
2187 & // 'nParticles_glb)')
2188 if (f_lag_entity_in_physical_domain(vals(1:3))) then
2189 n_loc = n_loc + 1
2190 rows(n_loc,:) = vals
2191 ids(n_loc) = n_read
2192 end if
2193 end do
2194 close (iunit)
2195
2196 end subroutine s_read_lag_input
2197
2198 !> Read restart_data/lag_<lag_kind>_<save_count>.dat written by s_write_lag_restart: set mytime and dt from the header and
2199 !! return this rank's n_loc rows in io_data(1:n_loc, 1:lag_io_vars). Each rank reads what the same rank wrote, so the run must
2200 !! use the same number of ranks as the one that wrote the file.
2201 impure subroutine s_read_lag_restart(lag_kind, save_count, io_data, n_loc)
2202
2203 character(len=*), intent(in) :: lag_kind
2204 integer, intent(in) :: save_count
2205 real(wp), allocatable, dimension(:,:), intent(out) :: io_data
2206 integer, intent(out) :: n_loc
2207 character(LEN=path_len + 2*name_len) :: file_loc
2208 character(len=200) :: abort_msg
2209 logical :: file_exist
2210
2211#ifndef MFC_MPI
2212 n_loc = 0
2213 if (.true.) then
2214# 1332 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2215 call s_prohibit_abort(".true.", "Lagrangian restart requires MPI (--mpi)")
2216# 1332 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2217 end if
2218# 1333 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2219#else
2220 real(wp) :: file_time, file_dt
2221 integer :: file_num_procs, file_tot_part, ifile, ierr, view, i
2222 integer, dimension(MPI_STATUS_SIZE) :: status
2223 integer(kind=MPI_OFFSET_KIND) :: disp
2224 integer, dimension(2) :: gsizes, lsizes, start_idx_part
2225 integer, dimension(:), allocatable :: proc_counts
2226 real(wp), dimension(1:1,1:lag_io_vars) :: dummy
2227
2228 dummy = 0._wp
2229 n_loc = 0
2230
2231 write (file_loc, '(A,A,A,I0,A)') 'lag_', lag_kind, '_', save_count, '.dat'
2232 file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // trim(file_loc)
2233
2234 inquire (file=trim(file_loc), exist=file_exist)
2235 if (.not. file_exist) call s_mpi_abort('Restart file ' // trim(file_loc) // ' does not exist!')
2236
2237 if (proc_rank == 0) then
2238 call mpi_file_open(mpi_comm_self, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
2239 call s_check_mpi_file_open(ierr, file_loc)
2240 call mpi_file_read(ifile, file_tot_part, 1, mpi_integer, status, ierr)
2241 call mpi_file_read(ifile, file_time, 1, mpi_p, status, ierr)
2242 call mpi_file_read(ifile, file_dt, 1, mpi_p, status, ierr)
2243 call mpi_file_read(ifile, file_num_procs, 1, mpi_integer, status, ierr)
2244 call mpi_file_close(ifile, ierr)
2245 end if
2246
2247 call mpi_bcast(file_tot_part, 1, mpi_integer, 0, mpi_comm_world, ierr)
2248 call mpi_bcast(file_time, 1, mpi_p, 0, mpi_comm_world, ierr)
2249 call mpi_bcast(file_dt, 1, mpi_p, 0, mpi_comm_world, ierr)
2250 call mpi_bcast(file_num_procs, 1, mpi_integer, 0, mpi_comm_world, ierr)
2251
2252 if (file_num_procs /= num_procs) then
2253 write (abort_msg, &
2254 & '(A,I0,A,I0)') 'Lagrangian restart needs the same number of ranks as the run that wrote the ' &
2255 & // 'restart file. Ranks in the file: ', file_num_procs, ', ranks in this run: ', num_procs
2256 call s_mpi_abort(trim(abort_msg))
2257 end if
2258
2259 allocate (proc_counts(file_num_procs))
2260 if (proc_rank == 0) then
2261 call mpi_file_open(mpi_comm_self, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
2262 call s_check_mpi_file_open(ierr, file_loc)
2263 disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs), mpi_offset_kind)
2264 call mpi_file_seek(ifile, disp, mpi_seek_set, ierr)
2265 call mpi_file_read(ifile, proc_counts, file_num_procs, mpi_integer, status, ierr)
2266 call mpi_file_close(ifile, ierr)
2267 end if
2268 call mpi_bcast(proc_counts, file_num_procs, mpi_integer, 0, mpi_comm_world, ierr)
2269
2270 mytime = file_time
2271 dt = file_dt
2272
2273 n_loc = proc_counts(proc_rank + 1)
2274 start_idx_part(1) = 0
2275 do i = 1, proc_rank
2276 start_idx_part(1) = start_idx_part(1) + proc_counts(i)
2277 end do
2278 start_idx_part(2) = 0
2279 lsizes(1) = n_loc
2280 lsizes(2) = lag_io_vars
2281 gsizes(1) = file_tot_part
2282 gsizes(2) = lag_io_vars
2283
2284 allocate (io_data(max(1, n_loc),1:lag_io_vars))
2285
2286 if (n_loc > 0) then
2287 call mpi_type_create_subarray(2, gsizes, lsizes, start_idx_part, mpi_order_fortran, mpi_p, view, ierr)
2288 else
2289 call mpi_type_contiguous(0, mpi_p, view, ierr)
2290 end if
2291 call mpi_type_commit(view, ierr)
2292
2293 call mpi_file_open(mpi_comm_world, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
2294 call s_check_mpi_file_open(ierr, file_loc)
2295
2296 ! Skip the header
2297 disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs) + file_num_procs*sizeof(proc_counts(1)), &
2298 & mpi_offset_kind)
2299 call mpi_file_set_view(ifile, disp, mpi_p, view, 'native', mpi_info_int, ierr)
2300
2301 if (n_loc > 0) then
2302 call mpi_file_read_all(ifile, io_data, lag_io_vars*n_loc, mpi_p, status, ierr)
2303 else
2304 call mpi_file_read_all(ifile, dummy, 0, mpi_p, status, ierr)
2305 end if
2306
2307 call mpi_file_close(ifile, ierr)
2308 call mpi_type_free(view, ierr)
2309 deallocate (proc_counts)
2310
2311 if (proc_rank == 0) then
2312 write (*, '(A,I0,A,A,A,I0)') 'Read ', file_tot_part, ' Lagrangian ', lag_kind, ' from restart file at t_step = ', &
2313 & save_count
2314 write (*, '(A,E15.7,A,E15.7)') 'Restart time = ', mytime, ', dt = ', dt
2315 end if
2316#endif
2317
2318 end subroutine s_read_lag_restart
2319
2320 !> Finalize and deallocate all simulation sub-modules in reverse initialization order
2321 impure subroutine s_finalize_modules
2322
2323 if (ib) call s_close_ib_history()
2324
2325 if (model_eqns == model_eqns_6eq) call s_report_pressure_relaxation()
2326 if (ib .and. (chemistry .or. ib_wall_order == 2)) call s_report_ibm_surface()
2327
2328 if (ib) call s_ibm_note_fine_memory()
2329 call s_finalize_amr_registers()
2330 call s_finalize_amr_module()
2331 call s_phase_report()
2332 call s_finalize_time_steppers_module()
2333 if (hypoelasticity) call s_finalize_hypoelastic_module()
2334 call s_finalize_derived_variables_module()
2335 call s_finalize_data_output_module()
2336 call s_finalize_rhs_module()
2337 if (igr) then
2338 call s_finalize_igr_module()
2339 else
2340 call s_finalize_cbc_module()
2341 call s_finalize_riemann_solvers_module()
2342 if (recon_type == recon_type_weno) then
2343 call s_finalize_weno_module()
2344 else if (recon_type == recon_type_muscl) then
2345 call s_finalize_muscl_module()
2346 end if
2347 end if
2348 if (int_comp > 0) call s_finalize_thinc_module()
2349 call s_finalize_variables_conversion_module()
2350 call s_finalize_eos_module()
2351 if (grid_geometry == 3) call s_finalize_fftw_module
2352 call s_finalize_mpi_common_module()
2353 call s_finalize_global_parameters_module()
2354 call s_finalize_boundary_common_module()
2355 if (relax) call s_finalize_relaxation_solver_module()
2356 if (bubbles_lagrange) call s_finalize_lagrangian_solver()
2357 if (particles_lagrange) call s_finalize_particles_el_module()
2358 if (viscous .and. (.not. igr)) then
2359 call s_finalize_viscous_module()
2360 end if
2361 call s_finalize_mpi_proxy_module()
2362
2363 if (surface_tension) call s_finalize_surface_tension_module()
2364 if (bodyforces .or. synthetic_turbulence) call s_finalize_body_forces_module()
2365 if (ib) call s_finalize_ibm_module()
2366
2367 call s_mpi_finalize()
2368
2369 end subroutine s_finalize_modules
2370
2371 !> @brief Fills the properties of a generated particle-cloud IB that the IB state file does not carry (geometry, mass,
2372 !! moving_ibm, inert surface, identity rotation matrix, zeroed step state). This is the only place they are set - pre_process
2373 !! (s_add_cloud_particle) generates only position, kinematics and radius. cloud_ib_idx is the global patch id minus the number
2374 !! of namelist patches; pre_process numbers particles cloud by cloud.
2375 subroutine s_assign_particle_cloud_ib_defaults(cloud_ib_idx, ib_patch)
2376
2377 integer, intent(in) :: cloud_ib_idx
2378 type(ib_patch_parameters), intent(inout) :: ib_patch
2379 integer :: cloud_idx, idx_in_cloud
2380
2381 idx_in_cloud = cloud_ib_idx
2382 do cloud_idx = 1, num_particle_clouds - 1
2383 if (idx_in_cloud <= particle_cloud(cloud_idx)%num_particles) exit
2384 idx_in_cloud = idx_in_cloud - particle_cloud(cloud_idx)%num_particles
2385 end do
2386
2387 ib_patch%geometry = merge(2, 8, num_dims < 3)
2388 ib_patch%step_x_centroid = 0._wp
2389 ib_patch%step_y_centroid = 0._wp
2390 ib_patch%step_z_centroid = 0._wp
2391 ib_patch%step_angles(:) = 0._wp
2392 ib_patch%step_vel(:) = 0._wp
2393 ib_patch%step_angular_vel(:) = 0._wp
2394 ib_patch%accel(:) = 0._wp
2395 ib_patch%angular_accel(:) = 0._wp
2396 ib_patch%force(:) = 0._wp
2397 ib_patch%torque(:) = 0._wp
2398 ib_patch%centroid_offset(:) = 0._wp
2399 ib_patch%rotation_matrix = 0._wp
2400 ib_patch%rotation_matrix(1, 1) = 1._wp
2401 ib_patch%rotation_matrix(2, 2) = 1._wp
2402 ib_patch%rotation_matrix(3, 3) = 1._wp
2403 ib_patch%rotation_matrix_inverse = ib_patch%rotation_matrix
2404 ib_patch%mass = particle_cloud(cloud_idx)%mass
2405 ib_patch%moment = dflt_real
2406 ib_patch%moving_ibm = particle_cloud(cloud_idx)%moving_ibm
2407 ib_patch%slip = .false.
2408 ! Particles are inert surfaces: a cloud IB carries no case-file surface condition, so the thermal,
2409 ! reaction and blowing fields must be set here rather than left as whatever patch_ib held.
2410 ib_patch%thermal_bc = 0
2411 ib_patch%Twall = 0._wp
2412 ib_patch%thermal_layer = 0._wp
2413 ib_patch%rho_solid = 0._wp
2414 ib_patch%cp_solid = 0._wp
2415 ib_patch%emissivity = 0._wp
2416 ib_patch%T_rad = 0._wp
2417 ib_patch%heat_power = 0._wp
2418 ib_patch%wall_column = .false.
2419 ib_patch%wall_column_len = 0._wp
2420 ib_patch%surface_reaction = 0
2421 ib_patch%v_blow = 0._wp
2422 ib_patch%inj_species = 0
2423 ib_patch%burn_rate_exp = 0._wp
2424 ib_patch%mass_bank = 0._wp
2425 ib_patch%burn_rate_pref = 0._wp
2426 ! Selector for the prescribed-kinematics block; zero leaves the eleven kin_* reals unread.
2427 ib_patch%kin_model = 0
2428
2430
2431 !> @brief Loads the IBs this rank owns from the IB state file for t_step into patch_ib(1:num_ibs), all of which are local. Under
2432 !! file_per_process the rank reads only its own restart_data/lustre_<t_step>/ib_state_<t_step>_<rank>.dat, which holds exactly
2433 !! its IBs; otherwise every rank reads every record of restart_data/ib_state_<t_step>.dat and keeps the ones
2434 !! f_local_rank_owns_location assigns it. Records carry kinematics, position, radius and the lumped wall temperature (read for
2435 !! thermal_bc = 3 only); every other property comes from the namelist patch (global id <= num_ibs) or the particle cloud the IB
2436 !! was generated from. Written by pre_process at t_step = 0 (src/pre_process/m_data_output.fpp:s_write_ib_state_0_file) and by
2437 !! s_write_ib_state_file on later steps.
2438 impure subroutine s_read_ib_restart_data(t_step)
2439
2440 integer, intent(in) :: t_step
2441 type(ib_patch_parameters), allocatable, dimension(:) :: namelist_ibs
2442 character(len=path_len + 2*name_len) :: file_loc
2443 integer :: i, ios, file_unit, gbl_id, n_records, rec_bytes
2444 integer(kind=8) :: file_size
2445 real(wp) :: ib_buf(ib_state_nfields), t_rst, t_rst_glb
2446 character(len=10) :: t_step_string
2447
2448 moving_immersed_boundary_flag = any(patch_ib(1:num_ibs)%moving_ibm /= 0) &
2449 & .or. any(particle_cloud(1:num_particle_clouds)%moving_ibm /= 0)
2450
2452
2453 allocate (namelist_ibs(num_ibs))
2454 namelist_ibs(:) = patch_ib(1:num_ibs)
2455 num_gbl_ibs = num_ibs + sum(particle_cloud(1:num_particle_clouds)%num_particles)
2456
2457 if (file_per_process) then
2458 call s_int_to_str(t_step, t_step_string)
2459 write (file_loc, '(A,I0,A,i7.7,A)') 'ib_state_', t_step, '_', proc_rank, '.dat'
2460 file_loc = trim(case_dir) // '/restart_data/lustre_' // trim(t_step_string) // '/' // trim(file_loc)
2461 else
2462 write (file_loc, '(A,I0,A)') '/restart_data/ib_state_', t_step, '.dat'
2463 file_loc = trim(case_dir) // trim(file_loc)
2464 end if
2465
2466 open (newunit=file_unit, file=trim(file_loc), form='unformatted', access='stream', status='old', action='read', iostat=ios)
2467 if (ios /= 0) call s_mpi_abort('Error opening IB state file: ' // trim(file_loc))
2468
2469 n_records = num_gbl_ibs
2470 if (file_per_process) then
2471 read (file_unit, iostat=ios) n_records
2472 if (ios /= 0) call s_mpi_abort('Error reading IB state file header: ' // trim(file_loc))
2473 end if
2474
2475 ! A file from before the ib_mass_relax bank joined the record has one real fewer per body, and its records would shift
2476 inquire (unit=file_unit, size=file_size)
2477 rec_bytes = (ib_state_nfields - 1)*storage_size(0._wp)/8
2478 if (file_per_process) rec_bytes = rec_bytes + storage_size(0)/8
2479 if (file_size == int(n_records, 8)*rec_bytes + merge(int(storage_size(0)/8, 8), 0_8, file_per_process)) then
2480 call s_mpi_abort('IB state file ' // trim(file_loc) // ' predates the ib_mass_relax bank (one real per body ' &
2481 & // 'fewer) and cannot be restarted; rerun from t_step_start = 0')
2482 end if
2483
2484 num_ibs = 0
2485 t_rst = -huge(1._wp)
2486 do i = 1, n_records
2487 gbl_id = i
2488 if (file_per_process) read (file_unit, iostat=ios) gbl_id
2489 if (ios == 0) read (file_unit, iostat=ios) ib_buf
2490 if (ios /= 0) call s_mpi_abort('Error reading IB state file: ' // trim(file_loc))
2491 t_rst = max(t_rst, ib_buf(1))
2492
2493 if (.not. file_per_process) then
2494 if (.not. f_local_rank_owns_location(ib_buf(17:19), glb_bounds)) cycle
2495 end if
2496
2497 num_ibs = num_ibs + 1
2498 if (num_ibs > num_local_ibs_max) then
2499# 1612 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2500 call s_prohibit_abort("num_ibs > num_local_ibs_max", "Too many IBs on a single processor rank. Modify case file or increase limit of num_local_ibs_max to resolve.")
2501# 1612 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2502 end if
2503# 1614 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2504 if (gbl_id <= size(namelist_ibs)) then
2505 patch_ib(num_ibs) = namelist_ibs(gbl_id)
2506 else
2507 call s_assign_particle_cloud_ib_defaults(gbl_id - size(namelist_ibs), patch_ib(num_ibs))
2508 end if
2509 patch_ib(num_ibs)%gbl_patch_id = gbl_id
2510 patch_ib(num_ibs)%force = ib_buf(2:4)
2511 patch_ib(num_ibs)%torque = ib_buf(5:7)
2512 patch_ib(num_ibs)%vel = ib_buf(8:10)
2513 patch_ib(num_ibs)%angular_vel = ib_buf(11:13)
2514 patch_ib(num_ibs)%angles = ib_buf(14:16)
2515 patch_ib(num_ibs)%x_centroid = ib_buf(17)
2516 patch_ib(num_ibs)%y_centroid = ib_buf(18)
2517 patch_ib(num_ibs)%z_centroid = ib_buf(19)
2518 patch_ib(num_ibs)%radius = ib_buf(20)
2519 if (patch_ib(num_ibs)%thermal_bc == 3) patch_ib(num_ibs)%Twall = ib_buf(21)
2520 patch_ib(num_ibs)%mass_bank = ib_buf(22)
2521 local_ib_patch_ids(num_ibs) = num_ibs
2522 end do
2523
2524 close (file_unit)
2525 deallocate (namelist_ibs)
2526
2527 num_local_ibs = num_ibs
2528
2529 ! A CFL-mode save lands past t_save*n_start; resume from the time it was written at (ranks may hold no record)
2530 if (cfl_dt .and. t_step > 0) then
2531 t_rst_glb = t_rst
2532#ifdef MFC_MPI
2533 call s_mpi_allreduce_max(t_rst, t_rst_glb)
2534#endif
2535 if (t_rst_glb > 0._wp) mytime = t_rst_glb
2536 end if
2537
2538 end subroutine s_read_ib_restart_data
2539
2540 !> ib_mass_relax = -1 (default): N = 30 for a moving body, else 0 (a fixed body leaks little, and the slip-wall N = 1 costs too
2541 !! much on some GPUs to be a default). It is 0 wherever an explicit value is refused (amr, cyl_coord, igr, bubbles, model_eqns
2542 !! /= 2, a blowing body), with a surface reaction (ib_flux_wall conserves there), and with hypoelasticity or mhd (their extra
2543 !! variables are not scaled), so the default never invalidates a case. Explicit values are unchanged. Called while patch_ib
2544 !! still holds the case-file patches (particle-cloud bodies carry no blowing or reaction), so every rank resolves alike.
2545 impure subroutine s_resolve_ib_mass_relax()
2546
2547 if (ib_mass_relax >= 0) return
2548 ib_mass_relax = 0
2549 if (amr .or. cyl_coord .or. igr .or. bubbles_euler .or. model_eqns /= 2 .or. hypoelasticity .or. mhd) return
2550 if (any(patch_ib(1:num_ibs)%v_blow > 0._wp) .or. any(patch_ib(1:num_ibs)%inj_species > 0)) return
2551 if (any(patch_ib(1:num_ibs)%surface_reaction /= 0)) return
2552 if (moving_immersed_boundary_flag) ib_mass_relax = 30
2553
2554 end subroutine s_resolve_ib_mass_relax
2555
2556 !> @brief Completes this rank's IB neighborhood once s_read_ib_restart_data has loaded only the IBs it owns: every rank sends
2557 !! its own IBs to, and receives the owned IBs of, each distinct rank in ib_neighbor_ranks, appending them to patch_ib after its
2558 !! own.
2560
2561#ifdef MFC_MPI
2562 integer, allocatable, dimension(:) :: nbr_ranks, recv_counts, requests
2563 type(ib_patch_parameters), allocatable, dimension(:,:) :: recv_ibs
2564 integer :: i, n_nbrs, nreqs, patch_bytes, ierr
2565#endif
2566
2568
2569#ifdef MFC_MPI
2570 if (num_procs > 1) then
2571 ! A rank can fill several table slots (periodicity, few ranks) or be its own neighbor; exchange once per distinct rank
2572 allocate (nbr_ranks(size(ib_neighbor_ranks)))
2573 nbr_ranks = reshape(ib_neighbor_ranks, [size(ib_neighbor_ranks)])
2574 n_nbrs = 0
2575 do i = 1, size(nbr_ranks)
2576 if (nbr_ranks(i) < 0 .or. nbr_ranks(i) == proc_rank) cycle
2577 if (any(nbr_ranks(1:n_nbrs) == nbr_ranks(i))) cycle
2578 n_nbrs = n_nbrs + 1
2579 nbr_ranks(n_nbrs) = nbr_ranks(i)
2580 end do
2581
2582 ! the IBs loaded from restart are this rank's own; neighbors learn their owner from the sender below
2583 patch_ib(1:num_local_ibs)%owner_rank = proc_rank
2584
2585 allocate (recv_counts(n_nbrs), requests(2*n_nbrs))
2586 do i = 1, n_nbrs
2587 call mpi_irecv(recv_counts(i), 1, mpi_integer, nbr_ranks(i), 500, mpi_comm_world, requests(2*i - 1), ierr)
2588 call mpi_isend(num_local_ibs, 1, mpi_integer, nbr_ranks(i), 500, mpi_comm_world, requests(2*i), ierr)
2589 end do
2590 call mpi_waitall(2*n_nbrs, requests, mpi_statuses_ignore, ierr)
2591
2592 patch_bytes = storage_size(patch_ib(1))/8
2593 allocate (recv_ibs(max(1, maxval(recv_counts)), n_nbrs))
2594 nreqs = 0
2595 do i = 1, n_nbrs
2596 if (recv_counts(i) > 0) then
2597 nreqs = nreqs + 1
2598 call mpi_irecv(recv_ibs(:,i), recv_counts(i)*patch_bytes, mpi_byte, nbr_ranks(i), 501, mpi_comm_world, &
2599 & requests(nreqs), ierr)
2600 end if
2601 if (num_local_ibs > 0) then
2602 nreqs = nreqs + 1
2603 call mpi_isend(patch_ib, num_local_ibs*patch_bytes, mpi_byte, nbr_ranks(i), 501, mpi_comm_world, &
2604 & requests(nreqs), ierr)
2605 end if
2606 end do
2607 call mpi_waitall(nreqs, requests, mpi_statuses_ignore, ierr)
2608
2609 do i = 1, n_nbrs
2610 if (num_ibs + recv_counts(i) > num_ib_patches_max_namelist) then
2611# 1720 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2612 call s_prohibit_abort("num_ibs + recv_counts(i) > num_ib_patches_max_namelist", "IB neighborhood exceeds patch_ib capacity. Increase num_ib_patches_max_namelist.")
2613# 1720 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2614 end if
2615# 1722 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2616 if (num_ibs + recv_counts(i) > num_local_ibs_max) then
2617# 1722 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2618 call s_prohibit_abort("num_ibs + recv_counts(i) > num_local_ibs_max", "Owned plus neighboring IBs on a rank exceed num_local_ibs_max, which sizes ib_box and ib_face_ft. Use more ranks or increase num_local_ibs_max.")
2619# 1722 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2620 end if
2621# 1724 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2622 patch_ib(num_ibs + 1:num_ibs + recv_counts(i)) = recv_ibs(1:recv_counts(i),i)
2623 patch_ib(num_ibs + 1:num_ibs + recv_counts(i))%owner_rank = nbr_ranks(i)
2624 num_ibs = num_ibs + recv_counts(i)
2625 end do
2626
2627 deallocate (nbr_ranks, recv_counts, requests, recv_ibs)
2628 end if
2629#endif
2630
2631 end subroutine s_build_ib_neighborhood
2632
2633 !> Build ib_neighbor_ranks(-1:1,-1:1,-1:1): MPI ranks of all neighbor domains. Uses two rounds of MPI_SENDRECV cascades - face
2634 !! neighbors are known from bc_*, edge neighbors are obtained in round 1, and (3D) corner neighbors in round 2.
2636
2637 integer :: ax, k, nbr_idx, nreqs, sx, sy, sz, dx, dy, dz
2638 integer, allocatable :: send_table(:,:,:), recv_tables(:,:,:,:)
2639 integer, dimension(52) :: requests
2640
2641#ifdef MFC_MPI
2642 integer :: ierr
2643 integer, dimension(4) :: buf4, rbuf4
2644 integer, dimension(2) :: buf2, rbuf2
2645
2646 ax = ib_neighborhood_radius
2647
2648 if (allocated(ib_neighbor_ranks)) deallocate (ib_neighbor_ranks)
2649 allocate (ib_neighbor_ranks(-ax:ax,-ax:ax,-ax:ax))
2650 ib_neighbor_ranks = mpi_proc_null
2651 ib_neighbor_ranks(0, 0, 0) = proc_rank
2652
2653 ! Fill radius-1 entries: face neighbors are known from domain decomposition
2654 ib_neighbor_ranks(-1, 0, 0) = bc_x%beg
2655 ib_neighbor_ranks(+1, 0, 0) = bc_x%end
2656 if (num_dims >= 2) then
2657 ib_neighbor_ranks(0, -1, 0) = bc_y%beg
2658 ib_neighbor_ranks(0, +1, 0) = bc_y%end
2659 end if
2660 if (num_dims == 3) then
2661 ib_neighbor_ranks(0, 0, -1) = bc_z%beg
2662 ib_neighbor_ranks(0, 0, +1) = bc_z%end
2663 end if
2664
2665 if (num_dims >= 2) then
2666 ! Round 1a: exchange y/z face ranks with +/-x face neighbors -> xy and xz edge ranks
2667 buf4 = [bc_y%beg, bc_y%end, bc_z%beg, bc_z%end]
2668
2669 ! Send to -x, receive from +x -> edges (+1,+/-1,0) and (+1,0,+/-1)
2670 call mpi_sendrecv(buf4, 4, mpi_integer, merge(bc_x%beg, mpi_proc_null, bc_x%beg >= 0), 310, rbuf4, 4, mpi_integer, &
2671 & merge(bc_x%end, mpi_proc_null, bc_x%end >= 0), 310, mpi_comm_world, mpi_status_ignore, ierr)
2672 if (bc_x%end >= 0) then
2673 ib_neighbor_ranks(+1, -1, 0) = rbuf4(1)
2674 ib_neighbor_ranks(+1, +1, 0) = rbuf4(2)
2675 ib_neighbor_ranks(+1, 0, -1) = rbuf4(3)
2676 ib_neighbor_ranks(+1, 0, +1) = rbuf4(4)
2677 end if
2678
2679 call mpi_sendrecv(buf4, 4, mpi_integer, merge(bc_x%end, mpi_proc_null, bc_x%end >= 0), 311, rbuf4, 4, mpi_integer, &
2680 & merge(bc_x%beg, mpi_proc_null, bc_x%beg >= 0), 311, mpi_comm_world, mpi_status_ignore, ierr)
2681 if (bc_x%beg >= 0) then
2682 ib_neighbor_ranks(-1, -1, 0) = rbuf4(1)
2683 ib_neighbor_ranks(-1, +1, 0) = rbuf4(2)
2684 ib_neighbor_ranks(-1, 0, -1) = rbuf4(3)
2685 ib_neighbor_ranks(-1, 0, +1) = rbuf4(4)
2686 end if
2687 end if
2688
2689 if (num_dims == 3) then
2690 ! Round 1b: exchange z face ranks with +/-y face neighbors -> yz edge ranks
2691 buf2 = [bc_z%beg, bc_z%end]
2692
2693 call mpi_sendrecv(buf2, 2, mpi_integer, merge(bc_y%beg, mpi_proc_null, bc_y%beg >= 0), 312, rbuf2, 2, mpi_integer, &
2694 & merge(bc_y%end, mpi_proc_null, bc_y%end >= 0), 312, mpi_comm_world, mpi_status_ignore, ierr)
2695 if (bc_y%end >= 0) then
2696 ib_neighbor_ranks(0, +1, -1) = rbuf2(1)
2697 ib_neighbor_ranks(0, +1, +1) = rbuf2(2)
2698 end if
2699
2700 call mpi_sendrecv(buf2, 2, mpi_integer, merge(bc_y%end, mpi_proc_null, bc_y%end >= 0), 313, rbuf2, 2, mpi_integer, &
2701 & merge(bc_y%beg, mpi_proc_null, bc_y%beg >= 0), 313, mpi_comm_world, mpi_status_ignore, ierr)
2702 if (bc_y%beg >= 0) then
2703 ib_neighbor_ranks(0, -1, -1) = rbuf2(1)
2704 ib_neighbor_ranks(0, -1, +1) = rbuf2(2)
2705 end if
2706
2707 ! Round 2: exchange z face ranks with xy-diagonal edge neighbors -> corner ranks. Each of the 4 xy diagonals gives 2
2708 ! corners (the +/-z variants). Pattern: send buf2 to mirror diagonal, receive from this diagonal -> that edge's z face
2709 ! ranks.
2710# 1813 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2711 call mpi_sendrecv(buf2, 2, mpi_integer, merge(ib_neighbor_ranks(-1, -1, 0), mpi_proc_null, &
2712# 1814 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2713 & ib_neighbor_ranks(-1, -1, 0) >= 0), 320, rbuf2, 2, mpi_integer, &
2714# 1815 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2715 & merge(ib_neighbor_ranks(1, 1, 0), mpi_proc_null, ib_neighbor_ranks(1, 1, &
2716# 1816 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2717 & 0) >= 0), 320, mpi_comm_world, mpi_status_ignore, ierr)
2718# 1817 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2719 if (ib_neighbor_ranks(1, 1, 0) >= 0) then
2720# 1818 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2721 ib_neighbor_ranks(1, 1, -1) = rbuf2(1)
2722# 1819 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2723 ib_neighbor_ranks(1, 1, +1) = rbuf2(2)
2724# 1820 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2725 end if
2726# 1813 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2727 call mpi_sendrecv(buf2, 2, mpi_integer, merge(ib_neighbor_ranks(-1, 1, 0), mpi_proc_null, &
2728# 1814 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2729 & ib_neighbor_ranks(-1, 1, 0) >= 0), 321, rbuf2, 2, mpi_integer, &
2730# 1815 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2731 & merge(ib_neighbor_ranks(1, -1, 0), mpi_proc_null, ib_neighbor_ranks(1, -1, &
2732# 1816 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2733 & 0) >= 0), 321, mpi_comm_world, mpi_status_ignore, ierr)
2734# 1817 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2735 if (ib_neighbor_ranks(1, -1, 0) >= 0) then
2736# 1818 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2737 ib_neighbor_ranks(1, -1, -1) = rbuf2(1)
2738# 1819 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2739 ib_neighbor_ranks(1, -1, +1) = rbuf2(2)
2740# 1820 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2741 end if
2742# 1813 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2743 call mpi_sendrecv(buf2, 2, mpi_integer, merge(ib_neighbor_ranks(1, -1, 0), mpi_proc_null, &
2744# 1814 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2745 & ib_neighbor_ranks(1, -1, 0) >= 0), 322, rbuf2, 2, mpi_integer, &
2746# 1815 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2747 & merge(ib_neighbor_ranks(-1, 1, 0), mpi_proc_null, ib_neighbor_ranks(-1, 1, &
2748# 1816 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2749 & 0) >= 0), 322, mpi_comm_world, mpi_status_ignore, ierr)
2750# 1817 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2751 if (ib_neighbor_ranks(-1, 1, 0) >= 0) then
2752# 1818 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2753 ib_neighbor_ranks(-1, 1, -1) = rbuf2(1)
2754# 1819 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2755 ib_neighbor_ranks(-1, 1, +1) = rbuf2(2)
2756# 1820 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2757 end if
2758# 1813 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2759 call mpi_sendrecv(buf2, 2, mpi_integer, merge(ib_neighbor_ranks(1, 1, 0), mpi_proc_null, &
2760# 1814 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2761 & ib_neighbor_ranks(1, 1, 0) >= 0), 323, rbuf2, 2, mpi_integer, &
2762# 1815 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2763 & merge(ib_neighbor_ranks(-1, -1, 0), mpi_proc_null, ib_neighbor_ranks(-1, -1, &
2764# 1816 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2765 & 0) >= 0), 323, mpi_comm_world, mpi_status_ignore, ierr)
2766# 1817 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2767 if (ib_neighbor_ranks(-1, -1, 0) >= 0) then
2768# 1818 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2769 ib_neighbor_ranks(-1, -1, -1) = rbuf2(1)
2770# 1819 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2771 ib_neighbor_ranks(-1, -1, +1) = rbuf2(2)
2772# 1820 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2773 end if
2774# 1822 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2775 end if
2776
2777 ! For radius > 1: extend the table by iterative 26-neighbor full-table exchanges. In each round, every rank broadcasts its
2778 ! current table to all 26 immediate neighbors. Their entry at offset (dx,dy,dz) from them = our entry at
2779 ! (dx+sx,dy+sy,dz+sz). One extension round fills the entire next shell, so ax-1 rounds suffice.
2780 if (ax > 1) then
2781 allocate (send_table(-ax:ax,-ax:ax,-ax:ax))
2782 allocate (recv_tables(-ax:ax,-ax:ax,-ax:ax,1:26))
2783
2784 do k = 2, ax
2785 send_table = ib_neighbor_ranks
2786
2787 nreqs = 0
2788 nbr_idx = 0
2789 do sz = -1, 1
2790 do sy = -1, 1
2791 do sx = -1, 1
2792 if (sx == 0 .and. sy == 0 .and. sz == 0) cycle
2793 nbr_idx = nbr_idx + 1
2794 if (ib_neighbor_ranks(sx, sy, sz) < 0) cycle
2795 nreqs = nreqs + 1
2796 call mpi_irecv(recv_tables(:,:,:,nbr_idx), (2*ax + 1)**3, mpi_integer, ib_neighbor_ranks(sx, sy, sz), &
2797 & 400, mpi_comm_world, requests(nreqs), ierr)
2798 end do
2799 end do
2800 end do
2801
2802 do sz = -1, 1
2803 do sy = -1, 1
2804 do sx = -1, 1
2805 if (sx == 0 .and. sy == 0 .and. sz == 0) cycle
2806 if (ib_neighbor_ranks(sx, sy, sz) < 0) cycle
2807 nreqs = nreqs + 1
2808 call mpi_isend(send_table, (2*ax + 1)**3, mpi_integer, ib_neighbor_ranks(sx, sy, sz), 400, &
2809 & mpi_comm_world, requests(nreqs), ierr)
2810 end do
2811 end do
2812 end do
2813
2814 call mpi_waitall(nreqs, requests, mpi_statuses_ignore, ierr)
2815
2816 nbr_idx = 0
2817 do sz = -1, 1
2818 do sy = -1, 1
2819 do sx = -1, 1
2820 if (sx == 0 .and. sy == 0 .and. sz == 0) cycle
2821 nbr_idx = nbr_idx + 1
2822 if (ib_neighbor_ranks(sx, sy, sz) < 0) cycle
2823 do dz = -ax, ax
2824 do dy = -ax, ax
2825 do dx = -ax, ax
2826 if (recv_tables(dx, dy, dz, nbr_idx) == mpi_proc_null) cycle
2827 if (dx + sx < -ax .or. dx + sx > ax) cycle
2828 if (dy + sy < -ax .or. dy + sy > ax) cycle
2829 if (dz + sz < -ax .or. dz + sz > ax) cycle
2830 if (ib_neighbor_ranks(dx + sx, dy + sy, dz + sz) /= mpi_proc_null) cycle
2831 ib_neighbor_ranks(dx + sx, dy + sy, dz + sz) = recv_tables(dx, dy, dz, nbr_idx)
2832 end do
2833 end do
2834 end do
2835 end do
2836 end do
2837 end do
2838 end do
2839
2840 deallocate (send_table, recv_tables)
2841 end if
2842#endif
2843
2844 end subroutine s_compute_ib_neighbor_ranks
2845
2847
2848 real(wp) :: beg_val, end_val, recv_val, bound, max_ib_bound, local_rank_width, min_rank_width
2849 integer :: k, send_neighbor, recv_neighbor, ierr, temporary_radius
2850
2851 ! Default: unbounded in all directions (covers single-rank and no-MPI cases)
2852
2853 neighbor_domain_x%beg = -huge(0._wp)
2854 neighbor_domain_x%end = huge(0._wp)
2855 neighbor_domain_y%beg = -huge(0._wp)
2856 neighbor_domain_y%end = huge(0._wp)
2857 neighbor_domain_z%beg = -huge(0._wp)
2858 neighbor_domain_z%end = huge(0._wp)
2859
2860#ifdef MFC_MPI
2861 ! perform setup if we are doing automatic radius checking
2862 if (ib_neighborhood_radius < 1) then
2863 ib_neighborhood_radius = 0 ! ensure we are starting with 0 neighborhood radius
2864
2865 ! determine the maximum length of space that needs to be contained by the neighborhood
2866 max_ib_bound = -1._wp
2867 do k = 1, num_ibs
2868 call s_get_ib_bound(patch_ib(k), bound)
2869 max_ib_bound = max(max_ib_bound, bound)
2870 end do
2871 do k = 1, num_particle_clouds
2872 max_ib_bound = max(max_ib_bound, particle_cloud(k)%radius)
2873 end do
2874
2875 ! Narrowest rank extent, over every direction as well as every rank. The radius is a count of rank
2876 ! hops, so the distance one hop covers is the extent of the rank it steps over, and the direction
2877 ! needing the most hops to span the body is the one whose ranks are thinnest. Reducing over each
2878 ! rank's widest extent first reports the wrong number whenever ranks are anisotropic, which is the
2879 ! norm on a stretched grid or an elongated domain.
2880 local_rank_width = huge(0._wp)
2881# 1929 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2882 if (num_dims >= 1) local_rank_width = min(local_rank_width, abs(x_cb(m) - x_cb(-1)))
2883# 1930 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2884# 1929 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2885 if (num_dims >= 2) local_rank_width = min(local_rank_width, abs(y_cb(n) - y_cb(-1)))
2886# 1930 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2887# 1929 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2888 if (num_dims >= 3) local_rank_width = min(local_rank_width, abs(z_cb(p) - z_cb(-1)))
2889# 1930 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2890# 1931 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2891 call s_mpi_allreduce_min(local_rank_width, min_rank_width)
2892
2893 ! approximate the size of the neighborhood with a local 1.1x fudge factor for safety, lower bound of 1
2894 ib_neighborhood_radius = max(1, ceiling(1.1_wp*max_ib_bound/(min_rank_width)))
2895 if (proc_rank == 0) print *, "Automatic choice of ib_neighborhood_radius selected: ", ib_neighborhood_radius
2896 end if
2897
2898 ! For each direction, propagate the left/right boundary edges outward ib_neighborhood_radius hops. After k rounds: beg_val =
2899 ! left edge of the rank k hops to the left; end_val = right edge of the rank k hops to the right.
2900# 1941 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2901 if (num_dims >= 1) then
2902# 1942 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2903 beg_val = x_cb(-1)
2904# 1943 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2905 end_val = x_cb(m)
2906# 1944 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2907 do k = 1, ib_neighborhood_radius
2908 send_neighbor = merge(bc_x%end, mpi_proc_null, bc_x%end >= 0)
2909# 1946 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2910 recv_neighbor = merge(bc_x%beg, mpi_proc_null, bc_x%beg >= 0)
2911# 1947 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2912 recv_val = -huge(0._wp)
2913 call mpi_sendrecv(beg_val, 1, mpi_p, send_neighbor, 100, recv_val, 1, mpi_p, recv_neighbor, 100, &
2914# 1949 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2915 & mpi_comm_world, mpi_status_ignore, ierr)
2916 beg_val = recv_val
2917
2918 send_neighbor = merge(bc_x%beg, mpi_proc_null, bc_x%beg >= 0)
2919# 1953 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2920 recv_neighbor = merge(bc_x%end, mpi_proc_null, bc_x%end >= 0)
2921# 1954 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2922 recv_val = huge(0._wp)
2923 call mpi_sendrecv(end_val, 1, mpi_p, send_neighbor, 101, recv_val, 1, mpi_p, recv_neighbor, &
2924# 1956 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2925 & 101, mpi_comm_world, mpi_status_ignore, ierr)
2926# 1957 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2927 end_val = recv_val
2928
2929 ! protect from looping back around on yourself multiple times
2930 if (f_approx_equal(beg_val, x_cb(m)) .or. f_approx_equal(end_val, x_cb(-1))) then
2931# 1961 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2932 beg_val = -huge(0._wp)
2933 end_val = huge(0._wp)
2934 exit
2935 end if
2936 end do
2937 neighbor_domain_x%beg = beg_val
2938# 1967 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2939 neighbor_domain_x%end = end_val
2940# 1968 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2941 end if
2942# 1941 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2943 if (num_dims >= 2) then
2944# 1942 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2945 beg_val = y_cb(-1)
2946# 1943 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2947 end_val = y_cb(n)
2948# 1944 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2949 do k = 1, ib_neighborhood_radius
2950 send_neighbor = merge(bc_y%end, mpi_proc_null, bc_y%end >= 0)
2951# 1946 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2952 recv_neighbor = merge(bc_y%beg, mpi_proc_null, bc_y%beg >= 0)
2953# 1947 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2954 recv_val = -huge(0._wp)
2955 call mpi_sendrecv(beg_val, 1, mpi_p, send_neighbor, 102, recv_val, 1, mpi_p, recv_neighbor, 102, &
2956# 1949 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2957 & mpi_comm_world, mpi_status_ignore, ierr)
2958 beg_val = recv_val
2959
2960 send_neighbor = merge(bc_y%beg, mpi_proc_null, bc_y%beg >= 0)
2961# 1953 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2962 recv_neighbor = merge(bc_y%end, mpi_proc_null, bc_y%end >= 0)
2963# 1954 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2964 recv_val = huge(0._wp)
2965 call mpi_sendrecv(end_val, 1, mpi_p, send_neighbor, 103, recv_val, 1, mpi_p, recv_neighbor, &
2966# 1956 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2967 & 103, mpi_comm_world, mpi_status_ignore, ierr)
2968# 1957 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2969 end_val = recv_val
2970
2971 ! protect from looping back around on yourself multiple times
2972 if (f_approx_equal(beg_val, y_cb(n)) .or. f_approx_equal(end_val, y_cb(-1))) then
2973# 1961 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2974 beg_val = -huge(0._wp)
2975 end_val = huge(0._wp)
2976 exit
2977 end if
2978 end do
2979 neighbor_domain_y%beg = beg_val
2980# 1967 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2981 neighbor_domain_y%end = end_val
2982# 1968 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2983 end if
2984# 1941 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2985 if (num_dims >= 3) then
2986# 1942 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2987 beg_val = z_cb(-1)
2988# 1943 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2989 end_val = z_cb(p)
2990# 1944 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2991 do k = 1, ib_neighborhood_radius
2992 send_neighbor = merge(bc_z%end, mpi_proc_null, bc_z%end >= 0)
2993# 1946 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2994 recv_neighbor = merge(bc_z%beg, mpi_proc_null, bc_z%beg >= 0)
2995# 1947 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2996 recv_val = -huge(0._wp)
2997 call mpi_sendrecv(beg_val, 1, mpi_p, send_neighbor, 104, recv_val, 1, mpi_p, recv_neighbor, 104, &
2998# 1949 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
2999 & mpi_comm_world, mpi_status_ignore, ierr)
3000 beg_val = recv_val
3001
3002 send_neighbor = merge(bc_z%beg, mpi_proc_null, bc_z%beg >= 0)
3003# 1953 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
3004 recv_neighbor = merge(bc_z%end, mpi_proc_null, bc_z%end >= 0)
3005# 1954 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
3006 recv_val = huge(0._wp)
3007 call mpi_sendrecv(end_val, 1, mpi_p, send_neighbor, 105, recv_val, 1, mpi_p, recv_neighbor, &
3008# 1956 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
3009 & 105, mpi_comm_world, mpi_status_ignore, ierr)
3010# 1957 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
3011 end_val = recv_val
3012
3013 ! protect from looping back around on yourself multiple times
3014 if (f_approx_equal(beg_val, z_cb(p)) .or. f_approx_equal(end_val, z_cb(-1))) then
3015# 1961 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
3016 beg_val = -huge(0._wp)
3017 end_val = huge(0._wp)
3018 exit
3019 end if
3020 end do
3021 neighbor_domain_z%beg = beg_val
3022# 1967 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
3023 neighbor_domain_z%end = end_val
3024# 1968 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
3025 end if
3026# 1970 "/home/runner/work/MFC/MFC/src/simulation/m_start_up.fpp"
3027#endif
3028
3029 end subroutine s_get_neighbor_bounds
3030
3031end module m_start_up
type(scalar_field), dimension(sys_size), intent(inout) q_cons_vf
One-way acoustic source injection, Maeda and Colonius JCP (2017).
impure subroutine, public s_precalculate_acoustic_spatial_sources
Pre-compute non-zero spatial source weights before time-stepping.
impure subroutine, public s_initialize_acoustic_src
Initialize the acoustic source module.
AMR flux registers: per-RK-stage refluxing at the coarse/fine block boundary. Depends only on m_deriv...
impure subroutine, public s_finalize_amr_registers()
impure subroutine, public s_initialize_amr_registers(maxc_fit)
Dynamic regrid for the AMR level set: density-gradient tagging, clustering (m_amr_cluster),...
impure subroutine, public s_amr_regrid(q_cons_base)
Regrid: tag by density gradient, cluster, shape, nest and rebuild the slots, carrying old data into t...
AMR fine-level restart I/O: writes/reads the fine-level restart file alongside the level-0 restart (s...
impure subroutine, public s_read_amr_restart(restored)
Restore the fine level from the AMR restart file at t_step_start (n_start under cfl_dt),...
impure subroutine, public s_write_amr_restart(t_step)
Write the fine-level restart file for save step t_step alongside the level-0 restart: the writing ran...
The AMR hooks of the SSP-RK stage loop (m_time_steppers): the stage-top coarse halo,...
impure subroutine, public s_amr_relax_fine(q_cons)
End-of-step phase-change relaxation on the fine blocks (the coarse grid's is in m_start_up),...
impure subroutine, public s_amr_apply_ic_patches(q_cons)
Fresh start: set every owned fine block to the initial condition patches evaluated at its own cell ce...
Block-structured AMR: up to amr_max_blocks refined blocks (2:1 or 4:1 per amr_ref_ratio),...
impure subroutine s_finalize_amr_module()
impure subroutine s_initialize_amr_module()
Re-exports every AMR service module.
Computes gravitational and body force source terms for the momentum equations.
impure subroutine, public s_initialize_body_forces_module
Initialize the body forces module. When synthetic_turbulence is enabled, generates random wave vector...
Noncharacteristic and processor boundary condition application for ghost cells and buffer regions.
subroutine, public s_populate_grid_variables_buffers(x_cb_in, x_cc_in, dx_in, x_offset, y_offset, z_offset, y_cb_in, y_cc_in, dy_in, z_cb_in, z_cc_in, dz_in, global_bounds)
Populate the buffers of the grid variables, which are constituted of the cell-boundary locations and ...
impure subroutine, public s_initialize_boundary_common_module(use_dirichlet_buffers, nvar_io)
Allocate and set up boundary condition buffer arrays for all coordinate directions.
impure subroutine, public s_populate_variables_buffers(bc_type, q_prim_vf, pb_in, mv_in, q_t_sf, skip_mpi)
Populate the buffers of the primitive variables based on the selected boundary conditions.
Boundary condition restart I/O, capillary/IGR buffer population, and grid-variable buffers.
subroutine s_assign_default_bc_type(bc_type)
Initialize the per-cell boundary condition type arrays with the global default BC values.
subroutine s_read_serial_boundary_condition_files(step_dirpath, bc_type)
Read boundary condition type and buffer data from serial (unformatted) restart files.
subroutine s_read_parallel_boundary_condition_files(bc_type, strict)
Read boundary condition type and buffer data from per-rank parallel files using MPI I/O.
Computes ensemble-averaged (Euler–Euler) bubble source terms for radius, velocity,...
impure subroutine s_initialize_bubbles_ee_module
Initialize the Euler-Euler bubble module.
Real fields of a bubble MPI slot, as (names, indices, count) in pack order. Used by both pack and unp...
impure subroutine s_sync_bubbles_for_save()
Bring the bubble state and void fraction to the host for a save, aborting on a negative or NaN radius...
type(scalar_field), dimension(:), allocatable q_beta
Projection of the Lagrangian bubbles in the Eulerian framework.
impure subroutine s_initialize_bubbles_el_module(q_cons_vf, bc_type, rows, ids, n_loc)
Initialize the Lagrangian subgrid bubble solver with this rank's n_loc bubbles from rows (input file,...
Characteristic boundary conditions (CBCs) for slip walls, non-reflecting subsonic inflow/outflow,...
impure subroutine, public s_initialize_cbc_module
Initialize the CBC module.
Shared input validation checks for grid dimensions and AMD GPU compiler limits.
impure subroutine, public s_check_inputs_common(check_total_cells, n_global)
Checks compatibility of parameters in the input file. Used by all three stages.
Validates simulation input parameters for consistency and supported configurations.
impure subroutine, public s_check_inputs
Checks compatibility of parameters in the input file. Used by the simulation stage.
Multi-species chemistry interface for thermodynamic properties, reaction rates, and transport coeffic...
subroutine s_compute_q_t_sf(q_t_sf, q_cons_vf, bounds)
Initialize the temperature field from conservative variables by inverting the energy equation.
Ghost-node immersed boundary method: locates ghost/image points, computes interpolation coefficients,...
Platform-specific file and directory operations: create, delete, inquire, getcwd, and basename.
impure subroutine my_inquire(fileloc, dircheck)
Inquire on the existence of a directory or file.
Compile-time constant parameters: default values, tolerances, and physical constants.
integer, parameter ib_state_nfields
Reals per IB in restart_data/ib_state: time, force(3), torque(3), vel(3), angular_vel(3),...
real(wp), parameter dflt_t_guess
Default guess for temperature (when a previous value is not available).
integer, parameter time_stepper_rk2
real(wp), parameter sgm_eps
Segmentation tolerance.
integer, parameter recon_type_muscl
integer, parameter time_stepper_rk1
integer, parameter time_stepper_rk3
integer, parameter nnode
Number of QBMM nodes.
integer, parameter recon_type_weno
integer, parameter model_eqns_6eq
integer, parameter bc_periodic
Writes solution data, run-time stability diagnostics (ICFL, VCFL, CCFL, Rc), and probe/center-of-mass...
impure subroutine, public s_initialize_lag_output(save_count, qtime)
Create D/, open the Lagrangian output files, and write the initial output, from the restart point (sa...
impure subroutine, public s_initialize_data_output_module
Initialize the data output module.
impure subroutine, public s_write_lag_save_data(save_count)
Write the Lagrangian restart file, and the bubble statistics, for save save_count....
impure subroutine, public s_write_data_files(q_cons_vf, q_t_sf, q_prim_vf, t_step, bc_type, beta)
Write data files. Dispatch subroutine that replaces procedure pointer.
impure subroutine, public s_write_ib_state_file(time_step)
Writes IB state records to restart_data/ib_state.dat. Called on every rank.
subroutine, public s_write_ib_data_file(time_step)
Dispatch immersed boundary data output to the serial or parallel writer.
Shared derived types for field data, patch geometry, bubble dynamics, and MPI I/O structures.
Derives diagnostic flow quantities (vorticity, speed of sound, numerical Schlieren,...
impure subroutine, public s_initialize_derived_variables
Allocate and open derived variables. Computing FD coefficients.
impure subroutine, public s_initialize_derived_variables_module
Computation of parameters, allocation procedures, and/or any other tasks needed to properly setup the...
Equations of state in Gamma/Pi form, rho e = Gamma(rho) p + Pi(rho).
impure subroutine, public s_initialize_eos_module()
Resolve every fluid's EOS coefficients once, before any conversion runs.
subroutine, public s_phase_internal_energy(pres, alpha, alpha_rho, i, e_phase)
Internal energy per unit volume of phase i at pressure pres: alpha (Gamma p + Pi) + alpha_rho qv,...
Utilities shared by the Euler-Lagrange bubble and solid-particle solvers: cell location,...
subroutine, public s_get_lag_restart_point(save_count, qtime)
Save index and time the run starts from: zero on a fresh start, the restart point otherwise.
Global parameters for the computational domain, fluid properties, and simulation algorithm configurat...
real(wp) mytime
Current simulation time.
real(wp), dimension(num_synth_shells_max) synth_k_shell
type(part_q_idx_info) part_q_idx
Lagrangian particle projected-field indices.
real(wp), dimension(num_synth_shells_max) synth_amp_shell
type(int_bounds_info), dimension(1:3) idwint
real(wp), dimension(:), allocatable, target z_cb
logical, dimension(3) periodic_bc
integer proc_rank
Rank of the local processor.
type(mpi_io_ib_var), public mpi_io_ib_data
type(bounds_info), dimension(3) glb_bounds
type(int_bounds_info), dimension(1:3) idwbuff
integer buff_size
Number of ghost cells for boundary condition storage.
type(bub_q_idx_info) bub_q_idx
Lagrangian bubble projected-field indices.
impure subroutine s_initialize_global_parameters_module
Initialize the global parameters module.
real(wp), dimension(:), allocatable, target y_cc
type(pres_field), dimension(:), allocatable pb_ts
type(pres_field), dimension(:), allocatable mv_ts
real(wp), dimension(:), allocatable, target z_cc
integer num_procs
Number of processors.
real(wp), dimension(:), allocatable, target x_cc
integer, dimension(num_synth_shells_max) synth_n_waves_per_shell
real(wp), dimension(num_turb_sources_max, 3) turb_pos
real(wp), dimension(:), allocatable, target y_cb
type(cell_num_bounds) cells_bounds
type(mpi_io_var), public mpi_io_data
real(wp), dimension(:), allocatable, target dy
real(wp), dimension(num_turb_sources_max, 3) synth_l
real(wp), dimension(:), allocatable, target dz
real(wp), dimension(:), allocatable, target dx
real(wp), dimension(:), allocatable, target x_cb
Basic floating-point utilities: approximate equality, default detection, and coordinate bounds.
elemental subroutine, public s_update_cell_bounds(bounds, m, n, p)
Update the min and max number of cells in each set of axes.
logical elemental function, public f_is_default(var)
Check if a real(wp) variable is of default value.
Utility routines for bubble model setup, coordinate transforms, array sampling, and special functions...
subroutine, public s_upsample_data(q_cons_vf, q_cons_temp)
Upsample conservative variable fields from a coarsened grid back to the original resolution using int...
impure subroutine, public s_initialize_bubbles_model()
Initialize bubble model arrays for Euler or Lagrangian bubbles with polytropic or non-polytropic gas.
elemental subroutine, public s_int_to_str(i, res)
Convert an integer to its trimmed string representation.
Computes hypoelastic stress-rate source terms and damage-state evolution.
impure subroutine, public s_initialize_hypoelastic_module
Initialize the hypoelastic module.
Allocate memory and read initial condition data for IC extrusion.
subroutine, public s_initialize_ib_airfoils()
Initialize the NACA surface grids for all airfoil IB patches. Must be called after the grid is establ...
Ghost-node immersed boundary method: locates ghost/image points, computes interpolation coefficients,...
impure subroutine, public s_ibm_setup()
Initializes the values of various IBM variables, such as ghost points and image points.
impure subroutine, public s_write_ib_surface(save_count)
Write this rank's surface records to D/ib_surface_<rank>_<save>.dat, one line per weighted ghost poin...
type(integer_field), public ib_markers
impure subroutine, public s_read_ib_conduction_temperature(t_step)
Restore T_cond of this rank's ghosts from the file of s_write_ib_conduction_temperature,...
impure subroutine, public s_initialize_ibm_module()
Allocates memory for the variables in the IBM module.
Iterative ghost rasterization (IGR) for sharp immersed boundary treatment.
subroutine, public s_initialize_igr_module()
Initialize the IGR module.
integer(kind=8) j
integer(kind=8) i
integer(kind=8) l
integer(kind=8) r
integer(kind=8) k
Binary STL file reader and processor for immersed boundary geometry.
subroutine, public s_instantiate_stl_models()
Load, transform, and register STL/OBJ immersed-boundary models onto the simulation grid.
MPI communication layer: domain decomposition, halo exchange, reductions, and parallel I/O setup.
impure subroutine s_mpi_abort(prnt, code)
The subroutine terminates the MPI execution environment.
impure subroutine s_initialize_mpi_common_module(exchange_all_chemistry_temperatures_in, use_rdma_transport_in, num_beta_vars_in)
Initialize the module.
impure subroutine s_mpi_barrier
Halts all processes until all have reached barrier.
impure subroutine s_check_mpi_file_open(ierr, file_loc)
Abort naming the file if MPI_FILE_OPEN failed. File errors default to MPI_ERRORS_RETURN,...
subroutine s_apply_grid_from_global_dim(x_cb_glb, m_dim_glb, m_dim, sidx, bc_beg, bc_end, cb_lo, cb_hi, cw_lo, cw_hi, x_cb_loc, x_cc_loc, dx_loc)
Populate the local cell-boundary, cell-center, and cell-width arrays in one direction directly from t...
impure subroutine s_initialize_mpi_data(q_cons_vf, ib_markers, ib_mpi_data, beta, qbmm_pb, qbmm_mv)
Set up MPI I/O data views and variable pointers for parallel file output.
impure subroutine mpi_bcast_time_step_values(proc_time, time_avg)
Gather per-rank time step wall-clock times onto rank 0 for performance reporting.
subroutine s_initialize_mpi_data_ds(m_ds, n_ds, p_ds, q_cons_vf)
Set up MPI I/O data views for downsampled (coarsened) parallel file output.
MPI halo exchange, domain decomposition, and buffer packing/unpacking for the simulation solver.
subroutine s_initialize_mpi_proxy_module()
Initialize the MPI proxy module.
MUSCL reconstruction with interface sharpening for contact-preserving advection.
subroutine, public s_initialize_muscl_module()
Allocate and initialize MUSCL reconstruction working arrays.
NVIDIA NVTX profiling API bindings for GPU performance instrumentation.
Definition m_nvtx.f90:6
subroutine nvtxstartrange(name, id)
Push a named NVTX range for GPU profiling, optionally with a color based on the given identifier.
Definition m_nvtx.f90:62
subroutine nvtxendrange
Pop the current NVTX range to end the GPU profiling region.
Definition m_nvtx.f90:83
Real fields of a particle MPI slot, as (names, indices, count) in pack order. Used by both pack and u...
impure subroutine, public s_initialize_particles_el_module(bc_type, rows, ids, n_loc)
Allocate the particle and projected-field arrays, load this rank's n_loc particles from rows (input f...
type(scalar_field), dimension(:), allocatable, public q_particles
Eulerian projection of particle data (volume fraction, momentum, sources).
impure subroutine, public s_sync_particles_for_save()
Copy the particle state and projected volume fraction to the host before a save, and abort if any par...
Phase transition relaxation solvers for liquid-vapor flows with cavitation and boiling.
subroutine, public s_infinite_relaxation_k(q_cons_vf)
Apply pT- or pTg-equilibrium relaxation with mass depletion based on the incoming state conditions.
impure subroutine, public s_initialize_phasechange_module
Initialize the phase change module (no module-level state to set up; the pT/pTg relaxation solvers ar...
Per-phase wall-time budget of the AMR step, reported when rank_time_wrt is on. Brackets are disjoint ...
integer, parameter, public ph_regrid
regrid
impure subroutine, public s_phase_step_toc()
impure subroutine, public s_phase_step_tic()
impure subroutine, public s_phase_report()
Mean and max over ranks per phase, share of the step-loop wall, imbalance (max/mean) and calls; the r...
impure subroutine, public s_phase_tic(id)
impure subroutine, public s_phase_toc(id)
Pressure relaxation for the six-equation multi-component model via Newton–Raphson equilibration and v...
impure subroutine, public s_report_pressure_relaxation
One line at the end of a run if the equilibration ever stopped on its iteration cap....
Quadrature-based moment methods (QBMM) for polydisperse bubble moment inversion and transport.
impure subroutine, public s_initialize_qbmm_module
Initialize the QBMM module.
Assemble the right-hand side of the governing equations using finite-volume flux differencing,...
impure subroutine, public s_initialize_rhs_module
Initialize the RHS module.
Approximate and exact Riemann solvers (HLL, HLLC, HLLD, exact) for the multicomponent Navier–Stokes e...
impure subroutine, public s_initialize_riemann_solvers_module
Initialize the Riemann solvers module.
Simulation helper routines for cell state, CFL calculation, and stability checks.
character(len=4), public dt_limiter
Criterion currently limiting the adaptive time step (ICFL, VCFL, CCFL, TCFL, the collision cap,...
Reads input files, loads initial conditions and grid data, and orchestrates solver initialization and...
impure subroutine s_read_ib_restart_data(t_step)
Loads the IBs this rank owns from the IB state file for t_step into patch_ib(1:num_ibs),...
impure subroutine, public s_read_serial_data_files(q_cons_vf)
Read serial initial condition and grid data files and compute cell-width distributions.
impure subroutine, public s_initialize_modules
Initialize all simulation sub-modules in the required dependency order.
impure subroutine, public s_read_data_files(q_cons_vf)
Read data files. Dispatch subroutine that replaces procedure pointer.
subroutine s_assign_particle_cloud_ib_defaults(cloud_ib_idx, ib_patch)
Fills the properties of a generated particle-cloud IB that the IB state file does not carry (geometry...
impure subroutine, public s_read_parallel_data_files(q_cons_vf)
Read parallel initial condition and grid data files via MPI I/O.
subroutine, public s_initialize_internal_energy_equations(v_vf)
Initialize internal-energy equations from phase mass, mixture momentum, and total energy.
impure subroutine, public s_save_performance_metrics(time_avg, time_final, io_time_avg, io_time_final, proc_time, io_proc_time, file_exists)
Collect per-process wall-clock times and write aggregate performance metrics to file.
subroutine s_compute_ib_neighbor_ranks()
Build ib_neighbor_ranks(-1:1,-1:1,-1:1): MPI ranks of all neighbor domains. Uses two rounds of MPI_SE...
logical amr_fresh_start
AMR: the fine level was prolonged from level 0 at start-up (no restart file), so the first step regri...
impure subroutine, public s_save_data(t_step, start, finish, io_time_avg, nt)
Save conservative variable data to disk at the current time step.
impure subroutine s_read_lag_restart(lag_kind, save_count, io_data, n_loc)
Read restart_data/lag_<lag_kind>_<save_count>.dat written by s_write_lag_restart: set mytime and dt f...
subroutine s_get_neighbor_bounds()
type(scalar_field), dimension(:), allocatable q_cons_temp
impure subroutine s_read_lag_input(path, ncols, n_glb, rows, ids, n_loc, n_read)
Read the initial Lagrangian entities from path, one per line with ncols values, and return those in t...
subroutine, public s_initialize_gpu_vars
Transfer initial conservative variable and model parameter data to the GPU device.
impure subroutine s_check_restart_file_size(ifile, file_loc, expected_bytes)
Abort if an open restart file holds fewer bytes than are about to be read from it,...
impure subroutine, public s_initialize_mpi_domain
Set up the MPI execution environment, bind GPUs, and decompose the computational domain.
impure subroutine s_resolve_ib_mass_relax()
ib_mass_relax = -1 (default): N = 30 for a moving body, else 0 (a fixed body leaks little,...
impure subroutine, public s_amr_start_fresh_blocks
Fresh AMR run, before the first save: put the initial condition patches on the blocks and,...
impure subroutine, public s_finalize_modules
Finalize and deallocate all simulation sub-modules in reverse initialization order.
impure subroutine, public s_read_input_file
Verify the input file exists and read it.
impure subroutine, public s_check_input_file
Validate that all user-provided inputs form a consistent simulation configuration.
subroutine s_build_ib_neighborhood()
Completes this rank's IB neighborhood once s_read_ib_restart_data has loaded only the IBs it owns: ev...
impure subroutine, public s_perform_time_step(t_step, time_avg)
Advance the simulation by one time step, handling CFL-based dt and time-stepper dispatch.
impure subroutine s_read_lag_entities(save_count, rows, ids, n_loc)
Read the Lagrangian bubbles or particles this rank starts with: the input-file rows (and their global...
Computes capillary source fluxes and color-function gradients for the diffuse-interface surface tensi...
impure subroutine, public s_initialize_surface_tension_module
Allocate and initialize surface tension module arrays.
THINC and MTHINC interface compression for volume fraction sharpening. THINC (int_comp=1): 1D directi...
subroutine, public s_initialize_thinc_module()
real(wp), dimension(:,:,:), allocatable position
Total-variation-diminishing (TVD) Runge–Kutta time integrators (1st-, 2nd-, and 3rd-order SSP).
type(scalar_field) q_t_sf
Cell-average temperature variables at the current time-stage.
type(integer_field), dimension(:,:), allocatable bc_type
Boundary condition identifiers.
impure subroutine s_initialize_time_steppers_module
Initialize the time steppers module.
type(vector_field), dimension(:), allocatable q_cons_ts
Cell-average conservative variables at each time-stage (TS).
impure subroutine s_amr_check_fixed_dt(reach)
AMR with a fixed dt: abort if dt exceeds the finest level's inviscid limit (ICFL = 1,...
impure subroutine s_compute_dt(dt_cand)
Compute the global time step size from CFL stability constraints across all cells Sets dt from the CF...
type(scalar_field), dimension(:), allocatable q_prim_vf
Cell-average primitive variables at the current time-stage.
impure subroutine s_tvd_rk(t_step, time_avg, nstage)
Advance the solution one full step using a TVD Runge-Kutta time integrator.
integer stor
storage index
Conservative-to-primitive variable conversion, mixture property evaluation, and pressure computation.
subroutine, public s_compute_pressure(energy, alf, dyn_p, pi_inf, gamma, rho, qv, rhoyks, pres, t, e_e_in, pres_mag)
Compute the pressure from the appropriate equation of state.
impure subroutine, public s_initialize_variables_conversion_module(store_mixture_fields, enforce_density_floor, preserve_qbmm_number, lagrange_beta_index)
Initialize the variables conversion module.
subroutine, public s_convert_to_mixture_variables(q_vf, i, j, k, rho, gamma, pi_inf, qv, re_k, g_k, g)
Dispatch to the s_convert_mixture_to_mixture_variables and s_convert_species_to_mixture_variables sub...
Computes viscous stress tensors and diffusive flux contributions for the Navier–Stokes equations.
impure subroutine, public s_initialize_viscous_module
Initialize the viscous module.
WENO/WENO-Z/TENO reconstructions with optional monotonicity-preserving bounds and mapped weights.
impure subroutine, public s_initialize_weno_module
Initialize the WENO module.
Integer bounds for variables.
Derived type annexing a scalar field (SF).