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/post_process/m_data_output.fpp"
2!>
3!! @file
4!! @brief Contains module m_data_output
5
6!> @brief Writes post-processed grid and flow-variable data to Silo-HDF5 or binary database files
8
9#ifdef MFC_MPI
10 use mpi
11#endif
12
16 use m_mpi_proxy
18 use m_helper
22 use m_eos
24
25 implicit none
26
33
34 ! Include Silo-HDF5 interface library
35 include 'silo_f9x.inc'
36
37 !> Silo datatype of a real(wp) array (grid coordinates, point meshes and point variables). A --single build must not declare
38 !! DB_DOUBLE for wp data: Silo then reads two floats per coordinate and the second half of every array from past its end
39 !! (garbage, sometimes NaN).
40 integer, parameter :: db_real = merge(db_double, db_float, wp == dp)
41
42 !> Output workspace: flow variable buffers, VisIt extents/offsets, directory paths, file handles, and variable count.
44
45 ! Generic error flag for Silo-HDF5 and Binary I/O operations
46 integer, private :: err
47
48 !> Name of the Lagrangian output files and Silo point mesh: lag_bubbles or lag_particles
49 character(len=13), private :: lag_name = 'lag_bubbles'
50
51contains
52
53 !> Allocate storage arrays, configure output directories, and count flow variables for formatted database output.
55
56 character(LEN=len_trim(case_dir) + 2*name_len) :: file_loc
57 logical :: dir_check
58
59 allocate (out%q_sf(-offset_x%beg:m + offset_x%end,-offset_y%beg:n + offset_y%end,-offset_z%beg:p + offset_z%end))
60 if (grid_geometry == 3) then
61 allocate (out%cyl_q_sf(-offset_y%beg:n + offset_y%end,-offset_z%beg:p + offset_z%end,-offset_x%beg:m + offset_x%end))
62 end if
63
64 if (precision == precision_single) then
65 allocate (out%q_sf_s(-offset_x%beg:m + offset_x%end,-offset_y%beg:n + offset_y%end,-offset_z%beg:p + offset_z%end))
66 if (grid_geometry == 3) then
67 allocate (out%cyl_q_sf_s(-offset_y%beg:n + offset_y%end,-offset_z%beg:p + offset_z%end, &
68 & -offset_x%beg:m + offset_x%end))
69 end if
70 end if
71
72 if (n == 0) then
73 allocate (out%q_root_sf(0:m_root,0:0,0:0))
74 if (precision == precision_single) then
75 allocate (out%q_root_sf_s(0:m_root,0:0,0:0))
76 end if
77 end if
78
79 ! Allocating the spatial and data extents and also the variables for the offsets and the one bookkeeping the number of
80 ! cell-boundaries in each active coordinate direction. Note that all these variables are only needed by the Silo-HDF5 format
81 ! for multidimensional data.
82 if (format == format_silo) then
83 allocate (out%data_extents(1:2,0:num_procs - 1))
84
85 if (p > 0) then
86 allocate (out%spatial_extents(1:6,0:num_procs - 1))
87 allocate (out%lo_offset(1:3))
88 allocate (out%hi_offset(1:3))
89 allocate (out%dims(1:3))
90 else if (n > 0) then
91 allocate (out%spatial_extents(1:4,0:num_procs - 1))
92 allocate (out%lo_offset(1:2))
93 allocate (out%hi_offset(1:2))
94 allocate (out%dims(1:2))
95 else
96 allocate (out%spatial_extents(1:2,0:num_procs - 1))
97 allocate (out%lo_offset(1:1))
98 allocate (out%hi_offset(1:1))
99 allocate (out%dims(1:1))
100 end if
101 end if
102
103 ! The size of the ghost zone layer in each of the active coordinate directions was set in the module m_mpi_proxy.f90. The
104 ! results are now transferred to the local variables of this module when they are required by the Silo-HDF5 format, for
105 ! multidimensional data sets. With the same, latter, requirements, the variables bookkeeping the number of cell-boundaries
106 ! in each active coordinate direction are also set here.
107 if (format == format_silo) then
108 if (p > 0) then
109 if (grid_geometry == 3) then
110 out%lo_offset(:) = (/offset_y%beg, offset_z%beg, offset_x%beg/)
111 out%hi_offset(:) = (/offset_y%end, offset_z%end, offset_x%end/)
112 else
113 out%lo_offset(:) = (/offset_x%beg, offset_y%beg, offset_z%beg/)
114 out%hi_offset(:) = (/offset_x%end, offset_y%end, offset_z%end/)
115 end if
116
117 if (grid_geometry == 3) then
118 out%dims(:) = (/n + offset_y%beg + offset_y%end + 2, p + offset_z%beg + offset_z%end + 2, &
119 & m + offset_x%beg + offset_x%end + 2/)
120 else
121 out%dims(:) = (/m + offset_x%beg + offset_x%end + 2, n + offset_y%beg + offset_y%end + 2, &
122 & p + offset_z%beg + offset_z%end + 2/)
123 end if
124 else if (n > 0) then
125 out%lo_offset(:) = (/offset_x%beg, offset_y%beg/)
126 out%hi_offset(:) = (/offset_x%end, offset_y%end/)
127
128 out%dims(:) = (/m + offset_x%beg + offset_x%end + 2, n + offset_y%beg + offset_y%end + 2/)
129 else
130 out%lo_offset(:) = (/offset_x%beg/)
131 out%hi_offset(:) = (/offset_x%end/)
132 out%dims(:) = (/m + offset_x%beg + offset_x%end + 2/)
133 end if
134 end if
135
136 if (format == format_silo) then
137 out%dbdir = trim(case_dir) // '/silo_hdf5'
138
139 write (out%proc_rank_dir, '(A,I0)') '/p', proc_rank
140
141 out%proc_rank_dir = trim(out%dbdir) // trim(out%proc_rank_dir)
142
143 file_loc = trim(out%proc_rank_dir) // '/.'
144
145 call my_inquire(file_loc, dir_check)
146 if (dir_check .neqv. .true.) then
147 call s_create_directory(trim(out%proc_rank_dir))
148 end if
149
150 if (proc_rank == 0) then
151 out%rootdir = trim(out%dbdir) // '/root'
152
153 file_loc = trim(out%rootdir) // '/.'
154
155 call my_inquire(file_loc, dir_check)
156 if (dir_check .neqv. .true.) then
157 call s_create_directory(trim(out%rootdir))
158 end if
159 end if
160 else
161 out%dbdir = trim(case_dir) // '/binary'
162
163 write (out%proc_rank_dir, '(A,I0)') '/p', proc_rank
164
165 out%proc_rank_dir = trim(out%dbdir) // trim(out%proc_rank_dir)
166
167 file_loc = trim(out%proc_rank_dir) // '/.'
168
169 call my_inquire(file_loc, dir_check)
170
171 if (dir_check .neqv. .true.) then
172 call s_create_directory(trim(out%proc_rank_dir))
173 end if
174
175 if (n == 0 .and. proc_rank == 0) then
176 out%rootdir = trim(out%dbdir) // '/root'
177
178 file_loc = trim(out%rootdir) // '/.'
179
180 call my_inquire(file_loc, dir_check)
181
182 if (dir_check .neqv. .true.) then
183 call s_create_directory(trim(out%rootdir))
184 end if
185 end if
186 end if
187
188 if (particles_lagrange) lag_name = 'lag_particles'
189 if (euler_lagrange) then ! Lagrangian solver
190 if (lag_txt_wrt) then
191 out%dbdir = trim(case_dir) // '/' // trim(lag_name) // '_post_process'
192 file_loc = trim(out%dbdir) // '/.'
193 call my_inquire(file_loc, dir_check)
194
195 if (dir_check .neqv. .true.) then
196 call s_create_directory(trim(out%dbdir))
197 end if
198 end if
199 end if
200
201 ! Contrary to the Silo-HDF5 database format, handles of the Binary database master/root and slave/local process files are
202 ! perfectly static throughout post-process. Hence, they are set here so that they do not have to be repetitively computed in
203 ! later procedures.
204 if (format == format_binary) then
205 if (n == 0 .and. proc_rank == 0) out%dbroot = 2
206 out%dbfile = 1
207 end if
208
210
211 !> Compute the cell-index bounds for the user-specified partial output domain in each coordinate direction.
212 impure subroutine s_define_output_region
213
214 integer :: i
215 integer :: lower_bound, upper_bound
216
217# 217 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
218 if (m == 0) return ! Early return for y or z if simulation is 1D or 2D
219# 218 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
220
221 lower_bound = -offset_x%beg
222# 220 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
223 upper_bound = m + offset_x%end
224# 221 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
225
226 do i = lower_bound, upper_bound
227 if (x_cc(i) > x_output%beg) then
228# 224 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
229 x_output_idx%beg = i + offset_x%beg
230# 225 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
231 exit
232 end if
233 end do
234
235 do i = upper_bound, lower_bound, -1
236 if (x_cc(i) < x_output%end) then
237# 231 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
238 x_output_idx%end = i + offset_x%beg
239# 232 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
240 exit
241 end if
242 end do
243
244 ! If no grid points are within the output region
245 if ((x_cc(lower_bound) > x_output%end) .or. (x_cc(upper_bound) < x_output%beg)) then
246# 238 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
247 x_output_idx%beg = 0
248# 239 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
249 x_output_idx%end = 0
250# 240 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
251 end if
252# 217 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
253 if (n == 0) return ! Early return for y or z if simulation is 1D or 2D
254# 218 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
255
256 lower_bound = -offset_y%beg
257# 220 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
258 upper_bound = n + offset_y%end
259# 221 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
260
261 do i = lower_bound, upper_bound
262 if (y_cc(i) > y_output%beg) then
263# 224 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
264 y_output_idx%beg = i + offset_y%beg
265# 225 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
266 exit
267 end if
268 end do
269
270 do i = upper_bound, lower_bound, -1
271 if (y_cc(i) < y_output%end) then
272# 231 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
273 y_output_idx%end = i + offset_y%beg
274# 232 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
275 exit
276 end if
277 end do
278
279 ! If no grid points are within the output region
280 if ((y_cc(lower_bound) > y_output%end) .or. (y_cc(upper_bound) < y_output%beg)) then
281# 238 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
282 y_output_idx%beg = 0
283# 239 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
284 y_output_idx%end = 0
285# 240 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
286 end if
287# 217 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
288 if (p == 0) return ! Early return for y or z if simulation is 1D or 2D
289# 218 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
290
291 lower_bound = -offset_z%beg
292# 220 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
293 upper_bound = p + offset_z%end
294# 221 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
295
296 do i = lower_bound, upper_bound
297 if (z_cc(i) > z_output%beg) then
298# 224 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
299 z_output_idx%beg = i + offset_z%beg
300# 225 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
301 exit
302 end if
303 end do
304
305 do i = upper_bound, lower_bound, -1
306 if (z_cc(i) < z_output%end) then
307# 231 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
308 z_output_idx%end = i + offset_z%beg
309# 232 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
310 exit
311 end if
312 end do
313
314 ! If no grid points are within the output region
315 if ((z_cc(lower_bound) > z_output%end) .or. (z_cc(upper_bound) < z_output%beg)) then
316# 238 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
317 z_output_idx%beg = 0
318# 239 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
319 z_output_idx%end = 0
320# 240 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
321 end if
322# 242 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
323
324 end subroutine s_define_output_region
325
326 !> Open (or create) the Silo-HDF5 or Binary formatted database slave and master files for a given time step.
327 impure subroutine s_open_formatted_database_file(t_step)
328
329 integer, intent(in) :: t_step
330 character(LEN=len_trim(case_dir) + 3*name_len) :: file_loc
331 integer :: ierr
332
333 if (format == format_silo) then
334 write (file_loc, '(A,I0,A)') '/', t_step, '.silo'
335 file_loc = trim(out%proc_rank_dir) // trim(file_loc)
336
337 ierr = dbcreate(trim(file_loc), len_trim(file_loc), db_clobber, db_local, 'MFC v3.0', 8, db_hdf5, out%dbfile)
338
339 if (out%dbfile == -1) then
340 call s_mpi_abort('Unable to create Silo-HDF5 database ' // 'slave file ' // trim(file_loc) // '. ' // 'Exiting.')
341 end if
342
343 if (proc_rank == 0) then
344 write (file_loc, '(A,I0,A)') '/collection_', t_step, '.silo'
345 file_loc = trim(out%rootdir) // trim(file_loc)
346
347 ierr = dbcreate(trim(file_loc), len_trim(file_loc), db_clobber, db_local, 'MFC v3.0', 8, db_hdf5, out%dbroot)
348
349 if (out%dbroot == -1) then
350 call s_mpi_abort('Unable to create Silo-HDF5 database ' // 'master file ' // trim(file_loc) // '. ' &
351 & // 'Exiting.')
352 end if
353 end if
354 else
355 write (file_loc, '(A,I0,A)') '/', t_step, '.dat'
356 file_loc = trim(out%proc_rank_dir) // trim(file_loc)
357
358 open (out%dbfile, iostat=err, file=trim(file_loc), form='unformatted', status='replace')
359
360 if (err /= 0) then
361 call s_mpi_abort('Unable to create Binary database slave ' // 'file ' // trim(file_loc) // '. Exiting.')
362 end if
363
364 ! Counted as variables are written and backfilled on close
365 out%dbvars = 0
366
367 if (output_partial_domain) then
368 write (out%dbfile) x_output_idx%end - x_output_idx%beg, y_output_idx%end - y_output_idx%beg, &
369 & z_output_idx%end - z_output_idx%beg, out%dbvars
370 else
371 write (out%dbfile) m, n, p, out%dbvars
372 end if
373
374 if (n == 0 .and. proc_rank == 0) then
375 write (file_loc, '(A,I0,A)') '/', t_step, '.dat'
376 file_loc = trim(out%rootdir) // trim(file_loc)
377
378 open (out%dbroot, iostat=err, file=trim(file_loc), form='unformatted', status='replace')
379
380 if (err /= 0) then
381 call s_mpi_abort('Unable to create Binary database ' // 'master file ' // trim(file_loc) // '. Exiting.')
382 end if
383
384 if (output_partial_domain) then
385 write (out%dbroot) x_output_idx%end - x_output_idx%beg, 0, 0, out%dbvars
386 else
387 write (out%dbroot) m_root, 0, 0, out%dbvars
388 end if
389 end if
390 end if
391
392 end subroutine s_open_formatted_database_file
393
394 !> Open the interface data file for appending extracted interface coordinates.
395 impure subroutine s_open_intf_data_file()
396
397 character(LEN=path_len + 3*name_len) :: file_path
398
399 write (file_path, '(A)') '/intf_data.dat'
400 file_path = trim(case_dir) // trim(file_path)
401
402 open (211, file=trim(file_path), form='formatted', position='append', status='unknown')
403
404 end subroutine s_open_intf_data_file
405
406 !> Open the energy data file for appending volume-integrated energy budget quantities.
407 impure subroutine s_open_energy_data_file()
408
409 character(LEN=path_len + 3*name_len) :: file_path
410
411 write (file_path, '(A)') '/eng_data.dat'
412 file_path = trim(case_dir) // trim(file_path)
413
414 open (251, file=trim(file_path), form='formatted', position='append', status='unknown')
415
416 end subroutine s_open_energy_data_file
417
418 !> Write the computational grid (cell-boundary coordinates) to the formatted database slave and master files.
420
421 integer, intent(in) :: t_step
422
423 ! NAG compiler requires these to be statically sized
424 character(LEN=4*name_len), dimension(num_procs) :: meshnames
425 integer, dimension(num_procs) :: meshtypes
426 integer :: i
427 integer :: ierr
428 !> DBADDDOPT takes doubles whatever wp is. Allocated explicitly, never by assignment: ifx/ifort default to -assume
429 !! norealloc_lhs, where assigning to an unallocated allocatable is an error, not an allocation.
430 real(dp), allocatable :: extents_dp(:,:)
431 integer :: extents_size
432
433 if (format == format_silo) then
434 ! For multidimensional data sets, the spatial extents of all of the grid(s) handled by the local processor(s) are
435 ! recorded so that they may be written, by root processor, to the formatted database master file.
436 if (num_procs > 1) then
437 call s_mpi_gather_spatial_extents(out%spatial_extents)
438 else if (p > 0) then
439 if (grid_geometry == 3) then
440 out%spatial_extents(:,0) = (/minval(y_cb), minval(z_cb), minval(x_cb), maxval(y_cb), maxval(z_cb), &
441 & maxval(x_cb)/)
442 else
443 out%spatial_extents(:,0) = (/minval(x_cb), minval(y_cb), minval(z_cb), maxval(x_cb), maxval(y_cb), &
444 & maxval(z_cb)/)
445 end if
446 else if (n > 0) then
447 out%spatial_extents(:,0) = (/minval(x_cb), minval(y_cb), maxval(x_cb), maxval(y_cb)/)
448 else
449 out%spatial_extents(:,0) = (/minval(x_cb), maxval(x_cb)/)
450 end if
451
452 ! Next, the root processor proceeds to record all of the spatial extents in the formatted database master file. In
453 ! addition, it also records a sub-domain connectivity map so that the entire grid may be reassembled by looking at the
454 ! master file.
455 if (proc_rank == 0) then
456 do i = 1, num_procs
457 write (meshnames(i), '(A,I0,A,I0,A)') '../p', i - 1, '/', t_step, '.silo:rectilinear_grid'
458 end do
459
460 meshtypes = db_quad_rect
461
462 err = dbset2dstrlen(len(meshnames(1)))
463 err = dbmkoptlist(2, out%optlist)
464 extents_size = size(out%spatial_extents, 1)
465 err = dbaddiopt(out%optlist, dbopt_extents_size, extents_size)
466 allocate (extents_dp(size(out%spatial_extents, 1), size(out%spatial_extents, 2)))
467 extents_dp = real(out%spatial_extents, dp)
468 err = dbadddopt(out%optlist, dbopt_extents, extents_dp)
469 err = dbputmmesh(out%dbroot, 'rectilinear_grid', 16, num_procs, meshnames, len_trim(meshnames), meshtypes, &
470 & out%optlist, ierr)
471 err = dbfreeoptlist(out%optlist)
472 deallocate (extents_dp)
473 end if
474
475 ! Finally, the local quadrilateral mesh, either 2D or 3D, along with its offsets that indicate the presence and size of
476 ! ghost zone layer(s), are put in the formatted database slave file.
477
478 ! Silo carries the mesh coordinates in their own datatype, separate from the flow variables, so the cell boundaries
479 ! are copied down to single precision here when that is what was asked for. Without this the mesh is always written as
480 ! DB_DOUBLE, which keeps downstream readers on a double-precision path regardless of `precision`.
481 if (precision == precision_single) then
482 x_cb_s = real(x_cb, sp)
483 if (n > 0) then
484 y_cb_s = real(y_cb, sp)
485 if (p > 0) z_cb_s = real(z_cb, sp)
486 end if
487 end if
488
489 if (p > 0) then
490 err = dbmkoptlist(2, out%optlist)
491 err = dbaddiaopt(out%optlist, dbopt_lo_offset, size(out%lo_offset), out%lo_offset)
492 err = dbaddiaopt(out%optlist, dbopt_hi_offset, size(out%hi_offset), out%hi_offset)
493# 413 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
494 if (precision == 1) then
495# 414 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
496 if (grid_geometry == 3) then
497 err = dbputqm(out%dbfile, 'rectilinear_grid', 16, 'x', 1, 'y', 1, 'z', 1, y_cb_s, z_cb_s, &
498# 416 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
499 & x_cb_s, out%dims, 3, db_float, db_collinear, out%optlist, ierr)
500# 417 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
501 else
502 err = dbputqm(out%dbfile, 'rectilinear_grid', 16, 'x', 1, 'y', 1, 'z', 1, x_cb_s, y_cb_s, &
503# 419 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
504 & z_cb_s, out%dims, 3, db_float, db_collinear, out%optlist, ierr)
505# 420 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
506 end if
507 end if
508# 413 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
509 if (precision == 2) then
510# 414 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
511 if (grid_geometry == 3) then
512 err = dbputqm(out%dbfile, 'rectilinear_grid', 16, 'x', 1, 'y', 1, 'z', 1, y_cb, z_cb, &
513# 416 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
514 & x_cb, out%dims, 3, db_real, db_collinear, out%optlist, ierr)
515# 417 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
516 else
517 err = dbputqm(out%dbfile, 'rectilinear_grid', 16, 'x', 1, 'y', 1, 'z', 1, x_cb, y_cb, &
518# 419 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
519 & z_cb, out%dims, 3, db_real, db_collinear, out%optlist, ierr)
520# 420 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
521 end if
522 end if
523# 423 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
524 err = dbfreeoptlist(out%optlist)
525 else if (n > 0) then
526 err = dbmkoptlist(2, out%optlist)
527 err = dbaddiaopt(out%optlist, dbopt_lo_offset, size(out%lo_offset), out%lo_offset)
528 err = dbaddiaopt(out%optlist, dbopt_hi_offset, size(out%hi_offset), out%hi_offset)
529# 429 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
530 if (precision == 1) then
531# 430 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
532 err = dbputqm(out%dbfile, 'rectilinear_grid', 16, 'x', 1, 'y', 1, 'z', 1, x_cb_s, y_cb_s, &
533# 431 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
534 & db_f77null, out%dims, 2, db_float, db_collinear, out%optlist, ierr)
535# 432 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
536 end if
537# 429 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
538 if (precision == 2) then
539# 430 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
540 err = dbputqm(out%dbfile, 'rectilinear_grid', 16, 'x', 1, 'y', 1, 'z', 1, x_cb, y_cb, &
541# 431 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
542 & db_f77null, out%dims, 2, db_real, db_collinear, out%optlist, ierr)
543# 432 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
544 end if
545# 434 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
546 err = dbfreeoptlist(out%optlist)
547 else
548 err = dbmkoptlist(2, out%optlist)
549 err = dbaddiaopt(out%optlist, dbopt_lo_offset, size(out%lo_offset), out%lo_offset)
550 err = dbaddiaopt(out%optlist, dbopt_hi_offset, size(out%hi_offset), out%hi_offset)
551# 440 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
552 if (precision == 1) then
553# 441 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
554 err = dbputqm(out%dbfile, 'rectilinear_grid', 16, 'x', 1, 'y', 1, 'z', 1, x_cb_s, db_f77null, &
555# 442 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
556 & db_f77null, out%dims, 1, db_float, db_collinear, out%optlist, ierr)
557# 443 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
558 end if
559# 440 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
560 if (precision == 2) then
561# 441 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
562 err = dbputqm(out%dbfile, 'rectilinear_grid', 16, 'x', 1, 'y', 1, 'z', 1, x_cb, db_f77null, &
563# 442 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
564 & db_f77null, out%dims, 1, db_real, db_collinear, out%optlist, ierr)
565# 443 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
566 end if
567# 445 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
568 err = dbfreeoptlist(out%optlist)
569 end if
570 else if (format == format_binary) then
571 ! Multidimensional local grid data is written to the formatted database slave file. Recall that no master file to
572 ! maintained in multidimensions.
573 if (p > 0) then
574 if (precision == precision_single) then
575 write (out%dbfile) real(x_cb, sp), real(y_cb, sp), real(z_cb, sp)
576 else
577 if (output_partial_domain) then
578 write (out%dbfile) x_cb(x_output_idx%beg - 1:x_output_idx%end), &
579 & y_cb(y_output_idx%beg - 1:y_output_idx%end), z_cb(z_output_idx%beg - 1:z_output_idx%end)
580 else
581 write (out%dbfile) x_cb, y_cb, z_cb
582 end if
583 end if
584 else if (n > 0) then
585 if (precision == precision_single) then
586 write (out%dbfile) real(x_cb, sp), real(y_cb, sp)
587 else
588 if (output_partial_domain) then
589 write (out%dbfile) x_cb(x_output_idx%beg - 1:x_output_idx%end), y_cb(y_output_idx%beg - 1:y_output_idx%end)
590 else
591 write (out%dbfile) x_cb, y_cb
592 end if
593 end if
594
595 ! One-dimensional local grid data is written to the formatted database slave file. In addition, the local grid data
596 ! is put together by the root process and written to the master file.
597 else
598 if (precision == precision_single) then
599 write (out%dbfile) real(x_cb, sp)
600 else
601 if (output_partial_domain) then
602 write (out%dbfile) x_cb(x_output_idx%beg - 1:x_output_idx%end)
603 else
604 write (out%dbfile) x_cb
605 end if
606 end if
607
608 if (num_procs > 1) then
610 else
611 x_root_cb(:) = x_cb(:)
612 end if
613
614 if (proc_rank == 0) then
615 if (precision == precision_single) then
616 write (out%dbroot) real(x_root_cb, wp)
617 else
618 if (output_partial_domain) then
619 write (out%dbroot) x_root_cb(x_output_idx%beg - 1:x_output_idx%end)
620 else
621 write (out%dbroot) x_root_cb
622 end if
623 end if
624 end if
625 end if
626 end if
627
629
630 !> Write a single flow variable field to the formatted database slave and master files for a given time step.
631 impure subroutine s_write_variable_to_formatted_database_file(varname, t_step)
632
633 character(LEN=*), intent(in) :: varname
634 integer, intent(in) :: t_step
635 !> see s_open_formatted_database_file: allocated explicitly for -assume norealloc_lhs
636 real(dp), allocatable :: extents_dp(:,:)
637
638 ! NAG compiler requires these to be statically sized
639 character(LEN=4*name_len), dimension(num_procs) :: varnames
640 integer, dimension(num_procs) :: vartypes
641 integer :: i, j, k
642 integer :: ierr
643 integer :: extents_size
644
645 if (format == format_silo) then
646 ! Determining the extents of the flow variable on each local process and gathering all this information on root process
647 if (num_procs > 1) then
648 call s_mpi_gather_data_extents(out%q_sf, out%data_extents)
649 else
650 out%data_extents(:,0) = (/minval(out%q_sf), maxval(out%q_sf)/)
651 end if
652
653 if (proc_rank == 0) then
654 do i = 1, num_procs
655 write (varnames(i), '(A,I0,A,I0,A)') '../p', i - 1, '/', t_step, '.silo:' // trim(varname)
656 end do
657
658 vartypes = db_quadvar
659
660 err = dbset2dstrlen(len(varnames(1)))
661 err = dbmkoptlist(2, out%optlist)
662 extents_size = size(out%data_extents, 1)
663 err = dbaddiopt(out%optlist, dbopt_extents_size, extents_size)
664 allocate (extents_dp(size(out%data_extents, 1), size(out%data_extents, 2)))
665 extents_dp = real(out%data_extents, dp)
666 err = dbadddopt(out%optlist, dbopt_extents, extents_dp)
667 err = dbputmvar(out%dbroot, trim(varname), len_trim(varname), num_procs, varnames, len_trim(varnames), vartypes, &
668 & out%optlist, ierr)
669 err = dbfreeoptlist(out%optlist)
670 deallocate (extents_dp)
671 end if
672
673 if (wp == dp) then
674 if (precision == precision_single) then
675 do i = -offset_x%beg, m + offset_x%end
676 do j = -offset_y%beg, n + offset_y%end
677 do k = -offset_z%beg, p + offset_z%end
678 out%q_sf_s(i, j, k) = real(out%q_sf(i, j, k), sp)
679 end do
680 end do
681 end do
682 if (grid_geometry == 3) then
683 do i = -offset_x%beg, m + offset_x%end
684 do j = -offset_y%beg, n + offset_y%end
685 do k = -offset_z%beg, p + offset_z%end
686 out%cyl_q_sf_s(j, k, i) = out%q_sf_s(i, j, k)
687 end do
688 end do
689 end do
690 end if
691 else
692 if (grid_geometry == 3) then
693 do i = -offset_x%beg, m + offset_x%end
694 do j = -offset_y%beg, n + offset_y%end
695 do k = -offset_z%beg, p + offset_z%end
696 out%cyl_q_sf(j, k, i) = out%q_sf(i, j, k)
697 end do
698 end do
699 end do
700 end if
701 end if
702 else if (wp == sp) then
703 do i = -offset_x%beg, m + offset_x%end
704 do j = -offset_y%beg, n + offset_y%end
705 do k = -offset_z%beg, p + offset_z%end
706 out%q_sf_s(i, j, k) = out%q_sf(i, j, k)
707 end do
708 end do
709 end do
710 if (grid_geometry == 3) then
711 do i = -offset_x%beg, m + offset_x%end
712 do j = -offset_y%beg, n + offset_y%end
713 do k = -offset_z%beg, p + offset_z%end
714 out%cyl_q_sf_s(j, k, i) = out%q_sf_s(i, j, k)
715 end do
716 end do
717 end do
718 end if
719 end if
720
721# 599 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
722 if (precision == 1) then
723# 600 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
724 if (p > 0) then
725 if (grid_geometry == 3) then
726 err = dbputqv1(out%dbfile, trim(varname), len_trim(varname), 'rectilinear_grid', 16, &
727 & out%cyl_q_sf_s, out%dims - 1, 3, db_f77null, 0, db_float, db_zonecent, &
728# 604 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
729 & db_f77null, ierr)
730 else
731 err = dbputqv1(out%dbfile, trim(varname), len_trim(varname), 'rectilinear_grid', 16, out%q_sf_s, &
732# 607 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
733 & out%dims - 1, 3, db_f77null, 0, db_float, db_zonecent, db_f77null, ierr)
734# 608 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
735 end if
736 else if (n > 0) then
737 err = dbputqv1(out%dbfile, trim(varname), len_trim(varname), 'rectilinear_grid', 16, out%q_sf_s, &
738# 611 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
739 & out%dims - 1, 2, db_f77null, 0, db_float, db_zonecent, db_f77null, ierr)
740# 612 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
741 else
742 err = dbputqv1(out%dbfile, trim(varname), len_trim(varname), 'rectilinear_grid', 16, out%q_sf_s, &
743# 614 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
744 & out%dims - 1, 1, db_f77null, 0, db_float, db_zonecent, db_f77null, ierr)
745# 615 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
746 end if
747 end if
748# 599 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
749 if (precision == 2) then
750# 600 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
751 if (p > 0) then
752 if (grid_geometry == 3) then
753 err = dbputqv1(out%dbfile, trim(varname), len_trim(varname), 'rectilinear_grid', 16, &
754 & out%cyl_q_sf, out%dims - 1, 3, db_f77null, 0, db_double, db_zonecent, &
755# 604 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
756 & db_f77null, ierr)
757 else
758 err = dbputqv1(out%dbfile, trim(varname), len_trim(varname), 'rectilinear_grid', 16, out%q_sf, &
759# 607 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
760 & out%dims - 1, 3, db_f77null, 0, db_double, db_zonecent, db_f77null, ierr)
761# 608 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
762 end if
763 else if (n > 0) then
764 err = dbputqv1(out%dbfile, trim(varname), len_trim(varname), 'rectilinear_grid', 16, out%q_sf, &
765# 611 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
766 & out%dims - 1, 2, db_f77null, 0, db_double, db_zonecent, db_f77null, ierr)
767# 612 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
768 else
769 err = dbputqv1(out%dbfile, trim(varname), len_trim(varname), 'rectilinear_grid', 16, out%q_sf, &
770# 614 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
771 & out%dims - 1, 1, db_f77null, 0, db_double, db_zonecent, db_f77null, ierr)
772# 615 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
773 end if
774 end if
775# 618 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
776 else
777 ! Writing the name of the flow variable and its data, associated with the local processor, to the formatted database
778 ! slave file
779 out%dbvars = out%dbvars + 1
780 if (precision == precision_single) then
781 write (out%dbfile) varname, real(out%q_sf, wp)
782 else
783 write (out%dbfile) varname, out%q_sf
784 end if
785
786 ! In 1D, the root process also takes care of gathering the flow variable data from all of the local processor(s) and
787 ! writes it to the formatted database master file.
788 if (n == 0) then
789 if (num_procs > 1) then
790 call s_mpi_defragment_1d_flow_variable(out%q_sf, out%q_root_sf)
791 else
792 out%q_root_sf(:,:,:) = out%q_sf(:,:,:)
793 end if
794
795 if (proc_rank == 0) then
796 if (precision == precision_single) then
797 write (out%dbroot) varname, real(out%q_root_sf, wp)
798 else
799 write (out%dbroot) varname, out%q_root_sf
800 end if
801 end if
802 end if
803 end if
804
806
807 !> Overlay the AMR refined solution. Each owned fine block is written as an extra rectilinear quadmesh (Silo) or an appended
808 !! block record (binary), carrying the primitive fields (mixture density, velocities, pressure, volume fractions) at true fine
809 !! resolution. On rank 0 the Silo block meshes/vars are registered into the /root 'amr_blocks' multimesh and 'amr_<var>'
810 !! multivars so VisIt/ParaView overlays them on the coarse 'rectilinear_grid'. Guarded by `amr` at the caller; a no-op when no
811 !! fine blocks are present. Binary layout per rank: an integer block count, then per block a header [lo(3), hi(3), m, n, p,
812 !! nvars], the fine cell boundaries (x_cb, then y_cb/z_cb if active), then per variable a [name, field] record (same convention
813 !! as the coarse binary variables).
815
816 integer, intent(in) :: t_step
817 character(LEN=name_len), allocatable :: vnames(:)
818 real(wp), allocatable, dimension(:,:,:) :: vbuf
819 type(scalar_field), allocatable, dimension(:) :: q_prim_blk
820 type(scalar_field) :: q_t_blk
821 type(int_bounds_info) :: ibnd(3)
822 character(LEN=4*name_len), allocatable :: entry(:)
823 integer, allocatable :: etypes(:), counts(:)
824 character(LEN=4*name_len) :: mname, mvar
825 integer :: ndims, dims(3), vdims(3), nvars, nadv
826 integer :: k, i, ii, d, fm, fn, fp, ierr, r, kk, tot, e
827
828 ! Variable list (same order used both for writing and for the /root multivar registration).
829
830 nadv = eqn_idx%adv%end - eqn_idx%adv%beg + 1
831 nvars = 2 + num_dims + nadv
832 allocate (vnames(nvars))
833 vnames(1) = 'rho'; vnames(2) = 'pres'
834 do d = 1, num_dims
835 write (vnames(2 + d), '(A,I0)') 'vel', d
836 end do
837 do i = 1, nadv
838 write (vnames(2 + num_dims + i), '(A,I0)') 'alpha', i
839 end do
840
841 if (format == format_binary) write (out%dbfile) amr_num_fine
842
843 do k = 1, amr_num_fine
844 fm = amr_fine(k)%m; fn = amr_fine(k)%n; fp = amr_fine(k)%p
845
846 ! Convert this block's fine conservative state to primitives (same routine as the coarse path).
847 allocate (q_prim_blk(1:sys_size))
848 do i = 1, sys_size
849 allocate (q_prim_blk(i)%sf(0:fm,0:fn,0:fp))
850 end do
851 allocate (q_t_blk%sf(0:fm,0:fn,0:fp))
852 ibnd(1)%beg = 0; ibnd(1)%end = fm
853 ibnd(2)%beg = 0; ibnd(2)%end = fn
854 ibnd(3)%beg = 0; ibnd(3)%end = fp
855 ! seed the temperature guess from the fine conservative state (the reacting-EOS cons->prim
856 ! uses q_T as its Newton initial guess); without this q_T_blk is uninitialized -> NaN under
857 ! bounds-checked/NaN-init builds, mirroring the coarse path (m_start_up: s_compute_q_T_sf)
858 if (chemistry) call s_compute_q_t_sf(q_t_blk, amr_fine(k)%q_cons, ibnd)
859 ! block-local indices exceed the coarse-grid mixture caches (rho_sf etc.) when a pinned block cap is larger
860 ! than the rank subdomain: do not store them (out-of-bounds writes corrupt the heap)
861 skip_mixture_store = .true.
862 call s_convert_conservative_to_primitive_variables(amr_fine(k)%q_cons, q_t_blk, q_prim_blk, ibnd)
863 skip_mixture_store = .false.
864
865 if (fp > 0) then
866 ndims = 3
867 else if (fn > 0) then
868 ndims = 2
869 else
870 ndims = 1
871 end if
872 dims = (/fm + 2, fn + 2, fp + 2/) ! cell-boundary counts per active dim
873 vdims = (/fm + 1, fn + 1, fp + 1/) ! zone counts per active dim
874
875 write (mname, '(A,I0,A,I0)') 'amr_blk', proc_rank, '_', k
876
877 if (format == format_silo) then
878 if (ndims == 3) then
879 err = dbputqm(out%dbfile, trim(mname), len_trim(mname), 'x', 1, 'y', 1, 'z', 1, amr_fine(k)%x_cb, &
880 & amr_fine(k)%y_cb, amr_fine(k)%z_cb, dims, 3, db_real, db_collinear, db_f77null, ierr)
881 else if (ndims == 2) then
882 err = dbputqm(out%dbfile, trim(mname), len_trim(mname), 'x', 1, 'y', 1, 'z', 1, amr_fine(k)%x_cb, &
883 & amr_fine(k)%y_cb, db_f77null, dims, 2, db_real, db_collinear, db_f77null, ierr)
884 else
885 err = dbputqm(out%dbfile, trim(mname), len_trim(mname), 'x', 1, 'y', 1, 'z', 1, amr_fine(k)%x_cb, db_f77null, &
886 & db_f77null, dims, 1, db_real, db_collinear, db_f77null, ierr)
887 end if
888 else
889 write (out%dbfile) amr_fine(k)%lo, amr_fine(k)%hi, fm, fn, fp, nvars
890 write (out%dbfile) amr_fine(k)%x_cb
891 if (fn > 0) write (out%dbfile) amr_fine(k)%y_cb
892 if (fp > 0) write (out%dbfile) amr_fine(k)%z_cb
893 end if
894
895 allocate (vbuf(0:fm,0:fn,0:fp))
896 do ii = 1, nvars
897 if (ii == 1) then
898 vbuf = 0._wp
899 do i = eqn_idx%cont%beg, eqn_idx%cont%end
900 vbuf = vbuf + real(amr_fine(k)%q_cons(i)%sf(0:fm,0:fn,0:fp), wp)
901 end do
902 else if (ii == 2) then
903 vbuf = real(q_prim_blk(eqn_idx%E)%sf, wp)
904 else if (ii <= 2 + num_dims) then
905 vbuf = real(q_prim_blk(eqn_idx%mom%beg + (ii - 3))%sf, wp)
906 else
907 vbuf = real(q_prim_blk(eqn_idx%adv%beg + (ii - 3 - num_dims))%sf, wp)
908 end if
909 call s_put_amr_block_variable(trim(vnames(ii)))
910 end do
911 deallocate (vbuf)
912
913 do i = 1, sys_size
914 deallocate (q_prim_blk(i)%sf)
915 end do
916 deallocate (q_prim_blk, q_t_blk%sf)
917 end do
918
919 ! Register the block meshes/vars in the /root collection so they appear alongside the coarse multimesh (Silo only).
920 if (format == format_silo) then
921 allocate (counts(0:num_procs - 1))
922#ifdef MFC_MPI
923 call mpi_gather(amr_num_fine, 1, mpi_integer, counts, 1, mpi_integer, 0, mpi_comm_world, ierr)
924#else
925 counts(0) = amr_num_fine
926#endif
927 if (proc_rank == 0) then
928 tot = sum(counts)
929 if (tot > 0) then
930 allocate (entry(tot), etypes(tot))
931 e = 0
932 do r = 0, num_procs - 1
933 do kk = 1, counts(r)
934 e = e + 1
935 write (entry(e), '(A,I0,A,I0,A,I0,A,I0)') '../p', r, '/', t_step, '.silo:amr_blk', r, '_', kk
936 end do
937 end do
938 etypes = db_quad_rect
939 err = dbset2dstrlen(len(entry(1)))
940 err = dbputmmesh(out%dbroot, 'amr_blocks', 10, tot, entry, len_trim(entry), etypes, db_f77null, ierr)
941 etypes = db_quadvar
942 do ii = 1, nvars
943 e = 0
944 do r = 0, num_procs - 1
945 do kk = 1, counts(r)
946 e = e + 1
947 write (entry(e), '(A,I0,A,I0,A,A,A,I0,A,I0)') '../p', r, '/', t_step, '.silo:', trim(vnames(ii)), &
948 & '_amr', r, '_', kk
949 end do
950 end do
951 write (mvar, '(A,A)') 'amr_', trim(vnames(ii))
952 err = dbset2dstrlen(len(entry(1)))
953 err = dbputmvar(out%dbroot, trim(mvar), len_trim(mvar), tot, entry, len_trim(entry), etypes, db_f77null, &
954 & ierr)
955 end do
956 deallocate (entry, etypes)
957 end if
958 end if
959 deallocate (counts)
960 end if
961
962 deallocate (vnames)
963
964 contains
965
966 !> Write the already-filled `vbuf` for the current block `k` as variable `nm`: a Silo quadvar on the block mesh, or a [name,
967 !! field] binary record. Object names are unique per rank+block (`<nm>_amr<rank>_<k>`).
968 impure subroutine s_put_amr_block_variable(nm)
969
970 character(LEN=*), intent(in) :: nm
971 character(LEN=4*name_len) :: vn
972 integer :: ie
973
974 write (vn, '(A,A,I0,A,I0)') nm, '_amr', proc_rank, '_', k
975 if (format == format_silo) then
976 ie = dbputqv1(out%dbfile, trim(vn), len_trim(vn), trim(mname), len_trim(mname), vbuf, vdims, ndims, db_f77null, &
977 & 0, db_real, db_zonecent, db_f77null, ierr)
978 else
979 write (out%dbfile) vn, vbuf
980 end if
981
982 end subroutine s_put_amr_block_variable
983
985
986 !> Write the post-processed results in the folder 'lag_bubbles_data'
987 impure subroutine s_write_lag_bubbles_results_to_text(t_step)
988
989 integer, intent(in) :: t_step
990 character(len=len_trim(case_dir) + 3*name_len) :: file_loc
991 integer :: id
992
993#ifdef MFC_MPI
994 real(wp), dimension(20) :: inputvals
995 real(wp) :: time_real
996 integer, dimension(MPI_STATUS_SIZE) :: status
997 integer(KIND=MPI_OFFSET_KIND) :: disp
998 integer :: view
999 logical :: file_exist
1000 integer, dimension(2) :: gsizes, lsizes, start_idx_part
1001 integer :: ifile
1002 integer :: ierr
1003 real(wp) :: file_time, file_dt
1004 integer :: file_num_procs, file_tot_part
1005 integer :: i
1006 integer, dimension(:), allocatable :: proc_bubble_counts
1007 real(wp), dimension(1:1,1:lag_io_vars) :: lag_io_null
1008
1009 lag_io_null = 0._wp
1010
1011 ! Construct file path
1012 write (file_loc, '(A,I0,A)') trim(lag_name) // '_', t_step, '.dat'
1013 file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // trim(file_loc)
1014
1015 ! Check if file exists
1016 inquire (file=trim(file_loc), exist=file_exist)
1017 if (.not. file_exist) then
1018 call s_mpi_abort('Restart file ' // trim(file_loc) // ' does not exist!')
1019 end if
1020
1021 if (.not. parallel_io) return
1022
1023 if (proc_rank == 0) then
1024 call mpi_file_open(mpi_comm_self, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
1025 call s_check_mpi_file_open(ierr, file_loc)
1026
1027 call mpi_file_read(ifile, file_tot_part, 1, mpi_integer, status, ierr)
1028 call mpi_file_read(ifile, file_time, 1, mpi_p, status, ierr)
1029 call mpi_file_read(ifile, file_dt, 1, mpi_p, status, ierr)
1030 call mpi_file_read(ifile, file_num_procs, 1, mpi_integer, status, ierr)
1031
1032 call mpi_file_close(ifile, ierr)
1033 end if
1034
1035 call mpi_bcast(file_tot_part, 1, mpi_integer, 0, mpi_comm_world, ierr)
1036 call mpi_bcast(file_time, 1, mpi_p, 0, mpi_comm_world, ierr)
1037 call mpi_bcast(file_dt, 1, mpi_p, 0, mpi_comm_world, ierr)
1038 call mpi_bcast(file_num_procs, 1, mpi_integer, 0, mpi_comm_world, ierr)
1039 time_real = file_time
1040
1041 allocate (proc_bubble_counts(file_num_procs))
1042
1043 if (proc_rank == 0) then
1044 call mpi_file_open(mpi_comm_self, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
1045 call s_check_mpi_file_open(ierr, file_loc)
1046
1047 ! Skip to processor counts position
1048 disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs), mpi_offset_kind)
1049 call mpi_file_seek(ifile, disp, mpi_seek_set, ierr)
1050 call mpi_file_read(ifile, proc_bubble_counts, file_num_procs, mpi_integer, status, ierr)
1051
1052 call mpi_file_close(ifile, ierr)
1053 end if
1054
1055 call mpi_bcast(proc_bubble_counts, file_num_procs, mpi_integer, 0, mpi_comm_world, ierr)
1056
1057 if (file_tot_part > 0) then
1058 gsizes(1) = file_tot_part
1059 gsizes(2) = lag_io_vars
1060 lsizes(1) = file_tot_part
1061 lsizes(2) = lag_io_vars
1062 start_idx_part(1) = 0
1063 start_idx_part(2) = 0
1064
1065 call mpi_type_create_subarray(2, gsizes, lsizes, start_idx_part, mpi_order_fortran, mpi_p, view, ierr)
1066 call mpi_type_commit(view, ierr)
1067
1068 call mpi_file_open(mpi_comm_world, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
1069 call s_check_mpi_file_open(ierr, file_loc)
1070
1071 disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs) &
1072 & + file_num_procs*sizeof(proc_bubble_counts(1)), mpi_offset_kind)
1073 call mpi_file_set_view(ifile, disp, mpi_p, view, 'native', mpi_info_null, ierr)
1074
1075 allocate (mpi_io_data_lg_bubbles(file_tot_part,1:lag_io_vars))
1076
1077 call mpi_file_read_all(ifile, mpi_io_data_lg_bubbles, lag_io_vars*file_tot_part, mpi_p, status, ierr)
1078
1079 write (file_loc, '(A,I0,A)') trim(lag_name) // '_post_process_', t_step, '.dat'
1080 file_loc = trim(case_dir) // '/' // trim(lag_name) // '_post_process/' // trim(file_loc)
1081
1082 if (proc_rank == 0) then
1083 open (unit=29, file=file_loc, form='formatted', position='rewind')
1084
1085 if (lag_header) then
1086 write (29, '(A)', advance='no')
1087 if (lag_id_wrt) write (29, '(A8)', advance='no') 'id, '
1088 if (lag_pos_wrt) write (29, '(3(A17))', advance='no') 'px, ', 'py, ', 'pz, '
1089 if (lag_pos_prev_wrt) write (29, '(3(A17))', advance='no') 'pvx, ', 'pvy, ', 'pvz, '
1090 if (lag_vel_wrt) write (29, '(3(A17))', advance='no') 'vx, ', 'vy, ', 'vz, '
1091 if (lag_rad_wrt) write (29, '(A17)', advance='no') 'radius, '
1092 if (lag_rvel_wrt) write (29, '(A17)', advance='no') 'rvel, '
1093 if (lag_r0_wrt) write (29, '(A17)', advance='no') 'r0, '
1094 if (lag_rmax_wrt) write (29, '(A17)', advance='no') 'rmax, '
1095 if (lag_rmin_wrt) write (29, '(A17)', advance='no') 'rmin, '
1096 if (lag_dphidt_wrt) write (29, '(A17)', advance='no') 'dphidt, '
1097 if (lag_pres_wrt) write (29, '(A17)', advance='no') 'pressure, '
1098 if (lag_mv_wrt) write (29, '(A17)', advance='no') 'mv, '
1099 if (lag_mg_wrt) write (29, '(A17)', advance='no') 'mg, '
1100 if (lag_betat_wrt) write (29, '(A17)', advance='no') 'betaT, '
1101 if (lag_betac_wrt) write (29, '(A17)', advance='no') 'betaC, '
1102 if (lag_voidfrac_wrt) write (29, '(A17)', advance='no') 'voidFraction, '
1103 write (29, '(A15)') 'time'
1104 end if
1105
1106 do i = 1, file_tot_part
1107 id = int(mpi_io_data_lg_bubbles(i, 1))
1108 inputvals(1:20) = mpi_io_data_lg_bubbles(i,2:21)
1109 if (id > 0) then
1110 write (29, '(100(A))', advance='no') ''
1111 if (lag_id_wrt) write (29, '(I6, A)', advance='no') id, ', '
1112 if (lag_pos_wrt) write (29, '(3(E15.7, A))', advance='no') inputvals(1), ', ', inputvals(2), ', ', &
1113 & inputvals(3), ', '
1114 if (lag_pos_prev_wrt) write (29, '(3(E15.7, A))', advance='no') inputvals(4), ', ', inputvals(5), ', ', &
1115 & inputvals(6), ', '
1116 if (lag_vel_wrt) write (29, '(3(E15.7, A))', advance='no') inputvals(7), ', ', inputvals(8), ', ', &
1117 & inputvals(9), ', '
1118 if (lag_rad_wrt) write (29, '(E15.7, A)', advance='no') inputvals(10), ', '
1119 if (lag_rvel_wrt) write (29, '(E15.7, A)', advance='no') inputvals(11), ', '
1120 if (lag_r0_wrt) write (29, '(E15.7, A)', advance='no') inputvals(12), ', '
1121 if (lag_rmax_wrt) write (29, '(E15.7, A)', advance='no') inputvals(13), ', '
1122 if (lag_rmin_wrt) write (29, '(E15.7, A)', advance='no') inputvals(14), ', '
1123 if (lag_dphidt_wrt) write (29, '(E15.7, A)', advance='no') inputvals(15), ', '
1124 if (lag_pres_wrt) write (29, '(E15.7, A)', advance='no') inputvals(16), ', '
1125 if (lag_mv_wrt) write (29, '(E15.7, A)', advance='no') inputvals(17), ', '
1126 if (lag_mg_wrt) write (29, '(E15.7, A)', advance='no') inputvals(18), ', '
1127 if (lag_betat_wrt) write (29, '(E15.7, A)', advance='no') inputvals(19), ', '
1128 if (lag_betac_wrt) write (29, '(E15.7, A)', advance='no') inputvals(20), ', '
1129 ! Column 12: bubble radial velocity, or particle volume fraction for particles
1130 if (lag_voidfrac_wrt) write (29, '(E15.7, A)', advance='no') inputvals(11), ', '
1131 write (29, '(E15.7)') time_real
1132 end if
1133 end do
1134 close (29)
1135 end if
1136
1137 deallocate (mpi_io_data_lg_bubbles)
1138
1139 call s_mpi_barrier()
1140
1141 call mpi_file_close(ifile, ierr)
1142 else
1143 call mpi_type_contiguous(0, mpi_p, view, ierr)
1144 call mpi_type_commit(view, ierr)
1145
1146 call mpi_file_open(mpi_comm_world, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
1147 call s_check_mpi_file_open(ierr, file_loc)
1148
1149 disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs) &
1150 & + file_num_procs*sizeof(proc_bubble_counts(1)), mpi_offset_kind)
1151 call mpi_file_set_view(ifile, disp, mpi_p, view, 'native', mpi_info_null, ierr)
1152
1153 call mpi_file_read_all(ifile, lag_io_null, 0, mpi_p, status, ierr)
1154
1155 call mpi_file_close(ifile, ierr)
1156 call mpi_type_free(view, ierr)
1157 end if
1158#endif
1159
1161
1162 !> Read Lagrangian bubble restart data and write bubble positions and scalar fields to the Silo database.
1164
1165 integer, intent(in) :: t_step
1166 character(len=len_trim(case_dir) + 3*name_len) :: file_loc
1167 integer :: id
1168
1169#ifdef MFC_MPI
1170 real(wp) :: time_real
1171 integer, dimension(MPI_STATUS_SIZE) :: status
1172 integer(KIND=MPI_OFFSET_KIND) :: disp
1173 integer :: view
1174 logical :: file_exist
1175 integer, dimension(2) :: gsizes, lsizes, start_idx_part
1176 integer :: ifile, ierr, nbub
1177 real(wp) :: file_time, file_dt
1178 integer :: file_num_procs, file_tot_part
1179 integer, dimension(:), allocatable :: proc_bubble_counts
1180 real(wp), dimension(1:1,1:lag_io_vars) :: dummy
1181 character(LEN=4*name_len), dimension(num_procs) :: meshnames
1182 integer, dimension(num_procs) :: meshtypes
1183 real(wp) :: dummy_data
1184 integer :: i
1185 real(wp), dimension(:), allocatable :: bub_id
1186 real(wp), dimension(:), allocatable :: px, py, pz, ppx, ppy, ppz, vx, vy, vz
1187 real(wp), dimension(:), allocatable :: radius, rvel, rnot, rmax, rmin, dphidt
1188 real(wp), dimension(:), allocatable :: pressure, mv, mg, betat, betac
1189
1190 dummy = 0._wp
1191 dummy_data = 0._wp
1192
1193 ! Construct file path
1194 write (file_loc, '(A,I0,A)') trim(lag_name) // '_', t_step, '.dat'
1195 file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // trim(file_loc)
1196
1197 ! Check if file exists
1198 inquire (file=trim(file_loc), exist=file_exist)
1199 if (.not. file_exist) then
1200 call s_mpi_abort('Restart file ' // trim(file_loc) // ' does not exist!')
1201 end if
1202
1203 if (.not. parallel_io) return
1204
1205 if (proc_rank == 0) then
1206 call mpi_file_open(mpi_comm_self, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
1207 call s_check_mpi_file_open(ierr, file_loc)
1208
1209 call mpi_file_read(ifile, file_tot_part, 1, mpi_integer, status, ierr)
1210 call mpi_file_read(ifile, file_time, 1, mpi_p, status, ierr)
1211 call mpi_file_read(ifile, file_dt, 1, mpi_p, status, ierr)
1212 call mpi_file_read(ifile, file_num_procs, 1, mpi_integer, status, ierr)
1213
1214 call mpi_file_close(ifile, ierr)
1215 end if
1216
1217 call mpi_bcast(file_tot_part, 1, mpi_integer, 0, mpi_comm_world, ierr)
1218 call mpi_bcast(file_time, 1, mpi_p, 0, mpi_comm_world, ierr)
1219 call mpi_bcast(file_dt, 1, mpi_p, 0, mpi_comm_world, ierr)
1220 call mpi_bcast(file_num_procs, 1, mpi_integer, 0, mpi_comm_world, ierr)
1221 time_real = file_time
1222
1223 allocate (proc_bubble_counts(file_num_procs))
1224
1225 if (proc_rank == 0) then
1226 call mpi_file_open(mpi_comm_self, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
1227 call s_check_mpi_file_open(ierr, file_loc)
1228
1229 ! Skip to processor counts position
1230 disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs), mpi_offset_kind)
1231 call mpi_file_seek(ifile, disp, mpi_seek_set, ierr)
1232 call mpi_file_read(ifile, proc_bubble_counts, file_num_procs, mpi_integer, status, ierr)
1233
1234 call mpi_file_close(ifile, ierr)
1235 end if
1236
1237 call mpi_bcast(proc_bubble_counts, file_num_procs, mpi_integer, 0, mpi_comm_world, ierr)
1238
1239 ! Set time variables from file
1240
1241 ! Split the file's particles evenly over the post-process ranks, which need not match the simulation's rank count
1242 nbub = file_tot_part/num_procs
1243 start_idx_part(1) = proc_rank*nbub + min(proc_rank, mod(file_tot_part, num_procs))
1244 if (proc_rank < mod(file_tot_part, num_procs)) nbub = nbub + 1
1245
1246 start_idx_part(2) = 0
1247 lsizes(1) = nbub
1248 lsizes(2) = lag_io_vars
1249
1250 gsizes(1) = file_tot_part
1251 gsizes(2) = lag_io_vars
1252
1253 if (nbub > 0) then
1254# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1255 allocate (bub_id(nbub))
1256# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1257# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1258 allocate (px(nbub))
1259# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1260# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1261 allocate (py(nbub))
1262# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1263# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1264 allocate (pz(nbub))
1265# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1266# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1267 allocate (ppx(nbub))
1268# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1269# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1270 allocate (ppy(nbub))
1271# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1272# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1273 allocate (ppz(nbub))
1274# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1275# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1276 allocate (vx(nbub))
1277# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1278# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1279 allocate (vy(nbub))
1280# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1281# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1282 allocate (vz(nbub))
1283# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1284# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1285 allocate (radius(nbub))
1286# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1287# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1288 allocate (rvel(nbub))
1289# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1290# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1291 allocate (rnot(nbub))
1292# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1293# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1294 allocate (rmax(nbub))
1295# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1296# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1297 allocate (rmin(nbub))
1298# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1299# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1300 allocate (dphidt(nbub))
1301# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1302# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1303 allocate (pressure(nbub))
1304# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1305# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1306 allocate (mv(nbub))
1307# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1308# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1309 allocate (mg(nbub))
1310# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1311# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1312 allocate (betat(nbub))
1313# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1314# 1099 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1315 allocate (betac(nbub))
1316# 1100 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1317# 1101 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1318 allocate (mpi_io_data_lg_bubbles(nbub,1:lag_io_vars))
1319
1320 call mpi_type_create_subarray(2, gsizes, lsizes, start_idx_part, mpi_order_fortran, mpi_p, view, ierr)
1321 call mpi_type_commit(view, ierr)
1322
1323 call mpi_file_open(mpi_comm_world, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
1324 call s_check_mpi_file_open(ierr, file_loc)
1325
1326 ! Skip extended header
1327 disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs) &
1328 & + file_num_procs*sizeof(proc_bubble_counts(1)), mpi_offset_kind)
1329 call mpi_file_set_view(ifile, disp, mpi_p, view, 'native', mpi_info_int, ierr)
1330
1331 call mpi_file_read_all(ifile, mpi_io_data_lg_bubbles, lag_io_vars*nbub, mpi_p, status, ierr)
1332
1333 call mpi_file_close(ifile, ierr)
1334 call mpi_type_free(view, ierr)
1335
1336 ! Extract data from MPI_IO_DATA_lg_bubbles array Adjust these indices based on your actual data layout
1337# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1338 bub_id(:) = mpi_io_data_lg_bubbles(:,1)
1339# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1340# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1341 px(:) = mpi_io_data_lg_bubbles(:,2)
1342# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1343# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1344 py(:) = mpi_io_data_lg_bubbles(:,3)
1345# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1346# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1347 pz(:) = mpi_io_data_lg_bubbles(:,4)
1348# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1349# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1350 ppx(:) = mpi_io_data_lg_bubbles(:,5)
1351# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1352# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1353 ppy(:) = mpi_io_data_lg_bubbles(:,6)
1354# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1355# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1356 ppz(:) = mpi_io_data_lg_bubbles(:,7)
1357# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1358# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1359 vx(:) = mpi_io_data_lg_bubbles(:,8)
1360# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1361# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1362 vy(:) = mpi_io_data_lg_bubbles(:,9)
1363# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1364# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1365 vz(:) = mpi_io_data_lg_bubbles(:,10)
1366# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1367# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1368 radius(:) = mpi_io_data_lg_bubbles(:,11)
1369# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1370# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1371 rvel(:) = mpi_io_data_lg_bubbles(:,12)
1372# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1373# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1374 rnot(:) = mpi_io_data_lg_bubbles(:,13)
1375# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1376# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1377 rmax(:) = mpi_io_data_lg_bubbles(:,14)
1378# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1379# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1380 rmin(:) = mpi_io_data_lg_bubbles(:,15)
1381# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1382# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1383 dphidt(:) = mpi_io_data_lg_bubbles(:,16)
1384# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1385# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1386 pressure(:) = mpi_io_data_lg_bubbles(:,17)
1387# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1388# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1389 mv(:) = mpi_io_data_lg_bubbles(:,18)
1390# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1391# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1392 mg(:) = mpi_io_data_lg_bubbles(:,19)
1393# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1394# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1395 betat(:) = mpi_io_data_lg_bubbles(:,20)
1396# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1397# 1124 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1398 betac(:) = mpi_io_data_lg_bubbles(:,21)
1399# 1125 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1400# 1126 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1401
1402 ! Next, the root processor proceeds to record all of the spatial extents in the formatted database master file. In
1403 ! addition, it also records a sub-domain connectivity map so that the entire grid may be reassembled by looking at the
1404 ! master file.
1405 if (proc_rank == 0) then
1406 do i = 1, num_procs
1407 write (meshnames(i), '(A,I0,A,I0,A)') '../p', i - 1, '/', t_step, '.silo:' // trim(lag_name)
1408 meshtypes(i) = db_pointmesh
1409 end do
1410 err = dbset2dstrlen(len(meshnames(1)))
1411 err = dbputmmesh(out%dbroot, trim(lag_name), len_trim(lag_name), num_procs, meshnames, len_trim(meshnames), &
1412 & meshtypes, db_f77null, ierr)
1413 end if
1414
1415 err = dbputpm(out%dbfile, trim(lag_name), len_trim(lag_name), 3, px, py, pz, nbub, db_real, db_f77null, ierr)
1416
1417 if (lag_id_wrt) call s_write_lag_variable_to_formatted_database_file('part_id', t_step, bub_id, nbub)
1418 if (lag_vel_wrt) then
1419 call s_write_lag_variable_to_formatted_database_file('part_vel1', t_step, vx, nbub)
1420 call s_write_lag_variable_to_formatted_database_file('part_vel2', t_step, vy, nbub)
1421 if (p > 0) call s_write_lag_variable_to_formatted_database_file('part_vel3', t_step, vz, nbub)
1422 end if
1423 if (lag_rad_wrt) call s_write_lag_variable_to_formatted_database_file('part_radius', t_step, radius, nbub)
1424 if (lag_rvel_wrt) call s_write_lag_variable_to_formatted_database_file('part_rdot', t_step, rvel, nbub)
1425 if (lag_r0_wrt) call s_write_lag_variable_to_formatted_database_file('part_r0', t_step, rnot, nbub)
1426 if (lag_rmax_wrt) call s_write_lag_variable_to_formatted_database_file('part_rmax', t_step, rmax, nbub)
1427 if (lag_rmin_wrt) call s_write_lag_variable_to_formatted_database_file('part_rmin', t_step, rmin, nbub)
1428 if (lag_dphidt_wrt) call s_write_lag_variable_to_formatted_database_file('part_dphidt', t_step, dphidt, nbub)
1429 if (lag_pres_wrt) call s_write_lag_variable_to_formatted_database_file('part_pressure', t_step, pressure, nbub)
1430 if (lag_mv_wrt) call s_write_lag_variable_to_formatted_database_file('part_mv', t_step, mv, nbub)
1431 if (lag_mg_wrt) call s_write_lag_variable_to_formatted_database_file('part_mg', t_step, mg, nbub)
1432 if (lag_betat_wrt) call s_write_lag_variable_to_formatted_database_file('part_betaT', t_step, betat, nbub)
1433 if (lag_betac_wrt) call s_write_lag_variable_to_formatted_database_file('part_betaC', t_step, betac, nbub)
1434 ! Column 12 (rvel) holds the particle volume fraction for Lagrangian particles
1435 if (lag_voidfrac_wrt) call s_write_lag_variable_to_formatted_database_file('part_voidFraction', t_step, rvel, nbub)
1436
1437 deallocate (bub_id, px, py, pz, ppx, ppy, ppz, vx, vy, vz, radius, rvel, rnot, rmax, rmin, dphidt, pressure, mv, mg, &
1438 & betat, betac)
1439 deallocate (mpi_io_data_lg_bubbles)
1440 else
1441 call mpi_type_contiguous(0, mpi_p, view, ierr)
1442 call mpi_type_commit(view, ierr)
1443
1444 call mpi_file_open(mpi_comm_world, file_loc, mpi_mode_rdonly, mpi_info_int, ifile, ierr)
1445 call s_check_mpi_file_open(ierr, file_loc)
1446
1447 ! Skip extended header
1448 disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs) &
1449 & + file_num_procs*sizeof(proc_bubble_counts(1)), mpi_offset_kind)
1450 call mpi_file_set_view(ifile, disp, mpi_p, view, 'native', mpi_info_int, ierr)
1451
1452 call mpi_file_read_all(ifile, dummy, 0, mpi_p, status, ierr)
1453
1454 call mpi_file_close(ifile, ierr)
1455 call mpi_type_free(view, ierr)
1456
1457 if (proc_rank == 0) then
1458 do i = 1, num_procs
1459 write (meshnames(i), '(A,I0,A,I0,A)') '../p', i - 1, '/', t_step, '.silo:' // trim(lag_name)
1460 meshtypes(i) = db_pointmesh
1461 end do
1462 err = dbset2dstrlen(len(meshnames(1)))
1463 err = dbputmmesh(out%dbroot, trim(lag_name), len_trim(lag_name), num_procs, meshnames, len_trim(meshnames), &
1464 & meshtypes, db_f77null, ierr)
1465 end if
1466
1467 err = dbsetemptyok(1)
1468 err = dbputpm(out%dbfile, trim(lag_name), len_trim(lag_name), 3, dummy_data, dummy_data, dummy_data, 0, db_real, &
1469 & db_f77null, ierr)
1470
1471 if (lag_id_wrt) call s_write_lag_variable_to_formatted_database_file('part_id', t_step)
1472 if (lag_vel_wrt) then
1473 call s_write_lag_variable_to_formatted_database_file('part_vel1', t_step)
1474 call s_write_lag_variable_to_formatted_database_file('part_vel2', t_step)
1475 if (p > 0) call s_write_lag_variable_to_formatted_database_file('part_vel3', t_step)
1476 end if
1477 if (lag_rad_wrt) call s_write_lag_variable_to_formatted_database_file('part_radius', t_step)
1478 if (lag_rvel_wrt) call s_write_lag_variable_to_formatted_database_file('part_rdot', t_step)
1479 if (lag_r0_wrt) call s_write_lag_variable_to_formatted_database_file('part_r0', t_step)
1480 if (lag_rmax_wrt) call s_write_lag_variable_to_formatted_database_file('part_rmax', t_step)
1481 if (lag_rmin_wrt) call s_write_lag_variable_to_formatted_database_file('part_rmin', t_step)
1482 if (lag_dphidt_wrt) call s_write_lag_variable_to_formatted_database_file('part_dphidt', t_step)
1483 if (lag_pres_wrt) call s_write_lag_variable_to_formatted_database_file('part_pressure', t_step)
1484 if (lag_mv_wrt) call s_write_lag_variable_to_formatted_database_file('part_mv', t_step)
1485 if (lag_mg_wrt) call s_write_lag_variable_to_formatted_database_file('part_mg', t_step)
1486 if (lag_betat_wrt) call s_write_lag_variable_to_formatted_database_file('part_betaT', t_step)
1487 if (lag_betac_wrt) call s_write_lag_variable_to_formatted_database_file('part_betaC', t_step)
1488 if (lag_voidfrac_wrt) call s_write_lag_variable_to_formatted_database_file('part_voidFraction', t_step)
1489 end if
1490#endif
1491
1493
1494 !> Write a single Lagrangian bubble point-variable to the Silo database slave and master files.
1495 subroutine s_write_lag_variable_to_formatted_database_file(varname, t_step, data, nBubs)
1496
1497 character(len=*), intent(in) :: varname
1498 integer, intent(in) :: t_step
1499 real(wp), dimension(1:), intent(in), optional :: data
1500 integer, intent(in), optional :: nBubs
1501 character(len=64), dimension(num_procs) :: var_names
1502 integer, dimension(num_procs) :: var_types
1503 real(wp) :: dummy_data
1504 integer :: ierr
1505 integer :: i
1506
1507 dummy_data = 0._wp
1508
1509 if (present(nbubs) .and. present(data)) then
1510 if (proc_rank == 0) then
1511 do i = 1, num_procs
1512 write (var_names(i), '(A,I0,A,I0,A)') '../p', i - 1, '/', t_step, '.silo:' // trim(varname)
1513 var_types(i) = db_pointvar
1514 end do
1515 err = dbset2dstrlen(len(var_names(1)))
1516 err = dbputmvar(out%dbroot, trim(varname), len_trim(varname), num_procs, var_names, len_trim(var_names), &
1517 & var_types, db_f77null, ierr)
1518 end if
1519
1520 err = dbputpv1(out%dbfile, trim(varname), len_trim(varname), trim(lag_name), len_trim(lag_name), data, nbubs, &
1521 & db_real, db_f77null, ierr)
1522 else
1523 if (proc_rank == 0) then
1524 do i = 1, num_procs
1525 write (var_names(i), '(A,I0,A,I0,A)') '../p', i - 1, '/', t_step, '.silo:' // trim(varname)
1526 var_types(i) = db_pointvar
1527 end do
1528 err = dbset2dstrlen(len(var_names(1)))
1529 err = dbsetemptyok(1)
1530 err = dbputmvar(out%dbroot, trim(varname), len_trim(varname), num_procs, var_names, len_trim(var_names), &
1531 & var_types, db_f77null, ierr)
1532 end if
1533
1534 err = dbsetemptyok(1)
1535 err = dbputpv1(out%dbfile, trim(varname), len_trim(varname), trim(lag_name), len_trim(lag_name), dummy_data, 0, &
1536 & db_real, db_f77null, ierr)
1537 end if
1538
1540
1541 !> Convert the binary immersed-boundary state file to per-body formatted text files
1542 impure subroutine s_write_ib_state_files()
1543
1544 character(len=len_trim(case_dir) + 4*name_len) :: in_file, out_file, file_loc
1545 integer :: iu_in, ios, i, rec_id
1546 integer, allocatable, dimension(:) :: iu_out
1547 real(wp) :: rec_time
1548 real(wp), dimension(3) :: rec_force, rec_torque
1549 real(wp), dimension(3) :: rec_vel, rec_angular_vel
1550 real(wp), dimension(3) :: rec_angles, rec_centroid
1551
1552 file_loc = trim(case_dir) // '/D'
1553
1554 in_file = trim(file_loc) // '/ib_state.dat'
1555 open (newunit=iu_in, file=trim(in_file), form='unformatted', access='stream', status='old', action='read', iostat=ios)
1556 if (ios /= 0) then
1557 call s_mpi_abort('Cannot open IB state input file: ' // trim(in_file))
1558 end if
1559
1560 allocate (iu_out(num_ibs))
1561 do i = 1, num_ibs
1562 write (out_file, '(A,I0,A)') trim(file_loc) // '/ib_', i, '.txt'
1563 open (newunit=iu_out(i), file=trim(out_file), form='formatted', status='replace', action='write', iostat=ios)
1564 if (ios /= 0) then
1565 call s_mpi_abort('Cannot open IB state output file: ' // trim(out_file))
1566 end if
1567 write (iu_out(i), &
1568 & '(A)') 'mytime fx fy fz Tau_x Tau_y Tau_z vx vy vz omega_x omega_y omega_z angle_x angle_y angle_z x_c y_c z_c'
1569 end do
1570
1571 do
1572 read (iu_in, iostat=ios) rec_time, rec_id, rec_force, rec_torque, rec_vel, rec_angular_vel, rec_angles, &
1573 & rec_centroid(1), rec_centroid(2), rec_centroid(3)
1574 if (ios /= 0) exit
1575
1576 if (rec_id >= 1 .and. rec_id <= num_ibs) then
1577 write (iu_out(rec_id), '(19(ES24.16E3,1X))') rec_time, rec_force(1), rec_force(2), rec_force(3), rec_torque(1), &
1578 & rec_torque(2), rec_torque(3), rec_vel(1), rec_vel(2), rec_vel(3), rec_angular_vel(1), &
1579 & rec_angular_vel(2), rec_angular_vel(3), rec_angles(1), rec_angles(2), rec_angles(3), rec_centroid(1), &
1580 & rec_centroid(2), rec_centroid(3)
1581 end if
1582 end do
1583
1584 close (iu_in)
1585 do i = 1, num_ibs
1586 close (iu_out(i))
1587 end do
1588 deallocate (iu_out)
1589
1590 end subroutine s_write_ib_state_files
1591
1592 !> Extract the volume-fraction interface contour from primitive fields and write the coordinates to the interface data file.
1593 impure subroutine s_write_intf_data_file(q_prim_vf)
1594
1595 type(scalar_field), dimension(sys_size), intent(in) :: q_prim_vf
1596 integer :: i, j, k, l, cent
1597 integer :: counter, root !< number of data points extracted to fit shape to SH perturbations
1598 real(wp), allocatable :: x_td(:), y_td(:), x_d1(:), y_d1(:), y_d(:), x_d(:)
1599 real(wp) :: axp, axm, ayp, aym, tgp, euc_d, thres, maxalph_loc, maxalph_glb
1600
1601 allocate (x_d1(m*n))
1602 allocate (y_d1(m*n))
1603 counter = 0
1604 maxalph_loc = 0._wp
1605 do k = 0, p
1606 do j = 0, n
1607 do i = 0, m
1608 if (q_prim_vf(eqn_idx%E + 2)%sf(i, j, k) > maxalph_loc) then
1609 maxalph_loc = q_prim_vf(eqn_idx%E + 2)%sf(i, j, k)
1610 end if
1611 end do
1612 end do
1613 end do
1614
1615 call s_mpi_allreduce_max(maxalph_loc, maxalph_glb)
1616 if (p > 0) then
1617 do l = 0, p
1618 if (z_cc(l) < dz(l) .and. z_cc(l) > 0) then
1619 cent = l
1620 end if
1621 end do
1622 else
1623 cent = 0
1624 end if
1625
1626 thres = 0.9_wp*maxalph_glb
1627 do k = 0, n
1628 do j = 0, m
1629 axp = q_prim_vf(eqn_idx%E + 2)%sf(j + 1, k, cent)
1630 axm = q_prim_vf(eqn_idx%E + 2)%sf(j, k, cent)
1631 ayp = q_prim_vf(eqn_idx%E + 2)%sf(j, k + 1, cent)
1632 aym = q_prim_vf(eqn_idx%E + 2)%sf(j, k, cent)
1633 if ((axp > thres .and. axm < thres) .or. (axp < thres .and. axm > thres) .or. (ayp > thres .and. aym < thres) &
1634 & .or. (ayp < thres .and. aym > thres)) then
1635 if (counter == 0) then
1636 counter = counter + 1
1637 x_d1(counter) = x_cc(j)
1638 y_d1(counter) = y_cc(k)
1639 else
1640 tgp = sqrt(dx(j)**2 + dy(k)**2)
1641 do i = 1, counter
1642 euc_d = sqrt((x_cc(j) - x_d1(i))**2 + (y_cc(k) - y_d1(i))**2)
1643 if (euc_d < tgp) then
1644 exit
1645 else if (i == counter) then
1646 counter = counter + 1
1647 x_d1(counter) = x_cc(j)
1648 y_d1(counter) = y_cc(k)
1649 end if
1650 end do
1651 end if
1652 end if
1653 end do
1654 end do
1655
1656 allocate (x_d(counter), y_d(counter))
1657
1658 do i = 1, counter
1659 y_d(i) = y_d1(i)
1660 x_d(i) = x_d1(i)
1661 end do
1662 root = 0
1663
1664 call s_mpi_gather_data(x_d, counter, x_td, root)
1665 call s_mpi_gather_data(y_d, counter, y_td, root)
1666 if (proc_rank == 0) then
1667 do i = 1, size(x_td)
1668 if (i == size(x_td)) then
1669 write (211, '(F12.9,1X,F12.9,1X,I4)') x_td(i), y_td(i), size(x_td)
1670 else
1671 write (211, '(F12.9,1X,F12.9,1X,F3.1)') x_td(i), y_td(i), 0._wp
1672 end if
1673 end do
1674 end if
1675
1676 end subroutine s_write_intf_data_file
1677
1678 !> Compute volume-integrated kinetic, potential, and internal energies and write the energy budget to the energy data file.
1679 impure subroutine s_write_energy_data_file(q_prim_vf, q_cons_vf)
1680
1681 type(scalar_field), dimension(sys_size), intent(in) :: q_prim_vf, q_cons_vf
1682 real(wp) :: elk, egk, elp, egint, eg_phase, vb, vl, pres_av, et
1683 real(wp) :: rho, pres, dv, tmp, gamma, pi_inf, qv, maxma, maxma_glb, maxvel, c, ma
1684 real(wp), dimension(num_vels) :: vel
1685 real(wp), dimension(num_fluids) :: adv, alpha_rho
1686 integer :: i, j, k, l, s !< looping indices
1687
1688 egk = 0._wp
1689 elp = 0._wp
1690 egint = 0._wp
1691 vb = 0._wp
1692 maxvel = 0._wp
1693 maxma = 0._wp
1694 vl = 0._wp
1695 elk = 0._wp
1696 et = 0._wp
1697 vb = 0._wp
1698 dv = 0._wp
1699 pres_av = 0._wp
1700 pres = 0._wp
1701 c = 0._wp
1702
1703 do k = 0, p
1704 do j = 0, n
1705 do i = 0, m
1706 dv = dx(i)*dy(j)*dz(k)
1707 pres = q_prim_vf(eqn_idx%E)%sf(i, j, k)
1708 do s = 1, num_vels
1709 vel(s) = q_prim_vf(num_fluids + s)%sf(i, j, k)
1710 egk = egk + 0.5_wp*q_prim_vf(eqn_idx%E + 2)%sf(i, j, k)*q_prim_vf(2)%sf(i, j, k)*vel(s)*vel(s)*dv
1711 elk = elk + 0.5_wp*q_prim_vf(eqn_idx%E + 1)%sf(i, j, k)*q_prim_vf(1)%sf(i, j, k)*vel(s)*vel(s)*dv
1712 if (abs(vel(s)) > maxvel) then
1713 maxvel = abs(vel(s))
1714 end if
1715 end do
1716 do l = 1, num_fluids
1717 adv(l) = q_prim_vf(eqn_idx%E + l)%sf(i, j, k)
1718 alpha_rho(l) = q_prim_vf(l)%sf(i, j, k)
1719 end do
1720
1721 call s_phase_internal_energy(pres, adv(2), alpha_rho(2), 2, eg_phase)
1722 egint = egint + eg_phase*dv
1723
1724 call s_compute_mixture_coefficients(alpha_rho, adv, rho, gamma, pi_inf, qv)
1725
1726 call s_compute_speed_of_sound(pres, rho, gamma, pi_inf, adv, c, alpha_rho)
1727
1728 ma = maxvel/c
1729 if (ma > maxma .and. (adv(1) > (1.0_wp - 1.0e-10_wp))) then
1730 maxma = ma
1731 end if
1732 vl = vl + adv(1)*dv
1733 vb = vb + adv(2)*dv
1734 pres_av = pres_av + adv(1)*pres*dv
1735 et = et + q_cons_vf(eqn_idx%E)%sf(i, j, k)*dv
1736 end do
1737 end do
1738 end do
1739
1740 tmp = pres_av
1741 call s_mpi_allreduce_sum(tmp, pres_av)
1742 tmp = vl
1743 call s_mpi_allreduce_sum(tmp, vl)
1744
1745 call s_mpi_allreduce_max(maxma, maxma_glb)
1746 tmp = elk
1747 call s_mpi_allreduce_sum(tmp, elk)
1748 tmp = egint
1749 call s_mpi_allreduce_sum(tmp, egint)
1750 tmp = egk
1751 call s_mpi_allreduce_sum(tmp, egk)
1752 tmp = vb
1753 call s_mpi_allreduce_sum(tmp, vb)
1754 tmp = et
1755 call s_mpi_allreduce_sum(tmp, et)
1756
1757 elp = pres_av/vl*vb
1758 if (proc_rank == 0) then
1759 write (251, '(10X, 8F24.8)') elp, egint, elk, egk, et, vb, vl, maxma_glb
1760 end if
1761
1762 end subroutine s_write_energy_data_file
1763
1764 !> Read IB state and write a Silo point mesh with per-body scalar fields.
1766
1767 integer, intent(in) :: t_step
1768 character(len=len_trim(case_dir) + 3*name_len) :: file_loc
1769
1770#ifdef MFC_MPI
1771 real(wp) :: ib_buf(ib_state_nfields)
1772 real(wp), dimension(:,:), allocatable :: ib_data
1773 logical :: file_exist
1774 character(LEN=4*name_len), dimension(num_procs) :: meshnames
1775 integer, dimension(num_procs) :: meshtypes
1776 integer :: i, ios, file_unit
1777 integer :: ierr, nbodies
1778 integer :: r, nlocal, gbl_id
1779 character(len=10) :: t_step_string
1780 real(wp), dimension(:), allocatable :: px, py, pz
1781 real(wp), dimension(:), allocatable :: force_x, force_y, force_z
1782 real(wp), dimension(:), allocatable :: torque_x, torque_y, torque_z
1783 real(wp), dimension(:), allocatable :: vel_x, vel_y, vel_z
1784 real(wp), dimension(:), allocatable :: omega_x, omega_y, omega_z
1785 real(wp), dimension(:), allocatable :: angle_x, angle_y, angle_z
1786 real(wp), dimension(:), allocatable :: ib_diameter
1787 real(sp), dimension(:), allocatable :: px_s, py_s, pz_s
1788 logical, dimension(:), allocatable :: keep
1789 integer :: nkept
1790 real(wp) :: r_ib
1791
1792 if (proc_rank == 0) then
1793 nbodies = num_ibs
1794
1795 if (nbodies > 0) then
1796 allocate (ib_data(nbodies, ib_state_nfields))
1797 allocate (px(nbodies), py(nbodies), pz(nbodies))
1798 allocate (force_x(nbodies), force_y(nbodies), force_z(nbodies))
1799 allocate (torque_x(nbodies), torque_y(nbodies), torque_z(nbodies))
1800 allocate (vel_x(nbodies), vel_y(nbodies), vel_z(nbodies))
1801 allocate (omega_x(nbodies), omega_y(nbodies), omega_z(nbodies))
1802 allocate (angle_x(nbodies), angle_y(nbodies), angle_z(nbodies))
1803 allocate (ib_diameter(nbodies))
1804
1805 if (file_per_process) then
1806 call s_int_to_str(t_step, t_step_string)
1807 ib_data = 0._wp
1808 do r = 0, num_procs - 1
1809 write (file_loc, '(A,I0,A,i7.7,A)') 'ib_state_', t_step, '_', r, '.dat'
1810 file_loc = trim(case_dir) // '/restart_data/lustre_' // trim(t_step_string) // '/' // trim(file_loc)
1811
1812 inquire (file=trim(file_loc), exist=file_exist)
1813 if (.not. file_exist) call s_mpi_abort('Restart file ' // trim(file_loc) // ' does not exist!')
1814
1815 open (newunit=file_unit, file=trim(file_loc), form='unformatted', access='stream', status='old', iostat=ios)
1816 if (ios /= 0) call s_mpi_abort('Cannot open IB state file: ' // trim(file_loc))
1817
1818 read (file_unit, iostat=ios) nlocal
1819 if (ios /= 0) call s_mpi_abort('Error reading IB state file header: ' // trim(file_loc))
1820
1821 do i = 1, nlocal
1822 read (file_unit, iostat=ios) gbl_id
1823 if (ios /= 0) call s_mpi_abort('Error reading IB patch ID: ' // trim(file_loc))
1824 read (file_unit, iostat=ios) ib_buf
1825 if (ios /= 0) call s_mpi_abort('Error reading IB state data: ' // trim(file_loc))
1826 ib_data(gbl_id,:) = ib_buf(:)
1827 end do
1828
1829 close (file_unit)
1830 end do
1831 else
1832 ! Build path to per-timestep IB state file
1833 write (file_loc, '(A,I0,A)') '/restart_data/ib_state_', t_step, '.dat'
1834 file_loc = trim(case_dir) // trim(file_loc)
1835
1836 inquire (file=trim(file_loc), exist=file_exist)
1837 if (.not. file_exist) call s_mpi_abort('Restart file ' // trim(file_loc) // ' does not exist!')
1838
1839 open (newunit=file_unit, file=trim(file_loc), form='unformatted', access='stream', status='old', iostat=ios)
1840 if (ios /= 0) call s_mpi_abort('Cannot open IB state file: ' // trim(file_loc))
1841
1842 do i = 1, nbodies
1843 read (file_unit, iostat=ios) ib_buf
1844 if (ios /= 0) call s_mpi_abort('Error reading IB state file')
1845 ib_data(i,:) = ib_buf(:)
1846 end do
1847
1848 close (file_unit)
1849 end if
1850
1851 do i = 1, nbodies
1852 force_x(i) = ib_data(i, 2); force_y(i) = ib_data(i, 3); force_z(i) = ib_data(i, 4)
1853 torque_x(i) = ib_data(i, 5); torque_y(i) = ib_data(i, 6); torque_z(i) = ib_data(i, 7)
1854 vel_x(i) = ib_data(i, 8); vel_y(i) = ib_data(i, 9); vel_z(i) = ib_data(i, 10)
1855 omega_x(i) = ib_data(i, 11); omega_y(i) = ib_data(i, 12); omega_z(i) = ib_data(i, 13)
1856 angle_x(i) = ib_data(i, 14); angle_y(i) = ib_data(i, 15); angle_z(i) = ib_data(i, 16)
1857 px(i) = ib_data(i, 17); py(i) = ib_data(i, 18); pz(i) = ib_data(i, 19)
1858 ib_diameter(i) = ib_data(i, 20)*2.0_wp
1859 end do
1860
1861 ! When only part of the domain is written, the bodies outside that window are dropped so the point mesh matches
1862 ! the cropped grid. A body is kept when its bounding sphere overlaps the window rather than when its centroid is
1863 ! inside it, so one straddling the boundary still appears instead of vanishing at the edge.
1864 if (output_partial_domain) then
1865 allocate (keep(nbodies))
1866
1867 do i = 1, nbodies
1868 r_ib = 0.5_wp*ib_diameter(i)
1869 keep(i) = (px(i) + r_ib >= x_output%beg) .and. (px(i) - r_ib <= x_output%end)
1870 if (n > 0) keep(i) = keep(i) .and. (py(i) + r_ib >= y_output%beg) .and. (py(i) - r_ib <= y_output%end)
1871 if (p > 0) keep(i) = keep(i) .and. (pz(i) + r_ib >= z_output%beg) .and. (pz(i) - r_ib <= z_output%end)
1872 end do
1873
1874 nkept = count(keep)
1875
1876 if (nkept < nbodies) then
1877# 1603 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1878 px(1:nkept) = pack(px(1:nbodies), keep)
1879# 1604 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1880# 1603 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1881 py(1:nkept) = pack(py(1:nbodies), keep)
1882# 1604 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1883# 1603 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1884 pz(1:nkept) = pack(pz(1:nbodies), keep)
1885# 1604 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1886# 1603 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1887 ib_diameter(1:nkept) = pack(ib_diameter(1:nbodies), keep)
1888# 1604 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1889# 1603 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1890 force_x(1:nkept) = pack(force_x(1:nbodies), keep)
1891# 1604 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1892# 1603 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1893 force_y(1:nkept) = pack(force_y(1:nbodies), keep)
1894# 1604 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1895# 1603 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1896 force_z(1:nkept) = pack(force_z(1:nbodies), keep)
1897# 1604 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1898# 1603 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1899 torque_x(1:nkept) = pack(torque_x(1:nbodies), keep)
1900# 1604 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1901# 1603 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1902 torque_y(1:nkept) = pack(torque_y(1:nbodies), keep)
1903# 1604 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1904# 1603 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1905 torque_z(1:nkept) = pack(torque_z(1:nbodies), keep)
1906# 1604 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1907# 1605 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1908# 1606 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1909 vel_x(1:nkept) = pack(vel_x(1:nbodies), keep)
1910# 1607 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1911# 1606 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1912 vel_y(1:nkept) = pack(vel_y(1:nbodies), keep)
1913# 1607 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1914# 1606 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1915 vel_z(1:nkept) = pack(vel_z(1:nbodies), keep)
1916# 1607 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1917# 1606 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1918 omega_x(1:nkept) = pack(omega_x(1:nbodies), keep)
1919# 1607 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1920# 1606 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1921 omega_y(1:nkept) = pack(omega_y(1:nbodies), keep)
1922# 1607 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1923# 1606 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1924 omega_z(1:nkept) = pack(omega_z(1:nbodies), keep)
1925# 1607 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1926# 1606 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1927 angle_x(1:nkept) = pack(angle_x(1:nbodies), keep)
1928# 1607 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1929# 1606 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1930 angle_y(1:nkept) = pack(angle_y(1:nbodies), keep)
1931# 1607 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1932# 1606 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1933 angle_z(1:nkept) = pack(angle_z(1:nbodies), keep)
1934# 1607 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1935# 1608 "/home/runner/work/MFC/MFC/src/post_process/m_data_output.fpp"
1936 end if
1937
1938 nbodies = nkept
1939 deallocate (keep)
1940 end if
1941
1942 write (meshnames(1), '(A,I0,A)') '../p0/', t_step, '.silo:ib_bodies'
1943 meshtypes(1) = db_pointmesh
1944 err = dbset2dstrlen(len(meshnames(1)))
1945 err = dbputmmesh(out%dbroot, 'ib_bodies', 16, 1, meshnames, len_trim(meshnames), meshtypes, db_f77null, ierr)
1946
1947 ! Silo carries the point-mesh coordinates in their own datatype, so they need the same single-precision
1948 ! treatment as the rectilinear mesh.
1949 if (precision == precision_single) then
1950 allocate (px_s(nbodies), py_s(nbodies), pz_s(nbodies))
1951 px_s(1:nbodies) = real(px(1:nbodies), sp)
1952 py_s(1:nbodies) = real(py(1:nbodies), sp)
1953 pz_s(1:nbodies) = real(pz(1:nbodies), sp)
1954 err = dbputpm(out%dbfile, 'ib_bodies', 9, 3, px_s, py_s, pz_s, nbodies, db_float, db_f77null, ierr)
1955 deallocate (px_s, py_s, pz_s)
1956 else
1957 err = dbputpm(out%dbfile, 'ib_bodies', 9, 3, px, py, pz, nbodies, db_real, db_f77null, ierr)
1958 end if
1959
1960 call s_write_ib_variable('ib_force_x', t_step, force_x, nbodies)
1961 call s_write_ib_variable('ib_force_y', t_step, force_y, nbodies)
1962 call s_write_ib_variable('ib_force_z', t_step, force_z, nbodies)
1963 call s_write_ib_variable('ib_torque_x', t_step, torque_x, nbodies)
1964 call s_write_ib_variable('ib_torque_y', t_step, torque_y, nbodies)
1965 call s_write_ib_variable('ib_torque_z', t_step, torque_z, nbodies)
1966 call s_write_ib_variable('ib_vel_x', t_step, vel_x, nbodies)
1967 call s_write_ib_variable('ib_vel_y', t_step, vel_y, nbodies)
1968 call s_write_ib_variable('ib_vel_z', t_step, vel_z, nbodies)
1969 call s_write_ib_variable('ib_omega_x', t_step, omega_x, nbodies)
1970 call s_write_ib_variable('ib_omega_y', t_step, omega_y, nbodies)
1971 call s_write_ib_variable('ib_omega_z', t_step, omega_z, nbodies)
1972 call s_write_ib_variable('ib_angle_x', t_step, angle_x, nbodies)
1973 call s_write_ib_variable('ib_angle_y', t_step, angle_y, nbodies)
1974 call s_write_ib_variable('ib_angle_z', t_step, angle_z, nbodies)
1975 call s_write_ib_variable('ib_diameter', t_step, ib_diameter, nbodies)
1976
1977 deallocate (ib_data, px, py, pz, force_x, force_y, force_z)
1978 deallocate (torque_x, torque_y, torque_z, vel_x, vel_y, vel_z)
1979 deallocate (omega_x, omega_y, omega_z, angle_x, angle_y, angle_z)
1980 deallocate (ib_diameter)
1981 end if
1982 end if
1983#endif
1984
1986
1987 !> Write a single IB point-variable to the Silo database slave and master files.
1988 subroutine s_write_ib_variable(varname, t_step, data, nBodies)
1989
1990 character(len=*), intent(in) :: varname
1991 integer, intent(in) :: t_step
1992 real(wp), dimension(:), intent(in) :: data
1993 integer, intent(in) :: nBodies
1994 character(len=4*name_len) :: var_name_entry
1995 integer :: var_type_entry, ierr
1996 real(sp), dimension(:), allocatable :: data_s
1997
1998 write (var_name_entry, '(A,I0,A)') '../p0/', t_step, '.silo:' // trim(varname)
1999 var_type_entry = db_pointvar
2000 err = dbset2dstrlen(len(var_name_entry))
2001 err = dbputmvar(out%dbroot, trim(varname), len_trim(varname), 1, var_name_entry, len_trim(var_name_entry), &
2002 & var_type_entry, db_f77null, ierr)
2003
2004 if (precision == precision_single) then
2005 allocate (data_s(nbodies))
2006 data_s(1:nbodies) = real(data(1:nbodies), sp)
2007 err = dbputpv1(out%dbfile, trim(varname), len_trim(varname), 'ib_bodies', 9, data_s, nbodies, db_float, db_f77null, &
2008 & ierr)
2009 deallocate (data_s)
2010 else
2011 err = dbputpv1(out%dbfile, trim(varname), len_trim(varname), 'ib_bodies', 9, data, nbodies, db_real, db_f77null, ierr)
2012 end if
2013
2014 end subroutine s_write_ib_variable
2015
2016 !> Close the formatted database slave file and, for the root process, the master file.
2018
2019 integer :: ierr
2020
2021 if (format == format_silo) then
2022 ierr = dbclose(out%dbfile)
2023 if (proc_rank == 0) ierr = dbclose(out%dbroot)
2024 else
2026 if (n == 0 .and. proc_rank == 0) call s_close_binary_database_file(out%dbroot)
2027 end if
2028
2029 end subroutine s_close_formatted_database_file
2030
2031 !> Close a Binary database file and backfill the variable count into its header record (m, n, p, dbvars).
2032 impure subroutine s_close_binary_database_file(unit)
2033
2034 integer, intent(in) :: unit
2035 character(LEN=path_len + 3*name_len) :: file_loc
2036 integer :: rec_len, int_bytes
2037
2038 inquire (unit=unit, name=file_loc)
2039 close (unit)
2040
2041 int_bytes = storage_size(rec_len)/8
2042 open (unit, file=trim(file_loc), form='unformatted', access='stream', status='old', action='readwrite')
2043 read (unit, pos=1) rec_len
2044 if (rec_len /= 4*int_bytes) call s_mpi_abort('Unexpected Binary database header in ' // trim(file_loc) // '. Exiting.')
2045 ! Skip the 4-byte record marker and m, n, p
2046 write (unit, pos=1 + 4 + 3*int_bytes) out%dbvars
2047 close (unit)
2048
2049 end subroutine s_close_binary_database_file
2050
2051 !> Close the interface data file.
2052 impure subroutine s_close_intf_data_file()
2053
2054 close (211)
2055
2056 end subroutine s_close_intf_data_file
2057
2058 !> Close the energy data file.
2059 impure subroutine s_close_energy_data_file()
2060
2061 close (251)
2062
2063 end subroutine s_close_energy_data_file
2064
2065 !> Deallocate module arrays and release all data-output resources.
2067
2068 deallocate (out%q_sf)
2069 if (n == 0) deallocate (out%q_root_sf)
2070 if (grid_geometry == 3) then
2071 deallocate (out%cyl_q_sf)
2072 end if
2073
2074 ! Deallocating spatial and data extents and also the variables for the offsets and the one bookkeeping the number of
2075 ! cell-boundaries in each active coordinate direction. Note that all these variables were only needed by Silo-HDF5 format
2076 ! for multidimensional data.
2077 if (format == format_silo) then
2078 deallocate (out%spatial_extents)
2079 deallocate (out%data_extents)
2080 deallocate (out%lo_offset)
2081 deallocate (out%hi_offset)
2082 deallocate (out%dims)
2083 end if
2084
2085 end subroutine s_finalize_data_output_module
2086
2087end module m_data_output
impure subroutine s_put_amr_block_variable(nm)
Write the already-filled vbuf for the current block k as variable nm: a Silo quadvar on the block mes...
integer, intent(in) k
integer, intent(in) j
integer, intent(in) l
Multi-species chemistry interface for thermodynamic properties, reaction rates, and transport coeffic...
subroutine s_compute_q_t_sf(q_t_sf, q_cons_vf, bounds)
Initialize the temperature field from conservative variables by inverting the energy equation.
Platform-specific file and directory operations: create, delete, inquire, getcwd, and basename.
impure subroutine my_inquire(fileloc, dircheck)
Inquire on the existence of a directory or file.
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 ib_state_nfields
Reals per IB in restart_data/ib_state: time, force(3), torque(3), vel(3), angular_vel(3),...
integer, parameter format_silo
integer, parameter format_binary
integer, parameter precision_single
Reads raw simulation grid and conservative-variable data for a given time-step and fills buffer regio...
type(amr_fine_block), dimension(:), allocatable, public amr_fine
this rank's owned block pieces
type(scalar_field), dimension(:), allocatable, public q_cons_vf
Conservative variables.
type(scalar_field), dimension(:), allocatable, public q_prim_vf
Primitive variables.
integer, public amr_num_fine
number of block pieces this rank owns (<= file's block count)
Writes post-processed grid and flow-variable data to Silo-HDF5 or binary database files.
impure subroutine, public s_write_grid_to_formatted_database_file(t_step)
Write the computational grid (cell-boundary coordinates) to the formatted database slave and master f...
impure subroutine, public s_write_amr_to_formatted_database_file(t_step)
Overlay the AMR refined solution. Each owned fine block is written as an extra rectilinear quadmesh (...
impure subroutine, public s_write_variable_to_formatted_database_file(varname, t_step)
Write a single flow variable field to the formatted database slave and master files for a given time ...
impure subroutine, public s_open_energy_data_file()
Open the energy data file for appending volume-integrated energy budget quantities.
impure subroutine, public s_open_intf_data_file()
Open the interface data file for appending extracted interface coordinates.
impure subroutine, public s_write_ib_state_files()
Convert the binary immersed-boundary state file to per-body formatted text files.
impure subroutine, public s_write_energy_data_file(q_prim_vf, q_cons_vf)
Compute volume-integrated kinetic, potential, and internal energies and write the energy budget to th...
impure subroutine, public s_write_lag_bubbles_to_formatted_database_file(t_step)
Read Lagrangian bubble restart data and write bubble positions and scalar fields to the Silo database...
impure subroutine, public s_write_intf_data_file(q_prim_vf)
Extract the volume-fraction interface contour from primitive fields and write the coordinates to the ...
subroutine s_write_ib_variable(varname, t_step, data, nbodies)
Write a single IB point-variable to the Silo database slave and master files.
impure subroutine, public s_initialize_data_output_module()
Allocate storage arrays, configure output directories, and count flow variables for formatted databas...
impure subroutine, public s_close_energy_data_file()
Close the energy data file.
impure subroutine, public s_close_formatted_database_file()
Close the formatted database slave file and, for the root process, the master file.
impure subroutine, public s_open_formatted_database_file(t_step)
Open (or create) the Silo-HDF5 or Binary formatted database slave and master files for a given time s...
impure subroutine, public s_close_intf_data_file()
Close the interface data file.
impure subroutine, public s_write_lag_bubbles_results_to_text(t_step)
Write the post-processed results in the folder 'lag_bubbles_data'.
impure subroutine, public s_finalize_data_output_module()
Deallocate module arrays and release all data-output resources.
integer, parameter db_real
Silo datatype of a real(wp) array (grid coordinates, point meshes and point variables)....
integer, private err
impure subroutine, public s_define_output_region
Compute the cell-index bounds for the user-specified partial output domain in each coordinate directi...
impure subroutine s_close_binary_database_file(unit)
Close a Binary database file and backfill the variable count into its header record (m,...
impure subroutine, public s_write_ib_bodies_to_formatted_database_file(t_step)
Read IB state and write a Silo point mesh with per-body scalar fields.
type(output_context), public out
Output workspace: flow variable buffers, VisIt extents/offsets, directory paths, file handles,...
subroutine s_write_lag_variable_to_formatted_database_file(varname, t_step, data, nbubs)
Write a single Lagrangian bubble point-variable to the Silo database slave and master files.
character(len=13), private lag_name
Name of the Lagrangian output files and Silo point mesh: lag_bubbles or lag_particles.
Shared derived types for field data, patch geometry, bubble dynamics, and MPI I/O structures.
Computes derived flow quantities (sound speed, vorticity, Schlieren, etc.) from conservative and prim...
Equations of state in Gamma/Pi form, rho e = Gamma(rho) p + Pi(rho).
subroutine, public s_phase_internal_energy(pres, alpha, alpha_rho, i, e_phase)
Internal energy per unit volume of phase i at pressure pres: alpha (Gamma p + Pi) + alpha_rho qv,...
subroutine, public s_compute_mixture_coefficients(alpha_rho_k, alpha_k, rho_k, gamma_k, pi_inf_k, qv_k)
Mixture coefficients of one state. Under bubbles_euler with num_fluids == 1 the sole advection slot a...
subroutine, public s_compute_speed_of_sound(pres, rho, gamma, pi_inf, adv, c, alpha_rho)
Speed of sound of a thermodynamic state. Enthalpy is not an argument: for a real state H,...
Global parameters for the post-process: domain geometry, equation of state, and output database setti...
real(sp), dimension(:), allocatable z_cb_s
real(sp), dimension(:), allocatable x_cb_s
type(int_bounds_info) offset_y
real(wp), dimension(:,:), allocatable, public mpi_io_data_lg_bubbles
real(wp), dimension(:), allocatable y_cc
integer proc_rank
Rank of the local processor.
real(wp), dimension(:), allocatable adv
Advection variables.
type(int_bounds_info) z_output_idx
Indices of domain to output for post-processing.
real(wp), dimension(:), allocatable y_cb
real(wp), dimension(:), allocatable dz
real(wp), dimension(:), allocatable x_root_cb
real(wp), dimension(:), allocatable z_cb
type(bounds_info) z_output
Portion of domain to output for post-processing.
type(int_bounds_info) x_output_idx
real(wp), dimension(:), allocatable x_cc
real(wp), dimension(:), allocatable x_cb
real(wp), dimension(:), allocatable dy
type(int_bounds_info) offset_x
real(wp), dimension(:), allocatable z_cc
real(sp), dimension(:), allocatable y_cb_s
integer num_procs
Number of processors.
type(int_bounds_info) y_output_idx
type(int_bounds_info) offset_z
real(wp), dimension(:), allocatable dx
Cell-width distributions in the x-, y- and z-coordinate directions.
Utility routines for bubble model setup, coordinate transforms, array sampling, and special functions...
elemental subroutine, public s_int_to_str(i, res)
Convert an integer to its trimmed string representation.
MPI gather and scatter operations for distributing post-process grid and flow-variable data.
impure subroutine s_mpi_defragment_1d_grid_variable
Collect the sub-domain cell-boundary or cell-center location data from all processors and put back to...
impure subroutine s_mpi_defragment_1d_flow_variable(q_sf, q_root_sf)
Gather the sub-domain flow variable data from all processors and reassemble it for the entire computa...
impure subroutine s_mpi_gather_spatial_extents(spatial_extents)
Gather spatial extents from all ranks for Silo database metadata.
impure subroutine s_mpi_gather_data_extents(q_sf, data_extents)
Gather the Silo database metadata for the flow variable's extents to boost performance of the multidi...
Conservative-to-primitive variable conversion, mixture property evaluation, and pressure computation.
logical, public skip_mixture_store
post_process's AMR overlay converts fine blocks larger than the coarse rank grid these caches span; i...
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,...
Integer bounds for variables.
Output workspace for post_process: flow variable buffers, VisIt extents/offsets, directory paths,...
Derived type annexing a scalar field (SF).