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/pre_process/m_data_output.fpp"
2!>
3!! @file
4!! @brief Contains module m_data_output
5
6!> @brief Writes grid and initial condition data to serial or parallel output files
8
11 use m_helper
12 use m_mpi_proxy
13#ifdef MFC_MPI
14 use mpi
15#endif
16
19 use m_helper
24 use m_thermochem, only: species_names
25 use m_helper
27
28 implicit none
29
30 private
33
34 type(scalar_field), allocatable, dimension(:) :: q_cons_temp
35
36 abstract interface
37
38 !> Interface for the conservative data
39 impure subroutine s_write_abstract_data_files(q_cons_vf, q_prim_vf, bc_type, q_T_sf)
40
41 import :: scalar_field, integer_field, sys_size, m, n, p, pres_field, num_dims
42
43 type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf, q_prim_vf
44 type(integer_field), dimension(1:num_dims,1:2), intent(in) :: bc_type
45 type(scalar_field), intent(inout), optional :: q_t_sf
46
47 end subroutine s_write_abstract_data_files
48 end interface
49
50 !> Time-step folder into which grid and initial condition data will be placed
51 character(LEN=path_len + 2*name_len), private :: t_step_dir
52 character(LEN=path_len + 2*name_len), public :: restart_dir !< Restart data folder
53 procedure(s_write_abstract_data_files), pointer :: s_write_data_files => null()
54
55contains
56
57 !> Writes grid and initial condition data files to the "0" time-step directory in the local processor rank folder
58 impure subroutine s_write_serial_data_files(q_cons_vf, q_prim_vf, bc_type, q_T_sf)
59
60 type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf, q_prim_vf
61 type(integer_field), dimension(1:num_dims,1:2), intent(in) :: bc_type
62 logical :: file_exist
63 character(LEN=15) :: fmt
64 character(LEN=3) :: status
65 character(len=int(floor(log10(real(sys_size, wp)))) + 1) :: file_num
66 character(LEN=len_trim(t_step_dir) + name_len) :: file_loc
67 integer :: i, j, k, l, r, c
68 integer :: t_step
69 real(wp), dimension(nb) :: nrtmp
70 real(wp) :: nbub
71 real(wp) :: gamma, pi_inf, qv
72 real(wp) :: rho
73 real(wp) :: pres, t
74 real(wp) :: rhoyks(1:num_species)
75 real(wp) :: pres_mag
76 type(scalar_field), intent(inout), optional :: q_t_sf
77
78 pres_mag = 0._wp
79
80 t = dflt_t_guess
81
82 t_step = 0
83
84 if (old_grid) then
85 status = 'old'
86 else
87 status = 'new'
88 end if
89
90 if (bc_io) then
91 if (igr) then
93 else
94 call s_pack_boundary_condition_buffers(q_prim_vf, q_t_sf)
95 end if
97 end if
98
99 file_loc = trim(t_step_dir) // '/x_cb.dat'
100 open (1, file=trim(file_loc), form='unformatted', status=status)
101 write (1) x_cb(-1:m)
102 close (1)
103
104 if (n > 0) then
105 file_loc = trim(t_step_dir) // '/y_cb.dat'
106 open (1, file=trim(file_loc), form='unformatted', status=status)
107 write (1) y_cb(-1:n)
108 close (1)
109
110 if (p > 0) then
111 file_loc = trim(t_step_dir) // '/z_cb.dat'
112 open (1, file=trim(file_loc), form='unformatted', status=status)
113 write (1) z_cb(-1:p)
114 close (1)
115 end if
116 end if
117
118 do i = 1, sys_size
119 write (file_num, '(I0)') i
120 file_loc = trim(t_step_dir) // '/q_cons_vf' // trim(file_num) // '.dat'
121 open (1, file=trim(file_loc), form='unformatted', status=status)
122 write (1) q_cons_vf(i)%sf(0:m,0:n,0:p)
123 close (1)
124 end do
125
126 if (euler_lagrange) then
127 block
128 real(stp), allocatable :: beta_ones(:,:,:)
129 character(LEN=len_trim(t_step_dir) + name_len) :: beta_file_loc
130 integer :: jj, kk, ll
131 allocate (beta_ones(0:m,0:n,0:p))
132 do ll = 0, p
133 do kk = 0, n
134 do jj = 0, m
135 beta_ones(jj, kk, ll) = 1.0_stp
136 end do
137 end do
138 end do
139 write (beta_file_loc, '(A,I0,A)') trim(t_step_dir) // '/q_cons_vf', sys_size + 1, '.dat'
140 open (1, file=trim(beta_file_loc), form='unformatted', status=status)
141 write (1) beta_ones
142 close (1)
143 deallocate (beta_ones)
144 end block
145 end if
146
147 if (qbmm .and. .not. polytropic) then
148 do i = 1, nb
149 do r = 1, nnode
150 write (file_num, '(I0)') r + (i - 1)*nnode + sys_size
151 file_loc = trim(t_step_dir) // '/pb' // trim(file_num) // '.dat'
152 open (1, file=trim(file_loc), form='unformatted', status=status)
153 write (1) pb%sf(:,:,:,r, i)
154 close (1)
155 end do
156 end do
157
158 do i = 1, nb
159 do r = 1, nnode
160 write (file_num, '(I0)') r + (i - 1)*nnode + sys_size
161 file_loc = trim(t_step_dir) // '/mv' // trim(file_num) // '.dat'
162 open (1, file=trim(file_loc), form='unformatted', status=status)
163 write (1) mv%sf(:,:,:,r, i)
164 close (1)
165 end do
166 end do
167 end if
168
169 if (precision == precision_single) then
170 fmt = "(2F30.3)"
171 else
172 fmt = "(2F40.14)"
173 end if
174
175 write (t_step_dir, '(A,I0,A,I0)') trim(case_dir) // '/D'
176 file_loc = trim(t_step_dir) // '/.'
177
178 inquire (file=trim(file_loc), exist=file_exist)
179
180 if (.not. file_exist) call s_create_directory(trim(t_step_dir))
181
182 if (cfl_dt) t_step = n_start
183
184 if (n == 0 .and. p == 0) then
185 if (model_eqns == model_eqns_5eq) then
186 do i = 1, sys_size
187 write (file_loc, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/prim.', i, '.', proc_rank, '.', t_step, '.dat'
188
189 open (2, file=trim(file_loc))
190 do j = 0, m
191 if (chemistry) then
192 do c = 1, num_species
193 rhoyks(c) = q_cons_vf(eqn_idx%species%beg + c - 1)%sf(j, 0, 0)
194 end do
195 end if
196
197 call s_convert_to_mixture_variables(q_cons_vf, j, 0, 0, rho, gamma, pi_inf, qv)
198
199 if ((i >= eqn_idx%species%beg) .and. (i <= eqn_idx%species%end)) then
200 write (2, fmt) x_cb(j), q_cons_vf(i)%sf(j, 0, 0)/rho
201 else if (((i >= eqn_idx%cont%beg) .and. (i <= eqn_idx%cont%end)) .or. ((i >= eqn_idx%adv%beg) &
202 & .and. (i <= eqn_idx%adv%end)) .or. ((i >= eqn_idx%species%beg) .and. (i <= eqn_idx%species%end) &
203 & )) then
204 write (2, fmt) x_cb(j), q_cons_vf(i)%sf(j, 0, 0)
205 else if (i == eqn_idx%mom%beg) then ! u
206 write (2, fmt) x_cb(j), q_cons_vf(eqn_idx%mom%beg)%sf(j, 0, 0)/rho
207 else if (i == eqn_idx%stress%beg) then ! tau_e
208 write (2, fmt) x_cb(j), q_cons_vf(eqn_idx%stress%beg)%sf(j, 0, 0)/rho
209 else if (i == eqn_idx%E) then ! p
210 if (mhd) then
211 pres_mag = 0.5_wp*(bx0**2 + q_cons_vf(eqn_idx%B%beg)%sf(j, 0, &
212 & 0)**2 + q_cons_vf(eqn_idx%B%beg + 1)%sf(j, 0, 0)**2)
213 end if
214
215 call s_compute_pressure(q_cons_vf(eqn_idx%E)%sf(j, 0, 0), q_cons_vf(eqn_idx%alf)%sf(j, 0, 0), &
216 & 0.5_wp*(q_cons_vf(eqn_idx%mom%beg)%sf(j, 0, 0)**2._wp)/rho, pi_inf, gamma, &
217 & rho, qv, rhoyks, pres, t, pres_mag=pres_mag)
218 write (2, fmt) x_cb(j), pres
219 else if (mhd) then
220 if (i == eqn_idx%mom%beg + 1) then ! v
221 write (2, fmt) x_cb(j), q_cons_vf(eqn_idx%mom%beg + 1)%sf(j, 0, 0)/rho
222 else if (i == eqn_idx%mom%beg + 2) then ! w
223 write (2, fmt) x_cb(j), q_cons_vf(eqn_idx%mom%beg + 2)%sf(j, 0, 0)/rho
224 else if (i == eqn_idx%B%beg .or. i == eqn_idx%B%beg + 1) then ! By, Bz: conserved = primitive
225 write (2, fmt) x_cb(j), q_cons_vf(i)%sf(j, 0, 0)
226 end if
227 else if ((i >= eqn_idx%bub%beg) .and. (i <= eqn_idx%bub%end) .and. bubbles_euler) then
228 if (qbmm) then
229 nbub = q_cons_vf(eqn_idx%bub%beg)%sf(j, 0, 0)
230 else
231 if (adv_n) then
232 nbub = q_cons_vf(eqn_idx%n)%sf(j, 0, 0)
233 else
234 do k = 1, nb
235 nrtmp(k) = q_cons_vf(qbmm_idx%rs(k))%sf(j, 0, 0)
236 end do
237
238 call s_comp_n_from_cons(real(q_cons_vf(eqn_idx%alf)%sf(j, 0, 0), kind=wp), nrtmp, nbub, weight)
239 end if
240 end if
241 write (2, fmt) x_cb(j), q_cons_vf(i)%sf(j, 0, 0)/nbub
242 else if (i == eqn_idx%n .and. adv_n .and. bubbles_euler) then
243 write (2, fmt) x_cb(j), q_cons_vf(i)%sf(j, 0, 0)
244 else if (i == eqn_idx%damage) then
245 write (2, fmt) x_cb(j), q_cons_vf(i)%sf(j, 0, 0)
246 end if
247 end do
248 close (2)
249 end do
250 end if
251
252 do i = 1, sys_size
253 write (file_loc, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/cons.', i, '.', proc_rank, '.', t_step, '.dat'
254
255 open (2, file=trim(file_loc))
256 do j = 0, m
257 write (2, fmt) x_cb(j), q_cons_vf(i)%sf(j, 0, 0)
258 end do
259 close (2)
260 end do
261
262 if (qbmm .and. .not. polytropic) then
263 do i = 1, nb
264 do r = 1, nnode
265 write (file_loc, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/pres.', i, '.', r, '.', proc_rank, &
266 & '.', t_step, '.dat'
267
268 open (2, file=trim(file_loc))
269 do j = 0, m
270 write (2, fmt) x_cb(j), pb%sf(j, 0, 0, r, i)
271 end do
272 close (2)
273 end do
274 end do
275 do i = 1, nb
276 do r = 1, nnode
277 write (file_loc, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/mv.', i, '.', r, '.', proc_rank, &
278 & '.', t_step, '.dat'
279
280 open (2, file=trim(file_loc))
281 do j = 0, m
282 write (2, fmt) x_cb(j), mv%sf(j, 0, 0, r, i)
283 end do
284 close (2)
285 end do
286 end do
287 end if
288 end if
289
290 if (precision == precision_single) then
291 fmt = "(3F30.7)"
292 else
293 fmt = "(3F40.14)"
294 end if
295
296 if ((n > 0) .and. (p == 0)) then
297 do i = 1, sys_size
298 write (file_loc, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/cons.', i, '.', proc_rank, '.', t_step, '.dat'
299 open (2, file=trim(file_loc))
300 do j = 0, m
301 do k = 0, n
302 write (2, fmt) x_cb(j), y_cb(k), q_cons_vf(i)%sf(j, k, 0)
303 end do
304 write (2, *)
305 end do
306 close (2)
307 end do
308
309 if (qbmm .and. .not. polytropic) then
310 do i = 1, nb
311 do r = 1, nnode
312 write (file_loc, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/pres.', i, '.', r, '.', proc_rank, &
313 & '.', t_step, '.dat'
314
315 open (2, file=trim(file_loc))
316 do j = 0, m
317 do k = 0, n
318 write (2, fmt) x_cb(j), y_cb(k), pb%sf(j, k, 0, r, i)
319 end do
320 end do
321 close (2)
322 end do
323 end do
324 do i = 1, nb
325 do r = 1, nnode
326 write (file_loc, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/mv.', i, '.', r, '.', proc_rank, &
327 & '.', t_step, '.dat'
328
329 open (2, file=trim(file_loc))
330 do j = 0, m
331 do k = 0, n
332 write (2, fmt) x_cb(j), y_cb(k), mv%sf(j, k, 0, r, i)
333 end do
334 end do
335 close (2)
336 end do
337 end do
338 end if
339 end if
340
341 if (precision == precision_single) then
342 fmt = "(4F30.7)"
343 else
344 fmt = "(4F40.14)"
345 end if
346
347 if (p > 0) then
348 do i = 1, sys_size
349 write (file_loc, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/cons.', i, '.', proc_rank, '.', t_step, '.dat'
350 open (2, file=trim(file_loc))
351 do j = 0, m
352 do k = 0, n
353 do l = 0, p
354 write (2, fmt) x_cb(j), y_cb(k), z_cb(l), q_cons_vf(i)%sf(j, k, l)
355 end do
356 write (2, *)
357 end do
358 write (2, *)
359 end do
360 close (2)
361 end do
362
363 if (qbmm .and. .not. polytropic) then
364 do i = 1, nb
365 do r = 1, nnode
366 write (file_loc, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/pres.', i, '.', r, '.', proc_rank, &
367 & '.', t_step, '.dat'
368
369 open (2, file=trim(file_loc))
370 do j = 0, m
371 do k = 0, n
372 do l = 0, p
373 write (2, fmt) x_cb(j), y_cb(k), z_cb(l), pb%sf(j, k, l, r, i)
374 end do
375 end do
376 end do
377 close (2)
378 end do
379 end do
380 do i = 1, nb
381 do r = 1, nnode
382 write (file_loc, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/mv.', i, '.', r, '.', proc_rank, &
383 & '.', t_step, '.dat'
384
385 open (2, file=trim(file_loc))
386 do j = 0, m
387 do k = 0, n
388 do l = 0, p
389 write (2, fmt) x_cb(j), y_cb(k), z_cb(l), mv%sf(j, k, l, r, i)
390 end do
391 end do
392 end do
393 close (2)
394 end do
395 end do
396 end if
397 end if
398
399 end subroutine s_write_serial_data_files
400
401 !> Writes grid and initial condition data files in parallel to the "0" time-step directory in the local processor rank folder
402 impure subroutine s_write_parallel_data_files(q_cons_vf, q_prim_vf, bc_type, q_T_sf)
403
404 type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf, q_prim_vf
405 type(integer_field), dimension(1:num_dims,1:2), intent(in) :: bc_type
406 type(scalar_field), optional, intent(inout) :: q_t_sf
407
408#ifdef MFC_MPI
409 integer :: ifile, ierr, data_size
410 integer, dimension(MPI_STATUS_SIZE) :: status
411 integer(KIND=MPI_OFFSET_KIND) :: disp
412 integer(KIND=MPI_OFFSET_KIND) :: m_mok, n_mok, p_mok
413 integer(KIND=MPI_OFFSET_KIND) :: wp_mok, var_mok, str_mok
414 integer(KIND=MPI_OFFSET_KIND) :: nvars_mok
415 integer(KIND=MPI_OFFSET_KIND) :: mok
416 character(LEN=path_len + 2*name_len) :: file_loc
417 logical :: file_exist, dir_check
418 integer :: i, j, k, l
419 real(wp) :: loc_violations, glb_violations
420 integer :: m_ds, n_ds, p_ds
421 integer :: m_glb_ds, n_glb_ds, p_glb_ds
422 integer :: m_glb_save, n_glb_save, p_glb_save !< Size of array being saved
423
424 loc_violations = 0._wp
425
426 if (down_sample) then
427 if ((mod(m + 1, 3) > 0) .or. (mod(n + 1, 3) > 0) .or. (mod(p + 1, 3) > 0)) then
428 loc_violations = 1._wp
429 end if
430 call s_mpi_allreduce_sum(loc_violations, glb_violations)
431 if (proc_rank == 0 .and. nint(glb_violations) > 0) then
432 print *, &
433 & "WARNING: Attempting to downsample data but there are" &
434 & // "processors with local problem sizes that are not divisible by 3."
435 end if
436 call s_populate_variables_buffers(bc_type, q_cons_vf)
437 call s_downsample_data(q_cons_vf, q_cons_temp, m_ds, n_ds, p_ds, m_glb_ds, n_glb_ds, p_glb_ds)
438 end if
439
440 if (file_per_process) then
441 if (proc_rank == 0) then
442 file_loc = trim(case_dir) // '/restart_data/lustre_0'
443 call my_inquire(file_loc, dir_check)
444 if (dir_check .neqv. .true.) then
445 call s_create_directory(trim(file_loc))
446 end if
447 call s_create_directory(trim(file_loc))
448 end if
449 call s_mpi_barrier()
450 call s_delay_file_access(proc_rank)
451
452 if (down_sample) then
453 call s_initialize_mpi_data_ds(m_ds, n_ds, p_ds)
454 else
455 call s_initialize_mpi_data(q_cons_vf, qbmm_pb=pb, qbmm_mv=mv)
456 end if
457
458 if (cfl_dt) then
459 write (file_loc, '(I0,A,i7.7,A)') n_start, '_', proc_rank, '.dat'
460 else
461 write (file_loc, '(I0,A,i7.7,A)') t_step_start, '_', proc_rank, '.dat'
462 end if
463 file_loc = trim(restart_dir) // '/lustre_0' // trim(mpiiofs) // trim(file_loc)
464 inquire (file=trim(file_loc), exist=file_exist)
465 if (file_exist .and. proc_rank == 0) then
466 call mpi_file_delete(file_loc, mpi_info_int, ierr)
467 end if
468 if (file_exist) call mpi_file_delete(file_loc, mpi_info_int, ierr)
469 call mpi_file_open(mpi_comm_self, file_loc, ior(mpi_mode_wronly, mpi_mode_create), mpi_info_int, ifile, ierr)
470 call s_check_mpi_file_open(ierr, file_loc)
471
472 if (down_sample) then
473 data_size = (m_ds + 3)*(n_ds + 3)*(p_ds + 3)
474 m_glb_save = m_glb_ds + 3
475 n_glb_save = n_glb_ds + 3
476 p_glb_save = p_glb_ds + 3
477 else
478 data_size = (m + 1)*(n + 1)*(p + 1)
479 m_glb_save = m_glb + 1
480 n_glb_save = n_glb + 1
481 p_glb_save = p_glb + 1
482 end if
483
484 ! Resize some integers so MPI can write even the biggest files
485 m_mok = int(m_glb_save, mpi_offset_kind)
486 n_mok = int(n_glb_save, mpi_offset_kind)
487 p_mok = int(p_glb_save, mpi_offset_kind)
488 wp_mok = int(storage_size(0._stp)/8, mpi_offset_kind)
489 mok = int(1._wp, mpi_offset_kind)
490 str_mok = int(name_len, mpi_offset_kind)
491 nvars_mok = int(sys_size, mpi_offset_kind)
492
493 if (bubbles_euler) then
494 do i = 1, sys_size
495 var_mok = int(i, mpi_offset_kind)
496
497 call mpi_file_write_all(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
498 end do
499 if (qbmm .and. .not. polytropic) then
500 do i = sys_size + 1, sys_size + 2*nb*nnode
501 var_mok = int(i, mpi_offset_kind)
502
503 call mpi_file_write_all(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
504 end do
505 end if
506 else
507 if (down_sample) then
508 do i = 1, sys_size
509 var_mok = int(i, mpi_offset_kind)
510
511 call mpi_file_write_all(ifile, q_cons_temp(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
512 end do
513 else
514 do i = 1, sys_size
515 var_mok = int(i, mpi_offset_kind)
516
517 call mpi_file_write_all(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
518 end do
519 end if
520 end if
521
522 if (euler_lagrange) then
523 block
524 real(stp), allocatable :: beta_ones(:,:,:)
525 integer :: jj, kk, ll
526 allocate (beta_ones(0:m,0:n,0:p))
527 do ll = 0, p
528 do kk = 0, n
529 do jj = 0, m
530 beta_ones(jj, kk, ll) = 1.0_stp
531 end do
532 end do
533 end do
534 call mpi_file_write_all(ifile, beta_ones, data_size*mpi_io_type, mpi_io_p, status, ierr)
535 deallocate (beta_ones)
536 end block
537 end if
538
539 call mpi_file_close(ifile, ierr)
540 else
541 call s_initialize_mpi_data(q_cons_vf, qbmm_pb=pb, qbmm_mv=mv)
542
543 if (cfl_dt) then
544 write (file_loc, '(I0,A)') n_start, '.dat'
545 else
546 write (file_loc, '(I0,A)') t_step_start, '.dat'
547 end if
548 file_loc = trim(restart_dir) // trim(mpiiofs) // trim(file_loc)
549 inquire (file=trim(file_loc), exist=file_exist)
550 if (file_exist .and. proc_rank == 0) then
551 call mpi_file_delete(file_loc, mpi_info_int, ierr)
552 end if
553 call mpi_file_open(mpi_comm_world, file_loc, ior(mpi_mode_wronly, mpi_mode_create), mpi_info_int, ifile, ierr)
554 call s_check_mpi_file_open(ierr, file_loc)
555
556 data_size = (m + 1)*(n + 1)*(p + 1)
557
558 ! Resize some integers so MPI can write even the biggest files
559 m_mok = int(m_glb + 1, mpi_offset_kind)
560 n_mok = int(n_glb + 1, mpi_offset_kind)
561 p_mok = int(p_glb + 1, mpi_offset_kind)
562 wp_mok = int(storage_size(0._stp)/8, mpi_offset_kind)
563 mok = int(1._wp, mpi_offset_kind)
564 str_mok = int(name_len, mpi_offset_kind)
565 nvars_mok = int(sys_size, mpi_offset_kind)
566
567 if (bubbles_euler) then
568 do i = 1, sys_size
569 var_mok = int(i, mpi_offset_kind)
570
571 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1)
572
573 call mpi_file_set_view(ifile, disp, mpi_io_p, mpi_io_data%view(i), 'native', mpi_info_int, ierr)
574 call mpi_file_write_all(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
575 end do
576 if (qbmm .and. .not. polytropic) then
577 do i = sys_size + 1, sys_size + 2*nb*nnode
578 var_mok = int(i, mpi_offset_kind)
579
580 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1)
581
582 call mpi_file_set_view(ifile, disp, mpi_io_p, mpi_io_data%view(i), 'native', mpi_info_int, ierr)
583 call mpi_file_write_all(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
584 end do
585 end if
586 else
587 do i = 1, sys_size
588 var_mok = int(i, mpi_offset_kind)
589
590 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1)
591
592 call mpi_file_set_view(ifile, disp, mpi_io_p, mpi_io_data%view(i), 'native', mpi_info_int, ierr)
593 call mpi_file_write_all(ifile, mpi_io_data%var(i)%sf(:,:,:), data_size*mpi_io_type, mpi_io_p, status, ierr)
594 end do
595 end if
596
597 if (euler_lagrange) then
598 block
599 real(stp), allocatable :: beta_ones(:,:,:)
600 integer :: jj, kk, ll
601 allocate (beta_ones(0:m,0:n,0:p))
602 do ll = 0, p
603 do kk = 0, n
604 do jj = 0, m
605 beta_ones(jj, kk, ll) = 1.0_stp
606 end do
607 end do
608 end do
609 var_mok = int(sys_size + 1, mpi_offset_kind)
610 disp = m_mok*max(mok, n_mok)*max(mok, p_mok)*wp_mok*(var_mok - 1)
611 call mpi_file_set_view(ifile, disp, mpi_io_p, mpi_io_data%view(1), 'native', mpi_info_int, ierr)
612 call mpi_file_write_all(ifile, beta_ones, data_size*mpi_io_type, mpi_io_p, status, ierr)
613 deallocate (beta_ones)
614 end block
615 end if
616
617 call mpi_file_close(ifile, ierr)
618 end if
619#endif
620
621 if (bc_io) then
622 if (igr) then
623 call s_write_parallel_boundary_condition_files(q_cons_vf, bc_type)
624 else
625 call s_write_parallel_boundary_condition_files(q_prim_vf, bc_type, q_t_sf)
626 end if
627 end if
628
629 end subroutine s_write_parallel_data_files
630
631 !> Computation of parameters, allocation procedures, and/or any other tasks needed to properly setup the module
633
634 character(LEN=len_trim(case_dir) + 2*name_len) :: file_loc
635 character(len=15) :: temp
636 character(LEN=1), dimension(3), parameter :: coord = (/'x', 'y', 'z'/)
637 logical :: dir_check
638 integer :: i, iu
639 integer :: m_ds, n_ds, p_ds
640
641 if (parallel_io .neqv. .true.) then
642 write (t_step_dir, '(A,I0,A)') '/p_all/p', proc_rank, '/0'
643 t_step_dir = trim(case_dir) // trim(t_step_dir)
644
645 if (old_grid .neqv. .true.) then
646 file_loc = trim(t_step_dir) // '/'
647
648 call my_inquire(file_loc, dir_check)
649
650 if (dir_check) call s_delete_directory(trim(t_step_dir))
651
652 call s_create_directory(trim(t_step_dir))
653 end if
654
656 else
657 write (restart_dir, '(A)') '/restart_data'
658 restart_dir = trim(case_dir) // trim(restart_dir)
659
660 if ((old_grid .neqv. .true.) .and. (proc_rank == 0)) then
661 file_loc = trim(restart_dir) // '/'
662 call my_inquire(file_loc, dir_check)
663
664 if (dir_check) call s_delete_directory(trim(restart_dir))
665 call s_create_directory(trim(restart_dir))
666 end if
667
668 call s_mpi_barrier()
669
671 end if
672
673 open (newunit=iu, file='indices.dat', status='unknown')
674
675 write (iu, '(A)') "Warning: The creation of file is currently experimental."
676 write (iu, '(A)') "This file may contain errors and not support all features."
677
678 write (iu, '(A3,A20,A20)') "#", "Conservative", "Primitive"
679 write (iu, '(A)') " "
680 do i = eqn_idx%cont%beg, eqn_idx%cont%end
681 write (temp, '(I0)') i - eqn_idx%cont%beg + 1
682 write (iu, '(I3,A20,A20)') i, "\alpha_{" // trim(temp) // "} \rho_{" // trim(temp) // "}", &
683 & "\alpha_{" // trim(temp) // "} \rho"
684 end do
685 do i = eqn_idx%mom%beg, eqn_idx%mom%end
686 write (iu, '(I3,A20,A20)') i, "\rho u_" // coord(i - eqn_idx%mom%beg + 1), "u_" // coord(i - eqn_idx%mom%beg + 1)
687 end do
688 if (eqn_idx%E /= 0) write (iu, '(I3,A20,A20)') eqn_idx%E, "\rho U", "p"
689 do i = eqn_idx%adv%beg, eqn_idx%adv%end
690 write (temp, '(I0)') i - eqn_idx%cont%beg + 1
691 write (iu, '(I3,A20,A20)') i, "\alpha_{" // trim(temp) // "}", "\alpha_{" // trim(temp) // "}"
692 end do
693 if (chemistry) then
694 do i = 1, num_species
695 write (iu, '(I3,A20,A20)') eqn_idx%species%beg + i - 1, "Y_{" // trim(species_names(i)) // "} \rho", &
696 & "Y_{" // trim(species_names(i)) // "}"
697 end do
698 end if
699
700 write (iu, '(A)') ""
701 call write_range(eqn_idx%cont%beg, eqn_idx%cont%end, " Continuity")
702 call write_range(eqn_idx%mom%beg, eqn_idx%mom%end, " Momentum")
703 call write_range(eqn_idx%E, eqn_idx%E, " Energy/Pressure")
704 call write_range(eqn_idx%adv%beg, eqn_idx%adv%end, " Advection")
705 call write_range(eqn_idx%bub%beg, eqn_idx%bub%end, " Bubbles")
706 call write_range(eqn_idx%stress%beg, eqn_idx%stress%end, " Stress")
707 call write_range(eqn_idx%int_en%beg, eqn_idx%int_en%end, " Internal Energies")
708 call write_range(eqn_idx%B%beg, eqn_idx%B%end, " Magnetic Field")
709 call write_range(eqn_idx%c, eqn_idx%c, " Color Function")
710 call write_range(eqn_idx%species%beg, eqn_idx%species%end, " Chemistry")
711
712 close (iu)
713
714 if (down_sample) then
715 m_ds = int((m + 1)/3) - 1
716 n_ds = int((n + 1)/3) - 1
717 p_ds = int((p + 1)/3) - 1
718
719 allocate (q_cons_temp(1:sys_size))
720 do i = 1, sys_size
721 allocate (q_cons_temp(i)%sf(-1:m_ds + 1,-1:n_ds + 1,-1:p_ds + 1))
722 end do
723 end if
724
725 contains
726
727 subroutine write_range(beg, end, label)
728
729 integer, intent(in) :: beg, end
730 character(*), intent(in) :: label
731
732 if (beg /= 0) write (iu, '("[",I0,",",I0,"]",A)') beg, end, label
733
734 end subroutine write_range
735
737
738 !> @brief Writes the initial IB layout (namelist patch_ib entries, then generated particle-cloud beds) that simulation reads
739 !! back at startup (s_read_ib_restart_data, src/simulation/m_start_up.fpp), in the layouts simulation's own IB state writers
740 !! use. Under file_per_process each rank writes only the IBs it owns to restart_data/lustre_0/ib_state_0_<rank>.dat; otherwise
741 !! only rank 0 calls this and writes every IB, in global-id order, to restart_data/ib_state_0.dat.
742 impure subroutine s_write_ib_state_0_file(glb_bounds, particle_cloud_ibs, num_particle_cloud_ibs)
743
744 type(bounds_info), dimension(3), intent(in) :: glb_bounds
745 type(ib_patch_parameters), dimension(:), intent(in) :: particle_cloud_ibs
746 integer, intent(in) :: num_particle_cloud_ibs
747 character(LEN=len_trim(case_dir) + 2*name_len) :: file_loc
748 integer :: i, ios, file_unit
749 logical, dimension(num_ibs) :: owned
750 real(wp), dimension(3) :: centroid
751
752 if (file_per_process) then
753 do i = 1, num_ibs
754 centroid = [patch_ib(i)%x_centroid, patch_ib(i)%y_centroid, patch_ib(i)%z_centroid]
755 owned(i) = f_local_rank_owns_location(centroid, glb_bounds)
756 end do
757
758 if (proc_rank == 0) call s_create_directory(trim(case_dir) // '/restart_data/lustre_0')
759 call s_mpi_barrier()
760 call s_delay_file_access(proc_rank)
761 write (file_loc, '(A,i7.7,A)') '/restart_data/lustre_0/ib_state_0_', proc_rank, '.dat'
762 else
763 owned = .true.
764 call s_create_directory(trim(case_dir) // '/restart_data')
765 file_loc = '/restart_data/ib_state_0.dat'
766 end if
767 file_loc = trim(case_dir) // trim(file_loc)
768
769 open (newunit=file_unit, file=trim(file_loc), form='unformatted', access='stream', status='replace', iostat=ios)
770 if (ios /= 0) call s_mpi_abort('Cannot open IB state output file: ' // trim(file_loc))
771
772 if (file_per_process) write (file_unit) count(owned) + num_particle_cloud_ibs
773 do i = 1, num_ibs
774 if (owned(i)) call s_write_ib_state_record(patch_ib(i), i)
775 end do
776 do i = 1, num_particle_cloud_ibs
777 call s_write_ib_state_record(particle_cloud_ibs(i), particle_cloud_ibs(i)%gbl_patch_id)
778 end do
779
780 close (file_unit)
781
782 contains
783
784 !> Writes one IB state record, prefixed by its global id under file_per_process.
785 subroutine s_write_ib_state_record(ib_patch, gbl_id)
786
787 type(ib_patch_parameters), intent(in) :: ib_patch
788 integer, intent(in) :: gbl_id
789 real(wp), dimension(ib_state_nfields) :: ib_buf
790
791 call s_pack_ib_state(ib_patch, 0._wp, ib_buf)
792 ib_buf(2:7) = 0._wp ! no force or torque before the first step
793
794 if (file_per_process) write (file_unit) gbl_id
795 write (file_unit) ib_buf
796
797 end subroutine s_write_ib_state_record
798
799 end subroutine s_write_ib_state_0_file
800
801 !> Resets s_write_data_files pointer
803
804 integer :: i
805
806 s_write_data_files => null()
807
808 if (down_sample) then
809 do i = 1, sys_size
810 deallocate (q_cons_temp(i)%sf)
811 end do
812 deallocate (q_cons_temp)
813 end if
814
815 end subroutine s_finalize_data_output_module
816
817end module m_data_output
Interface for the conservative data.
subroutine s_write_ib_state_record(ib_patch, gbl_id)
Writes one IB state record, prefixed by its global id under file_per_process.
subroutine write_range(beg, end, label)
type(scalar_field), dimension(sys_size), intent(inout) q_cons_vf
integer, intent(in) k
integer, intent(in) j
integer, intent(in) l
Noncharacteristic and processor boundary condition application for ghost cells and buffer regions.
Applies spatially varying boundary condition patches along domain edges and faces.
Boundary condition restart I/O, capillary/IGR buffer population, and grid-variable buffers.
subroutine s_pack_boundary_condition_buffers(q_prim_vf, q_t_sf)
Pack primitive variable boundary slices into bc_buffers arrays for serialization.
subroutine s_write_serial_boundary_condition_files(bc_type, step_dirpath, old_grid_in)
Write bc type and bc_buffers to serial restart files (pre_process packs them first; simulation writes...
Platform-specific file and directory operations: create, delete, inquire, getcwd, and basename.
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 model_eqns_5eq
integer, parameter ib_state_nfields
Reals per IB in restart_data/ib_state: time, force(3), torque(3), vel(3), angular_vel(3),...
real(wp), parameter dflt_t_guess
Default guess for temperature (when a previous value is not available).
integer, parameter nnode
Number of QBMM nodes.
integer, parameter precision_single
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_ib_state_0_file(glb_bounds, particle_cloud_ibs, num_particle_cloud_ibs)
Writes the initial IB layout (namelist patch_ib entries, then generated particle-cloud beds) that sim...
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.
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.
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
real(wp), dimension(:), allocatable weight
real(wp), dimension(:), allocatable z_cb
real(wp), dimension(:), allocatable x_cb
Locations of cell-boundaries (cb) in x-, y- and z-directions, respectively.
Utility routines for bubble model setup, coordinate transforms, array sampling, and special functions...
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.
subroutine, public s_compute_pressure(energy, alf, dyn_p, pi_inf, gamma, rho, qv, rhoyks, pres, t, e_e_in, pres_mag)
Compute the pressure from the appropriate equation of state.
subroutine, public s_convert_to_mixture_variables(q_vf, i, j, k, rho, gamma, pi_inf, qv, re_k, g_k, g)
Dispatch to the s_convert_mixture_to_mixture_variables and s_convert_species_to_mixture_variables sub...
Derived type annexing an integer scalar field (SF).
Derived type for bubble variables pb and mv at quadrature nodes (qbmm).
Derived type annexing a scalar field (SF).