forked from MFlowCode/MFC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm_data_output.fpp
More file actions
1694 lines (1404 loc) · 72.2 KB
/
m_data_output.fpp
File metadata and controls
1694 lines (1404 loc) · 72.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!>
!! @file
!! @brief Contains module m_data_output
#:include 'macros.fpp'
#:include 'case.fpp'
!> @brief Writes solution data, run-time stability diagnostics (ICFL, VCFL, CCFL, Rc), and probe/center-of-mass files
module m_data_output
use m_derived_types
use m_global_parameters
use m_mpi_proxy
use m_variables_conversion
use m_compile_specific
use m_helper
use m_helper_basic
use m_sim_helpers
use m_delay_file_access
use m_ibm
use m_boundary_common
implicit none
private
public :: s_initialize_data_output_module, s_open_run_time_information_file, s_open_com_files, s_open_probe_files, &
& s_write_run_time_information, s_write_data_files, s_write_serial_data_files, s_write_parallel_data_files, &
& s_write_ib_data_file, s_write_com_files, s_write_probe_files, s_write_ib_state_file, s_close_run_time_information_file, &
& s_close_com_files, s_close_probe_files, s_finalize_data_output_module
real(wp), allocatable, dimension(:,:,:) :: icfl_sf !< ICFL stability criterion
real(wp), allocatable, dimension(:,:,:) :: vcfl_sf !< VCFL stability criterion
real(wp), allocatable, dimension(:,:,:) :: Rc_sf !< Rc stability criterion
real(wp), public, allocatable, dimension(:,:) :: c_mass
$:GPU_DECLARE(create='[icfl_sf, vcfl_sf, Rc_sf, c_mass]')
real(wp) :: icfl_max_loc, icfl_max_glb !< ICFL stability extrema on local and global grids
real(wp) :: vcfl_max_loc, vcfl_max_glb !< VCFL stability extrema on local and global grids
real(wp) :: Rc_min_loc, Rc_min_glb !< Rc stability extrema on local and global grids
$:GPU_DECLARE(create='[icfl_max_loc, icfl_max_glb, vcfl_max_loc, vcfl_max_glb]')
$:GPU_DECLARE(create='[Rc_min_loc, Rc_min_glb]')
!> @name ICFL, VCFL, and Rc stability criteria extrema over all the time-steps
!> @{
real(wp) :: icfl_max !< ICFL criterion maximum
real(wp) :: vcfl_max !< VCFL criterion maximum
real(wp) :: Rc_min !< Rc criterion maximum
!> @}
type(scalar_field), allocatable, dimension(:) :: q_cons_temp_ds
contains
!> Write data files. Dispatch subroutine that replaces procedure pointer.
impure subroutine s_write_data_files(q_cons_vf, q_T_sf, q_prim_vf, t_step, bc_type, beta)
type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
type(scalar_field), intent(inout) :: q_T_sf
type(scalar_field), dimension(sys_size), intent(inout) :: q_prim_vf
integer, intent(in) :: t_step
type(scalar_field), intent(inout), optional :: beta
type(integer_field), dimension(1:num_dims,-1:1), intent(in) :: bc_type
if (.not. parallel_io) then
call s_write_serial_data_files(q_cons_vf, q_T_sf, q_prim_vf, t_step, bc_type, beta)
else
call s_write_parallel_data_files(q_cons_vf, t_step, bc_type, beta)
end if
end subroutine s_write_data_files
!> Open the run-time information file and write the stability criteria table header
impure subroutine s_open_run_time_information_file
character(LEN=name_len), parameter :: file_name = 'run_time.inf' !< Name of the run-time information file
character(LEN=path_len + name_len) :: file_path !< Relative path to a file in the case directory
character(LEN=8) :: file_date !< Creation date of the run-time information file
file_path = trim(case_dir) // '/' // trim(file_name)
open (3, FILE=trim(file_path), form='formatted', STATUS='replace')
write (3, '(A)') 'Description: Stability information at ' // 'each time-step of the simulation. This'
write (3, '(13X,A)') 'data is composed of the inviscid ' // 'Courant-Friedrichs-Lewy (ICFL)'
write (3, '(13X,A)') 'number, the viscous CFL (VCFL) number, ' // 'the capillary CFL (CCFL)'
write (3, '(13X,A)') 'number and the cell Reynolds (Rc) ' // 'number. Please note that only'
write (3, '(13X,A)') 'those stability conditions pertinent ' // 'to the physics included in'
write (3, '(13X,A)') 'the current computation are displayed.'
call date_and_time(DATE=file_date)
write (3, '(A)') 'Date: ' // file_date(5:6) // '/' // file_date(7:8) // '/' // file_date(3:4)
write (3, '(A)') ''; write (3, '(A)') ''
write (3, '(13X,A9,13X,A10,13X,A10,13X,A10)', advance="no") trim('Time-step'), trim('dt'), trim('Time'), trim('ICFL Max')
if (viscous) then
write (3, '(13X,A10,13X,A16)', advance="no") trim('VCFL Max'), trim('Rc Min')
end if
write (3, *) ! new line
end subroutine s_open_run_time_information_file
!> Open center-of-mass data files for writing
impure subroutine s_open_com_files()
character(len=path_len + 3*name_len) :: file_path !< Relative path to the CoM file in the case directory
integer :: i !< Generic loop iterator
do i = 1, num_fluids
write (file_path, '(A,I0,A)') '/fluid', i, '_com.dat'
file_path = trim(case_dir) // trim(file_path)
open (i + 120, file=trim(file_path), form='formatted', position='append', status='unknown')
if (n == 0) then
write (i + 120, '(A)') ' Non-Dimensional Time ' // ' Total Mass ' // ' x-loc ' // ' Total Volume '
else if (p == 0) then
write (i + 120, &
& '(A)') ' Non-Dimensional Time ' // ' Total Mass ' // ' x-loc ' // ' y-loc ' &
& // ' Total Volume '
else
write (i + 120, &
& '(A)') ' Non-Dimensional Time ' // ' Total Mass ' // ' x-loc ' // ' y-loc ' // ' z-loc ' &
& // ' Total Volume '
end if
end do
end subroutine s_open_com_files
!> Open flow probe data files for writing
impure subroutine s_open_probe_files
character(LEN=path_len + 3*name_len) :: file_path !< Relative path to the probe data file in the case directory
integer :: i !< Generic loop iterator
logical :: file_exist
do i = 1, num_probes
write (file_path, '(A,I0,A)') '/D/probe', i, '_prim.dat'
file_path = trim(case_dir) // trim(file_path)
inquire (file=trim(file_path), exist=file_exist)
if (file_exist) then
open (i + 30, FILE=trim(file_path), form='formatted', STATUS='old', POSITION='append')
else
open (i + 30, FILE=trim(file_path), form='formatted', STATUS='unknown')
end if
end do
if (integral_wrt) then
do i = 1, num_integrals
write (file_path, '(A,I0,A)') '/D/integral', i, '_prim.dat'
file_path = trim(case_dir) // trim(file_path)
open (i + 70, FILE=trim(file_path), form='formatted', POSITION='append', STATUS='unknown')
end do
end if
end subroutine s_open_probe_files
!> Write stability criteria extrema to the run-time information file at the given time step
impure subroutine s_write_run_time_information(q_prim_vf, t_step)
type(scalar_field), dimension(sys_size), intent(in) :: q_prim_vf
integer, intent(in) :: t_step
real(wp) :: rho !< Cell-avg. density
#:if not MFC_CASE_OPTIMIZATION and USING_AMD
real(wp), dimension(3) :: alpha !< Cell-avg. volume fraction
real(wp), dimension(3) :: vel !< Cell-avg. velocity
#:else
real(wp), dimension(num_fluids) :: alpha !< Cell-avg. volume fraction
real(wp), dimension(num_vels) :: vel !< Cell-avg. velocity
#:endif
real(wp) :: vel_sum !< Cell-avg. velocity sum
real(wp) :: pres !< Cell-avg. pressure
real(wp) :: gamma !< Cell-avg. sp. heat ratio
real(wp) :: pi_inf !< Cell-avg. liquid stiffness function
real(wp) :: qv !< Cell-avg. internal energy reference value
real(wp) :: c !< Cell-avg. sound speed
real(wp) :: H !< Cell-avg. enthalpy
real(wp), dimension(2) :: Re !< Cell-avg. Reynolds numbers
integer :: j, k, l
! Computing Stability Criteria at Current Time-step
$:GPU_PARALLEL_LOOP(collapse=3, private='[j, k, l, vel, alpha, Re, rho, vel_sum, pres, gamma, pi_inf, c, H, qv]')
do l = 0, p
do k = 0, n
do j = 0, m
call s_compute_enthalpy(q_prim_vf, pres, rho, gamma, pi_inf, Re, H, alpha, vel, vel_sum, qv, j, k, l)
call s_compute_speed_of_sound(pres, rho, gamma, pi_inf, H, alpha, vel_sum, 0._wp, c, qv)
if (viscous) then
call s_compute_stability_from_dt(vel, c, rho, Re, j, k, l, icfl_sf, vcfl_sf, Rc_sf)
else
call s_compute_stability_from_dt(vel, c, rho, Re, j, k, l, icfl_sf)
end if
end do
end do
end do
$:END_GPU_PARALLEL_LOOP()
#ifdef _CRAYFTN
$:GPU_UPDATE(host='[icfl_sf]')
if (viscous) then
$:GPU_UPDATE(host='[vcfl_sf, Rc_sf]')
end if
icfl_max_loc = maxval(icfl_sf)
if (viscous) then
vcfl_max_loc = maxval(vcfl_sf)
Rc_min_loc = minval(Rc_sf)
end if
#else
#:call GPU_PARALLEL(copyout='[icfl_max_loc]', copyin='[icfl_sf]')
icfl_max_loc = maxval(icfl_sf)
#:endcall GPU_PARALLEL
if (viscous) then
#:call GPU_PARALLEL(copyout='[vcfl_max_loc, Rc_min_loc]', copyin='[vcfl_sf,Rc_sf]')
vcfl_max_loc = maxval(vcfl_sf)
Rc_min_loc = minval(Rc_sf)
#:endcall GPU_PARALLEL
end if
#endif
if (num_procs > 1) then
call s_mpi_reduce_stability_criteria_extrema(icfl_max_loc, vcfl_max_loc, Rc_min_loc, icfl_max_glb, vcfl_max_glb, &
& Rc_min_glb)
else
icfl_max_glb = icfl_max_loc
if (viscous) vcfl_max_glb = vcfl_max_loc
if (viscous) Rc_min_glb = Rc_min_loc
end if
if (icfl_max_glb > icfl_max) icfl_max = icfl_max_glb
if (viscous) then
if (vcfl_max_glb > vcfl_max) vcfl_max = vcfl_max_glb
if (Rc_min_glb < Rc_min) Rc_min = Rc_min_glb
end if
if (proc_rank == 0) then
write (3, '(13X,I9,13X,F10.6,13X,F10.6,13X,F10.6)', advance="no") t_step, dt, mytime, icfl_max_glb
if (viscous) then
write (3, '(13X,F10.6,13X,ES16.6)', advance="no") vcfl_max_glb, Rc_min_glb
end if
write (3, *) ! new line
if (.not. f_approx_equal(icfl_max_glb, icfl_max_glb)) then
call s_mpi_abort('ICFL is NaN. Exiting.')
else if (icfl_max_glb > 1._wp) then
print *, 'icfl', icfl_max_glb
call s_mpi_abort('ICFL is greater than 1.0. Exiting.')
end if
if (viscous) then
if (.not. f_approx_equal(vcfl_max_glb, vcfl_max_glb)) then
call s_mpi_abort('VCFL is NaN. Exiting.')
else if (vcfl_max_glb > 1._wp) then
print *, 'vcfl', vcfl_max_glb
call s_mpi_abort('VCFL is greater than 1.0. Exiting.')
end if
end if
end if
call s_mpi_barrier()
end subroutine s_write_run_time_information
!> Write grid and conservative variable data files in serial format
impure subroutine s_write_serial_data_files(q_cons_vf, q_T_sf, q_prim_vf, t_step, bc_type, beta)
type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
type(scalar_field), intent(inout) :: q_T_sf
type(scalar_field), dimension(sys_size), intent(inout) :: q_prim_vf
integer, intent(in) :: t_step
type(scalar_field), intent(inout), optional :: beta
type(integer_field), dimension(1:num_dims,-1:1), intent(in) :: bc_type
character(LEN=path_len + 2*name_len) :: t_step_dir !< Relative path to the current time-step directory
character(LEN=path_len + 3*name_len) :: file_path !< Relative path to the grid and conservative variables data files
logical :: file_exist !< Logical used to check existence of current time-step directory
character(LEN=15) :: FMT
integer :: i, j, k, l, r
real(wp) :: gamma, lit_gamma, pi_inf, qv !< Temporary EOS params
write (t_step_dir, '(A,I0,A,I0)') trim(case_dir) // '/p_all'
write (t_step_dir, '(a,i0,a,i0)') trim(case_dir) // '/p_all/p', proc_rank, '/', t_step
file_path = trim(t_step_dir) // '/.'
call my_inquire(file_path, file_exist)
if (file_exist) call s_delete_directory(trim(t_step_dir))
call s_create_directory(trim(t_step_dir))
file_path = trim(t_step_dir) // '/x_cb.dat'
open (2, FILE=trim(file_path), form='unformatted', STATUS='new')
write (2) x_cb(-1:m); close (2)
if (n > 0) then
file_path = trim(t_step_dir) // '/y_cb.dat'
open (2, FILE=trim(file_path), form='unformatted', STATUS='new')
write (2) y_cb(-1:n); close (2)
if (p > 0) then
file_path = trim(t_step_dir) // '/z_cb.dat'
open (2, FILE=trim(file_path), form='unformatted', STATUS='new')
write (2) z_cb(-1:p); close (2)
end if
end if
do i = 1, sys_size
write (file_path, '(A,I0,A)') trim(t_step_dir) // '/q_cons_vf', i, '.dat'
open (2, FILE=trim(file_path), form='unformatted', STATUS='new')
write (2) q_cons_vf(i)%sf(0:m,0:n,0:p); close (2)
end do
! Lagrangian beta (void fraction) written as q_cons_vf(sys_size+1) to match the parallel I/O path and allow post_process to
! read it.
if (bubbles_lagrange) then
write (file_path, '(A,I0,A)') trim(t_step_dir) // '/q_cons_vf', sys_size + 1, '.dat'
open (2, FILE=trim(file_path), form='unformatted', STATUS='new')
write (2) beta%sf(0:m,0:n,0:p); close (2)
end if
if (qbmm .and. .not. polytropic) then
do i = 1, nb
do r = 1, nnode
write (file_path, '(A,I0,A)') trim(t_step_dir) // '/pb', sys_size + (i - 1)*nnode + r, '.dat'
open (2, FILE=trim(file_path), form='unformatted', STATUS='new')
write (2) pb_ts(1)%sf(0:m,0:n,0:p,r, i); close (2)
end do
end do
do i = 1, nb
do r = 1, nnode
write (file_path, '(A,I0,A)') trim(t_step_dir) // '/mv', sys_size + (i - 1)*nnode + r, '.dat'
open (2, FILE=trim(file_path), form='unformatted', STATUS='new')
write (2) mv_ts(1)%sf(0:m,0:n,0:p,r, i); close (2)
end do
end do
end if
! Writing the IB markers
if (ib) then
call s_write_serial_ib_data(t_step)
end if
gamma = gammas(1)
lit_gamma = gs_min(1)
pi_inf = pi_infs(1)
qv = qvs(1)
if (precision == 1) then
FMT = "(2F30.3)"
else
FMT = "(2F40.14)"
end if
write (t_step_dir, '(A,I0,A,I0)') trim(case_dir) // '/D'
file_path = trim(t_step_dir) // '/.'
inquire (FILE=trim(file_path), EXIST=file_exist)
if (.not. file_exist) call s_create_directory(trim(t_step_dir))
if ((prim_vars_wrt .or. (n == 0 .and. p == 0)) .and. (.not. igr)) then
call s_convert_conservative_to_primitive_variables(q_cons_vf, q_T_sf, q_prim_vf, idwint)
do i = 1, sys_size
$:GPU_UPDATE(host='[q_prim_vf(i)%sf(:, :, :)]')
end do
! q_prim_vf(eqn_idx%bub%beg) stores the value of nb needed in riemann solvers, so replace with true primitive value
! (=1._wp)
if (qbmm) then
q_prim_vf(eqn_idx%bub%beg)%sf = 1._wp
end if
end if
if (n == 0 .and. p == 0) then
if (model_eqns == 2 .and. (.not. igr)) then
do i = 1, sys_size
write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/prim.', i, '.', proc_rank, '.', t_step, '.dat'
open (2, FILE=trim(file_path))
do j = 0, m
! todo: revisit change here
if (((i >= eqn_idx%adv%beg) .and. (i <= eqn_idx%adv%end))) then
write (2, FMT) x_cb(j), q_cons_vf(i)%sf(j, 0, 0)
else
write (2, FMT) x_cb(j), q_prim_vf(i)%sf(j, 0, 0)
end if
end do
close (2)
end do
end if
do i = 1, sys_size
write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/cons.', i, '.', proc_rank, '.', t_step, '.dat'
open (2, FILE=trim(file_path))
do j = 0, m
write (2, FMT) x_cb(j), q_cons_vf(i)%sf(j, 0, 0)
end do
close (2)
end do
if (qbmm .and. .not. polytropic) then
do i = 1, nb
do r = 1, nnode
write (file_path, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/pres.', i, '.', r, '.', proc_rank, &
& '.', t_step, '.dat'
open (2, FILE=trim(file_path))
do j = 0, m
write (2, FMT) x_cb(j), pb_ts(1)%sf(j, 0, 0, r, i)
end do
close (2)
end do
end do
do i = 1, nb
do r = 1, nnode
write (file_path, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/mv.', i, '.', r, '.', proc_rank, &
& '.', t_step, '.dat'
open (2, FILE=trim(file_path))
do j = 0, m
write (2, FMT) x_cb(j), mv_ts(1)%sf(j, 0, 0, r, i)
end do
close (2)
end do
end do
end if
end if
if (precision == 1) then
FMT = "(3F30.7)"
else
FMT = "(3F40.14)"
end if
if ((n > 0) .and. (p == 0)) then
do i = 1, sys_size
write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/cons.', i, '.', proc_rank, '.', t_step, '.dat'
open (2, FILE=trim(file_path))
do j = 0, m
do k = 0, n
write (2, FMT) x_cb(j), y_cb(k), q_cons_vf(i)%sf(j, k, 0)
end do
write (2, *)
end do
close (2)
end do
if (present(beta)) then
write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/beta.', i, '.', proc_rank, '.', t_step, '.dat'
open (2, FILE=trim(file_path))
do j = 0, m
do k = 0, n
write (2, FMT) x_cb(j), y_cb(k), beta%sf(j, k, 0)
end do
write (2, *)
end do
close (2)
end if
if (qbmm .and. .not. polytropic) then
do i = 1, nb
do r = 1, nnode
write (file_path, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/pres.', i, '.', r, '.', proc_rank, &
& '.', t_step, '.dat'
open (2, FILE=trim(file_path))
do j = 0, m
do k = 0, n
write (2, FMT) x_cb(j), y_cb(k), pb_ts(1)%sf(j, k, 0, r, i)
end do
end do
close (2)
end do
end do
do i = 1, nb
do r = 1, nnode
write (file_path, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/mv.', i, '.', r, '.', proc_rank, &
& '.', t_step, '.dat'
open (2, FILE=trim(file_path))
do j = 0, m
do k = 0, n
write (2, FMT) x_cb(j), y_cb(k), mv_ts(1)%sf(j, k, 0, r, i)
end do
end do
close (2)
end do
end do
end if
if (prim_vars_wrt .and. (.not. igr)) then
do i = 1, sys_size
write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/prim.', i, '.', proc_rank, '.', t_step, '.dat'
open (2, FILE=trim(file_path))
do j = 0, m
do k = 0, n
if (((i >= eqn_idx%cont%beg) .and. (i <= eqn_idx%cont%end)) .or. ((i >= eqn_idx%adv%beg) &
& .and. (i <= eqn_idx%adv%end))) then
write (2, FMT) x_cb(j), y_cb(k), q_cons_vf(i)%sf(j, k, 0)
else
write (2, FMT) x_cb(j), y_cb(k), q_prim_vf(i)%sf(j, k, 0)
end if
end do
write (2, *)
end do
close (2)
end do
end if
end if
if (precision == 1) then
FMT = "(4F30.7)"
else
FMT = "(4F40.14)"
end if
if (p > 0) then
do i = 1, sys_size
write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/cons.', i, '.', proc_rank, '.', t_step, '.dat'
open (2, FILE=trim(file_path))
do j = 0, m
do k = 0, n
do l = 0, p
write (2, FMT) x_cb(j), y_cb(k), z_cb(l), q_cons_vf(i)%sf(j, k, l)
end do
write (2, *)
end do
write (2, *)
end do
close (2)
end do
if (present(beta)) then
write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/beta.', i, '.', proc_rank, '.', t_step, '.dat'
open (2, FILE=trim(file_path))
do j = 0, m
do k = 0, n
do l = 0, p
write (2, FMT) x_cb(j), y_cb(k), z_cb(l), beta%sf(j, k, l)
end do
write (2, *)
end do
write (2, *)
end do
close (2)
end if
if (qbmm .and. .not. polytropic) then
do i = 1, nb
do r = 1, nnode
write (file_path, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/pres.', i, '.', r, '.', proc_rank, &
& '.', t_step, '.dat'
open (2, FILE=trim(file_path))
do j = 0, m
do k = 0, n
do l = 0, p
write (2, FMT) x_cb(j), y_cb(k), z_cb(l), pb_ts(1)%sf(j, k, l, r, i)
end do
end do
end do
close (2)
end do
end do
do i = 1, nb
do r = 1, nnode
write (file_path, '(A,I0,A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/mv.', i, '.', r, '.', proc_rank, &
& '.', t_step, '.dat'
open (2, FILE=trim(file_path))
do j = 0, m
do k = 0, n
do l = 0, p
write (2, FMT) x_cb(j), y_cb(k), z_cb(l), mv_ts(1)%sf(j, k, l, r, i)
end do
end do
end do
close (2)
end do
end do
end if
if (prim_vars_wrt .and. (.not. igr)) then
do i = 1, sys_size
write (file_path, '(A,I0,A,I2.2,A,I6.6,A)') trim(t_step_dir) // '/prim.', i, '.', proc_rank, '.', t_step, '.dat'
open (2, FILE=trim(file_path))
do j = 0, m
do k = 0, n
do l = 0, p
if (((i >= eqn_idx%cont%beg) .and. (i <= eqn_idx%cont%end)) .or. ((i >= eqn_idx%adv%beg) &
& .and. (i <= eqn_idx%adv%end)) .or. ((i >= eqn_idx%species%beg) &
& .and. (i <= eqn_idx%species%end))) then
write (2, FMT) x_cb(j), y_cb(k), z_cb(l), q_cons_vf(i)%sf(j, k, l)
else
write (2, FMT) x_cb(j), y_cb(k), z_cb(l), q_prim_vf(i)%sf(j, k, l)
end if
end do
write (2, *)
end do
write (2, *)
end do
close (2)
end do
end if
end if
end subroutine s_write_serial_data_files
!> Write grid and conservative variable data files in parallel via MPI I/O
impure subroutine s_write_parallel_data_files(q_cons_vf, t_step, bc_type, beta, q_T_sf)
type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
integer, intent(in) :: t_step
type(scalar_field), intent(inout), optional :: beta
type(integer_field), dimension(1:num_dims,-1:1), intent(in) :: bc_type
type(scalar_field), intent(inout), optional :: q_T_sf
#ifdef MFC_MPI
integer :: ifile, ierr, data_size
integer, dimension(MPI_STATUS_SIZE) :: status
integer(kind=MPI_OFFSET_kind) :: disp
integer(kind=MPI_OFFSET_kind) :: m_MOK, n_MOK, p_MOK
integer(kind=MPI_OFFSET_kind) :: WP_MOK, var_MOK, str_MOK
integer(kind=MPI_OFFSET_kind) :: NVARS_MOK
integer(kind=MPI_OFFSET_kind) :: MOK
character(LEN=path_len + 2*name_len) :: file_loc
logical :: file_exist, dir_check
character(len=10) :: t_step_string
integer :: i !< Generic loop iterator
integer :: alt_sys !< Altered system size for the lagrangian subgrid bubble model
! Down sampling variables
integer :: m_ds, n_ds, p_ds
integer :: m_glb_ds, n_glb_ds, p_glb_ds
integer :: m_glb_save, n_glb_save, p_glb_save !< Global save size
if (down_sample) then
call s_downsample_data(q_cons_vf, q_cons_temp_ds, m_ds, n_ds, p_ds, m_glb_ds, n_glb_ds, p_glb_ds)
end if
if (present(beta)) then
alt_sys = sys_size + 1
else
alt_sys = sys_size
end if
if (file_per_process) then
call s_int_to_str(t_step, t_step_string)
if (down_sample) then
call s_initialize_mpi_data_ds(q_cons_temp_ds)
else
if (ib) then
call s_initialize_mpi_data(q_cons_vf, ib_markers)
else
call s_initialize_mpi_data(q_cons_vf)
end if
end if
if (proc_rank == 0) then
file_loc = trim(case_dir) // '/restart_data/lustre_' // trim(t_step_string)
call my_inquire(file_loc, dir_check)
if (dir_check .neqv. .true.) then
call s_create_directory(trim(file_loc))
end if
call s_create_directory(trim(file_loc))
end if
call s_mpi_barrier()
call DelayFileAccess(proc_rank)
call s_initialize_mpi_data(q_cons_vf)
write (file_loc, '(I0,A,i7.7,A)') t_step, '_', proc_rank, '.dat'
file_loc = trim(case_dir) // '/restart_data/lustre_' // trim(t_step_string) // trim(mpiiofs) // trim(file_loc)
inquire (FILE=trim(file_loc), EXIST=file_exist)
if (file_exist .and. proc_rank == 0) then
call MPI_FILE_DELETE(file_loc, mpi_info_int, ierr)
end if
call MPI_FILE_OPEN(MPI_COMM_SELF, file_loc, ior(MPI_MODE_WRONLY, MPI_MODE_CREATE), mpi_info_int, ifile, ierr)
if (down_sample) then
data_size = (m_ds + 3)*(n_ds + 3)*(p_ds + 3)
m_glb_save = m_glb_ds + 1
n_glb_save = n_glb_ds + 1
p_glb_save = p_glb_ds + 1
else
data_size = (m + 1)*(n + 1)*(p + 1)
m_glb_save = m_glb + 1
n_glb_save = n_glb + 1
p_glb_save = p_glb + 1
end if
m_MOK = int(m_glb_save + 1, MPI_OFFSET_KIND)
n_MOK = int(n_glb_save + 1, MPI_OFFSET_KIND)
p_MOK = int(p_glb_save + 1, MPI_OFFSET_KIND)
WP_MOK = int(storage_size(0._stp)/8, MPI_OFFSET_KIND)
MOK = int(1._wp, MPI_OFFSET_KIND)
str_MOK = int(name_len, MPI_OFFSET_KIND)
NVARS_MOK = int(sys_size, MPI_OFFSET_KIND)
if (bubbles_euler) then
do i = 1, sys_size
var_MOK = int(i, MPI_OFFSET_KIND)
call MPI_FILE_WRITE_ALL(ifile, MPI_IO_DATA%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
end do
if (qbmm .and. .not. polytropic) then
do i = sys_size + 1, sys_size + 2*nb*nnode
var_MOK = int(i, MPI_OFFSET_KIND)
call MPI_FILE_WRITE_ALL(ifile, MPI_IO_DATA%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
end do
end if
else
if (down_sample) then
do i = 1, sys_size ! TODO: check if sys_size is correct
var_MOK = int(i, MPI_OFFSET_KIND)
call MPI_FILE_WRITE_ALL(ifile, q_cons_temp_ds(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
end do
else
do i = 1, sys_size ! TODO: check if sys_size is correct
var_MOK = int(i, MPI_OFFSET_KIND)
call MPI_FILE_WRITE_ALL(ifile, MPI_IO_DATA%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
end do
end if
end if
call MPI_FILE_CLOSE(ifile, ierr)
else
if (ib) then
call s_initialize_mpi_data(q_cons_vf, ib_markers)
else if (present(beta)) then
call s_initialize_mpi_data(q_cons_vf, beta=beta)
else
call s_initialize_mpi_data(q_cons_vf)
end if
write (file_loc, '(I0,A)') t_step, '.dat'
file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // trim(file_loc)
inquire (FILE=trim(file_loc), EXIST=file_exist)
if (file_exist .and. proc_rank == 0) then
call MPI_FILE_DELETE(file_loc, mpi_info_int, ierr)
end if
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, ior(MPI_MODE_WRONLY, MPI_MODE_CREATE), mpi_info_int, ifile, ierr)
data_size = (m + 1)*(n + 1)*(p + 1)
m_MOK = int(m_glb + 1, MPI_OFFSET_KIND)
n_MOK = int(n_glb + 1, MPI_OFFSET_KIND)
p_MOK = int(p_glb + 1, MPI_OFFSET_KIND)
WP_MOK = int(storage_size(0._stp)/8, MPI_OFFSET_KIND)
MOK = int(1._wp, MPI_OFFSET_KIND)
str_MOK = int(name_len, MPI_OFFSET_KIND)
NVARS_MOK = int(alt_sys, MPI_OFFSET_KIND)
if (bubbles_euler) then
do i = 1, sys_size
var_MOK = int(i, MPI_OFFSET_KIND)
disp = m_MOK*max(MOK, n_MOK)*max(MOK, p_MOK)*WP_MOK*(var_MOK - 1)
call MPI_FILE_SET_VIEW(ifile, disp, mpi_p, MPI_IO_DATA%view(i), 'native', mpi_info_int, ierr)
call MPI_FILE_WRITE_ALL(ifile, MPI_IO_DATA%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
end do
if (qbmm .and. .not. polytropic) then
do i = sys_size + 1, sys_size + 2*nb*nnode
var_MOK = int(i, MPI_OFFSET_KIND)
disp = m_MOK*max(MOK, n_MOK)*max(MOK, p_MOK)*WP_MOK*(var_MOK - 1)
call MPI_FILE_SET_VIEW(ifile, disp, mpi_p, MPI_IO_DATA%view(i), 'native', mpi_info_int, ierr)
call MPI_FILE_WRITE_ALL(ifile, MPI_IO_DATA%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
end do
end if
else
do i = 1, sys_size ! TODO: check if sys_size is correct
var_MOK = int(i, MPI_OFFSET_KIND)
disp = m_MOK*max(MOK, n_MOK)*max(MOK, p_MOK)*WP_MOK*(var_MOK - 1)
call MPI_FILE_SET_VIEW(ifile, disp, mpi_p, MPI_IO_DATA%view(i), 'native', mpi_info_int, ierr)
call MPI_FILE_WRITE_ALL(ifile, MPI_IO_DATA%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
end do
end if
if (present(beta)) then
var_MOK = int(sys_size + 1, MPI_OFFSET_KIND)
disp = m_MOK*max(MOK, n_MOK)*max(MOK, p_MOK)*WP_MOK*(var_MOK - 1)
call MPI_FILE_SET_VIEW(ifile, disp, mpi_p, MPI_IO_DATA%view(sys_size + 1), 'native', mpi_info_int, ierr)
call MPI_FILE_WRITE_ALL(ifile, MPI_IO_DATA%var(sys_size + 1)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
end if
call MPI_FILE_CLOSE(ifile, ierr)
if (ib) then
call s_write_parallel_ib_data(t_step)
end if
end if
#endif
end subroutine s_write_parallel_data_files
!> Write immersed boundary marker data to a serial (per-processor) unformatted file
subroutine s_write_serial_ib_data(time_step)
integer, intent(in) :: time_step
character(LEN=path_len + 2*name_len) :: file_path
character(LEN=path_len + 2*name_len) :: t_step_dir
write (t_step_dir, '(A,I0,A,I0)') trim(case_dir) // '/p_all'
write (t_step_dir, '(a,i0,a,i0)') trim(case_dir) // '/p_all/p', proc_rank, '/', time_step
write (file_path, '(A,I0,A)') trim(t_step_dir) // '/ib_data.dat'
open (2, FILE=trim(file_path), form='unformatted', STATUS='new')
$:GPU_UPDATE(host='[ib_markers%sf]')
write (2) ib_markers%sf(0:m,0:n,0:p); close (2)
end subroutine s_write_serial_ib_data
!> Write immersed boundary marker data in parallel using MPI I/O
subroutine s_write_parallel_ib_data(time_step)
integer, intent(in) :: time_step
#ifdef MFC_MPI
character(LEN=path_len + 2*name_len) :: file_loc
integer(kind=MPI_OFFSET_kind) :: disp
integer(kind=MPI_OFFSET_kind) :: m_MOK, n_MOK, p_MOK
integer(kind=MPI_OFFSET_kind) :: WP_MOK, var_MOK, MOK
integer :: ifile, ierr, data_size
integer, dimension(MPI_STATUS_SIZE) :: status
$:GPU_UPDATE(host='[ib_markers%sf]')
data_size = (m + 1)*(n + 1)*(p + 1)
m_MOK = int(m_glb + 1, MPI_OFFSET_KIND)
n_MOK = int(n_glb + 1, MPI_OFFSET_KIND)
p_MOK = int(p_glb + 1, MPI_OFFSET_KIND)
WP_MOK = int(storage_size(0._stp)/8, MPI_OFFSET_KIND)
MOK = int(1._wp, MPI_OFFSET_KIND)
write (file_loc, '(A)') 'ib.dat'
file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // trim(file_loc)
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, ior(MPI_MODE_WRONLY, MPI_MODE_CREATE), mpi_info_int, ifile, ierr)
var_MOK = int(sys_size + 1, MPI_OFFSET_KIND)
disp = m_MOK*max(MOK, n_MOK)*max(MOK, p_MOK)*WP_MOK*(var_MOK - 1 + int(time_step/t_step_save))
if (time_step == 0) disp = 0
call MPI_FILE_SET_VIEW(ifile, disp, MPI_INTEGER, MPI_IO_IB_DATA%view, 'native', mpi_info_int, ierr)
call MPI_FILE_WRITE_ALL(ifile, MPI_IO_IB_DATA%var%sf, data_size, MPI_INTEGER, status, ierr)
call MPI_FILE_CLOSE(ifile, ierr)
#endif
end subroutine s_write_parallel_ib_data
!> Dispatch immersed boundary data output to the serial or parallel writer
subroutine s_write_ib_data_file(time_step)
integer, intent(in) :: time_step
if (parallel_io) then
call s_write_parallel_ib_data(time_step)
else
call s_write_serial_ib_data(time_step)
end if
end subroutine s_write_ib_data_file
!> Writes the IB state information out to file
subroutine s_write_parallel_ib_state(t_step)
integer, intent(in) :: t_step
#ifdef MFC_MPI
character(LEN=path_len + 2*name_len) :: file_loc
integer(kind=MPI_OFFSET_KIND) :: disp
integer(kind=MPI_OFFSET_KIND) :: WP_MOK
integer :: ifile, ierr
integer, dimension(MPI_STATUS_SIZE) :: status
logical :: file_exist
integer :: i
integer, parameter :: NFIELDS_PER_IB = 20
real(wp) :: ib_buf(NFIELDS_PER_IB)
! Partition IBs across ranks round-robin style
integer :: ib_start, ib_end, nibs_per_rank, remainder
WP_MOK = int(storage_size(0._wp)/8, MPI_OFFSET_KIND)
if (proc_rank == 0) then
call s_create_directory(trim(case_dir) // '/restart_data')
end if
call s_mpi_barrier()
! Divide num_ibs across num_procs
nibs_per_rank = num_ibs/num_procs
remainder = mod(num_ibs, num_procs)
! Ranks < remainder get one extra IB
if (proc_rank < remainder) then
ib_start = proc_rank*(nibs_per_rank + 1) + 1
ib_end = ib_start + nibs_per_rank ! nibs_per_rank + 1 total
else
ib_start = remainder*(nibs_per_rank + 1) + (proc_rank - remainder)*nibs_per_rank + 1
ib_end = ib_start + nibs_per_rank - 1
end if
write (file_loc, '(A,I0,A)') '/restart_data/ib_state_', t_step, '.dat'
file_loc = trim(case_dir) // trim(file_loc)
inquire (FILE=trim(file_loc), EXIST=file_exist)
if (file_exist .and. proc_rank == 0) then
call MPI_FILE_DELETE(file_loc, mpi_info_int, ierr)
end if
call s_mpi_barrier()
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, ior(MPI_MODE_WRONLY, MPI_MODE_CREATE), mpi_info_int, ifile, ierr)
do i = ib_start, ib_end
ib_buf(1) = mytime
ib_buf(2:4) = patch_ib(i)%force(1:3)
ib_buf(5:7) = patch_ib(i)%torque(1:3)
ib_buf(8:10) = patch_ib(i)%vel(1:3)
ib_buf(11:13) = patch_ib(i)%angular_vel(1:3)
ib_buf(14:16) = patch_ib(i)%angles(1:3)
ib_buf(17) = patch_ib(i)%x_centroid
ib_buf(18) = patch_ib(i)%y_centroid
ib_buf(19) = patch_ib(i)%z_centroid
ib_buf(20) = patch_ib(i)%radius
! Global IB index (i) determines position in file
disp = int(i - 1, MPI_OFFSET_KIND)*int(NFIELDS_PER_IB, MPI_OFFSET_KIND)*WP_MOK
call MPI_FILE_WRITE_AT(ifile, disp, ib_buf, NFIELDS_PER_IB, mpi_p, status, ierr)
end do
call MPI_FILE_CLOSE(ifile, ierr)
#endif
end subroutine s_write_parallel_ib_state
!> Write IB state data to a per-timestep serial (unformatted) file
subroutine s_write_serial_ib_state(t_step)
integer, intent(in) :: t_step
character(LEN=path_len + 2*name_len) :: file_loc
integer :: i, ios, file_unit
integer, parameter :: NFIELDS_PER_IB = 20
real(wp) :: ib_buf(NFIELDS_PER_IB)
call s_create_directory(trim(case_dir) // '/restart_data')
write (file_loc, '(A,I0,A)') '/restart_data/ib_state_', t_step, '.dat'
file_loc = trim(case_dir) // trim(file_loc)
open (newunit=file_unit, file=trim(file_loc), form='unformatted', access='stream', status='replace', iostat=ios)
if (ios /= 0) call s_mpi_abort('Cannot open IB state output file: ' // trim(file_loc))
do i = 1, num_ibs
ib_buf(1) = mytime
ib_buf(2:4) = patch_ib(i)%force(1:3)
ib_buf(5:7) = patch_ib(i)%torque(1:3)
ib_buf(8:10) = patch_ib(i)%vel(1:3)
ib_buf(11:13) = patch_ib(i)%angular_vel(1:3)
ib_buf(14:16) = patch_ib(i)%angles(1:3)
ib_buf(17) = patch_ib(i)%x_centroid
ib_buf(18) = patch_ib(i)%y_centroid
ib_buf(19) = patch_ib(i)%z_centroid
ib_buf(20) = patch_ib(i)%radius