1# 1 "/home/runner/work/MFC/MFC/src/pre_process/m_data_output.fpp"
23 use m_thermochem,
only: species_names
42 type(
integer_field),
dimension(1:num_dims,-1:1),
intent(in) :: bc_type
49 character(LEN=path_len + 2*name_len),
private ::
t_step_dir
59 type(
integer_field),
dimension(1:num_dims,-1:1),
intent(in) :: bc_type
61 character(LEN=15) :: fmt
62 character(LEN=3) :: status
63 character(len=int(floor(log10(real(
sys_size, wp)))) + 1) :: file_num
64 character(LEN=len_trim(t_step_dir) + name_len) :: file_loc
65 integer :: i,
j,
k,
l, r, c
67 real(wp),
dimension(nb) :: nrtmp
69 real(wp) :: gamma, lit_gamma, pi_inf, qv
72 real(wp) :: rhoyks(1:num_species)
97 open (1, file=trim(file_loc), form=
'unformatted', status=status)
103 open (1, file=trim(file_loc), form=
'unformatted', status=status)
109 open (1, file=trim(file_loc), form=
'unformatted', status=status)
116 write (file_num,
'(I0)') i
117 file_loc = trim(
t_step_dir) //
'/q_cons_vf' // trim(file_num) //
'.dat'
118 open (1, file=trim(file_loc), form=
'unformatted', status=status)
126 write (file_num,
'(I0)') r + (i - 1)*nnode +
sys_size
127 file_loc = trim(
t_step_dir) //
'/pb' // trim(file_num) //
'.dat'
128 open (1, file=trim(file_loc), form=
'unformatted', status=status)
129 write (1)
pb%sf(:,:,:,r, i)
136 write (file_num,
'(I0)') r + (i - 1)*nnode +
sys_size
137 file_loc = trim(
t_step_dir) //
'/mv' // trim(file_num) //
'.dat'
138 open (1, file=trim(file_loc), form=
'unformatted', status=status)
139 write (1)
mv%sf(:,:,:,r, i)
159 inquire (file=trim(file_loc), exist=file_exist)
165 if (
n == 0 .and.
p == 0)
then
168 write (file_loc,
'(A,I0,A,I2.2,A,I6.6,A)') trim(
t_step_dir) //
'/prim.', i,
'.',
proc_rank,
'.', t_step,
'.dat'
170 open (2, file=trim(file_loc))
173 do c = 1, num_species
180 lit_gamma = 1._wp/gamma + 1._wp
182 if ((i >=
eqn_idx%species%beg) .and. (i <=
eqn_idx%species%end))
then
188 else if (i ==
eqn_idx%mom%beg)
then
190 else if (i ==
eqn_idx%stress%beg)
then
200 & rho, qv, rhoyks, pres, t, pres_mag=pres_mag)
201 write (2, fmt)
x_cb(
j), pres
203 if (i ==
eqn_idx%mom%beg + 1)
then
205 else if (i ==
eqn_idx%mom%beg + 2)
then
207 else if (i ==
eqn_idx%B%beg)
then
209 else if (i ==
eqn_idx%B%beg + 1)
then
229 else if (i ==
eqn_idx%damage)
then
238 write (file_loc,
'(A,I0,A,I2.2,A,I6.6,A)') trim(
t_step_dir) //
'/cons.', i,
'.',
proc_rank,
'.', t_step,
'.dat'
240 open (2, file=trim(file_loc))
250 write (file_loc,
'(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(
t_step_dir) //
'/pres.', i,
'.', r,
'.',
proc_rank, &
251 &
'.', t_step,
'.dat'
253 open (2, file=trim(file_loc))
255 write (2, fmt)
x_cb(
j),
pb%sf(
j, 0, 0, r, i)
262 write (file_loc,
'(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(
t_step_dir) //
'/mv.', i,
'.', r,
'.',
proc_rank, &
263 &
'.', t_step,
'.dat'
265 open (2, file=trim(file_loc))
267 write (2, fmt)
x_cb(
j),
mv%sf(
j, 0, 0, r, i)
281 if ((
n > 0) .and. (
p == 0))
then
283 write (file_loc,
'(A,I0,A,I2.2,A,I6.6,A)') trim(
t_step_dir) //
'/cons.', i,
'.',
proc_rank,
'.', t_step,
'.dat'
284 open (2, file=trim(file_loc))
297 write (file_loc,
'(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(
t_step_dir) //
'/pres.', i,
'.', r,
'.',
proc_rank, &
298 &
'.', t_step,
'.dat'
300 open (2, file=trim(file_loc))
311 write (file_loc,
'(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(
t_step_dir) //
'/mv.', i,
'.', r,
'.',
proc_rank, &
312 &
'.', t_step,
'.dat'
314 open (2, file=trim(file_loc))
334 write (file_loc,
'(A,I0,A,I2.2,A,I6.6,A)') trim(
t_step_dir) //
'/cons.', i,
'.',
proc_rank,
'.', t_step,
'.dat'
335 open (2, file=trim(file_loc))
351 write (file_loc,
'(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(
t_step_dir) //
'/pres.', i,
'.', r,
'.',
proc_rank, &
352 &
'.', t_step,
'.dat'
354 open (2, file=trim(file_loc))
367 write (file_loc,
'(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(
t_step_dir) //
'/mv.', i,
'.', r,
'.',
proc_rank, &
368 &
'.', t_step,
'.dat'
370 open (2, file=trim(file_loc))
390 type(
integer_field),
dimension(1:num_dims,-1:1),
intent(in) :: bc_type
394 integer :: ifile, ierr, data_size
395 integer,
dimension(MPI_STATUS_SIZE) :: status
396 integer(KIND=MPI_OFFSET_KIND) :: disp
397 integer(KIND=MPI_OFFSET_KIND) :: m_mok, n_mok, p_mok
398 integer(KIND=MPI_OFFSET_KIND) :: wp_mok, var_mok, str_mok
399 integer(KIND=MPI_OFFSET_KIND) :: nvars_mok
400 integer(KIND=MPI_OFFSET_KIND) :: mok
401 character(LEN=path_len + 2*name_len) :: file_loc
402 logical :: file_exist, dir_check
403 integer :: i,
j,
k,
l
404 real(wp) :: loc_violations, glb_violations
405 integer :: m_ds, n_ds, p_ds
406 integer :: m_glb_ds, n_glb_ds, p_glb_ds
407 integer :: m_glb_save, n_glb_save, p_glb_save
409 loc_violations = 0._wp
412 if ((mod(
m + 1, 3) > 0) .or. (mod(
n + 1, 3) > 0) .or. (mod(
p + 1, 3) > 0))
then
413 loc_violations = 1._wp
415 call s_mpi_allreduce_sum(loc_violations, glb_violations)
416 if (
proc_rank == 0 .and. nint(glb_violations) > 0)
then
418 &
"WARNING: Attempting to downsample data but there are" &
419 & //
"processors with local problem sizes that are not divisible by 3."
427 file_loc = trim(
case_dir) //
'/restart_data/lustre_0'
429 if (dir_check .neqv. .true.)
then
449 inquire (file=trim(file_loc), exist=file_exist)
450 if (file_exist .and.
proc_rank == 0)
then
453 if (file_exist)
call mpi_file_delete(file_loc,
mpi_info_int, ierr)
454 call mpi_file_open(mpi_comm_self, file_loc, ior(mpi_mode_wronly, mpi_mode_create),
mpi_info_int, ifile, ierr)
457 data_size = (m_ds + 3)*(n_ds + 3)*(p_ds + 3)
458 m_glb_save = m_glb_ds + 3
459 n_glb_save = n_glb_ds + 3
460 p_glb_save = p_glb_ds + 3
462 data_size = (
m + 1)*(
n + 1)*(
p + 1)
463 m_glb_save =
m_glb + 1
464 n_glb_save =
n_glb + 1
465 p_glb_save =
p_glb + 1
469 m_mok = int(m_glb_save, mpi_offset_kind)
470 n_mok = int(n_glb_save, mpi_offset_kind)
471 p_mok = int(p_glb_save, mpi_offset_kind)
472 wp_mok = int(storage_size(0._stp)/8, mpi_offset_kind)
473 mok = int(1._wp, mpi_offset_kind)
474 str_mok = int(name_len, mpi_offset_kind)
475 nvars_mok = int(
sys_size, mpi_offset_kind)
479 var_mok = int(i, mpi_offset_kind)
481 call mpi_file_write_all(ifile,
mpi_io_data%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
485 var_mok = int(i, mpi_offset_kind)
487 call mpi_file_write_all(ifile,
mpi_io_data%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
493 var_mok = int(i, mpi_offset_kind)
495 call mpi_file_write_all(ifile,
q_cons_temp(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
499 var_mok = int(i, mpi_offset_kind)
501 call mpi_file_write_all(ifile,
mpi_io_data%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
506 call mpi_file_close(ifile, ierr)
511 write (file_loc,
'(I0,A)')
n_start,
'.dat'
516 inquire (file=trim(file_loc), exist=file_exist)
517 if (file_exist .and.
proc_rank == 0)
then
520 call mpi_file_open(mpi_comm_world, file_loc, ior(mpi_mode_wronly, mpi_mode_create),
mpi_info_int, ifile, ierr)
522 data_size = (
m + 1)*(
n + 1)*(
p + 1)
525 m_mok = int(
m_glb + 1, mpi_offset_kind)
526 n_mok = int(
n_glb + 1, mpi_offset_kind)
527 p_mok = int(
p_glb + 1, mpi_offset_kind)
528 wp_mok = int(storage_size(0._stp)/8, mpi_offset_kind)
529 mok = int(1._wp, mpi_offset_kind)
530 str_mok = int(name_len, mpi_offset_kind)
531 nvars_mok = int(
sys_size, mpi_offset_kind)
535 var_mok = int(i, mpi_offset_kind)
537 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1)
540 call mpi_file_write_all(ifile,
mpi_io_data%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
544 var_mok = int(i, mpi_offset_kind)
546 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1)
549 call mpi_file_write_all(ifile,
mpi_io_data%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
554 var_mok = int(i, mpi_offset_kind)
556 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1)
559 call mpi_file_write_all(ifile,
mpi_io_data%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
563 call mpi_file_close(ifile, ierr)
580 character(LEN=len_trim(case_dir) + 2*name_len) :: file_loc
581 character(len=15) :: temp
582 character(LEN=1),
dimension(3),
parameter :: coord = (/
'x',
'y',
'z'/)
585 integer :: m_ds, n_ds, p_ds
619 open (newunit=iu, file=
'indices.dat', status=
'unknown')
621 write (iu,
'(A)')
"Warning: The creation of file is currently experimental."
622 write (iu,
'(A)')
"This file may contain errors and not support all features."
624 write (iu,
'(A3,A20,A20)')
"#",
"Conservative",
"Primitive"
625 write (iu,
'(A)')
" "
627 write (temp,
'(I0)') i -
eqn_idx%cont%beg + 1
628 write (iu,
'(I3,A20,A20)') i,
"\alpha_{" // trim(temp) //
"} \rho_{" // trim(temp) //
"}", &
629 &
"\alpha_{" // trim(temp) //
"} \rho"
632 write (iu,
'(I3,A20,A20)') i,
"\rho u_" // coord(i -
eqn_idx%mom%beg + 1),
"u_" // coord(i -
eqn_idx%mom%beg + 1)
634 if (
eqn_idx%E /= 0)
write (iu,
'(I3,A20,A20)')
eqn_idx%E,
"\rho U",
"p"
636 write (temp,
'(I0)') i -
eqn_idx%cont%beg + 1
637 write (iu,
'(I3,A20,A20)') i,
"\alpha_{" // trim(temp) //
"}",
"\alpha_{" // trim(temp) //
"}"
640 do i = 1, num_species
641 write (iu,
'(I3,A20,A20)')
eqn_idx%species%beg + i - 1,
"Y_{" // trim(species_names(i)) //
"} \rho", &
642 &
"Y_{" // trim(species_names(i)) //
"}"
662 m_ds = int((
m + 1)/3) - 1
663 n_ds = int((
n + 1)/3) - 1
664 p_ds = int((
p + 1)/3) - 1
668 allocate (
q_cons_temp(i)%sf(-1:m_ds + 1,-1:n_ds + 1,-1:p_ds + 1))
676 integer,
intent(in) :: beg, end
677 character(*),
intent(in) :: label
679 if (beg /= 0)
write (iu,
'("[",I0,",",I0,"]",A)') beg,
end, label
692 if (down_sample)
then
Interface for the conservative data.
subroutine write_range(beg, end, label)
type(scalar_field), dimension(sys_size), intent(inout) q_cons_vf
Noncharacteristic and processor boundary condition application for ghost cells and buffer regions.
subroutine, public s_write_parallel_boundary_condition_files(q_prim_vf, bc_type, q_t_sf)
Write boundary condition type and buffer data to per-rank parallel files using MPI I/O.
subroutine, public s_write_serial_boundary_condition_files(q_prim_vf, bc_type, step_dirpath, old_grid_in, q_t_sf)
Write boundary condition type and buffer data to serial (unformatted) restart files.
impure subroutine, public s_populate_variables_buffers(bc_type, q_prim_vf, pb_in, mv_in, q_t_sf)
Populate the buffers of the primitive variables based on the selected boundary conditions.
Applies spatially varying boundary condition patches along domain edges and faces.
Platform-specific file and directory operations: create, delete, inquire, getcwd, and basename.
impure subroutine s_delete_directory(dir_name)
Recursively delete a directory using a platform-specific system command.
impure subroutine my_inquire(fileloc, dircheck)
Inquires on the existence of a directory.
impure subroutine s_create_directory(dir_name)
Create a directory and all its parents if it does not exist.
Writes grid and initial condition data to serial or parallel output files.
type(scalar_field), dimension(:), allocatable q_cons_temp
procedure(s_write_abstract_data_files), pointer, public s_write_data_files
impure subroutine, public s_write_serial_data_files(q_cons_vf, q_prim_vf, bc_type, q_t_sf)
Writes grid and initial condition data files to the "0" time-step directory in the local processor ra...
character(len=path_len+2 *name_len), private t_step_dir
Time-step folder into which grid and initial condition data will be placed.
impure subroutine, public s_initialize_data_output_module
Computation of parameters, allocation procedures, and/or any other tasks needed to properly setup the...
impure subroutine, public s_finalize_data_output_module
Resets s_write_data_files pointer.
impure subroutine, public s_write_parallel_data_files(q_cons_vf, q_prim_vf, bc_type, q_t_sf)
Writes grid and initial condition data files in parallel to the "0" time-step directory in the local ...
character(len=path_len+2 *name_len), public restart_dir
Restart data folder.
Rank-staggered file access delays to prevent I/O contention on parallel file systems.
impure subroutine, public delayfileaccess(processrank)
Introduce a rank-dependent busy-wait delay to stagger parallel file access and reduce I/O contention.
Shared derived types for field data, patch geometry, bubble dynamics, and MPI I/O structures.
Defines global parameters for the computational domain, simulation algorithm, and initial conditions.
integer p_glb
Global number of cells in each direction.
logical igr
Use information geometric regularization.
logical, parameter chemistry
Chemistry modeling.
integer mpi_info_int
MPI info for parallel IO with Lustre file systems.
type(qbmm_idx_info) qbmm_idx
QBMM moment index mappings.
integer proc_rank
Rank of the local processor Number of cells in the x-, y- and z-coordinate directions.
logical bc_io
whether or not to save BC data
real(wp), dimension(:), allocatable y_cb
character(len=name_len) mpiiofs
integer sys_size
Number of unknowns in the system of equations.
real(wp), dimension(:), allocatable weight
integer model_eqns
Multicomponent flow model.
integer precision
Precision of output files.
real(wp), dimension(:), allocatable z_cb
integer num_dims
Number of spatial dimensions.
real(wp), dimension(:), allocatable x_cb
Locations of cell-boundaries (cb) in x-, y- and z-directions, respectively.
logical qbmm
Quadrature moment method.
logical old_grid
Use existing grid data.
real(wp) bx0
Constant magnetic field in the x-direction (1D).
logical adv_n
Solve the number density equation and compute alpha from number density.
character(len=path_len) case_dir
Case folder location.
logical mhd
Magnetohydrodynamics.
logical parallel_io
Format of the data files.
logical down_sample
Down-sample the output data.
logical file_per_process
type of data output
integer t_step_start
Existing IC/grid folder.
type(mpi_io_var), public mpi_io_data
type(eqn_idx_info) eqn_idx
All conserved-variable equation index ranges and scalars.
Utility routines for bubble model setup, coordinate transforms, array sampling, and special functions...
subroutine, public s_downsample_data(q_cons_vf, q_cons_temp, m_ds, n_ds, p_ds, m_glb_ds, n_glb_ds, p_glb_ds)
Downsample conservative variable fields by a factor of 3 in each direction using volume averaging.
subroutine, public s_comp_n_from_cons(vftmp, nrtmp, ntmp, weights)
Compute the bubble number density from the conservative void fraction and weighted bubble radii.
Broadcasts user inputs and decomposes the domain across MPI ranks for pre-processing.
Conservative-to-primitive variable conversion, mixture property evaluation, and pressure computation.
real(wp), dimension(:), allocatable, public gammas
real(wp), dimension(:), allocatable, public gs_min
real(wp), dimension(:), allocatable, public qvs
subroutine, public s_compute_pressure(energy, alf, dyn_p, pi_inf, gamma, rho, qv, rhoyks, pres, t, stress, mom, g, pres_mag)
Compute the pressure from the appropriate equation of state.
real(wp), dimension(:), allocatable, public pi_infs
subroutine, public s_convert_to_mixture_variables(q_vf, i, j, k, rho, gamma, pi_inf, qv, re_k, g_k, g)
Dispatch to the s_convert_mixture_to_mixture_variables and s_convert_species_to_mixture_variables sub...
Derived type annexing an integer scalar field (SF).
Derived type for bubble variables pb and mv at quadrature nodes (qbmm).
Derived type annexing a scalar field (SF).