MFC
Exascale flow solver
Loading...
Searching...
No Matches
m_data_output.fpp.f90
Go to the documentation of this file.
1# 1 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2!>
3!! @file
4!! @brief Contains module m_data_output
5
6# 1 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp" 1
7# 1 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp" 1
8# 1 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp" 1
9# 2 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
10# 3 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
11# 4 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
12# 5 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
13# 6 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
14
15# 8 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
16# 9 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
17# 10 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
18
19# 12 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
20# 1 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp" 1
21! Default for Fypp runs outside the toolchain (e.g. documentation). Searched last, so the
22! build/include/<target>/thermochem.fpp the toolchain writes from m_thermochem takes precedence.
23# 4 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp"
24# 5 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp"
25# 13 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp" 2
26
27# 16 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
28# 17 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
29
30# 24 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
31
32# 53 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
33
34# 65 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
35
36# 75 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
37
38# 105 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
39
40# 117 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
41
42# 127 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
43
44# 174 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
45! New line at end of file is required for FYPP
46# 2 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp" 2
47# 1 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp" 1
48# 1 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp" 1
49# 2 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
50# 3 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
51# 4 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
52# 5 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
53# 6 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
54
55# 8 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
56# 9 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
57# 10 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
58
59# 12 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
60# 1 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp" 1
61! Default for Fypp runs outside the toolchain (e.g. documentation). Searched last, so the
62! build/include/<target>/thermochem.fpp the toolchain writes from m_thermochem takes precedence.
63# 4 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp"
64# 5 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp"
65# 13 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp" 2
66
67# 16 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
68# 17 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
69
70# 24 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
71
72# 53 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
73
74# 65 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
75
76# 75 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
77
78# 105 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
79
80# 117 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
81
82# 127 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
83
84# 174 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
85! New line at end of file is required for FYPP
86# 2 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp" 2
87
88# 4 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
89# 5 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
90# 6 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
91# 7 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
92# 8 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
93
94# 20 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
95
96# 49 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
97
98# 54 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
99
100# 59 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
101
102# 64 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
103
104# 69 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
105
106# 74 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
107
108# 87 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
109
110# 101 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
111
112# 106 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
113
114# 111 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
115
116# 116 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
117
118# 121 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
119
120# 126 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
121
122# 131 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
123
124# 136 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
125
126# 141 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
127
128# 171 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
129
130# 231 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
131
132# 245 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
133
134# 270 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
135
136# 281 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
137
138# 283 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
139# 294 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
140
141# 343 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
142
143# 353 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
144
145# 363 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
146
147# 372 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
148
149# 389 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
150
151# 399 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
152
153# 406 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
154
155# 412 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
156
157# 418 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
158
159# 424 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
160
161# 430 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
162
163# 436 "/home/runner/work/MFC/MFC/src/common/include/omp_macros.fpp"
164! New line at end of file is required for FYPP
165# 3 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp" 2
166# 1 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp" 1
167# 1 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp" 1
168# 2 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
169# 3 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
170# 4 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
171# 5 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
172# 6 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
173
174# 8 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
175# 9 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
176# 10 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
177
178# 12 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
179# 1 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp" 1
180! Default for Fypp runs outside the toolchain (e.g. documentation). Searched last, so the
181! build/include/<target>/thermochem.fpp the toolchain writes from m_thermochem takes precedence.
182# 4 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp"
183# 5 "/home/runner/work/MFC/MFC/src/common/include/defaults/thermochem.fpp"
184# 13 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp" 2
185
186# 16 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
187# 17 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
188
189# 24 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
190
191# 53 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
192
193# 65 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
194
195# 75 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
196
197# 105 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
198
199# 117 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
200
201# 127 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
202
203# 174 "/home/runner/work/MFC/MFC/src/common/include/shared_parallel_macros.fpp"
204! New line at end of file is required for FYPP
205# 2 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp" 2
206
207# 7 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
208
209# 17 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
210
211# 22 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
212
213# 27 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
214
215# 32 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
216
217# 37 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
218
219# 42 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
220
221# 47 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
222
223# 52 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
224
225# 57 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
226
227# 62 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
228
229# 73 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
230
231# 78 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
232
233# 83 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
234
235# 88 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
236
237# 103 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
238
239# 131 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
240
241# 161 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
242
243# 176 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
244
245# 194 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
246
247# 216 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
248
249# 245 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
250
251# 260 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
252
253# 270 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
254
255# 279 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
256
257# 295 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
258
259# 305 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
260
261# 312 "/home/runner/work/MFC/MFC/src/common/include/acc_macros.fpp"
262! New line at end of file is required for FYPP
263# 4 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp" 2
264
265! GPU parallel region (scalar reductions, maxval/minval)
266# 23 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
267
268! GPU parallel loop over threads (most common GPU macro)
269# 44 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
270
271! Required closing for GPU_PARALLEL_LOOP
272# 56 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
273
274! Mark routine for device compilation
275# 113 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
276
277! Declare device-resident data
278# 131 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
279
280! Inner loop within a GPU parallel region
281# 146 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
282
283! Scoped GPU data region
284# 165 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
285
286! Host code with device pointers (for MPI with GPU buffers)
287# 191 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
288
289! Allocate device memory (unscoped)
290# 205 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
291
292! Free device memory
293# 217 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
294
295! Atomic operation on device
296# 229 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
297
298! End atomic capture block
299# 240 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
300
301! Copy data between host and device
302# 252 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
303
304! Synchronization barrier
305# 264 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
306
307! Import GPU library module (openacc or omp_lib)
308# 273 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
309
310! Emit code only for AMD compiler
311# 280 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
312
313! Emit code for non-Cray compilers
314# 287 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
315
316! Emit code only for Cray compiler
317# 294 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
318
319! Cray compiler directive, emitted from Fypp so the formatter cannot turn it into a comment
320# 301 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
321
322! Emit code for non-NVIDIA compilers
323# 308 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
324
325# 310 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
326# 311 "/home/runner/work/MFC/MFC/src/common/include/parallel_macros.fpp"
327! New line at end of file is required for FYPP
328# 2 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp" 2
329
330# 14 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
331
332! Caution: This macro requires the use of a binding script to set CUDA_VISIBLE_DEVICES, such that we have one GPU device per MPI
333! rank. That's because for both cudaMemAdvise (preferred location) and cudaMemPrefetchAsync we use location = device_id = 0. For an
334! example see misc/nvidia_uvm/bind.sh.
335# 52 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
336
337! Allocate and create GPU device memory
338# 72 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
339
340! Free GPU device memory and deallocate
341# 80 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
342
343! Cray-specific GPU pointer setup for vector fields
344# 104 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
345
346! Cray-specific GPU pointer setup for scalar fields
347# 120 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
348
349! Cray-specific GPU pointer teardown for scalar fields - exact inverse of ACC_SETUP_SFs. Removes the
350! present-table entries ACC_SETUP_SFs added (the scalar_field descriptor and its %sf copyin). REQUIRED when
351! an ACC_SETUP'd field is freed MID-RUN (e.g. AMR slot free on regrid/restart): Cray 'exit data delete'
352! decrements the reference counter, so the lone @:DEALLOCATE(arg%sf) only undoes the @:ALLOCATE create ref
353! and leaves the descriptor + the ACC_SETUP %sf copyin dangling. Call BEFORE @:DEALLOCATE(arg%sf).
354# 140 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
355
356! Cray-specific GPU pointer setup for acoustic source spatials
357# 165 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
358
359! Whether stress index idx is a shear component. Spelled out because NVHPC 26.9 at -O2 vectorizes any(idx == shear_indices)
360! inside a loop to always true, which doubled the normal-stress elastic energy.
361# 171 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
362
363# 177 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
364
365# 184 "/home/runner/work/MFC/MFC/src/common/include/macros.fpp"
366! New line at end of file is required for FYPP
367# 6 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp" 2
368# 1 "/home/runner/work/MFC/MFC/src/common/include/case.fpp" 1
369! This file exists so that Fypp can be run without generating case.fpp files for
370! each target. This is useful when generating documentation, for example. This
371! should also let MFC be built with CMake directly, without invoking mfc.sh.
372
373! For pre-process.
374# 8 "/home/runner/work/MFC/MFC/src/common/include/case.fpp"
375
376! For moving immersed boundaries in simulation
377# 12 "/home/runner/work/MFC/MFC/src/common/include/case.fpp"
378# 7 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp" 2
379
380!> @brief Writes solution data, run-time stability diagnostics (ICFL, VCFL, CCFL, Rc), and probe/center-of-mass files
382
385 use m_mpi_proxy
388 use m_helper
390 use m_sim_helpers
392 use m_ibm
401
402 implicit none
403
404 private
410
411 !> @name ICFL, VCFL, CCFL, TCFL, and Rc stability criteria extrema over all the time-steps
412 !> @{
413 real(wp) :: icfl_max !< ICFL criterion maximum
414 real(wp) :: vcfl_max !< VCFL criterion maximum
415 real(wp) :: ccfl_max !< CCFL criterion maximum
416 real(wp) :: tcfl_max !< TCFL criterion maximum
417 real(wp) :: rc_min !< Rc criterion maximum
418 !> @}
419
420 type(scalar_field), allocatable, dimension(:) :: q_cons_temp_ds
421
422 !> Per-body history files, one fixed-width text record per body per recorded step (s_write_ib_record): reals per record, and the
423 !! units held open for the run (-1 until the first write)
424 integer, parameter :: ib_force_nf = 19, ib_heat_nf = 5
425 integer :: ib_hist_file = -1 !< D/ib_forces.dat
426 integer :: ib_heat_file = -1 !< D/ib_heat.dat
427 integer, parameter :: lag_evol_id = 11 !< Per-rank Lagrangian evolution files
428 integer, parameter :: lag_stats_id = 12 !< Per-rank bubble statistics files
429 integer, parameter :: lag_void_id = 13 !< D/voidfraction.dat
430 real(wp), parameter :: void_stat_min = 5.e-11_wp !< Volume fraction above which a cell counts in the void statistics
431 real(wp) :: next_write_time !< Time of the next particle evolution write
432
433contains
434
435 !> Write data files. Dispatch subroutine that replaces procedure pointer.
436 impure subroutine s_write_data_files(q_cons_vf, q_T_sf, q_prim_vf, t_step, bc_type, beta)
437
438 type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
439 type(scalar_field), intent(inout) :: q_t_sf
440 type(scalar_field), dimension(sys_size), intent(inout) :: q_prim_vf
441 integer, intent(in) :: t_step
442 type(integer_field), dimension(1:num_dims,1:2), intent(in) :: bc_type
443 type(scalar_field), intent(inout), optional :: beta
444
445 if (.not. parallel_io) then
446 call s_write_serial_data_files(q_cons_vf, q_t_sf, q_prim_vf, t_step, bc_type, beta)
447 else
448 call s_write_parallel_data_files(q_cons_vf, t_step, beta)
449 end if
450
451 end subroutine s_write_data_files
452
453 !> Open the run-time information file and write the stability criteria table header
455
456 character(LEN=name_len), parameter :: file_name = 'run_time.inf' !< Name of the run-time information file
457 character(LEN=path_len + name_len) :: file_path !< Relative path to a file in the case directory
458 character(LEN=8) :: file_date !< Creation date of the run-time information file
459
460 file_path = trim(case_dir) // '/' // trim(file_name)
461
462 open (3, file=trim(file_path), form='formatted', status='replace')
463
464 write (3, '(A)') 'Description: Stability information at ' // 'each time-step of the simulation. This'
465 write (3, '(13X,A)') 'data is composed of the inviscid ' // 'Courant-Friedrichs-Lewy (ICFL)'
466 write (3, '(13X,A)') 'number, the viscous CFL (VCFL) number, ' // 'the capillary CFL (CCFL)'
467 write (3, '(13X,A)') 'number, the thermal diffusion CFL (TCFL) ' // 'number, and the cell Reynolds (Rc)'
468 write (3, '(13X,A)') 'number. Please note that only'
469 write (3, '(13X,A)') 'those stability conditions pertinent ' // 'to the physics included in'
470 write (3, '(13X,A)') 'the current computation are displayed.'
471 if (hypoelasticity) then
472 write (3, '(13X,A)') 'NOTE: the reported ICFL uses the acoustic ' // 'sound speed only; it may'
473 write (3, '(13X,A)') 'underestimate the elastic characteristic ' // 'speeds.'
474 end if
475
476 call date_and_time(date=file_date)
477
478 write (3, '(A)') 'Date: ' // file_date(5:6) // '/' // file_date(7:8) // '/' // file_date(3:4)
479
480 write (3, '(A)') ''; write (3, '(A)') ''
481
482 write (3, '(13X,A9,13X,A10,13X,A10,13X,A10)', advance="no") trim('Time-step'), trim('dt'), trim('Time'), trim('ICFL Max')
483
484 if (surface_tension) then
485 write (3, '(13X,A10)', advance="no") trim('CCFL Max')
486 end if
487
488 if (heat_conduction) then
489 write (3, '(13X,A10)', advance="no") trim('TCFL Max')
490 end if
491
492 if (viscous) then
493 write (3, '(13X,A10,13X,A16)', advance="no") trim('VCFL Max'), trim('Rc Min')
494 end if
495
496 if (bubbles_lagrange) then
497 write (3, '(13X,A10)', advance="no") trim('N Bubbles')
498 end if
499
500 write (3, *) ! new line
501
503
504 !> Open flow probe data files for writing
505 impure subroutine s_open_probe_files
506
507 character(LEN=path_len + 3*name_len) :: file_path !< Relative path to the probe data file in the case directory
508 integer :: i !< Generic loop iterator
509 logical :: file_exist
510 logical :: fresh_start
511
512 ! A run continues from a checkpoint when t_step_start > 0, or under cfl_dt when n_start > 0 (t_step_start stays
513 ! at its default there); pick the criterion by mode -- OR-ing them made every cfl_dt run look fresh.
514
515 fresh_start = merge(n_start == 0, t_step_start == 0, cfl_dt)
516
517 do i = 1, num_probes
518 write (file_path, '(A,I0,A)') '/D/probe', i, '_prim.dat'
519 file_path = trim(case_dir) // trim(file_path)
520
521 inquire (file=trim(file_path), exist=file_exist)
522
523 ! Append only when continuing a run. A fresh start that appends splices the previous run's rows
524 ! onto this one's, and nothing in the file marks the join: the time column simply resets partway
525 ! down, and the two runs need not even share a grid. Readers see one monotonic series and are
526 ! silently wrong.
527 if (file_exist .and. .not. fresh_start) then
528 open (i + 30, file=trim(file_path), form='formatted', status='old', position='append')
529 else
530 open (i + 30, file=trim(file_path), form='formatted', status='replace')
531 end if
532 end do
533
534 end subroutine s_open_probe_files
535
536 !> Write stability criteria extrema to the run-time information file at the given time step
537 impure subroutine s_write_run_time_information(q_prim_vf, t_step)
538
539 type(scalar_field), dimension(sys_size), intent(in) :: q_prim_vf
540 integer, intent(in) :: t_step
541 real(wp) :: rho !< Cell-avg. density
542
543# 175 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
544 real(wp), dimension(num_fluids) :: alpha, alpha_rho !< Cell-avg. volume fraction, partial density
545 real(wp), dimension(num_vels) :: vel !< Cell-avg. velocity
546# 178 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
547 real(wp) :: vel_sum !< Cell-avg. velocity sum
548 real(wp) :: pres !< Cell-avg. pressure
549 real(wp) :: gamma !< Cell-avg. sp. heat ratio
550 real(wp) :: pi_inf !< Cell-avg. liquid stiffness function
551 real(wp) :: qv !< Cell-avg. internal energy reference value
552 real(wp) :: c !< Cell-avg. sound speed
553 real(wp), dimension(2) :: re !< Cell-avg. Reynolds numbers
554 integer :: j, k, l
555 real(wp) :: icfl_max_loc, icfl_max_glb !< ICFL stability extrema on local and global grids
556 real(wp) :: vcfl_max_loc, vcfl_max_glb !< VCFL stability extrema on local and global grids
557 real(wp) :: ccfl_max_loc, ccfl_max_glb !< CCFL stability extrema on local and global grids
558 real(wp) :: tcfl_max_loc, tcfl_max_glb !< TCFL stability extrema on local and global grids
559 real(wp) :: rc_min_loc, rc_min_glb !< Rc stability extrema on local and global grids
560 real(wp) :: icfl, vcfl, ccfl, tcfl, rc
561 real(wp) :: pw1, pw2, pw3 !< amr_cfl_pow (scalars for the kernel)
562 logical :: amr_on !< host copy of amr for the kernel
563 real(wp) :: mu_frac, mu_frac_max_loc, mu_frac_max_glb !< Compression as a fraction of the EOS limit
564 integer :: fl !< Fluid loop iterator
565 logical :: include_cell !< Cell is fluid, not ghost/inside an IB
566 real(wp), dimension(4) :: stab_max_loc, stab_max_glb !< Max-reduced criteria (ICFL, VCFL, CCFL, TCFL), packed
567 real(wp), dimension(1) :: stab_min_loc, stab_min_glb !< Min-reduced criteria (Rc), packed
568 !> Host copies; amdflang reads Re_size stale cross-TU
569 integer :: re_size_loc1, re_size_loc2
570
571 icfl_max_loc = 0._wp
572 vcfl_max_loc = 0._wp
573 ccfl_max_loc = 0._wp
574 tcfl_max_loc = 0._wp
575 rc_min_loc = huge(1.0_wp)
576 mu_frac_max_loc = 0._wp
577 re_size_loc1 = re_size(1); re_size_loc2 = re_size(2)
578 pw1 = amr_cfl_pow(1); pw2 = amr_cfl_pow(2); pw3 = amr_cfl_pow(3); amr_on = amr
579 ! Computing Stability Criteria at Current Time-step
580
581# 211 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
582
583# 211 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
584#if defined(MFC_OpenACC)
585# 211 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
586!$acc parallel loop collapse(3) gang vector default(present) &
587# 211 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
588!$acc& private(j, k, l, vel, alpha, alpha_rho, Re, rho, vel_sum, pres, gamma, pi_inf, c, qv, icfl, vcfl, Rc, ccfl, tcfl, fl, mu_frac, include_cell) &
589# 211 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
590!$acc& firstprivate(Re_size_loc1, Re_size_loc2, pw1, pw2, pw3, amr_on) reduction(max:icfl_max_loc, vcfl_max_loc, ccfl_max_loc, tcfl_max_loc, mu_frac_max_loc) reduction(min:Rc_min_loc)
591# 211 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
592#elif defined(MFC_OpenMP)
593# 211 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
594
595# 211 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
596
597# 211 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
598
599# 211 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
600!$omp target teams loop defaultmap(firstprivate:scalar) bind(teams,parallel) collapse(3) defaultmap(tofrom:aggregate) defaultmap(tofrom:allocatable) defaultmap(tofrom:pointer) &
601# 211 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
602!$omp& private(j, k, l, vel, alpha, alpha_rho, Re, rho, vel_sum, pres, gamma, pi_inf, c, qv, icfl, vcfl, Rc, ccfl, tcfl, fl, mu_frac, include_cell) &
603# 211 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
604!$omp& firstprivate(Re_size_loc1, Re_size_loc2, pw1, pw2, pw3, amr_on) reduction(max:icfl_max_loc, vcfl_max_loc, ccfl_max_loc, tcfl_max_loc, mu_frac_max_loc) reduction(min:Rc_min_loc)
605# 211 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
606#endif
607# 215 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
608 do l = 0, p
609 do k = 0, n
610 do j = 0, m
611 ! exclude cells inside of immersed boundaries
612 include_cell = .true.
613 if (ib) include_cell = (ib_markers%sf(j, k, l) == 0)
614 if (include_cell) then
615 call s_compute_cell_state(q_prim_vf, pres, rho, gamma, pi_inf, re, alpha, alpha_rho, vel, vel_sum, qv, j, &
616 & k, l, re_size_loc1, re_size_loc2)
617
618 call s_compute_speed_of_sound(pres, rho, gamma, pi_inf, alpha, c, alpha_rho)
619
620 ! How close each Mie-Gruneisen phase is to the compression its Hugoniot fit can represent.
621 ! Past 1 there is no shock state to find and the reference curve is fiction, so it is reduced
622 ! out of the kernel and turned into an abort on the host -- s_mpi_abort cannot be called here.
623 if (nvhpc_omp_state_dependent_eos) then
624
625# 231 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
626#if defined(MFC_OpenACC)
627# 231 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
628!$acc loop seq
629# 231 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
630#elif defined(MFC_OpenMP)
631# 231 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
632
633# 231 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
634#endif
635# 232 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
636 do fl = 1, num_fluids
637 if (eoss(fl) == eos_mie_gruneisen) then
638 mu_frac = (alpha_rho(fl)/max(alpha(fl), &
639 & sgm_eps)/eos_coeffs(fl)%rho0 - 1._wp)/eos_coeffs(fl)%mu_max
640 mu_frac_max_loc = max(mu_frac_max_loc, mu_frac)
641 end if
642 end do
643 end if
644
645 if (any_non_newtonian) then
646 re(1) = 0._wp
647 do fl = 1, num_fluids
648 if (is_non_newtonian(fl)) then
649 re(1) = re(1) + alpha(fl)*hb_mu_max(fl)
650 else
651 re(1) = re(1) + alpha(fl)*fluid_inv_re(fl)
652 end if
653 end do
654 re(1) = 1._wp/max(re(1), sgm_eps)
655 end if
656
657 call s_compute_stability_from_dt(vel, c, rho, re, alpha, alpha_rho, j, k, l, icfl, vcfl, rc, ccfl, tcfl)
658 if (amr_on) call s_amr_scale_stability(amr_cfl_rf(j, k, l), pw1, pw2, pw3, icfl, vcfl, rc, ccfl, tcfl)
659
660 icfl_max_loc = max(icfl_max_loc, icfl)
661 vcfl_max_loc = max(vcfl_max_loc, merge(vcfl, 0.0_wp, viscous))
662 ccfl_max_loc = max(ccfl_max_loc, merge(ccfl, 0.0_wp, surface_tension))
663 tcfl_max_loc = max(tcfl_max_loc, merge(tcfl, 0.0_wp, heat_conduction))
664 rc_min_loc = min(rc_min_loc, merge(rc, huge(1.0_wp), viscous))
665 end if
666 end do
667 end do
668 end do
669
670# 265 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
671#if defined(MFC_OpenACC)
672# 265 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
673!$acc end parallel loop
674# 265 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
675#elif defined(MFC_OpenMP)
676# 265 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
677
678# 265 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
679!$omp end target teams loop
680# 265 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
681#endif
682# 266 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
683 ! end: Computing Stability Criteria at Current Time-step
684
685 if (num_procs > 1) then
686 stab_max_loc = (/icfl_max_loc, vcfl_max_loc, ccfl_max_loc, tcfl_max_loc/)
687 stab_min_loc = (/rc_min_loc/)
688 call s_mpi_reduce_stability_criteria_extrema(stab_max_loc, stab_min_loc, n_el_bubs_loc, stab_max_glb, stab_min_glb, &
690 icfl_max_glb = stab_max_glb(1)
691 vcfl_max_glb = stab_max_glb(2)
692 ccfl_max_glb = stab_max_glb(3)
693 tcfl_max_glb = stab_max_glb(4)
694 rc_min_glb = stab_min_glb(1)
695 else
696 icfl_max_glb = icfl_max_loc
697 if (viscous) vcfl_max_glb = vcfl_max_loc
698 if (viscous) rc_min_glb = rc_min_loc
699 if (surface_tension) ccfl_max_glb = ccfl_max_loc
700 if (heat_conduction) tcfl_max_glb = tcfl_max_loc
701 if (bubbles_lagrange) n_el_bubs_glb = n_el_bubs_loc
702 end if
703
704 mu_frac_max_glb = mu_frac_max_loc
705 if (num_procs > 1) call s_mpi_allreduce_max(mu_frac_max_loc, mu_frac_max_glb)
706
707 if (icfl_max_glb > icfl_max) icfl_max = icfl_max_glb
708
709 if (surface_tension) then
710 if (ccfl_max_glb > ccfl_max) ccfl_max = ccfl_max_glb
711 end if
712
713 if (heat_conduction) then
714 if (tcfl_max_glb > tcfl_max) tcfl_max = tcfl_max_glb
715 end if
716
717 if (viscous) then
718 if (vcfl_max_glb > vcfl_max) vcfl_max = vcfl_max_glb
719 if (rc_min_glb < rc_min) rc_min = rc_min_glb
720 end if
721
722 ! Any rank whose own local extremum violates the limit is, by construction of the
723 ! max-reduction above, a rank that actually contains the offending cell(s).
724 if ((.not. f_approx_equal(icfl_max_loc, icfl_max_loc)) .or. icfl_max_loc > 1._wp) then
725 call s_report_icfl_violation(q_prim_vf)
726 end if
727 call s_mpi_barrier() ! ensure diagnostic output above is flushed before any rank aborts below
728
729 if (proc_rank == 0) then
730 write (3, '(13X,I9,13X,ES10.3,13X,ES10.3,13X,F10.6)', advance="no") t_step, dt, mytime, icfl_max_glb
731
732 if (surface_tension) then
733 write (3, '(13X,F10.6)', advance="no") ccfl_max_glb
734 end if
735
736 if (heat_conduction) then
737 write (3, '(13X,F10.6)', advance="no") tcfl_max_glb
738 end if
739
740 if (viscous) then
741 write (3, '(13X,F10.6,13X,ES16.6)', advance="no") vcfl_max_glb, rc_min_glb
742 end if
743
744 if (bubbles_lagrange) then
745 write (3, '(13X,I10)', advance="no") n_el_bubs_glb
746 end if
747
748 write (3, *) ! new line
749
750 if (mu_frac_max_glb > 1._wp) then
751 print *, 'compression as a fraction of the Hugoniot fit limit', mu_frac_max_glb
752 call s_mpi_abort('A Mie-Gruneisen phase is compressed past what its Hugoniot fit represents. Exiting.')
753 end if
754
755 if (.not. f_approx_equal(icfl_max_glb, icfl_max_glb)) then
756 call s_mpi_abort('ICFL is NaN. Exiting.')
757 else if (icfl_max_glb > 1._wp) then
758 print *, 'icfl', icfl_max_glb
759 call s_mpi_abort('ICFL is greater than 1.0. Exiting.')
760 end if
761
762 if (viscous) then
763 if (.not. f_approx_equal(vcfl_max_glb, vcfl_max_glb)) then
764 call s_mpi_abort('VCFL is NaN. Exiting.')
765 else if (vcfl_max_glb > 1._wp) then
766 print *, 'vcfl', vcfl_max_glb
767 call s_mpi_abort('VCFL is greater than 1.0. Exiting.')
768 end if
769 end if
770
771 if (bubbles_lagrange) then
772 if (n_el_bubs_glb == 0) then
773 call s_mpi_abort('No Lagrangian bubbles remain in the domain. Exiting.')
774 end if
775 end if
776 end if
777
778 call s_mpi_barrier()
779
780 end subroutine s_write_run_time_information
781
782 !> Locate the grid cell responsible for an ICFL violation on this rank and report its state plus the nearest immersed-boundary
783 !! particles, to aid debugging stability failures in particle-laden high-Mach cases.
784 impure subroutine s_report_icfl_violation(q_prim_vf)
785
786 type(scalar_field), dimension(sys_size), intent(in) :: q_prim_vf
787 real(wp), dimension(num_fluids) :: alpha, alpha_rho
788 real(wp), dimension(num_vels) :: vel, vel_hit
789 real(wp), dimension(2) :: re
790 real(wp) :: rho, vel_sum, pres, gamma, pi_inf, qv, c
791 real(wp) :: rho_hit, pres_hit, c_hit
792 real(wp) :: icfl, vcfl, rc, ccfl, tcfl, icfl_hit
793 integer :: i, j, k, l, fl, j_hit, k_hit, l_hit
794 real(wp) :: x_hit, y_hit, z_hit, dist
795 logical :: nan_hit
796 integer :: near1_id, near2_id
797 real(wp) :: near1_dist, near2_dist
798
799 do i = 1, sys_size
800
801# 383 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
802#if defined(MFC_OpenACC)
803# 383 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
804!$acc update host(q_prim_vf(i)%sf(:, :, :))
805# 383 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
806#elif defined(MFC_OpenMP)
807# 383 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
808!$omp target update from(q_prim_vf(i)%sf(:, :, :))
809# 383 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
810#endif
811# 384 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
812 end do
813 if (ib) then
814
815# 386 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
816#if defined(MFC_OpenACC)
817# 386 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
818!$acc update host(ib_markers%sf)
819# 386 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
820#elif defined(MFC_OpenMP)
821# 386 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
822!$omp target update from(ib_markers%sf)
823# 386 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
824#endif
825# 387 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
826 end if
827
828 icfl_hit = -huge(1._wp)
829 nan_hit = .false.
830 j_hit = 0; k_hit = 0; l_hit = 0
831
832 scan: do l = 0, p
833 do k = 0, n
834 do j = 0, m
835 if (ib) then
836 if (ib_markers%sf(j, k, l) /= 0) cycle
837 end if
838
839 call s_compute_cell_state(q_prim_vf, pres, rho, gamma, pi_inf, re, alpha, alpha_rho, vel, vel_sum, qv, j, k, &
840 & l, re_size(1), re_size(2))
841 call s_compute_speed_of_sound(pres, rho, gamma, pi_inf, alpha, c, alpha_rho)
842
843 if (any_non_newtonian) then
844 re(1) = 0._wp
845 do fl = 1, num_fluids
846 if (is_non_newtonian(fl)) then
847 re(1) = re(1) + alpha(fl)*hb_mu_max(fl)
848 else
849 re(1) = re(1) + alpha(fl)*fluid_inv_re(fl)
850 end if
851 end do
852 re(1) = 1._wp/max(re(1), sgm_eps)
853 end if
854
855 call s_compute_stability_from_dt(vel, c, rho, re, alpha, alpha_rho, j, k, l, icfl, vcfl, rc, ccfl, tcfl)
857 & icfl, vcfl, rc, ccfl, tcfl)
858
859 if (.not. f_approx_equal(icfl, icfl)) then
860 nan_hit = .true.
861 j_hit = j; k_hit = k; l_hit = l
862 rho_hit = rho; pres_hit = pres; c_hit = c; vel_hit = vel
863 exit scan
864 else if (icfl > icfl_hit) then
865 icfl_hit = icfl
866 j_hit = j; k_hit = k; l_hit = l
867 rho_hit = rho; pres_hit = pres; c_hit = c; vel_hit = vel
868 end if
869 end do
870 end do
871 end do scan
872
873 x_hit = x_cc(j_hit)
874 y_hit = 0._wp; if (n > 0) y_hit = y_cc(k_hit)
875 z_hit = 0._wp; if (p > 0) z_hit = z_cc(l_hit)
876
877 print '(A,I0,A,I0,A,I0,A,I0,A)', 'ICFL violation on rank ', proc_rank, ': cell (j,k,l) = (', j_hit, ',', k_hit, ',', &
878 & l_hit, ')'
879 if (nan_hit) then
880 print '(A)', ' icfl = NaN'
881 else
882 print '(A,ES16.6)', ' icfl = ', icfl_hit
883 end if
884 print '(A,3(ES16.6,1X))', ' position = ', x_hit, y_hit, z_hit
885 print '(A,ES16.6,A,ES16.6,A,ES16.6)', ' rho, pres, c = ', rho_hit, ', ', pres_hit, ', ', c_hit
886 print '(A,3(ES16.6,1X))', ' velocity = ', vel_hit
887 if (ib) print '(A,I0)', ' ib_markers = ', ib_markers%sf(j_hit, k_hit, l_hit)
888
889 if (ib .and. num_ibs > 0) then
890 near1_id = 0; near1_dist = huge(1._wp)
891 near2_id = 0; near2_dist = huge(1._wp)
892 do i = 1, num_ibs
893 dist = sqrt((x_hit - patch_ib(i)%x_centroid)**2 + (y_hit - patch_ib(i)%y_centroid)**2 + (z_hit &
894 & - patch_ib(i)%z_centroid)**2)
895 if (dist < near1_dist) then
896 near2_dist = near1_dist; near2_id = near1_id
897 near1_dist = dist; near1_id = i
898 else if (dist < near2_dist) then
899 near2_dist = dist; near2_id = i
900 end if
901 end do
902 if (near1_id > 0) then
903 print '(A,I0,A,ES16.6,A,ES16.6,A,3(ES16.6,1X))', ' nearest particle id=', near1_id, ' dist=', near1_dist, &
904 & ' gap=', near1_dist - patch_ib(near1_id)%radius, ' vel=', patch_ib(near1_id)%vel
905 print '(A,3(ES16.6,1X))', ' centroid = ', patch_ib(near1_id)%x_centroid, patch_ib(near1_id)%y_centroid, &
906 & patch_ib(near1_id)%z_centroid
907 print '(A,3(ES16.6,1X))', ' angular_vel = ', patch_ib(near1_id)%angular_vel
908 print '(A,3(ES16.6,1X))', ' force = ', patch_ib(near1_id)%force
909 print '(A,3(ES16.6,1X))', ' torque = ', patch_ib(near1_id)%torque
910 print '(A,I0,A,ES16.6,A,ES16.6)', ' moving_ibm = ', patch_ib(near1_id)%moving_ibm, ' mass=', &
911 & patch_ib(near1_id)%mass, ' moment=', patch_ib(near1_id)%moment
912 end if
913 if (near2_id > 0) then
914 print '(A,I0,A,ES16.6,A,ES16.6,A,3(ES16.6,1X))', ' 2nd nearest particle id=', near2_id, ' dist=', near2_dist, &
915 & ' gap=', near2_dist - patch_ib(near2_id)%radius, ' vel=', patch_ib(near2_id)%vel
916 print '(A,3(ES16.6,1X))', ' centroid = ', patch_ib(near2_id)%x_centroid, patch_ib(near2_id)%y_centroid, &
917 & patch_ib(near2_id)%z_centroid
918 print '(A,3(ES16.6,1X))', ' angular_vel = ', patch_ib(near2_id)%angular_vel
919 print '(A,3(ES16.6,1X))', ' force = ', patch_ib(near2_id)%force
920 end if
921 end if
922
923 ! Dump a small x-neighborhood around the violating cell (reaching into the ghost/halo region on either side) to
924 ! distinguish a sharp discontinuity at a processor boundary - the signature of stale or corrupted halo/IB state -
925 ! from a smoothly diverging field, which indicates a genuine physical/numerical instability.
926 print '(A)', ' x-neighborhood (dj, rho, pres, vel) around violating cell:'
927 do j = max(-buff_size, j_hit - 3), min(m + buff_size, j_hit + 3)
928 call s_compute_cell_state(q_prim_vf, pres, rho, gamma, pi_inf, re, alpha, alpha_rho, vel, vel_sum, qv, j, k_hit, &
929 & l_hit, re_size(1), re_size(2))
930 print '(A,I0,A,ES16.6,A,ES16.6,A,3(ES16.6,1X))', ' dj=', j - j_hit, ' rho=', rho, ' pres=', pres, ' vel=', vel
931 end do
932
933 call flush (6)
934
935 end subroutine s_report_icfl_violation
936
937 !> Write grid and conservative variable data files in serial format
938 impure subroutine s_write_serial_data_files(q_cons_vf, q_T_sf, q_prim_vf, t_step, bc_type, beta)
939
940 type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
941 type(scalar_field), intent(inout) :: q_t_sf
942 type(scalar_field), dimension(sys_size), intent(inout) :: q_prim_vf
943 integer, intent(in) :: t_step
944 type(scalar_field), intent(inout), optional :: beta
945 type(integer_field), dimension(1:num_dims,1:2), intent(in) :: bc_type
946 character(LEN=path_len + 2*name_len) :: t_step_dir !< Relative path to the current time-step directory
947 character(LEN=path_len + 3*name_len) :: file_path !< Relative path to the grid and conservative variables data files
948 logical :: file_exist !< Logical used to check existence of current time-step directory
949 character(LEN=15) :: fmt
950 integer :: i, j, k, l, r
951
952 write (t_step_dir, '(A,I0,A,I0)') trim(case_dir) // '/p_all'
953 write (t_step_dir, '(a,i0,a,i0)') trim(case_dir) // '/p_all/p', proc_rank, '/', t_step
954
955 file_path = trim(t_step_dir) // '/.'
956 call my_inquire(file_path, file_exist)
957 if (file_exist) call s_delete_directory(trim(t_step_dir))
958 call s_create_directory(trim(t_step_dir))
959 ! Serial readers (post_process, restart) need bc_type.dat and bc_buffers.dat in every step directory, not just step 0.
960 if (bc_io) call s_write_serial_boundary_condition_files(bc_type, t_step_dir, .false.)
961
962 file_path = trim(t_step_dir) // '/x_cb.dat'
963
964 open (2, file=trim(file_path), form='unformatted', status='new')
965 write (2) x_cb(-1:m); close (2)
966
967 if (n > 0) then
968 file_path = trim(t_step_dir) // '/y_cb.dat'
969
970 open (2, file=trim(file_path), form='unformatted', status='new')
971 write (2) y_cb(-1:n); close (2)
972
973 if (p > 0) then
974 file_path = trim(t_step_dir) // '/z_cb.dat'
975
976 open (2, file=trim(file_path), form='unformatted', status='new')
977 write (2) z_cb(-1:p); close (2)
978 end if
979 end if
980
981 do i = 1, sys_size
982 write (file_path, '(A,I0,A)') trim(t_step_dir) // '/q_cons_vf', i, '.dat'
983
984 open (2, file=trim(file_path), form='unformatted', status='new')
985
986 write (2) q_cons_vf(i)%sf(0:m,0:n,0:p); close (2)
987 end do
988
989 ! Lagrangian beta (void fraction) written as q_cons_vf(sys_size+1) to match the parallel I/O path and allow post_process to
990 ! read it.
991 if (euler_lagrange) then
992 write (file_path, '(A,I0,A)') trim(t_step_dir) // '/q_cons_vf', sys_size + 1, '.dat'
993
994 open (2, file=trim(file_path), form='unformatted', status='new')
995
996 write (2) beta%sf(0:m,0:n,0:p); close (2)
997 end if
998
999 if (qbmm .and. .not. polytropic) then
1000 do i = 1, nb
1001 do r = 1, nnode
1002 write (file_path, '(A,I0,A)') trim(t_step_dir) // '/pb', sys_size + (i - 1)*nnode + r, '.dat'
1003
1004 open (2, file=trim(file_path), form='unformatted', status='new')
1005
1006 write (2) pb_ts(1)%sf(0:m,0:n,0:p,r, i); close (2)
1007 end do
1008 end do
1009
1010 do i = 1, nb
1011 do r = 1, nnode
1012 write (file_path, '(A,I0,A)') trim(t_step_dir) // '/mv', sys_size + (i - 1)*nnode + r, '.dat'
1013
1014 open (2, file=trim(file_path), form='unformatted', status='new')
1015
1016 write (2) mv_ts(1)%sf(0:m,0:n,0:p,r, i); close (2)
1017 end do
1018 end do
1019 end if
1020
1021 ! Writing the IB markers
1022 if (ib) then
1023 call s_write_serial_ib_data(t_step)
1024 end if
1025
1026 if (precision == precision_single) then
1027 fmt = "(2F30.3)"
1028 else
1029 fmt = "(2F40.14)"
1030 end if
1031
1032 write (t_step_dir, '(A,I0,A,I0)') trim(case_dir) // '/D'
1033 file_path = trim(t_step_dir) // '/.'
1034
1035 inquire (file=trim(file_path), exist=file_exist)
1036
1037 if (.not. file_exist) call s_create_directory(trim(t_step_dir))
1038
1039 if ((prim_vars_wrt .or. (n == 0 .and. p == 0)) .and. (.not. igr)) then
1041 do i = 1, sys_size
1042
1043# 603 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1044#if defined(MFC_OpenACC)
1045# 603 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1046!$acc update host(q_prim_vf(i)%sf(:, :, :))
1047# 603 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1048#elif defined(MFC_OpenMP)
1049# 603 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1050!$omp target update from(q_prim_vf(i)%sf(:, :, :))
1051# 603 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1052#endif
1053# 604 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1054 end do
1055 ! q_prim_vf(eqn_idx%bub%beg) stores the value of nb needed in riemann solvers, so replace with true primitive value
1056 ! (=1._wp)
1057 if (qbmm) then
1058 q_prim_vf(eqn_idx%bub%beg)%sf = 1._wp
1059 end if
1060 end if
1061
1062 if (n == 0 .and. p == 0) then
1063 if (model_eqns == model_eqns_5eq .and. (.not. igr)) then
1064 do i = 1, sys_size
1065 write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/prim.', i, '.', proc_rank, '.', t_step, '.dat'
1066
1067 open (2, file=trim(file_path))
1068 do j = 0, m
1069 ! todo: revisit change here
1070 if (((i >= eqn_idx%adv%beg) .and. (i <= eqn_idx%adv%end))) then
1071 write (2, fmt) x_cb(j), q_cons_vf(i)%sf(j, 0, 0)
1072 else
1073 write (2, fmt) x_cb(j), q_prim_vf(i)%sf(j, 0, 0)
1074 end if
1075 end do
1076 close (2)
1077 end do
1078 end if
1079
1080 do i = 1, sys_size
1081 write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/cons.', i, '.', proc_rank, '.', t_step, '.dat'
1082
1083 open (2, file=trim(file_path))
1084 do j = 0, m
1085 write (2, fmt) x_cb(j), q_cons_vf(i)%sf(j, 0, 0)
1086 end do
1087 close (2)
1088 end do
1089
1090 if (qbmm .and. .not. polytropic) then
1091 do i = 1, nb
1092 do r = 1, nnode
1093 write (file_path, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/pres.', i, '.', r, '.', proc_rank, &
1094 & '.', t_step, '.dat'
1095
1096 open (2, file=trim(file_path))
1097 do j = 0, m
1098 write (2, fmt) x_cb(j), pb_ts(1)%sf(j, 0, 0, r, i)
1099 end do
1100 close (2)
1101 end do
1102 end do
1103 do i = 1, nb
1104 do r = 1, nnode
1105 write (file_path, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/mv.', i, '.', r, '.', proc_rank, &
1106 & '.', t_step, '.dat'
1107
1108 open (2, file=trim(file_path))
1109 do j = 0, m
1110 write (2, fmt) x_cb(j), mv_ts(1)%sf(j, 0, 0, r, i)
1111 end do
1112 close (2)
1113 end do
1114 end do
1115 end if
1116 end if
1117
1118 if (precision == precision_single) then
1119 fmt = "(3F30.7)"
1120 else
1121 fmt = "(3F40.14)"
1122 end if
1123
1124 if ((n > 0) .and. (p == 0)) then
1125 do i = 1, sys_size
1126 write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/cons.', i, '.', proc_rank, '.', t_step, '.dat'
1127 open (2, file=trim(file_path))
1128 do j = 0, m
1129 do k = 0, n
1130 write (2, fmt) x_cb(j), y_cb(k), q_cons_vf(i)%sf(j, k, 0)
1131 end do
1132 write (2, *)
1133 end do
1134 close (2)
1135 end do
1136
1137 if (present(beta)) then
1138 write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/beta.', i, '.', proc_rank, '.', t_step, '.dat'
1139 open (2, file=trim(file_path))
1140 do j = 0, m
1141 do k = 0, n
1142 write (2, fmt) x_cb(j), y_cb(k), beta%sf(j, k, 0)
1143 end do
1144 write (2, *)
1145 end do
1146 close (2)
1147 end if
1148
1149 if (qbmm .and. .not. polytropic) then
1150 do i = 1, nb
1151 do r = 1, nnode
1152 write (file_path, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/pres.', i, '.', r, '.', proc_rank, &
1153 & '.', t_step, '.dat'
1154
1155 open (2, file=trim(file_path))
1156 do j = 0, m
1157 do k = 0, n
1158 write (2, fmt) x_cb(j), y_cb(k), pb_ts(1)%sf(j, k, 0, r, i)
1159 end do
1160 end do
1161 close (2)
1162 end do
1163 end do
1164 do i = 1, nb
1165 do r = 1, nnode
1166 write (file_path, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/mv.', i, '.', r, '.', proc_rank, &
1167 & '.', t_step, '.dat'
1168
1169 open (2, file=trim(file_path))
1170 do j = 0, m
1171 do k = 0, n
1172 write (2, fmt) x_cb(j), y_cb(k), mv_ts(1)%sf(j, k, 0, r, i)
1173 end do
1174 end do
1175 close (2)
1176 end do
1177 end do
1178 end if
1179
1180 if (prim_vars_wrt .and. (.not. igr)) then
1181 do i = 1, sys_size
1182 write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/prim.', i, '.', proc_rank, '.', t_step, '.dat'
1183
1184 open (2, file=trim(file_path))
1185
1186 do j = 0, m
1187 do k = 0, n
1188 if (((i >= eqn_idx%cont%beg) .and. (i <= eqn_idx%cont%end)) .or. ((i >= eqn_idx%adv%beg) &
1189 & .and. (i <= eqn_idx%adv%end))) then
1190 write (2, fmt) x_cb(j), y_cb(k), q_cons_vf(i)%sf(j, k, 0)
1191 else
1192 write (2, fmt) x_cb(j), y_cb(k), q_prim_vf(i)%sf(j, k, 0)
1193 end if
1194 end do
1195 write (2, *)
1196 end do
1197 close (2)
1198 end do
1199 end if
1200 end if
1201
1202 if (precision == precision_single) then
1203 fmt = "(4F30.7)"
1204 else
1205 fmt = "(4F40.14)"
1206 end if
1207
1208 if (p > 0) then
1209 do i = 1, sys_size
1210 write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/cons.', i, '.', proc_rank, '.', t_step, '.dat'
1211 open (2, file=trim(file_path))
1212 do j = 0, m
1213 do k = 0, n
1214 do l = 0, p
1215 write (2, fmt) x_cb(j), y_cb(k), z_cb(l), q_cons_vf(i)%sf(j, k, l)
1216 end do
1217 write (2, *)
1218 end do
1219 write (2, *)
1220 end do
1221 close (2)
1222 end do
1223
1224 if (present(beta)) then
1225 write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/beta.', i, '.', proc_rank, '.', t_step, '.dat'
1226 open (2, file=trim(file_path))
1227 do j = 0, m
1228 do k = 0, n
1229 do l = 0, p
1230 write (2, fmt) x_cb(j), y_cb(k), z_cb(l), beta%sf(j, k, l)
1231 end do
1232 write (2, *)
1233 end do
1234 write (2, *)
1235 end do
1236 close (2)
1237 end if
1238
1239 if (qbmm .and. .not. polytropic) then
1240 do i = 1, nb
1241 do r = 1, nnode
1242 write (file_path, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/pres.', i, '.', r, '.', proc_rank, &
1243 & '.', t_step, '.dat'
1244
1245 open (2, file=trim(file_path))
1246 do j = 0, m
1247 do k = 0, n
1248 do l = 0, p
1249 write (2, fmt) x_cb(j), y_cb(k), z_cb(l), pb_ts(1)%sf(j, k, l, r, i)
1250 end do
1251 end do
1252 end do
1253 close (2)
1254 end do
1255 end do
1256 do i = 1, nb
1257 do r = 1, nnode
1258 write (file_path, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/mv.', i, '.', r, '.', proc_rank, &
1259 & '.', t_step, '.dat'
1260
1261 open (2, file=trim(file_path))
1262 do j = 0, m
1263 do k = 0, n
1264 do l = 0, p
1265 write (2, fmt) x_cb(j), y_cb(k), z_cb(l), mv_ts(1)%sf(j, k, l, r, i)
1266 end do
1267 end do
1268 end do
1269 close (2)
1270 end do
1271 end do
1272 end if
1273
1274 if (prim_vars_wrt .and. (.not. igr)) then
1275 do i = 1, sys_size
1276 write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/prim.', i, '.', proc_rank, '.', t_step, '.dat'
1277
1278 open (2, file=trim(file_path))
1279
1280 do j = 0, m
1281 do k = 0, n
1282 do l = 0, p
1283 if (((i >= eqn_idx%cont%beg) .and. (i <= eqn_idx%cont%end)) .or. ((i >= eqn_idx%adv%beg) &
1284 & .and. (i <= eqn_idx%adv%end)) .or. ((i >= eqn_idx%species%beg) &
1285 & .and. (i <= eqn_idx%species%end))) then
1286 write (2, fmt) x_cb(j), y_cb(k), z_cb(l), q_cons_vf(i)%sf(j, k, l)
1287 else
1288 write (2, fmt) x_cb(j), y_cb(k), z_cb(l), q_prim_vf(i)%sf(j, k, l)
1289 end if
1290 end do
1291 write (2, *)
1292 end do
1293 write (2, *)
1294 end do
1295 close (2)
1296 end do
1297 end if
1298 end if
1299
1300 end subroutine s_write_serial_data_files
1301
1302 !> Write grid and conservative variable data files in parallel via MPI I/O
1303 impure subroutine s_write_parallel_data_files(q_cons_vf, t_step, beta, q_T_sf)
1304
1305 type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
1306 integer, intent(in) :: t_step
1307 type(scalar_field), intent(inout), optional :: beta
1308 type(scalar_field), intent(inout), optional :: q_t_sf
1309
1310#ifdef MFC_MPI
1311 integer :: ifile, ierr, data_size
1312 integer, dimension(MPI_STATUS_SIZE) :: status
1313 integer(kind=MPI_OFFSET_kind) :: disp
1314 integer(kind=MPI_OFFSET_kind) :: m_mok, n_mok, p_mok
1315 integer(kind=MPI_OFFSET_kind) :: wp_mok, var_mok, str_mok
1316 integer(kind=MPI_OFFSET_kind) :: nvars_mok
1317 integer(kind=MPI_OFFSET_kind) :: mok
1318 character(LEN=path_len + 2*name_len) :: file_loc
1319 logical :: file_exist, dir_check
1320 character(len=10) :: t_step_string
1321 integer :: i !< Generic loop iterator
1322 integer :: alt_sys !< Altered system size for the lagrangian subgrid bubble model
1323 ! Down sampling variables
1324 integer :: m_ds, n_ds, p_ds
1325 integer :: m_glb_ds, n_glb_ds, p_glb_ds
1326 integer :: m_glb_save, n_glb_save, p_glb_save !< Global save size
1327
1328 if (down_sample) then
1329 call s_downsample_data(q_cons_vf, q_cons_temp_ds, m_ds, n_ds, p_ds, m_glb_ds, n_glb_ds, p_glb_ds)
1330 end if
1331
1332 if (present(beta)) then
1333 alt_sys = sys_size + 1
1334 else
1335 alt_sys = sys_size
1336 end if
1337
1338 if (file_per_process) then
1339 call s_int_to_str(t_step, t_step_string)
1340
1341 if (down_sample) then
1342 call s_initialize_mpi_data_ds(m_ds, n_ds, p_ds)
1343 else
1344 if (ib) then
1345 call s_initialize_mpi_data(q_cons_vf, ib_markers=ib_markers, ib_mpi_data=mpi_io_ib_data, qbmm_pb=pb_ts(1), &
1346 & qbmm_mv=mv_ts(1))
1347 else
1348 call s_initialize_mpi_data(q_cons_vf, qbmm_pb=pb_ts(1), qbmm_mv=mv_ts(1))
1349 end if
1350 end if
1351
1352 if (proc_rank == 0) then
1353 file_loc = trim(case_dir) // '/restart_data/lustre_' // trim(t_step_string)
1354 call my_inquire(file_loc, dir_check)
1355 if (dir_check .neqv. .true.) then
1356 call s_create_directory(trim(file_loc))
1357 end if
1358 end if
1359 call s_mpi_barrier()
1361
1362 write (file_loc, '(I0,A,i7.7,A)') t_step, '_', proc_rank, '.dat'
1363 file_loc = trim(case_dir) // '/restart_data/lustre_' // trim(t_step_string) // trim(mpiiofs) // trim(file_loc)
1364 inquire (file=trim(file_loc), exist=file_exist)
1365 if (file_exist .and. proc_rank == 0) then
1366 call mpi_file_delete(file_loc, mpi_info_int, ierr)
1367 end if
1368 call mpi_file_open(mpi_comm_self, file_loc, ior(mpi_mode_wronly, mpi_mode_create), mpi_info_int, ifile, ierr)
1369 call s_check_mpi_file_open(ierr, file_loc)
1370
1371 if (down_sample) then
1372 data_size = (m_ds + 3)*(n_ds + 3)*(p_ds + 3)
1373 m_glb_save = m_glb_ds + 1
1374 n_glb_save = n_glb_ds + 1
1375 p_glb_save = p_glb_ds + 1
1376 else
1377 data_size = (m + 1)*(n + 1)*(p + 1)
1378 m_glb_save = m_glb + 1
1379 n_glb_save = n_glb + 1
1380 p_glb_save = p_glb + 1
1381 end if
1382
1383 m_mok = int(m_glb_save + 1, mpi_offset_kind)
1384 n_mok = int(n_glb_save + 1, mpi_offset_kind)
1385 p_mok = int(p_glb_save + 1, mpi_offset_kind)
1386 wp_mok = int(storage_size(0._stp)/8, mpi_offset_kind)
1387 mok = int(1._wp, mpi_offset_kind)
1388 str_mok = int(name_len, mpi_offset_kind)
1389 nvars_mok = int(sys_size, mpi_offset_kind)
1390
1391 if (bubbles_euler) then
1392 do i = 1, sys_size
1393 var_mok = int(i, mpi_offset_kind)
1394
1395 call mpi_file_write_all(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
1396 end do
1397 if (qbmm .and. .not. polytropic) then
1398 do i = sys_size + 1, sys_size + 2*nb*nnode
1399 var_mok = int(i, mpi_offset_kind)
1400
1401 call mpi_file_write_all(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
1402 end do
1403 end if
1404 else
1405 if (down_sample) then
1406 do i = 1, sys_size ! TODO: check if sys_size is correct
1407 var_mok = int(i, mpi_offset_kind)
1408
1409 call mpi_file_write_all(ifile, q_cons_temp_ds(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
1410 end do
1411 else
1412 do i = 1, sys_size ! TODO: check if sys_size is correct
1413 var_mok = int(i, mpi_offset_kind)
1414
1415 call mpi_file_write_all(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
1416 end do
1417 end if
1418 end if
1419
1420 call mpi_file_close(ifile, ierr)
1421
1422 if (ib) then
1423 call s_write_parallel_ib_data(t_step)
1424 end if
1425 else
1426 if (ib) then
1427 call s_initialize_mpi_data(q_cons_vf, ib_markers=ib_markers, ib_mpi_data=mpi_io_ib_data, qbmm_pb=pb_ts(1), &
1428 & qbmm_mv=mv_ts(1))
1429 else if (present(beta)) then
1430 call s_initialize_mpi_data(q_cons_vf, beta=beta, qbmm_pb=pb_ts(1), qbmm_mv=mv_ts(1))
1431 else
1432 call s_initialize_mpi_data(q_cons_vf, qbmm_pb=pb_ts(1), qbmm_mv=mv_ts(1))
1433 end if
1434
1435 write (file_loc, '(I0,A)') t_step, '.dat'
1436 file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // trim(file_loc)
1437 inquire (file=trim(file_loc), exist=file_exist)
1438 if (file_exist .and. proc_rank == 0) then
1439 call mpi_file_delete(file_loc, mpi_info_int, ierr)
1440 end if
1441 call mpi_file_open(mpi_comm_world, file_loc, ior(mpi_mode_wronly, mpi_mode_create), mpi_info_int, ifile, ierr)
1442 call s_check_mpi_file_open(ierr, file_loc)
1443
1444 data_size = (m + 1)*(n + 1)*(p + 1)
1445
1446 m_mok = int(m_glb + 1, mpi_offset_kind)
1447 n_mok = int(n_glb + 1, mpi_offset_kind)
1448 p_mok = int(p_glb + 1, mpi_offset_kind)
1449 wp_mok = int(storage_size(0._stp)/8, mpi_offset_kind)
1450 mok = int(1._wp, mpi_offset_kind)
1451 str_mok = int(name_len, mpi_offset_kind)
1452 nvars_mok = int(alt_sys, mpi_offset_kind)
1453
1454 if (bubbles_euler) then
1455 do i = 1, sys_size
1456 var_mok = int(i, mpi_offset_kind)
1457
1458 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1)
1459
1460 call mpi_file_set_view(ifile, disp, mpi_p, mpi_io_data%view(i), 'native', mpi_info_int, ierr)
1461 call mpi_file_write_all(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
1462 end do
1463 if (qbmm .and. .not. polytropic) then
1464 do i = sys_size + 1, sys_size + 2*nb*nnode
1465 var_mok = int(i, mpi_offset_kind)
1466
1467 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1)
1468
1469 call mpi_file_set_view(ifile, disp, mpi_p, mpi_io_data%view(i), 'native', mpi_info_int, ierr)
1470 call mpi_file_write_all(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
1471 end do
1472 end if
1473 else
1474 do i = 1, sys_size ! TODO: check if sys_size is correct
1475 var_mok = int(i, mpi_offset_kind)
1476
1477 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1)
1478
1479 call mpi_file_set_view(ifile, disp, mpi_p, mpi_io_data%view(i), 'native', mpi_info_int, ierr)
1480 call mpi_file_write_all(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
1481 end do
1482 end if
1483
1484 if (present(beta)) then
1485 var_mok = int(sys_size + 1, mpi_offset_kind)
1486
1487 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1)
1488
1489 call mpi_file_set_view(ifile, disp, mpi_p, mpi_io_data%view(sys_size + 1), 'native', mpi_info_int, ierr)
1490 call mpi_file_write_all(ifile, mpi_io_data%var(sys_size + 1)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, &
1491 & ierr)
1492 end if
1493
1494 call mpi_file_close(ifile, ierr)
1495
1496 if (ib) then
1497 call s_write_parallel_ib_data(t_step)
1498 end if
1499 end if
1500#endif
1501
1502 end subroutine s_write_parallel_data_files
1503
1504 !> Write immersed boundary marker data to a serial (per-processor) unformatted file
1505 subroutine s_write_serial_ib_data(time_step)
1506
1507 integer, intent(in) :: time_step
1508 character(LEN=path_len + 2*name_len) :: file_path
1509 character(LEN=path_len + 2*name_len) :: t_step_dir
1510
1511 write (t_step_dir, '(A,I0,A,I0)') trim(case_dir) // '/p_all'
1512 write (t_step_dir, '(a,i0,a,i0)') trim(case_dir) // '/p_all/p', proc_rank, '/', time_step
1513 write (file_path, '(A,I0,A)') trim(t_step_dir) // '/ib_data.dat'
1514
1515 open (2, file=trim(file_path), form='unformatted', status='new')
1516
1517
1518# 1067 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1519#if defined(MFC_OpenACC)
1520# 1067 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1521!$acc update host(ib_markers%sf)
1522# 1067 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1523#elif defined(MFC_OpenMP)
1524# 1067 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1525!$omp target update from(ib_markers%sf)
1526# 1067 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1527#endif
1528# 1068 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1529 write (2) ib_markers%sf(0:m,0:n,0:p); close (2)
1530
1531 end subroutine s_write_serial_ib_data
1532
1533 !> Write immersed boundary marker data in parallel using MPI I/O
1534 subroutine s_write_parallel_ib_data(time_step)
1535
1536 integer, intent(in) :: time_step
1537
1538#ifdef MFC_MPI
1539 character(LEN=path_len + 2*name_len) :: file_loc
1540 integer(kind=MPI_OFFSET_kind) :: disp
1541 integer(kind=MPI_OFFSET_kind) :: m_MOK, n_MOK, p_MOK
1542 integer(kind=MPI_OFFSET_kind) :: WP_MOK, var_MOK, MOK
1543 integer :: ifile, ierr, data_size
1544 integer, dimension(MPI_STATUS_SIZE) :: status
1545 character(len=10) :: t_step_string
1546
1547
1548# 1086 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1549#if defined(MFC_OpenACC)
1550# 1086 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1551!$acc update host(ib_markers%sf)
1552# 1086 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1553#elif defined(MFC_OpenMP)
1554# 1086 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1555!$omp target update from(ib_markers%sf)
1556# 1086 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1557#endif
1558# 1087 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1559
1560 data_size = (m + 1)*(n + 1)*(p + 1)
1561 m_mok = int(m_glb + 1, mpi_offset_kind)
1562 n_mok = int(n_glb + 1, mpi_offset_kind)
1563 p_mok = int(p_glb + 1, mpi_offset_kind)
1564 wp_mok = int(storage_size(0._stp)/8, mpi_offset_kind)
1565 mok = int(1._wp, mpi_offset_kind)
1566
1567 if (file_per_process) then
1568 call s_int_to_str(time_step, t_step_string)
1569
1570 if (proc_rank == 0) then
1571 file_loc = trim(case_dir) // '/restart_data/lustre_' // trim(t_step_string)
1572 call s_create_directory(trim(file_loc))
1573 end if
1574 call s_mpi_barrier()
1576
1577 write (file_loc, '(A,I0,A,i7.7,A)') 'ib_markers_', time_step, '_', proc_rank, '.dat'
1578 file_loc = trim(case_dir) // '/restart_data/lustre_' // trim(t_step_string) // '/' // trim(file_loc)
1579
1580 call mpi_file_open(mpi_comm_self, file_loc, ior(mpi_mode_wronly, mpi_mode_create), mpi_info_int, ifile, ierr)
1581 call s_check_mpi_file_open(ierr, file_loc)
1582 call mpi_file_write_all(ifile, mpi_io_ib_data%var%sf, data_size, mpi_integer, status, ierr)
1583 call mpi_file_close(ifile, ierr)
1584 else
1585 write (file_loc, '(A)') 'ib.dat'
1586 file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // trim(file_loc)
1587
1588 call s_mpi_barrier()
1590
1591 call mpi_file_open(mpi_comm_world, file_loc, ior(mpi_mode_wronly, mpi_mode_create), mpi_info_int, ifile, ierr)
1592 call s_check_mpi_file_open(ierr, file_loc)
1593
1594 var_mok = int(sys_size + 1, mpi_offset_kind)
1595 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1 + f_save_index(time_step, cfl_dt, t_step_save))
1596 if (time_step == 0) disp = 0
1597
1598 call mpi_file_set_view(ifile, disp, mpi_integer, mpi_io_ib_data%view, 'native', mpi_info_int, ierr)
1599 call mpi_file_write_all(ifile, mpi_io_ib_data%var%sf, data_size, mpi_integer, status, ierr)
1600 call mpi_file_close(ifile, ierr)
1601 end if
1602#endif
1603
1604 end subroutine s_write_parallel_ib_data
1605
1606 !> Dispatch immersed boundary data output to the serial or parallel writer
1607 subroutine s_write_ib_data_file(time_step)
1608
1609 integer, intent(in) :: time_step
1610
1611
1612# 1139 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1613#if defined(MFC_OpenACC)
1614# 1139 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1615!$acc update host(patch_ib(1:num_ibs))
1616# 1139 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1617#elif defined(MFC_OpenMP)
1618# 1139 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1619!$omp target update from(patch_ib(1:num_ibs))
1620# 1139 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1621#endif
1622# 1140 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1623
1624 if (parallel_io) then
1625 call s_write_parallel_ib_data(time_step)
1626 else
1627 call s_write_serial_ib_data(time_step)
1628 end if
1629
1630 end subroutine s_write_ib_data_file
1631
1632 !> Writes the IB state information out to file
1633 subroutine s_write_parallel_ib_state(t_step)
1634
1635 integer, intent(in) :: t_step
1636
1637#ifdef MFC_MPI
1638 character(LEN=path_len + 2*name_len) :: file_loc
1639 integer(kind=MPI_OFFSET_KIND) :: disp
1640 integer(kind=MPI_OFFSET_KIND) :: WP_MOK
1641 integer :: ifile, ierr
1642 integer, dimension(MPI_STATUS_SIZE) :: status
1643 logical :: file_exist, dir_check
1644 integer :: i, ib_idx
1645 real(wp) :: ib_buf(ib_state_nfields)
1646 integer :: file_unit
1647 character(len=10) :: t_step_string
1648
1649 ! Partition IBs across ranks round-robin style
1650 integer :: ib_start, ib_end, nibs_per_rank, remainder
1651
1652 wp_mok = int(storage_size(0._wp)/8, mpi_offset_kind)
1653
1654 if (file_per_process) then
1655 call s_int_to_str(t_step, t_step_string)
1656
1657 if (proc_rank == 0) then
1658 file_loc = trim(case_dir) // '/restart_data/lustre_' // trim(t_step_string)
1659 call s_create_directory(trim(file_loc))
1660 end if
1661 call s_mpi_barrier()
1663
1664 write (file_loc, '(A,I0,A,i7.7,A)') 'ib_state_', t_step, '_', proc_rank, '.dat'
1665 file_loc = trim(case_dir) // '/restart_data/lustre_' // trim(t_step_string) // '/' // trim(file_loc)
1666
1667 inquire (file=trim(file_loc), exist=file_exist)
1668 if (file_exist) then
1669 open (newunit=file_unit, file=trim(file_loc), form='unformatted', access='stream', status='replace')
1670 else
1671 open (newunit=file_unit, file=trim(file_loc), form='unformatted', access='stream', status='new')
1672 end if
1673
1674 write (file_unit) num_local_ibs
1675 do i = 1, num_local_ibs
1676 ib_idx = local_ib_patch_ids(i)
1677 call s_pack_ib_state(patch_ib(ib_idx), mytime, ib_buf, patch_ib(ib_idx)%mass_bank)
1678
1679 write (file_unit) patch_ib(ib_idx)%gbl_patch_id
1680 write (file_unit) ib_buf
1681 end do
1682
1683 close (file_unit)
1684 else
1685 if (proc_rank == 0) then
1686 call s_create_directory(trim(case_dir) // '/restart_data')
1687 end if
1688 call s_mpi_barrier()
1689
1690 write (file_loc, '(A,I0,A)') '/restart_data/ib_state_', t_step, '.dat'
1691 file_loc = trim(case_dir) // trim(file_loc)
1692
1693 inquire (file=trim(file_loc), exist=file_exist)
1694 if (file_exist .and. proc_rank == 0) then
1695 call mpi_file_delete(file_loc, mpi_info_int, ierr)
1696 end if
1697 call s_mpi_barrier()
1698
1699 call mpi_file_open(mpi_comm_world, file_loc, ior(mpi_mode_wronly, mpi_mode_create), mpi_info_int, ifile, ierr)
1700 call s_check_mpi_file_open(ierr, file_loc)
1701
1702 do i = 1, num_local_ibs
1703 ib_idx = local_ib_patch_ids(i)
1704 call s_pack_ib_state(patch_ib(ib_idx), mytime, ib_buf, patch_ib(ib_idx)%mass_bank)
1705
1706 ! Global IB index determines position in file
1707 disp = int(patch_ib(ib_idx)%gbl_patch_id - 1, mpi_offset_kind)*int(ib_state_nfields, mpi_offset_kind)*wp_mok
1708
1709 call mpi_file_write_at(ifile, disp, ib_buf, ib_state_nfields, mpi_p, status, ierr)
1710 end do
1711
1712 call mpi_file_close(ifile, ierr)
1713 end if
1714#endif
1715
1716 end subroutine s_write_parallel_ib_state
1717
1718 !> Write IB state data to a per-timestep serial (unformatted) file
1719 subroutine s_write_serial_ib_state(t_step)
1720
1721 integer, intent(in) :: t_step
1722 character(LEN=path_len + 2*name_len) :: file_loc
1723 integer :: i, ios, file_unit
1724 real(wp) :: ib_buf(ib_state_nfields)
1725
1726 call s_create_directory(trim(case_dir) // '/restart_data')
1727
1728 write (file_loc, '(A,I0,A)') '/restart_data/ib_state_', t_step, '.dat'
1729 file_loc = trim(case_dir) // trim(file_loc)
1730
1731 open (newunit=file_unit, file=trim(file_loc), form='unformatted', access='stream', status='replace', iostat=ios)
1732 if (ios /= 0) call s_mpi_abort('Cannot open IB state output file: ' // trim(file_loc))
1733
1734 do i = 1, num_ibs
1735 call s_pack_ib_state(patch_ib(i), mytime, ib_buf, patch_ib(i)%mass_bank)
1736
1737 write (file_unit) ib_buf
1738 end do
1739
1740 close (file_unit)
1741
1742 end subroutine s_write_serial_ib_state
1743
1744 !> Record every immersed body's force, torque and kinematics (D/ib_forces.dat, ib_force_wrt with ib_state_wrt) and its mass and
1745 !! heat exchange (D/ib_heat.dat, ib_heat_wrt) for this step.
1746 !!
1747 !! One shared text file per quantity, opened once for the run. Each rank writes only the
1748 !! bodies it owns, at a byte offset computed from the step and the global body id, so the file
1749 !! is byte-identical however the domain is decomposed and needs no merge step. Writing a file
1750 !! per body instead costs an inquire, open and close per body per rank per step, which is
1751 !! 3e5 filesystem metadata operations per step at 1000 ranks holding 100 bodies each.
1752 !!
1753 !! Layout: row r holds all num_gbl_ibs bodies in global id order, so body g occupies bytes
1754 !! ((r*num_gbl_ibs) + g - 1)*record length. The files carry no header line, which would shift
1755 !! every offset after it; the columns are listed in docs/documentation/case.md.
1756 !!
1757 !! Rows are numbered from the first step this run records, not from t_step, so that row 0 is
1758 !! always written. Nothing pre-fills the file -- both open paths create it empty and every
1759 !! write lands at a computed offset -- so a row no rank ever writes stays a hole, and a hole
1760 !! reads back as NUL bytes rather than blanks. Counting from t_step would leave exactly such a
1761 !! hole wherever the run starts: the skip below means step t_step_start is never written, and
1762 !! on a restart every row beneath it would be missing as well.
1763 impure subroutine s_write_ib_history(t_step)
1764
1765 integer, intent(in) :: t_step
1766 real(wp) :: ib_buf(ib_state_nfields)
1767 integer :: i, ib_idx, n_write, row
1768 logical :: wrt_force
1769
1770 wrt_force = ib_force_wrt .and. ib_state_wrt
1771 if (.not. (wrt_force .or. ib_heat_wrt)) return
1772 if (mod(t_step, max(ib_force_stride, 1)) /= 0) return
1773 ! This runs at RK stage 1, before the step's force has been computed, so the row for step N carries the
1774 ! force from the end of step N-1. The first step of a run has no N-1: patch_ib%force is still zero and
1775 ! the row would record identically zero force. That is not a measurement, and on a run chained across a
1776 ! queue's walltime limit it lands once per restart -- in a six-wingbeat case, zeros at steps 20649,
1777 ! 34649 and 48649 sitting among neighbours of -0.134, +0.474 and -0.475, corrupting every per-beat
1778 ! trough taken over the joined trace.
1779 if (t_step == t_step_start) return
1780
1781 n_write = num_local_ibs
1782 if (num_procs == 1) n_write = num_ibs
1783 ! Relative to the first recorded step, so the first one written is row 0 and the file is
1784 ! dense. See the hole discussion above.
1785 row = t_step/max(ib_force_stride, 1) - t_step_start/max(ib_force_stride, 1) - 1
1786
1787
1788# 1304 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1789#if defined(MFC_OpenACC)
1790# 1304 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1791!$acc update host(patch_ib(1:num_ibs))
1792# 1304 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1793#elif defined(MFC_OpenMP)
1794# 1304 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1795!$omp target update from(patch_ib(1:num_ibs))
1796# 1304 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1797#endif
1798# 1305 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1799
1800 if (wrt_force) call s_open_ib_history(ib_hist_file, 'ib_forces', ib_force_nf)
1801 if (ib_heat_wrt) call s_open_ib_history(ib_heat_file, 'ib_heat', ib_heat_nf)
1802
1803 do i = 1, n_write
1804 ib_idx = i
1805 if (num_procs > 1) ib_idx = local_ib_patch_ids(i)
1806 if (wrt_force) then
1807 call s_pack_ib_state(patch_ib(ib_idx), mytime, ib_buf)
1808 call s_write_ib_record(ib_hist_file, row, patch_ib(ib_idx)%gbl_patch_id, ib_buf(1:ib_force_nf))
1809 end if
1810 ! Mass and heat exchange of step N-1, and Twall at its end
1811 if (ib_heat_wrt) call s_write_ib_record(ib_heat_file, row, patch_ib(ib_idx)%gbl_patch_id, [mytime, &
1812 & patch_ib(ib_idx)%mdot, patch_ib(ib_idx)%mdot_face, patch_ib(ib_idx)%qdot, patch_ib(ib_idx)%Twall])
1813 end do
1814
1815 end subroutine s_write_ib_history
1816
1817 !> Write body gid's record in the given row. The format is fixed width by construction: every ES descriptor right-justifies in
1818 !! its field, including for negatives, three-digit exponents, NaN and Inf, so a record is always 10 + 18*size(fields) characters
1819 !! plus its newline. That is what lets a rank write at a computed byte offset, with no gather and no per-rank shards.
1820 impure subroutine s_write_ib_record(unit, row, gid, fields)
1821
1822 integer, intent(in) :: unit, row, gid
1823 real(wp), dimension(:), intent(in) :: fields
1824 character(len=11 + 18*size(fields)) :: rec
1825
1826#ifdef MFC_MPI
1827 integer(kind=MPI_OFFSET_KIND) :: disp
1828 integer :: ierr, status(mpi_status_size)
1829#endif
1830
1831 write (rec, f_ib_rec_fmt(size(fields))) gid, fields
1832 rec(len(rec):len(rec)) = new_line('a')
1833#ifdef MFC_MPI
1834 disp = (int(row, mpi_offset_kind)*int(num_gbl_ibs, mpi_offset_kind) + int(gid - 1, mpi_offset_kind))*int(len(rec), &
1835 & mpi_offset_kind)
1836 call mpi_file_write_at(unit, disp, rec, len(rec), mpi_character, status, ierr)
1837#else
1838 write (unit, rec=row*num_gbl_ibs + gid) rec
1839#endif
1840
1841 end subroutine s_write_ib_record
1842
1843 !> Record format for nf reals after the body id
1844 pure function f_ib_rec_fmt(nf) result(fmt)
1845
1846 integer, intent(in) :: nf
1847 character(len=32) :: fmt
1848
1849 write (fmt, '(A,I0,A)') '(I10,', nf, '(1X,ES17.9E3))'
1850
1851 end function f_ib_rec_fmt
1852
1853 !> Open the shared history file D/<stem>.dat of nf-real records. Done once for the run.
1854 impure subroutine s_open_ib_history(unit, stem, nf)
1855
1856 integer, intent(inout) :: unit
1857 character(len=*), intent(in) :: stem
1858 integer, intent(in) :: nf
1859 character(LEN=path_len + 2*name_len) :: file_loc
1860 character(len=11 + 18*nf) :: probe
1861 integer :: i
1862
1863#ifdef MFC_MPI
1864 integer :: ierr
1865 logical :: file_exist
1866#endif
1867
1868 if (unit /= -1) return
1869
1870 ! Every offset assumes the format emits exactly len(probe) - 1 characters. Measure it once
1871 ! rather than trusting that the format and the length were edited together: a format one
1872 ! character wider would shear every record past the first without any other symptom.
1873 write (probe, f_ib_rec_fmt(nf)) 0, [(0._wp, i=1, nf)]
1874 if (len_trim(probe) /= len(probe) - 1) then
1875# 1380 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1876 call s_prohibit_abort("len_trim(probe) /= len(probe) - 1", "IB history record width disagrees with its format")
1877# 1380 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1878 end if
1879# 1381 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1880
1881 ! A resumed run writes its own file rather than overwriting the history of the runs before it
1882 if (cfl_dt .and. n_start > 0) then
1883 write (file_loc, '(A,I0,A)') trim(case_dir) // '/D/' // stem // '_n', n_start, '.dat'
1884 else if (t_step_start > 0) then
1885 write (file_loc, '(A,I0,A)') trim(case_dir) // '/D/' // stem // '_', t_step_start, '.dat'
1886 else
1887 file_loc = trim(case_dir) // '/D/' // stem // '.dat'
1888 end if
1889#ifdef MFC_MPI
1890 ! MPI_MODE_CREATE does not truncate, so a shorter run following a longer one in the same
1891 ! directory would keep the old tail past its last record. Delete first, as the ib_state
1892 ! writer does, then barrier so no rank opens before the delete lands.
1893 inquire (file=trim(file_loc), exist=file_exist)
1894 if (file_exist .and. proc_rank == 0) call mpi_file_delete(file_loc, mpi_info_null, ierr)
1895
1896 ! MPI_INFO_NULL, not mpi_info_int: the latter is only created when parallel_io is on
1897 ! (m_global_parameters_common.fpp returns before MPI_INFO_CREATE otherwise), and the
1898 ! history is written whatever parallel_io is set to. Passing the uninitialised
1899 ! handle aborted every IBM case that runs the solver with parallel_io = F, in
1900 ! MPI_Info_dup, at the first recorded step. The hint it carries only disables ROMIO
1901 ! write data sieving, which this writer does not depend on.
1902 ! Collective: every rank opens, including one holding no body this step.
1903 call s_mpi_barrier()
1904 call mpi_file_open(mpi_comm_world, file_loc, ior(mpi_mode_wronly, mpi_mode_create), mpi_info_null, unit, ierr)
1905 call s_check_mpi_file_open(ierr, file_loc)
1906#else
1907 ! Unformatted: the record is already a formatted string, so this writes its bytes verbatim and
1908 ! produces the same file the MPI branch does. A formatted direct-access write would need a
1909 ! format and would pad rather than emit the string as-is.
1910 open (newunit=unit, file=trim(file_loc), form='unformatted', access='direct', recl=len(probe), status='replace')
1911#endif
1912
1913 end subroutine s_open_ib_history
1914
1915 !> Close the history files. Nothing is buffered, so there is nothing to flush first.
1916 impure subroutine s_close_ib_history
1917
1920
1921 contains
1922
1923 impure subroutine s_close_unit(unit)
1924
1925 integer, intent(inout) :: unit
1926
1927#ifdef MFC_MPI
1928 integer :: ierr
1929#endif
1930
1931 if (unit == -1) return
1932#ifdef MFC_MPI
1933 call mpi_file_close(unit, ierr)
1934#else
1935 close (unit)
1936#endif
1937 unit = -1
1938
1939 end subroutine s_close_unit
1940
1941 end subroutine s_close_ib_history
1942
1943 !> @brief Writes IB state records to restart_data/ib_state.dat. Called on every rank.
1944 impure subroutine s_write_ib_state_file(time_step)
1945
1946 integer, intent(in) :: time_step
1947
1948
1949# 1449 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1950#if defined(MFC_OpenACC)
1951# 1449 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1952!$acc update host(patch_ib(1:num_ibs))
1953# 1449 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1954#elif defined(MFC_OpenMP)
1955# 1449 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1956!$omp target update from(patch_ib(1:num_ibs))
1957# 1449 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1958#endif
1959# 1450 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
1960
1961 if (parallel_io) then
1962 call s_write_parallel_ib_state(time_step)
1963 else
1964 call s_write_serial_ib_state(time_step)
1965 end if
1966 call s_write_centroid_offsets(time_step)
1967 if (chemistry .and. chem_params%diffusion) call s_write_ib_conduction_temperature(time_step)
1968
1969 end subroutine s_write_ib_state_file
1970
1971 !> Write each global patch's centroid_offset to restart_data/ib_offset_<step>.dat, so a restart continues about the same centre
1972 !! of mass instead of re-measuring it from the body voxelised at the restart attitude. Collective.
1973 impure subroutine s_write_centroid_offsets(step)
1974
1975 integer, intent(in) :: step
1976 character(len=path_len + 2*name_len) :: file_loc
1977 real(wp), dimension(:,:), allocatable :: off_loc, off_glb
1978 integer :: gid, i, ib_idx, n_own, file_unit
1979
1980 if (.not. centroid_offsets_active) return
1981 ! column 4 flags a patch that has an offset; only the owning rank contributes, so the sum is the value
1982 allocate (off_loc(num_gbl_ibs, 4), off_glb(num_gbl_ibs, 4))
1983 off_loc = 0._wp
1984 n_own = num_local_ibs
1985 if (num_procs == 1) n_own = num_ibs
1986 do i = 1, n_own
1987 ib_idx = i
1988 if (num_procs > 1) ib_idx = local_ib_patch_ids(i)
1989 if (.not. f_needs_centroid_offset(patch_ib(ib_idx))) cycle
1990 off_loc(patch_ib(ib_idx)%gbl_patch_id,:) = [patch_ib(ib_idx)%centroid_offset, 1._wp]
1991 end do
1992 call s_mpi_allreduce_vectors_sum(off_loc, off_glb, num_gbl_ibs, 4)
1993 if (proc_rank == 0) then
1994 write (file_loc, '(A,I0,A)') trim(case_dir) // '/restart_data/ib_offset_', step, '.dat'
1995 open (newunit=file_unit, file=trim(file_loc), status='replace', action='write')
1996 do gid = 1, num_gbl_ibs
1997 if (off_glb(gid, 4) > 0.5_wp) write (file_unit, '(I0,3(1X,ES24.16))') gid, off_glb(gid,1:3)
1998 end do
1999 close (file_unit)
2000 end if
2001 deallocate (off_loc, off_glb)
2002
2003 end subroutine s_write_centroid_offsets
2004
2005 !> Write flow probe data at the current time step
2006 impure subroutine s_write_probe_files(t_step, q_cons_vf, accel_mag)
2007
2008 integer, intent(in) :: t_step
2009 type(scalar_field), dimension(sys_size), intent(in) :: q_cons_vf
2010 real(wp), dimension(0:m,0:n,0:p), intent(in) :: accel_mag
2011 real(wp), dimension(-1:m) :: distx
2012 real(wp), dimension(-1:n) :: disty
2013 real(wp), dimension(-1:p) :: distz
2014
2015 ! The cell-averaged partial densities, density, velocity, pressure, volume fractions, specific heat ratio function, liquid
2016 ! stiffness function, and sound speed.
2017 real(wp) :: lit_gamma, nbub
2018 real(wp) :: rho
2019 real(wp), dimension(num_vels) :: vel
2020 real(wp) :: pres
2021 real(wp) :: ptilde
2022 real(wp) :: ptot
2023 real(wp) :: alf
2024 real(wp) :: alfgr
2025 real(wp), dimension(num_fluids) :: alpha, alpha_rho
2026 real(wp) :: gamma
2027 real(wp) :: pi_inf
2028 real(wp) :: qv
2029 real(wp) :: c
2030 real(wp) :: m00, m10, m01, m20, m02
2031 real(wp) :: varr, varv
2032 real(wp), dimension(Nb) :: nr, r, nrdot, rdot
2033 real(wp) :: nr3
2034 real(wp) :: accel
2035 real(wp) :: int_pres
2036 real(wp) :: max_pres
2037 real(wp), dimension(2) :: re
2038 real(wp), dimension(6) :: tau_e
2039 real(wp) :: g_undamaged, g_damaged
2040 real(wp) :: dyn_p, t
2041 real(wp) :: damage_state
2042 real(wp) :: solid_partial_density !< damageable-solid partial density at the probe cell
2043 integer :: i, j, k, l, s, d !< Generic loop iterator
2044 real(wp) :: nondim_time !< Non-dimensional time
2045 real(wp) :: tmp !< Temporary variable to store quantity for mpi_allreduce
2046 real(wp) :: rhoyks(1:num_species)
2047
2048 t = dflt_t_guess
2049
2050 if (time_stepper == 23) then
2051 nondim_time = mytime
2052 else
2053 if (t_step_old /= dflt_int) then
2054 nondim_time = real(t_step + t_step_old, wp)*dt
2055 else
2056 nondim_time = real(t_step, wp)*dt
2057 end if
2058 end if
2059
2060 do i = 1, num_probes
2061 rho = 0._wp
2062 do s = 1, num_vels
2063 vel(s) = 0._wp
2064 end do
2065 pres = 0._wp
2066 gamma = 0._wp
2067 pi_inf = 0._wp
2068 qv = 0._wp
2069 c = 0._wp
2070 accel = 0._wp
2071 nr = 0._wp; r = 0._wp
2072 nrdot = 0._wp; rdot = 0._wp
2073 nbub = 0._wp
2074 m00 = 0._wp
2075 m10 = 0._wp
2076 m01 = 0._wp
2077 m20 = 0._wp
2078 m02 = 0._wp
2079 varr = 0._wp; varv = 0._wp
2080 alf = 0._wp
2081 do s = 1, (num_dims*(num_dims + 1))/2
2082 tau_e(s) = 0._wp
2083 end do
2084 damage_state = 0._wp
2085 g_damaged = 0._wp
2086
2087 if (n == 0) then
2088 if (f_probe_owned(probe(i)%x, x_cb(-1), x_cb(m), 1)) then
2089 do s = -1, m
2090 distx(s) = x_cb(s) - probe(i)%x
2091 if (distx(s) < 0._wp) distx(s) = 1000._wp
2092 end do
2093 j = minloc(distx, 1)
2094 if (j == 1) j = 2 ! Pick first point if probe is at edge
2095 k = 0
2096 l = 0
2097
2098 if (chemistry) then
2099 do d = 1, num_species
2100 rhoyks(d) = q_cons_vf(eqn_idx%species%beg + d - 1)%sf(j - 2, k, l)
2101 end do
2102 end if
2103
2104 ! Computing/Sharing necessary state variables
2105 if (hypoelasticity) then
2106 call s_convert_to_mixture_variables(q_cons_vf, j - 2, k, l, rho, gamma, pi_inf, qv, re, g_undamaged, &
2107 & fluid_pp(:)%G)
2108 else
2109 call s_convert_to_mixture_variables(q_cons_vf, j - 2, k, l, rho, gamma, pi_inf, qv)
2110 end if
2111 do s = 1, num_vels
2112 vel(s) = q_cons_vf(eqn_idx%cont%end + s)%sf(j - 2, k, l)/rho
2113 end do
2114 do s = 1, num_fluids
2115 alpha(s) = q_cons_vf(eqn_idx%adv%beg + s - 1)%sf(j - 2, k, l)
2116 alpha_rho(s) = q_cons_vf(eqn_idx%cont%beg + s - 1)%sf(j - 2, k, l)
2117 end do
2118
2119 dyn_p = 0.5_wp*rho*dot_product(vel, vel)
2120
2121 if (hypoelasticity) then
2122 if (cont_damage) then
2123 ! Recover D = U_D/m_s, clamped to [0, 1]
2124 solid_partial_density = 0._wp
2125 do s = 1, num_fluids
2126 if (fluid_pp(s)%G > verysmall) then
2127 solid_partial_density = solid_partial_density + q_cons_vf(eqn_idx%cont%beg + s - 1)%sf(j - 2, &
2128 & k, l)
2129 end if
2130 end do
2131 damage_state = min(max(q_cons_vf(eqn_idx%damage)%sf(j - 2, k, l)/max(solid_partial_density, &
2132 & verysmall), 0._wp), 1._wp)
2133 end if
2134 g_damaged = g_undamaged*max(1._wp - damage_state, 0._wp)
2135
2136 call s_compute_pressure(q_cons_vf(eqn_idx%E)%sf(j - 2, k, l), q_cons_vf(eqn_idx%alf)%sf(j - 2, k, l), &
2137 & dyn_p, pi_inf, gamma, rho, qv, rhoyks(:), pres, t, &
2138 & f_hypoelastic_energy(q_cons_vf, j - 2, k, l, rho, g_undamaged))
2139 else
2140 call s_compute_pressure(q_cons_vf(eqn_idx%E)%sf(j - 2, k, l), q_cons_vf(eqn_idx%alf)%sf(j - 2, k, l), &
2141 & dyn_p, pi_inf, gamma, rho, qv, rhoyks, pres, t)
2142 end if
2143
2144 if (hypoelasticity) then
2145 tau_e(1) = q_cons_vf(eqn_idx%stress%end)%sf(j - 2, k, l)/rho
2146 end if
2147
2148 if (bubbles_euler) then
2149 alf = q_cons_vf(eqn_idx%alf)%sf(j - 2, k, l)
2150 if (num_fluids == 3) then
2151 alfgr = q_cons_vf(eqn_idx%alf - 1)%sf(j - 2, k, l)
2152 end if
2153 do s = 1, nb
2154 nr(s) = q_cons_vf(qbmm_idx%rs(s))%sf(j - 2, k, l)
2155 nrdot(s) = q_cons_vf(qbmm_idx%vs(s))%sf(j - 2, k, l)
2156 end do
2157
2158 if (adv_n) then
2159 nbub = q_cons_vf(eqn_idx%n)%sf(j - 2, k, l)
2160 else
2161 nr3 = 0._wp
2162 do s = 1, nb
2163 nr3 = nr3 + weight(s)*(nr(s)**3._wp)
2164 end do
2165
2166 nbub = sqrt((4._wp*pi/3._wp)*nr3/alf)
2167 end if
2168#ifdef MFC_DEBUG
2169 print *, 'In probe, nbub: ', nbub
2170#endif
2171 if (qbmm) then
2172 m00 = q_cons_vf(qbmm_idx%moms(1, 1))%sf(j - 2, k, l)/nbub
2173 m10 = q_cons_vf(qbmm_idx%moms(1, 2))%sf(j - 2, k, l)/nbub
2174 m01 = q_cons_vf(qbmm_idx%moms(1, 3))%sf(j - 2, k, l)/nbub
2175 m20 = q_cons_vf(qbmm_idx%moms(1, 4))%sf(j - 2, k, l)/nbub
2176 m02 = q_cons_vf(qbmm_idx%moms(1, 6))%sf(j - 2, k, l)/nbub
2177
2178 m10 = m10/m00
2179 m01 = m01/m00
2180 m20 = m20/m00
2181 m02 = m02/m00
2182
2183 varr = m20 - m10**2._wp
2184 varv = m02 - m01**2._wp
2185 end if
2186 r(:) = nr(:)/nbub
2187 rdot(:) = nrdot(:)/nbub
2188
2189 ptilde = ptil(j - 2, k, l)
2190 ptot = pres - ptilde
2191 end if
2192
2193 ! Compute mixture sound Speed
2194 call s_compute_speed_of_sound(pres, rho, gamma, pi_inf, alpha, c, alpha_rho)
2195 if (hypoelasticity) c = sqrt(c*c + (4._wp/3._wp)*g_damaged/rho)
2196
2197 accel = accel_mag(j - 2, k, l)
2198 end if
2199 else if (p == 0) then
2200 if (f_probe_owned(probe(i)%x, x_cb(-1), x_cb(m), 1)) then
2201 if (f_probe_owned(probe(i)%y, y_cb(-1), y_cb(n), 2)) then
2202 do s = -1, m
2203 distx(s) = x_cb(s) - probe(i)%x
2204 if (distx(s) < 0._wp) distx(s) = 1000._wp
2205 end do
2206 do s = -1, n
2207 disty(s) = y_cb(s) - probe(i)%y
2208 if (disty(s) < 0._wp) disty(s) = 1000._wp
2209 end do
2210 j = minloc(distx, 1)
2211 k = minloc(disty, 1)
2212 if (j == 1) j = 2 ! Pick first point if probe is at edge
2213 if (k == 1) k = 2 ! Pick first point if probe is at edge
2214 l = 0
2215
2216 ! Computing/Sharing necessary state variables
2217 call s_convert_to_mixture_variables(q_cons_vf, j - 2, k - 2, l, rho, gamma, pi_inf, qv, re, g_undamaged, &
2218 & fluid_pp(:)%G)
2219 do s = 1, num_vels
2220 vel(s) = q_cons_vf(eqn_idx%cont%end + s)%sf(j - 2, k - 2, l)/rho
2221 end do
2222 do s = 1, num_fluids
2223 alpha(s) = q_cons_vf(eqn_idx%adv%beg + s - 1)%sf(j - 2, k - 2, l)
2224 alpha_rho(s) = q_cons_vf(eqn_idx%cont%beg + s - 1)%sf(j - 2, k - 2, l)
2225 end do
2226
2227 dyn_p = 0.5_wp*rho*dot_product(vel, vel)
2228
2229 if (chemistry) then
2230 do d = 1, num_species
2231 rhoyks(d) = q_cons_vf(eqn_idx%species%beg + d - 1)%sf(j - 2, k - 2, l)
2232 end do
2233 end if
2234
2235 if (hypoelasticity) then
2236 if (cont_damage) then
2237 ! Recover D = U_D/m_s, clamped to [0, 1]
2238 solid_partial_density = 0._wp
2239 do s = 1, num_fluids
2240 if (fluid_pp(s)%G > verysmall) then
2241 solid_partial_density = solid_partial_density + q_cons_vf(eqn_idx%cont%beg + s - 1)%sf(j &
2242 & - 2, k - 2, l)
2243 end if
2244 end do
2245 damage_state = min(max(q_cons_vf(eqn_idx%damage)%sf(j - 2, k - 2, l)/max(solid_partial_density, &
2246 & verysmall), 0._wp), 1._wp)
2247 end if
2248 g_damaged = g_undamaged*max(1._wp - damage_state, 0._wp)
2249
2250 call s_compute_pressure(q_cons_vf(eqn_idx%E)%sf(j - 2, k - 2, l), q_cons_vf(eqn_idx%alf)%sf(j - 2, &
2251 & k - 2, l), dyn_p, pi_inf, gamma, rho, qv, rhoyks, pres, t, &
2252 & f_hypoelastic_energy(q_cons_vf, j - 2, k - 2, l, rho, g_undamaged))
2253 else
2254 call s_compute_pressure(q_cons_vf(eqn_idx%E)%sf(j - 2, k - 2, l), q_cons_vf(eqn_idx%alf)%sf(j - 2, &
2255 & k - 2, l), dyn_p, pi_inf, gamma, rho, qv, rhoyks, pres, t)
2256 end if
2257
2258 if (hypoelasticity) then
2259 do s = 1, 3
2260 tau_e(s) = q_cons_vf(eqn_idx%stress%beg + s - 1)%sf(j - 2, k - 2, l)/rho
2261 end do
2262 end if
2263
2264 if (bubbles_euler) then
2265 alf = q_cons_vf(eqn_idx%alf)%sf(j - 2, k - 2, l)
2266 do s = 1, nb
2267 nr(s) = q_cons_vf(qbmm_idx%rs(s))%sf(j - 2, k - 2, l)
2268 nrdot(s) = q_cons_vf(qbmm_idx%vs(s))%sf(j - 2, k - 2, l)
2269 end do
2270
2271 if (adv_n) then
2272 nbub = q_cons_vf(eqn_idx%n)%sf(j - 2, k - 2, l)
2273 else
2274 nr3 = 0._wp
2275 do s = 1, nb
2276 nr3 = nr3 + weight(s)*(nr(s)**3._wp)
2277 end do
2278
2279 nbub = sqrt((4._wp*pi/3._wp)*nr3/alf)
2280 end if
2281
2282 r(:) = nr(:)/nbub
2283 rdot(:) = nrdot(:)/nbub
2284 end if
2285 ! Compute mixture sound speed
2286 call s_compute_speed_of_sound(pres, rho, gamma, pi_inf, alpha, c, alpha_rho)
2287 if (hypoelasticity) c = sqrt(c*c + (4._wp/3._wp)*g_damaged/rho)
2288 end if
2289 end if
2290 else
2291 if (f_probe_owned(probe(i)%x, x_cb(-1), x_cb(m), 1)) then
2292 if (f_probe_owned(probe(i)%y, y_cb(-1), y_cb(n), 2)) then
2293 if (f_probe_owned(probe(i)%z, z_cb(-1), z_cb(p), 3)) then
2294 do s = -1, m
2295 distx(s) = x_cb(s) - probe(i)%x
2296 if (distx(s) < 0._wp) distx(s) = 1000._wp
2297 end do
2298 do s = -1, n
2299 disty(s) = y_cb(s) - probe(i)%y
2300 if (disty(s) < 0._wp) disty(s) = 1000._wp
2301 end do
2302 do s = -1, p
2303 distz(s) = z_cb(s) - probe(i)%z
2304 if (distz(s) < 0._wp) distz(s) = 1000._wp
2305 end do
2306 j = minloc(distx, 1)
2307 k = minloc(disty, 1)
2308 l = minloc(distz, 1)
2309 if (j == 1) j = 2 ! Pick first point if probe is at edge
2310 if (k == 1) k = 2 ! Pick first point if probe is at edge
2311 if (l == 1) l = 2 ! Pick first point if probe is at edge
2312
2313 ! Computing/Sharing necessary state variables
2314 call s_convert_to_mixture_variables(q_cons_vf, j - 2, k - 2, l - 2, rho, gamma, pi_inf, qv, re, &
2315 & g_undamaged, fluid_pp(:)%G)
2316 do s = 1, num_vels
2317 vel(s) = q_cons_vf(eqn_idx%cont%end + s)%sf(j - 2, k - 2, l - 2)/rho
2318 end do
2319 do s = 1, num_fluids
2320 alpha(s) = q_cons_vf(eqn_idx%adv%beg + s - 1)%sf(j - 2, k - 2, l - 2)
2321 alpha_rho(s) = q_cons_vf(eqn_idx%cont%beg + s - 1)%sf(j - 2, k - 2, l - 2)
2322 end do
2323
2324 dyn_p = 0.5_wp*rho*dot_product(vel, vel)
2325
2326 if (chemistry) then
2327 do d = 1, num_species
2328 rhoyks(d) = q_cons_vf(eqn_idx%species%beg + d - 1)%sf(j - 2, k - 2, l - 2)
2329 end do
2330 end if
2331
2332 if (hypoelasticity) then
2333 if (cont_damage) then
2334 ! Recover D = U_D/m_s, clamped to [0, 1]
2335 solid_partial_density = 0._wp
2336 do s = 1, num_fluids
2337 if (fluid_pp(s)%G > verysmall) then
2338 solid_partial_density = solid_partial_density + q_cons_vf(eqn_idx%cont%beg + s &
2339 & - 1)%sf(j - 2, k - 2, l - 2)
2340 end if
2341 end do
2342 damage_state = min(max(q_cons_vf(eqn_idx%damage)%sf(j - 2, k - 2, &
2343 & l - 2)/max(solid_partial_density, verysmall), 0._wp), 1._wp)
2344 end if
2345 g_damaged = g_undamaged*max(1._wp - damage_state, 0._wp)
2346
2347 call s_compute_pressure(q_cons_vf(eqn_idx%E)%sf(j - 2, k - 2, l - 2), &
2348 & q_cons_vf(eqn_idx%alf)%sf(j - 2, k - 2, l - 2), dyn_p, pi_inf, gamma, &
2349 & rho, qv, rhoyks, pres, t, f_hypoelastic_energy(q_cons_vf, j - 2, k - 2, &
2350 & l - 2, rho, g_undamaged))
2351 else
2352 call s_compute_pressure(q_cons_vf(eqn_idx%E)%sf(j - 2, k - 2, l - 2), &
2353 & q_cons_vf(eqn_idx%alf)%sf(j - 2, k - 2, l - 2), dyn_p, pi_inf, gamma, &
2354 & rho, qv, rhoyks, pres, t)
2355 end if
2356
2357 if (hypoelasticity) then
2358 do s = 1, 6
2359 tau_e(s) = q_cons_vf(eqn_idx%stress%beg + s - 1)%sf(j - 2, k - 2, l - 2)/rho
2360 end do
2361 end if
2362
2363 ! Compute mixture sound speed
2364 call s_compute_speed_of_sound(pres, rho, gamma, pi_inf, alpha, c, alpha_rho)
2365 if (hypoelasticity) c = sqrt(c*c + (4._wp/3._wp)*g_damaged/rho)
2366
2367 accel = accel_mag(j - 2, k - 2, l - 2)
2368 end if
2369 end if
2370 end if
2371 end if
2372 if (num_procs > 1) then
2373# 1864 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2374 tmp = rho
2375# 1865 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2376 call s_mpi_allreduce_sum(tmp, rho)
2377# 1866 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2378# 1864 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2379 tmp = pres
2380# 1865 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2381 call s_mpi_allreduce_sum(tmp, pres)
2382# 1866 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2383# 1864 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2384 tmp = gamma
2385# 1865 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2386 call s_mpi_allreduce_sum(tmp, gamma)
2387# 1866 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2388# 1864 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2389 tmp = pi_inf
2390# 1865 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2391 call s_mpi_allreduce_sum(tmp, pi_inf)
2392# 1866 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2393# 1864 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2394 tmp = qv
2395# 1865 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2396 call s_mpi_allreduce_sum(tmp, qv)
2397# 1866 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2398# 1864 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2399 tmp = c
2400# 1865 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2401 call s_mpi_allreduce_sum(tmp, c)
2402# 1866 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2403# 1864 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2404 tmp = accel
2405# 1865 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2406 call s_mpi_allreduce_sum(tmp, accel)
2407# 1866 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2408# 1867 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2409
2410 do s = 1, num_vels
2411 tmp = vel(s)
2412 call s_mpi_allreduce_sum(tmp, vel(s))
2413 end do
2414
2415 if (bubbles_euler) then
2416# 1875 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2417 tmp = alf
2418# 1876 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2419 call s_mpi_allreduce_sum(tmp, alf)
2420# 1877 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2421# 1875 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2422 tmp = alfgr
2423# 1876 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2424 call s_mpi_allreduce_sum(tmp, alfgr)
2425# 1877 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2426# 1875 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2427 tmp = nbub
2428# 1876 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2429 call s_mpi_allreduce_sum(tmp, nbub)
2430# 1877 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2431# 1875 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2432 tmp = nr(1)
2433# 1876 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2434 call s_mpi_allreduce_sum(tmp, nr(1))
2435# 1877 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2436# 1875 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2437 tmp = nrdot(1)
2438# 1876 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2439 call s_mpi_allreduce_sum(tmp, nrdot(1))
2440# 1877 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2441# 1875 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2442 tmp = m00
2443# 1876 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2444 call s_mpi_allreduce_sum(tmp, m00)
2445# 1877 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2446# 1875 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2447 tmp = r(1)
2448# 1876 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2449 call s_mpi_allreduce_sum(tmp, r(1))
2450# 1877 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2451# 1875 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2452 tmp = rdot(1)
2453# 1876 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2454 call s_mpi_allreduce_sum(tmp, rdot(1))
2455# 1877 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2456# 1875 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2457 tmp = ptilde
2458# 1876 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2459 call s_mpi_allreduce_sum(tmp, ptilde)
2460# 1877 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2461# 1875 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2462 tmp = ptot
2463# 1876 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2464 call s_mpi_allreduce_sum(tmp, ptot)
2465# 1877 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2466# 1878 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2467
2468 if (qbmm) then
2469# 1881 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2470 tmp = varr
2471# 1882 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2472 call s_mpi_allreduce_sum(tmp, varr)
2473# 1883 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2474# 1881 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2475 tmp = varv
2476# 1882 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2477 call s_mpi_allreduce_sum(tmp, varv)
2478# 1883 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2479# 1881 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2480 tmp = m10
2481# 1882 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2482 call s_mpi_allreduce_sum(tmp, m10)
2483# 1883 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2484# 1881 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2485 tmp = m01
2486# 1882 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2487 call s_mpi_allreduce_sum(tmp, m01)
2488# 1883 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2489# 1881 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2490 tmp = m20
2491# 1882 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2492 call s_mpi_allreduce_sum(tmp, m20)
2493# 1883 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2494# 1881 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2495 tmp = m02
2496# 1882 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2497 call s_mpi_allreduce_sum(tmp, m02)
2498# 1883 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2499# 1884 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2500 end if
2501 end if
2502
2503 if (hypoelasticity) then
2504 do s = 1, (num_dims*(num_dims + 1))/2
2505 tmp = tau_e(s)
2506 call s_mpi_allreduce_sum(tmp, tau_e(s))
2507 end do
2508 end if
2509
2510 if (cont_damage) then
2511 tmp = damage_state
2512 call s_mpi_allreduce_sum(tmp, damage_state)
2513 end if
2514 end if
2515 if (proc_rank == 0) then
2516 if (n == 0) then
2517 if (bubbles_euler .and. (num_fluids <= 2)) then
2518 if (qbmm) then
2519 write (i + 30, '(6x,f12.6,14f28.16)') nondim_time, rho, vel(1), pres, alf, r(1), rdot(1), nr(1), &
2520 & nrdot(1), varr, varv, m10, m01, m20, m02
2521 else
2522 write (i + 30, '(6x,f12.6,8f24.8)') nondim_time, rho, vel(1), pres, alf, r(1), rdot(1), nr(1), nrdot(1)
2523 ! ptilde, & ptot
2524 end if
2525 else if (bubbles_euler .and. (num_fluids == 3)) then
2526 write (i + 30, &
2527 & '(6x,f12.6,f24.8,f24.8,f24.8,f24.8,f24.8,' // 'f24.8,f24.8,f24.8,f24.8,f24.8, f24.8)') &
2528 & nondim_time, rho, vel(1), pres, alf, alfgr, nr(1), nrdot(1), r(1), rdot(1), ptilde, ptot
2529 else if (bubbles_euler .and. num_fluids == 4) then
2530 write (i + 30, &
2531 & '(6x,f12.6,f24.8,f24.8,f24.8,f24.8,' // 'f24.8,f24.8,f24.8,f24.8,f24.8,f24.8,f24.8,f24.8,f24.8)') &
2532 & nondim_time, q_cons_vf(1)%sf(j - 2, 0, 0), q_cons_vf(2)%sf(j - 2, 0, 0), q_cons_vf(3)%sf(j - 2, &
2533 & 0, 0), q_cons_vf(4)%sf(j - 2, 0, 0), q_cons_vf(5)%sf(j - 2, 0, 0), q_cons_vf(6)%sf(j - 2, 0, 0), &
2534 & q_cons_vf(7)%sf(j - 2, 0, 0), q_cons_vf(8)%sf(j - 2, 0, 0), q_cons_vf(9)%sf(j - 2, 0, 0), &
2535 & q_cons_vf(10)%sf(j - 2, 0, 0), nbub, r(1), rdot(1)
2536 else if (hypoelasticity) then
2537 write (i + 30, '(6X,F12.6,F24.8,F24.8,F24.8,F24.8)') nondim_time, rho, vel(1), pres, tau_e(1)
2538 else
2539 write (i + 30, '(6X,F12.6,F24.8,F24.8,F24.8)') nondim_time, rho, vel(1), pres
2540 end if
2541 else if (p == 0) then
2542 if (bubbles_euler) then
2543# 1928 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2544 write (i + 30, '(6X,10F24.8)') nondim_time, rho, vel(1), vel(2), pres, alf, nr(1), nrdot(1), r(1), &
2545 & rdot(1)
2546# 1931 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2547 else if (hypoelasticity) then
2548# 1933 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2549 write (i + 30, '(6X,F12.6,F24.8,F24.8,F24.8,F24.8,' // 'F24.8,F24.8,F24.8)') nondim_time, rho, &
2550 & vel(1), vel(2), pres, tau_e(1), tau_e(2), tau_e(3)
2551# 1936 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2552 else
2553# 1938 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2554 write (i + 30, '(6X,F12.6,F24.8,F24.8,F24.8,F24.8)') nondim_time, rho, vel(1), vel(2), pres
2555# 1940 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2556 end if
2557 else
2558# 1943 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2559 if (hypoelasticity) then
2560 write (i + 30, '(6X,F12.6,16F24.8)') nondim_time, rho, vel(1), vel(2), vel(3), pres, gamma, pi_inf, &
2561 & qv, c, accel, tau_e(1), tau_e(2), tau_e(3), tau_e(4), tau_e(5), tau_e(6)
2562 else
2563 write (i + 30, &
2564 & '(6X,F12.6,F24.8,F24.8,F24.8,F24.8,' // 'F24.8,F24.8,F24.8,F24.8,F24.8,' // 'F24.8)') &
2565 & nondim_time, rho, vel(1), vel(2), vel(3), pres, gamma, pi_inf, qv, c, accel
2566 end if
2567# 1952 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2568 end if
2569 end if
2570 end do
2571
2572 end subroutine s_write_probe_files
2573
2574 !> Write footer with stability criteria extrema and run-time to the information file, then close it
2576
2577 real(wp) :: run_time !< Run-time of the simulation
2578
2579 write (3, '(A)') ' '
2580 write (3, '(A)') ''
2581
2582 write (3, '(A,F9.6)') 'ICFL Max: ', icfl_max
2583 if (surface_tension) write (3, '(A,F9.6)') 'CCFL Max: ', ccfl_max
2584 if (heat_conduction) write (3, '(A,F9.6)') 'TCFL Max: ', tcfl_max
2585 if (viscous) write (3, '(A,F9.6)') 'VCFL Max: ', vcfl_max
2586 if (viscous) write (3, '(A,ES16.6)') 'Rc Min: ', rc_min
2587
2588 call cpu_time(run_time)
2589
2590 write (3, '(A)') ''
2591 write (3, '(A,I0,A)') 'Run-time: ', int(anint(run_time)), 's'
2592 write (3, '(A)') ' '
2593 close (3)
2594
2596
2597 !> Closes probe files
2598 impure subroutine s_close_probe_files
2599
2600 integer :: i !< Generic loop iterator
2601
2602 do i = 1, num_probes
2603 close (i + 30)
2604 end do
2605
2606 end subroutine s_close_probe_files
2607
2608 !> Initialize the data output module
2610
2611 integer :: i, m_ds, n_ds, p_ds
2612
2613 if (run_time_info) then
2614 icfl_max = 0._wp
2615 if (surface_tension) then
2616 ccfl_max = 0._wp
2617 end if
2618 if (heat_conduction) then
2619 tcfl_max = 0._wp
2620 end if
2621 if (viscous) then
2622 vcfl_max = 0._wp
2623 rc_min = 1.e12_wp
2624 end if
2625 end if
2626
2627 if (down_sample) then
2628 m_ds = int((m + 1)/3) - 1
2629 n_ds = int((n + 1)/3) - 1
2630 p_ds = int((p + 1)/3) - 1
2631
2632 allocate (q_cons_temp_ds(1:sys_size))
2633 do i = 1, sys_size
2634 allocate (q_cons_temp_ds(i)%sf(-1:m_ds + 1,-1:n_ds + 1,-1:p_ds + 1))
2635 end do
2636 end if
2637
2638 end subroutine s_initialize_data_output_module
2639
2640 !> Module deallocation and/or disassociation procedures
2642
2643 integer :: i
2644
2645 if (bubbles_lagrange .or. particles_lagrange) call s_close_lag_output()
2646
2647 if (down_sample) then
2648 do i = 1, sys_size
2649 deallocate (q_cons_temp_ds(i)%sf)
2650 end do
2651 deallocate (q_cons_temp_ds)
2652 end if
2653
2654 end subroutine s_finalize_data_output_module
2655
2656 !> Create D/, open the Lagrangian output files, and write the initial output, from the restart point (save_count, qtime).
2657 impure subroutine s_initialize_lag_output(save_count, qtime)
2658
2659 integer, intent(in) :: save_count
2660 real(wp), intent(in) :: qtime
2661
2662 call s_create_d_dir()
2663
2664 if (bubbles_lagrange) then
2665 if (lag_params%write_void_evol) call s_open_void_evol
2666 if (lag_params%write_bubbles) then
2667 call s_open_lag_evol('bubble', merge(16, 24, precision == precision_single), [character(len=22)::'currentTime', &
2668 & 'particleID', 'x', 'y', 'z', 'coreVaporMass', 'coreVaporConcentration', 'radius', &
2669 & 'interfaceVelocity', 'corePressure'])
2670 end if
2671 if (lag_params%write_bubbles_stats) call s_open_lag_bubble_stats()
2672 if (save_count == 0) then
2673 call s_write_restart_lag_bubbles(save_count) ! Needed for post_processing
2674 if (lag_params%write_void_evol) call s_write_void_evol(qtime, q_beta(bub_q_idx%alphaf)%sf, lag_params%charwidth)
2675 end if
2676 if (lag_params%write_bubbles) call s_write_lag_bubble_evol(qtime)
2677 else
2678 ! The evolution file is written every t_save; a restart resumes at the first multiple of t_save not before qtime
2679 next_write_time = 0._wp
2680 if (save_count > 0 .and. t_save > 0._wp) next_write_time = t_save*ceiling(qtime/t_save)
2681 if (particle_params%write_void_evol) call s_open_void_evol
2682 if (particle_params%write_particles) then
2683 call s_open_lag_evol('particle', merge(17, 25, precision == 1), [character(len=11)::'currentTime','particleID', &
2684 & 'x', 'y', 'z', 'Vx', 'Vy', 'Vz', 'Fp_x', 'Fp_y', 'Fp_z', 'radius', 'vFx_at_p', 'vFy_at_p', &
2685 & 'vFz_at_p', 'rhoF_at_p'])
2686 end if
2687 ! Particles are smeared onto the grid by now
2688 if (save_count == 0 .and. particle_params%write_void_evol) call s_write_void_evol(qtime, &
2689 & q_particles(part_q_idx%alphaf)%sf, particle_params%charwidth)
2690 end if
2691
2692 end subroutine s_initialize_lag_output
2693
2694 !> Append to the particle evolution file before an RK stage: at the first stage of t = 0, and at the last stage once mytime
2695 !! reaches the next t_save multiple.
2696 impure subroutine s_write_lag_particle_evol_if_due(stage)
2697
2698 integer, intent(in) :: stage
2699
2700 if (.not. particle_params%write_particles) return
2701 if (mytime == 0._wp .and. stage == 1) then
2704 end if
2705 if (mytime >= next_write_time .and. stage == time_stepper) then
2708 end if
2709
2711
2712 !> Append the per-step Lagrangian output after the last RK stage commits the step.
2713 impure subroutine s_write_lag_step_output()
2714
2715 if (bubbles_lagrange) then
2716 if (lag_params%write_void_evol) call s_write_void_evol(mytime, q_beta(bub_q_idx%alphaf)%sf, lag_params%charwidth)
2717 if (lag_params%write_bubbles) call s_write_lag_bubble_evol(mytime)
2718 else if (particle_params%write_void_evol) then
2719 call s_write_void_evol(mytime, q_particles(part_q_idx%alphaf)%sf, particle_params%charwidth)
2720 end if
2721
2722 end subroutine s_write_lag_step_output
2723
2724 !> Write the Lagrangian restart file, and the bubble statistics, for save save_count. The caller syncs the state to the host.
2725 impure subroutine s_write_lag_save_data(save_count)
2726
2727 integer, intent(in) :: save_count
2728
2729 if (bubbles_lagrange) then
2730 call s_write_restart_lag_bubbles(save_count)
2731 if (lag_params%write_bubbles_stats) call s_write_lag_bubble_stats()
2732 else
2733 call s_write_restart_lag_particles(save_count)
2734 end if
2735
2736 end subroutine s_write_lag_save_data
2737
2738 !> Close the Lagrangian output files.
2739 impure subroutine s_close_lag_output()
2740
2741 logical :: void_evol, evol
2742
2743 void_evol = merge(lag_params%write_void_evol, particle_params%write_void_evol, bubbles_lagrange)
2744 evol = merge(lag_params%write_bubbles, particle_params%write_particles, bubbles_lagrange)
2745 if (void_evol .and. proc_rank == 0) close (lag_void_id)
2746 if (evol) close (lag_evol_id)
2747 if (bubbles_lagrange .and. lag_params%write_bubbles_stats) close (lag_stats_id)
2748
2749 end subroutine s_close_lag_output
2750
2751 !> Create case_dir/D on rank 0 if it does not exist.
2752 impure subroutine s_create_d_dir()
2753
2754 character(LEN=path_len + 2*name_len) :: path_d_dir
2755 logical :: dir_exist
2756
2757 if (proc_rank == 0) then
2758 path_d_dir = trim(case_dir) // '/D'
2759 call my_inquire(trim(path_d_dir), dir_exist)
2760 if (.not. dir_exist) call s_create_directory(trim(path_d_dir))
2761 end if
2762 call s_mpi_barrier()
2763
2764 end subroutine s_create_d_dir
2765
2766 !> Open this rank's evolution file D/lag_<lag_kind>_evol_<rank>.dat: on a fresh start replace it and write the column headers
2767 !! (first header width 14, the others width), on a restart append to it.
2768 impure subroutine s_open_lag_evol(lag_kind, width, headers)
2769
2770 character(len=*), intent(in) :: lag_kind
2771 integer, intent(in) :: width
2772 character(len=*), dimension(:), intent(in) :: headers
2773 character(LEN=path_len + 2*name_len) :: file_loc
2774 character(LEN=32) :: fmt
2775 integer :: save_count, i
2776 real(wp) :: qtime
2777
2778 write (file_loc, '(A,A,A,I0,A)') 'lag_', lag_kind, '_evol_', proc_rank, '.dat'
2779 file_loc = trim(case_dir) // '/D/' // trim(file_loc)
2780
2781 call s_get_lag_restart_point(save_count, qtime)
2782 if (save_count > 0) then
2783 open (lag_evol_id, file=trim(file_loc), form='formatted', position='append')
2784 else
2785 open (lag_evol_id, file=trim(file_loc), form='formatted', position='rewind', status='replace')
2786 write (fmt, '(A,I0,A,I0,A,I0,A)') '(A', width, ',A14,', size(headers) - 2, 'A', width, ')'
2787 write (lag_evol_id, fmt) (trim(headers(i)), i=1, size(headers))
2788 end if
2789
2790 end subroutine s_open_lag_evol
2791
2792 !> Open D/voidfraction.dat on rank 0, appending if it exists.
2793 impure subroutine s_open_void_evol
2794
2795 character(LEN=path_len + 2*name_len) :: file_loc
2796 logical :: file_exist
2797
2798 if (proc_rank == 0) then
2799 file_loc = trim(case_dir) // '/D/voidfraction.dat'
2800 call my_inquire(trim(file_loc), file_exist)
2801 if (.not. file_exist) then
2802 open (lag_void_id, file=trim(file_loc), form='formatted', position='rewind')
2803 else
2804 open (lag_void_id, file=trim(file_loc), form='formatted', position='append')
2805 end if
2806 end if
2807
2808 end subroutine s_open_void_evol
2809
2810 !> Append the cloud's average and maximum Lagrangian volume fraction 1 - alpha_f and its total volume at qtime to
2811 !! D/voidfraction.dat. The average is over the cells the cloud occupies only.
2812 impure subroutine s_write_void_evol(qtime, alpha_f, charwidth)
2813
2814 real(wp), intent(in) :: qtime, charwidth
2815 real(stp), dimension(idwbuff(1)%beg:,idwbuff(2)%beg:,idwbuff(3)%beg:), intent(in) :: alpha_f
2816 real(wp) :: volcell, voltot
2817 real(wp) :: lag_void_max, lag_void_avg, lag_vol
2818 real(wp) :: void_max_glb, void_avg_glb, vol_glb
2819 integer :: i, j, k
2820
2821 lag_void_max = 0._wp
2822 lag_void_avg = 0._wp
2823 lag_vol = 0._wp
2824
2825# 2208 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2826
2827# 2208 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2828#if defined(MFC_OpenACC)
2829# 2208 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2830!$acc parallel loop collapse(3) gang vector default(present) private(volcell) reduction(+:lag_vol, lag_void_avg) reduction(MAX:lag_void_max) copy(lag_vol, lag_void_avg, lag_void_max) copyin(charwidth)
2831# 2208 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2832#elif defined(MFC_OpenMP)
2833# 2208 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2834
2835# 2208 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2836
2837# 2208 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2838
2839# 2208 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2840!$omp target teams loop defaultmap(firstprivate:scalar) bind(teams,parallel) collapse(3) defaultmap(tofrom:aggregate) defaultmap(tofrom:allocatable) defaultmap(tofrom:pointer) private(volcell) &
2841# 2208 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2842!$omp& reduction(+:lag_vol, lag_void_avg) reduction(MAX:lag_void_max) map(tofrom:lag_vol, lag_void_avg, lag_void_max) map(to:charwidth)
2843# 2208 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2844#endif
2845# 2210 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2846 do k = 0, p
2847 do j = 0, n
2848 do i = 0, m
2849 lag_void_max = max(lag_void_max, 1._wp - alpha_f(i, j, k))
2850 call s_get_char_vol(i, j, k, charwidth, volcell)
2851 if ((1._wp - alpha_f(i, j, k)) > void_stat_min) then
2852 lag_void_avg = lag_void_avg + (1._wp - alpha_f(i, j, k))*volcell
2853 lag_vol = lag_vol + volcell
2854 end if
2855 end do
2856 end do
2857 end do
2858
2859# 2222 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2860#if defined(MFC_OpenACC)
2861# 2222 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2862!$acc end parallel loop
2863# 2222 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2864#elif defined(MFC_OpenMP)
2865# 2222 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2866
2867# 2222 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2868!$omp end target teams loop
2869# 2222 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2870#endif
2871# 2223 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2872
2873#ifdef MFC_MPI
2874 if (num_procs > 1) then
2875 call s_mpi_allreduce_max(lag_void_max, void_max_glb)
2876 lag_void_max = void_max_glb
2877 call s_mpi_allreduce_sum(lag_vol, vol_glb)
2878 lag_vol = vol_glb
2879 call s_mpi_allreduce_sum(lag_void_avg, void_avg_glb)
2880 lag_void_avg = void_avg_glb
2881 end if
2882#endif
2883 voltot = lag_void_avg
2884 if (lag_vol > 0._wp) lag_void_avg = lag_void_avg/lag_vol
2885
2886 if (proc_rank == 0) then
2887 write (lag_void_id, '(6X,4e24.8)') qtime, lag_void_avg, lag_void_max, voltot
2888 end if
2889
2890 end subroutine s_write_void_evol
2891
2892 !> Append each local particle's position, velocity, force, radius and fluid state at the particle to the evolution file.
2893 impure subroutine s_write_lag_particle_evol(qtime)
2894
2895 real(wp), intent(in) :: qtime
2896 integer :: k
2897 character(LEN=32) :: fmt
2898
2899 if (precision == 1) then
2900 fmt = "(ES17.8E3,I14,14ES17.8E3)"
2901 else
2902 fmt = "(ES25.16E3,I14,14ES25.16E3)"
2903 end if
2904
2905
2906# 2256 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2907#if defined(MFC_OpenACC)
2908# 2256 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2909!$acc update host(lag_part_id, particle_pos, particle_vel, f_p, particle_rad, fluid_vel_at_particle, density_at_particle)
2910# 2256 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2911#elif defined(MFC_OpenMP)
2912# 2256 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2913!$omp target update from(lag_part_id, particle_pos, particle_vel, f_p, particle_rad, fluid_vel_at_particle, density_at_particle)
2914# 2256 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2915#endif
2916# 2257 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2917
2918 ! Cycle through list
2919 do k = 1, n_el_particles_loc
2920 write (lag_evol_id, fmt) qtime, lag_part_id(k, 1), particle_pos(k, 1, 1), particle_pos(k, 2, 1), particle_pos(k, 3, &
2921 & 1), particle_vel(k, 1, 1), particle_vel(k, 2, 1), particle_vel(k, 3, 1), f_p(k, 1), f_p(k, 2), f_p(k, 3), &
2924 end do
2925
2926 end subroutine s_write_lag_particle_evol
2927
2928 !> Write on each time step the changes of the lagrangian bubbles.
2929 impure subroutine s_write_lag_bubble_evol(qtime)
2930
2931 real(wp), intent(in) :: qtime
2932 integer :: k
2933 character(LEN=25) :: fmt
2934
2935 if (precision == precision_single) then
2936 fmt = "(F16.8,I14,8F16.8)"
2937 else
2938 fmt = "(F24.16,I14,8F24.16)"
2939 end if
2940
2941
2942# 2281 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2943#if defined(MFC_OpenACC)
2944# 2281 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2945!$acc update host(lag_id, mtn_pos, gas_p, gas_mv, gas_mg, intfc_rad, intfc_vel)
2946# 2281 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2947#elif defined(MFC_OpenMP)
2948# 2281 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2949!$omp target update from(lag_id, mtn_pos, gas_p, gas_mv, gas_mg, intfc_rad, intfc_vel)
2950# 2281 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2951#endif
2952# 2282 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2953
2954 ! Cycle through list
2955 do k = 1, n_el_bubs_loc
2956 write (lag_evol_id, fmt) qtime, lag_id(k, 1), mtn_pos(k, 1, 1), mtn_pos(k, 2, 1), mtn_pos(k, 3, 1), gas_mv(k, 1), &
2957 & gas_mv(k, 1)/(gas_mv(k, 1) + gas_mg(k)), intfc_rad(k, 1), intfc_vel(k, 1), gas_p(k, 1)
2958 end do
2959
2960 end subroutine s_write_lag_bubble_evol
2961
2962 !> Open this rank's bubble statistics file D/stats_lag_bubbles_<rank>.dat, appending if it exists.
2963 impure subroutine s_open_lag_bubble_stats()
2964
2965 character(LEN=path_len + 2*name_len) :: file_loc
2966 logical :: file_exist
2967
2968 write (file_loc, '(A,I0,A)') 'stats_lag_bubbles_', proc_rank, '.dat'
2969 file_loc = trim(case_dir) // '/D/' // trim(file_loc)
2970 call my_inquire(trim(file_loc), file_exist)
2971
2972 if (.not. file_exist) then
2973 open (lag_stats_id, file=trim(file_loc), form='formatted', position='rewind')
2974 write (lag_stats_id, *) 'proc_rank, particleID, x, y, z, Rmax_glb, Rmin_glb'
2975 else
2976 open (lag_stats_id, file=trim(file_loc), form='formatted', position='append')
2977 end if
2978
2979 end subroutine s_open_lag_bubble_stats
2980
2981 !> Write the maximum and minimum radius of each bubble.
2982 impure subroutine s_write_lag_bubble_stats()
2983
2984 integer :: k
2985 character(LEN=path_len + 2*name_len) :: file_loc
2986 character(LEN=20) :: fmt
2987
2988
2989# 2317 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2990#if defined(MFC_OpenACC)
2991# 2317 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2992!$acc update host(Rmax_glb, Rmin_glb)
2993# 2317 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2994#elif defined(MFC_OpenMP)
2995# 2317 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2996!$omp target update from(Rmax_glb, Rmin_glb)
2997# 2317 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
2998#endif
2999# 2318 "/home/runner/work/MFC/MFC/src/simulation/m_data_output.fpp"
3000
3001 if (precision == precision_single) then
3002 fmt = "(I10,I14,5F16.8)"
3003 else
3004 fmt = "(I10,I14,5F24.16)"
3005 end if
3006
3007 do k = 1, n_el_bubs_loc
3008 write (lag_stats_id, fmt) proc_rank, lag_id(k, 1), mtn_pos(k, 1, 1), mtn_pos(k, 2, 1), mtn_pos(k, 3, 1), &
3010 end do
3011
3012 end subroutine s_write_lag_bubble_stats
3013
3014 !> Write the particles in this rank's physical domain to restart_data/lustre_lag_particles_<t_step>.dat, in the bubble column
3015 !! layout so post_process reads both.
3016 impure subroutine s_write_restart_lag_particles(t_step)
3017
3018 integer, intent(in) :: t_step
3019 integer :: i, k, n_loc
3020 integer, dimension(3) :: cell
3021 real(wp), dimension(3) :: s_loc
3022 real(wp), allocatable, dimension(:,:) :: io_data
3023
3025 allocate (io_data(max(1, n_loc),1:lag_io_vars))
3026 io_data = 0._wp ! Unused columns are written as zero
3027
3028 i = 0
3029 do k = 1, n_el_particles_loc
3030 if (.not. f_lag_entity_in_physical_domain(particle_pos(k,1:3,1))) cycle
3031 i = i + 1
3032 io_data(i, 1) = real(lag_part_id(k, 1), wp)
3033 io_data(i,2:4) = particle_pos(k,1:3,1)
3034 io_data(i,5:7) = particle_posprev(k,1:3,1)
3035 io_data(i,8:10) = particle_vel(k,1:3,1)
3036 io_data(i, 11) = particle_rad(k)
3037 ! Particle volume fraction in the host cell, located from the current position
3038 call s_locate_cell(particle_pos(k,1:3,1), cell, s_loc)
3039 io_data(i, 12) = 1._wp - q_particles(part_q_idx%alphaf)%sf(cell(1), cell(2), cell(3))
3040 ! Bubble column layout: R0 is the (constant) radius and the radius-ratio extremes are 1
3041 io_data(i, 13) = particle_rad(k)
3042 io_data(i,14:15) = 1._wp
3043 io_data(i,16:18) = fqs_fluct(k,1:3) ! Drag-fluctuation state
3044 io_data(i, 19) = particle_mass(k)
3045 ! Seed as two 16-bit halves, exact in single and double precision
3046 io_data(i, 20) = real(ibits(particle_seed(k), 0, 16), wp)
3047 io_data(i, 21) = real(ibits(particle_seed(k), 16, 16), wp)
3048 end do
3049
3050 call s_write_lag_restart('particles', t_step, io_data, n_loc)
3051 deallocate (io_data)
3052
3053 end subroutine s_write_restart_lag_particles
3054
3055 !> Write the bubbles in this rank's physical domain to restart_data/lag_bubbles_<t_step>.dat (parallel I/O only).
3056 impure subroutine s_write_restart_lag_bubbles(t_step)
3057
3058 integer, intent(in) :: t_step
3059 integer :: i, k, n_loc
3060 real(wp), allocatable, dimension(:,:) :: io_data
3061
3062 if (.not. parallel_io) return
3063
3064 n_loc = count([(f_lag_entity_in_physical_domain(mtn_pos(k,1:3,1)), k=1, n_el_bubs_loc)])
3065 allocate (io_data(max(1, n_loc),1:lag_io_vars))
3066
3067 i = 0
3068 do k = 1, n_el_bubs_loc
3069 if (.not. f_lag_entity_in_physical_domain(mtn_pos(k,1:3,1))) cycle
3070 i = i + 1
3071 io_data(i, 1) = real(lag_id(k, 1), wp)
3072 io_data(i,2:4) = mtn_pos(k,1:3,1)
3073 io_data(i,5:7) = mtn_posprev(k,1:3,1)
3074 io_data(i,8:10) = mtn_vel(k,1:3,1)
3075 io_data(i, 11) = intfc_rad(k, 1)
3076 io_data(i, 12) = intfc_vel(k, 1)
3077 io_data(i, 13) = bub_r0(k)
3078 io_data(i, 14) = rmax_stats(k)
3079 io_data(i, 15) = rmin_stats(k)
3080 io_data(i, 16) = bub_dphidt(k)
3081 io_data(i, 17) = gas_p(k, 1)
3082 io_data(i, 18) = gas_mv(k, 1)
3083 io_data(i, 19) = gas_mg(k)
3084 io_data(i, 20) = gas_betat(k)
3085 io_data(i, 21) = gas_betac(k)
3086 end do
3087
3088 call s_write_lag_restart('bubbles', t_step, io_data, n_loc)
3089 deallocate (io_data)
3090
3091 end subroutine s_write_restart_lag_bubbles
3092
3093 !> Write restart_data/lag_<lag_kind>_<t_step>.dat: a header (total count, time, dt, number of ranks, per-rank counts) followed
3094 !! by the lag_io_vars columns of every rank's entities, which the caller packs into io_data(1:n_loc, :).
3095 impure subroutine s_write_lag_restart(lag_kind, t_step, io_data, n_loc)
3096
3097 character(len=*), intent(in) :: lag_kind
3098 integer, intent(in) :: t_step, n_loc
3099 real(wp), dimension(:,:), intent(in) :: io_data
3100
3101#ifdef MFC_MPI
3102 character(LEN=path_len + 2*name_len) :: file_loc
3103 logical :: file_exist
3104 integer :: tot_part, ifile, ierr, view
3105 integer, dimension(MPI_STATUS_SIZE) :: status
3106 integer(KIND=MPI_OFFSET_KIND) :: disp
3107 integer, dimension(2) :: gsizes, lsizes, start_idx_part
3108 integer, dimension(num_procs) :: proc_counts
3109 real(wp), dimension(1:1,1:lag_io_vars) :: dummy
3110
3111 dummy = 0._wp
3112 lsizes(1) = n_loc
3113 lsizes(2) = lag_io_vars
3114
3115 call mpi_allreduce(n_loc, tot_part, 1, mpi_integer, mpi_sum, mpi_comm_world, ierr)
3116 call mpi_allgather(n_loc, 1, mpi_integer, proc_counts, 1, mpi_integer, mpi_comm_world, ierr)
3117
3118 ! Starting row of this rank's entities
3119 call mpi_exscan(lsizes(1), start_idx_part(1), 1, mpi_integer, mpi_sum, mpi_comm_world, ierr)
3120 if (proc_rank == 0) start_idx_part(1) = 0
3121 start_idx_part(2) = 0
3122
3123 gsizes(1) = tot_part
3124 gsizes(2) = lag_io_vars
3125
3126 write (file_loc, '(A,A,A,I0,A)') 'lag_', lag_kind, '_', t_step, '.dat'
3127 file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // trim(file_loc)
3128
3129 if (proc_rank == 0) then
3130 ! Serial-I/O runs do not create restart_data
3131 call s_create_directory(trim(case_dir) // '/restart_data')
3132 inquire (file=trim(file_loc), exist=file_exist)
3133 if (file_exist) call mpi_file_delete(file_loc, mpi_info_int, ierr)
3134 end if
3135 call mpi_barrier(mpi_comm_world, ierr)
3136
3137 if (proc_rank == 0) then
3138 call mpi_file_open(mpi_comm_self, file_loc, ior(mpi_mode_wronly, mpi_mode_create), mpi_info_int, ifile, ierr)
3139 call s_check_mpi_file_open(ierr, file_loc)
3140 call mpi_file_write(ifile, tot_part, 1, mpi_integer, status, ierr)
3141 call mpi_file_write(ifile, mytime, 1, mpi_p, status, ierr)
3142 call mpi_file_write(ifile, dt, 1, mpi_p, status, ierr)
3143 call mpi_file_write(ifile, num_procs, 1, mpi_integer, status, ierr)
3144 call mpi_file_write(ifile, proc_counts, num_procs, mpi_integer, status, ierr)
3145 call mpi_file_close(ifile, ierr)
3146 end if
3147 call mpi_barrier(mpi_comm_world, ierr)
3148
3149 if (n_loc > 0) then
3150 call mpi_type_create_subarray(2, gsizes, lsizes, start_idx_part, mpi_order_fortran, mpi_p, view, ierr)
3151 else
3152 call mpi_type_contiguous(0, mpi_p, view, ierr)
3153 end if
3154 call mpi_type_commit(view, ierr)
3155
3156 call mpi_file_open(mpi_comm_world, file_loc, ior(mpi_mode_wronly, mpi_mode_create), mpi_info_int, ifile, ierr)
3157 call s_check_mpi_file_open(ierr, file_loc)
3158
3159 ! Skip the header written by rank 0
3160 disp = int(sizeof(tot_part) + 2*sizeof(mytime) + sizeof(num_procs) + num_procs*sizeof(proc_counts(1)), mpi_offset_kind)
3161 call mpi_file_set_view(ifile, disp, mpi_p, view, 'native', mpi_info_int, ierr)
3162
3163 if (n_loc > 0) then
3164 call mpi_file_write_all(ifile, io_data(1:n_loc,:), lag_io_vars*n_loc, mpi_p, status, ierr)
3165 else
3166 call mpi_file_write_all(ifile, dummy, 0, mpi_p, status, ierr)
3167 end if
3168
3169 call mpi_file_close(ifile, ierr)
3170 call mpi_type_free(view, ierr)
3171#endif
3172
3173 end subroutine s_write_lag_restart
3174
3175 !> Half-open ownership lo < v <= hi, so a probe on a rank face is sampled once, by the rank holding the cell the serial code
3176 !! samples (left of the face); the first rank in a direction also owns its lower face.
3177 logical function f_probe_owned(v, lo, hi, dir)
3178
3179 real(wp), intent(in) :: v, lo, hi
3180 integer, intent(in) :: dir
3181 logical :: first
3182
3183 first = num_procs == 1
3184 if (.not. first) first = proc_coords(dir) == 0
3185 f_probe_owned = v <= hi .and. (v > lo .or. (first .and. v >= lo))
3186
3187 end function f_probe_owned
3188
3189end module m_data_output
impure subroutine s_close_unit(unit)
type(scalar_field), dimension(sys_size), intent(inout) q_cons_vf
integer, intent(in) k
integer, intent(in) j
integer, intent(in) l
Noncharacteristic and processor boundary condition application for ghost cells and buffer regions.
Boundary condition restart I/O, capillary/IGR buffer population, and grid-variable buffers.
subroutine s_write_serial_boundary_condition_files(bc_type, step_dirpath, old_grid_in)
Write bc type and bc_buffers to serial restart files (pre_process packs them first; simulation writes...
Real fields of a bubble MPI slot, as (names, indices, count) in pack order. Used by both pack and unp...
real(wp) rmin_glb
Maximum and minimum bubbe size in the local domain.
real(wp), dimension(:,:,:), allocatable mtn_vel
Bubble's velocity.
real(wp), dimension(:), allocatable gas_betat
heatflux model (Preston et al., 2007)
real(wp), dimension(:), allocatable bub_dphidt
subgrid velocity potential (Maeda & Colonius, 2018)
real(wp), dimension(:), allocatable gas_mg
Bubble's gas mass.
real(wp), dimension(:), allocatable bub_r0
Initial bubble radius.
real(wp), dimension(:), allocatable rmin_stats
Minimum radius.
real(wp), dimension(:,:), allocatable gas_mv
Vapor mass in the bubble.
real(wp), dimension(:), allocatable rmax_stats
Maximum radius.
integer, dimension(:,:), allocatable lag_id
Global and local IDs.
type(scalar_field), dimension(:), allocatable q_beta
Projection of the Lagrangian bubbles in the Eulerian framework.
real(wp), dimension(:), allocatable gas_betac
massflux model (Preston et al., 2007)
real(wp), dimension(:,:), allocatable intfc_vel
Velocity of the bubble interface.
real(wp), dimension(:,:), allocatable gas_p
Pressure in the bubble.
real(wp), dimension(:,:), allocatable intfc_rad
Bubble radius.
real(wp), dimension(:,:,:), allocatable mtn_pos
Bubble's position.
real(wp), dimension(:,:,:), allocatable mtn_posprev
Bubble's previous position.
Platform-specific file and directory operations: create, delete, inquire, getcwd, and basename.
impure subroutine s_delete_directory(dir_name)
Recursively delete a directory using a platform-specific system command.
impure subroutine my_inquire(fileloc, dircheck)
Inquire on the existence of a directory or file.
impure subroutine s_create_directory(dir_name)
Create a directory and all its parents if it does not exist.
Compile-time constant parameters: default values, tolerances, and physical constants.
integer, parameter lag_io_vars
Number of variables per particle for MPI_IO.
integer, parameter model_eqns_5eq
integer, parameter name_len
Maximum name length.
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 dflt_int
Default integer value.
integer, parameter eos_mie_gruneisen
real(wp), parameter sgm_eps
Segmentation tolerance.
integer, parameter nnode
Number of QBMM nodes.
integer, parameter precision_single
real(wp), parameter pi
Pi.
real(wp), parameter verysmall
Very small number.
Writes solution data, run-time stability diagnostics (ICFL, VCFL, CCFL, Rc), and probe/center-of-mass...
impure subroutine s_write_restart_lag_particles(t_step)
Write the particles in this rank's physical domain to restart_data/lustre_lag_particles_<t_step>....
integer, parameter lag_evol_id
Per-rank Lagrangian evolution files.
impure subroutine s_write_ib_record(unit, row, gid, fields)
Write body gid's record in the given row. The format is fixed width by construction: every ES descrip...
impure subroutine s_write_lag_particle_evol(qtime)
Append each local particle's position, velocity, force, radius and fluid state at the particle to the...
impure subroutine s_open_lag_bubble_stats()
Open this rank's bubble statistics file D/stats_lag_bubbles_<rank>.dat, appending if it exists.
impure subroutine s_write_void_evol(qtime, alpha_f, charwidth)
Append the cloud's average and maximum Lagrangian volume fraction 1 - alpha_f and its total volume at...
impure subroutine, public s_open_probe_files
Open flow probe data files for writing.
impure subroutine s_report_icfl_violation(q_prim_vf)
Locate the grid cell responsible for an ICFL violation on this rank and report its state plus the nea...
impure subroutine s_write_centroid_offsets(step)
Write each global patch's centroid_offset to restart_data/ib_offset_<step>.dat, so a restart continue...
impure subroutine s_write_lag_restart(lag_kind, t_step, io_data, n_loc)
Write restart_data/lag_<lag_kind>_<t_step>.dat: a header (total count, time, dt, number of ranks,...
real(wp) rc_min
Rc criterion maximum.
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...
real(wp) vcfl_max
VCFL criterion maximum.
real(wp) tcfl_max
TCFL criterion maximum.
impure subroutine, public s_write_probe_files(t_step, q_cons_vf, accel_mag)
Write flow probe data at the current time step.
subroutine s_write_parallel_ib_state(t_step)
Writes the IB state information out to file.
impure subroutine, public s_write_ib_history(t_step)
Record every immersed body's force, torque and kinematics (D/ib_forces.dat, ib_force_wrt with ib_stat...
impure subroutine s_close_lag_output()
Close the Lagrangian output files.
impure subroutine, public s_write_lag_particle_evol_if_due(stage)
Append to the particle evolution file before an RK stage: at the first stage of t = 0,...
impure subroutine, public s_write_parallel_data_files(q_cons_vf, t_step, beta, q_t_sf)
Write grid and conservative variable data files in parallel via MPI I/O.
real(wp), parameter void_stat_min
Volume fraction above which a cell counts in the void statistics.
integer, parameter ib_force_nf
Per-body history files, one fixed-width text record per body per recorded step (s_write_ib_record): r...
impure subroutine, public s_initialize_data_output_module
Initialize the data output module.
real(wp) next_write_time
Time of the next particle evolution write.
impure subroutine, public s_finalize_data_output_module
Module deallocation and/or disassociation procedures.
integer, parameter lag_stats_id
Per-rank bubble statistics files.
subroutine s_write_serial_ib_state(t_step)
Write IB state data to a per-timestep serial (unformatted) file.
subroutine s_write_serial_ib_data(time_step)
Write immersed boundary marker data to a serial (per-processor) unformatted file.
impure subroutine, public s_close_run_time_information_file
Write footer with stability criteria extrema and run-time to the information file,...
impure subroutine s_open_lag_evol(lag_kind, width, headers)
Open this rank's evolution file D/lag_<lag_kind>evol<rank>.dat: on a fresh start replace it and write...
impure subroutine s_write_lag_bubble_stats()
Write the maximum and minimum radius of each bubble.
integer ib_heat_file
D/ib_heat.dat.
pure character(len=32) function f_ib_rec_fmt(nf)
Record format for nf reals after the body id.
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 s_open_void_evol
Open D/voidfraction.dat on rank 0, appending if it exists.
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_lag_step_output()
Append the per-step Lagrangian output after the last RK stage commits the step.
impure subroutine, public s_write_serial_data_files(q_cons_vf, q_t_sf, q_prim_vf, t_step, bc_type, beta)
Write grid and conservative variable data files in serial format.
logical function f_probe_owned(v, lo, hi, dir)
Half-open ownership lo < v <= hi, so a probe on a rank face is sampled once, by the rank holding the ...
impure subroutine, public s_close_probe_files
Closes probe files.
impure subroutine, public s_write_run_time_information(q_prim_vf, t_step)
Write stability criteria extrema to the run-time information file at the given time step.
impure subroutine, public s_open_run_time_information_file
Open the run-time information file and write the stability criteria table header.
integer ib_hist_file
D/ib_forces.dat.
integer, parameter ib_heat_nf
real(wp) icfl_max
ICFL criterion maximum.
impure subroutine s_write_lag_bubble_evol(qtime)
Write on each time step the changes of the lagrangian bubbles.
impure subroutine s_open_ib_history(unit, stem, nf)
Open the shared history file D/<stem>.dat of nf-real records. Done once for the run.
impure subroutine, public s_write_ib_state_file(time_step)
Writes IB state records to restart_data/ib_state.dat. Called on every rank.
impure subroutine, public s_close_ib_history
Close the history files. Nothing is buffered, so there is nothing to flush first.
type(scalar_field), dimension(:), allocatable q_cons_temp_ds
impure subroutine, public s_create_d_dir()
Create case_dir/D on rank 0 if it does not exist.
subroutine s_write_parallel_ib_data(time_step)
Write immersed boundary marker data in parallel using MPI I/O.
integer, parameter lag_void_id
D/voidfraction.dat.
impure subroutine s_write_restart_lag_bubbles(t_step)
Write the bubbles in this rank's physical domain to restart_data/lag_bubbles_<t_step>....
subroutine, public s_write_ib_data_file(time_step)
Dispatch immersed boundary data output to the serial or parallel writer.
real(wp) ccfl_max
CCFL criterion maximum.
Rank-staggered file access delays to prevent I/O contention on parallel file systems.
impure subroutine, public s_delay_file_access(process_rank)
Introduce a rank-dependent busy-wait delay to stagger parallel file access and reduce I/O contention.
Shared derived types for field data, patch geometry, bubble dynamics, and MPI I/O structures.
Utilities shared by the Euler-Lagrange bubble and solid-particle solvers: cell location,...
logical function, public f_lag_entity_in_physical_domain(pos_part)
True if pos lies in this rank's physical domain (ghost cells excluded).
subroutine, public s_get_char_vol(cellx, celly, cellz, charwidth, charvol)
Volume of cell (cellx, celly, cellz); in planar 2D the cell has depth charwidth.
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(:), allocatable fluid_inv_re
per-fluid Newtonian inverse-Re
type(part_q_idx_info) part_q_idx
Lagrangian particle projected-field indices.
type(int_bounds_info), dimension(1:3) idwint
real(wp), dimension(:), allocatable, target z_cb
logical any_non_newtonian
.true. if any fluid is non-Newtonian
real(wp), dimension(:,:,:), allocatable amr_cfl_rf
Spacing ratio of the finest cell over each coarse cell (1 where uncovered), and the powers of it by w...
type(qbmm_idx_info) qbmm_idx
QBMM moment index mappings (allocatable; GPU-managed separately).
integer proc_rank
Rank of the local processor.
type(mpi_io_ib_var), public mpi_io_ib_data
real(wp), dimension(:), allocatable weight
Simpson quadrature weights.
integer, dimension(num_local_ibs_max) local_ib_patch_ids
lookup table of IBs in the local compute domain
integer buff_size
Number of ghost cells for boundary condition storage.
type(bub_q_idx_info) bub_q_idx
Lagrangian bubble projected-field indices.
real(wp), dimension(:), allocatable, target y_cc
type(pres_field), dimension(:), allocatable pb_ts
integer n_el_bubs_glb
Number of Lagrangian bubbles (local and global).
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
real(wp), dimension(:), allocatable, target y_cb
real(wp), dimension(:,:,:), allocatable ptil
Pressure modification.
real(wp), dimension(3) amr_cfl_pow
type(mpi_io_var), public mpi_io_data
real(wp), dimension(:), allocatable hb_mu_max
logical, dimension(:), allocatable is_non_newtonian
per-fluid NN flag
real(wp), dimension(:), allocatable, target x_cb
Basic floating-point utilities: approximate equality, default detection, and coordinate bounds.
pure integer function, public f_save_index(t_step, cfl_mode, t_step_save)
Index of the save written at t_step: t_step itself under CFL-based stepping (the caller passes the sa...
logical elemental function, public f_approx_equal(a, b, tol_input)
Check if two floating point numbers of wp are within tolerance.
Utility routines for bubble model setup, coordinate transforms, array sampling, and special functions...
pure subroutine, public s_pack_ib_state(ib_patch, time, buf, mass_bank)
One IB's restart_data/ib_state record; see ib_state_nfields for the layout.
subroutine, public s_locate_cell(pos, cell, scoord)
Locate the cell holding pos by bisection on the cell boundaries, and its computational coordinates sc...
subroutine, public s_downsample_data(q_cons_vf, q_cons_temp, m_ds, n_ds, p_ds, m_glb_ds, n_glb_ds, p_glb_ds)
Downsample conservative variable fields by a factor of 3 in each direction using volume averaging.
elemental subroutine, public s_int_to_str(i, res)
Convert an integer to its trimmed string representation.
Ghost-node immersed boundary method: locates ghost/image points, computes interpolation coefficients,...
impure subroutine, public s_write_ib_conduction_temperature(t_step)
Write every ghost's T_cond to restart_data/ib_tcond_<t_step>.dat (lustre_<t_step>/ib_tcond_<t_step>_<...
type(integer_field), public ib_markers
pure logical function f_needs_centroid_offset(patch)
A moving airfoil or STL (geometries 4, 5, 11, 12) moves its centroid to the centre of mass and keeps ...
logical centroid_offsets_active
some patch is a moving airfoil or STL, which carries a centroid_offset
MPI halo exchange, domain decomposition, and buffer packing/unpacking for the simulation solver.
Real fields of a particle MPI slot, as (names, indices, count) in pack order. Used by both pack and u...
real(wp), dimension(:), allocatable, public density_at_particle
density at each particle
real(wp), dimension(:,:), allocatable, public fqs_fluct
QS fluctuation force on each particle.
real(wp), dimension(:), allocatable, public particle_rad
Particle radius (constant: particles are rigid).
real(wp), dimension(:,:,:), allocatable, public particle_posprev
Particle's previous position.
integer, dimension(:,:), allocatable, public lag_part_id
Global and local IDs.
real(wp), dimension(:), allocatable, public particle_mass
Particle Mass.
type(scalar_field), dimension(:), allocatable, public q_particles
Eulerian projection of particle data (volume fraction, momentum, sources).
integer(seed_kind), dimension(:), allocatable, public particle_seed
State of the particle's fluctuation-model RNG.
real(wp), dimension(:,:), allocatable, public f_p
force on each particle
real(wp), dimension(:,:,:), allocatable, public particle_pos
Particle's position.
real(wp), dimension(:,:,:), allocatable, public particle_vel
Particle's velocity.
real(wp), dimension(:,:), allocatable, public fluid_vel_at_particle
fluid velocity at each particle
Simulation helper routines for cell state, CFL calculation, and stability checks.
subroutine, public s_compute_stability_from_dt(vel, c, rho, re_l, alpha, alpha_rho, j, k, l, icfl, vcfl, rc, ccfl, tcfl)
Computes stability criterion for a specified dt.
subroutine, public s_amr_scale_stability(rf, pw1, pw2, pw3, icfl, vcfl, rc, ccfl, tcfl)
The stability numbers of the finest cell over a coarse cell, from the coarse cell's: rf is its spacin...
subroutine, public s_compute_cell_state(q_prim_vf, pres, rho, gamma, pi_inf, re, alpha, alpha_rho, vel, vel_sum, qv, j, k, l, re_size_loc1, re_size_loc2)
Computes the mixture coefficients, velocity and pressure of one cell.
Conservative-to-primitive variable conversion, mixture property evaluation, and pressure computation.
real(wp) function, public f_hypoelastic_energy(q_cons_vf, j, k, l, rho, g)
Hypoelastic strain energy at one cell, summed over the stress components.
subroutine, public s_convert_conservative_to_primitive_variables(qk_cons_vf, q_t_sf, qk_prim_vf, ibounds)
Convert conserved variables (rho*alpha, rho*u, E, alpha) to primitives (rho, u, p,...
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.
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...
Derived type annexing an integer scalar field (SF).
Derived type annexing a scalar field (SF).