-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathm_start_up.fpp
More file actions
1593 lines (1323 loc) · 68.3 KB
/
Copy pathm_start_up.fpp
File metadata and controls
1593 lines (1323 loc) · 68.3 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_start_up
#:include 'case.fpp'
#:include 'macros.fpp'
!> @brief Reads input files, loads initial conditions and grid data, and orchestrates solver initialization and finalization
module m_start_up
use m_derived_types
use m_global_parameters
use m_mpi_proxy
use m_mpi_common
use m_variables_conversion
use m_weno
use m_muscl
use m_thinc
use m_riemann_solvers
use m_cbc
use m_boundary_common
use m_boundary_io
use m_acoustic_src
use m_rhs
use m_pressure_relaxation, only: s_report_pressure_relaxation
use m_chemistry
use m_data_output
use m_time_steppers
use m_qbmm
use m_derived_variables
use m_hypoelastic
use m_phase_change
use m_viscous
use m_bubbles_EE
use m_bubbles_EL
use ieee_arithmetic
use m_helper_basic
use m_helper
$:USE_GPU_MODULE()
use m_nvtx
use m_ibm
use m_ib_patches
use m_model
use m_particle_cloud
use m_collisions
use m_compile_specific
use m_checker_common
use m_checker
use m_surface_tension
use m_body_forces
use m_sim_helpers
use m_igr
use m_constants, only: model_eqns_6eq, time_stepper_rk1, time_stepper_rk2, time_stepper_rk3, recon_type_weno, recon_type_muscl
implicit none
private; public :: s_read_input_file, s_check_input_file, s_read_data_files, s_read_serial_data_files, &
& s_read_parallel_data_files, s_initialize_internal_energy_equations, s_initialize_modules, s_initialize_gpu_vars, &
& s_initialize_mpi_domain, s_finalize_modules, s_perform_time_step, s_save_data, s_save_performance_metrics
type(scalar_field), allocatable, dimension(:) :: q_cons_temp
real(wp) :: dt_init
contains
!> Read data files. Dispatch subroutine that replaces procedure pointer.
impure subroutine s_read_data_files(q_cons_vf)
type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
if (.not. parallel_io) then
call s_read_serial_data_files(q_cons_vf)
else
call s_read_parallel_data_files(q_cons_vf)
end if
end subroutine s_read_data_files
!> Verify the input file exists and read it
impure subroutine s_read_input_file
character(LEN=name_len), parameter :: file_path = './simulation.inp'
logical :: file_exist !< Logical used to check the existence of the input file
integer :: iostatus
! Integer to check iostat of file read
character(len=1000) :: line
#:include 'generated_namelist.fpp'
inquire (FILE=trim(file_path), EXIST=file_exist)
if (file_exist) then
open (1, FILE=trim(file_path), form='formatted', ACTION='read', STATUS='old')
read (1, NML=user_inputs, iostat=iostatus)
if (iostatus /= 0) then
backspace (1)
read (1, fmt='(A)') line
print *, 'Invalid line in namelist: ' // trim(line)
call s_mpi_abort('Invalid line in simulation.inp. It is ' // 'likely due to a datatype mismatch. Exiting.')
end if
close (1)
if ((bf_x) .or. (bf_y) .or. (bf_z) .or. (bf_spatial_support)) then
bodyForces = .true.
end if
m_glb = m
n_glb = n
p_glb = p
call s_update_cell_bounds(cells_bounds, m, n, p)
if (cfl_adap_dt .or. cfl_const_dt) cfl_dt = .true.
if (any((/bc_x%beg, bc_x%end, bc_y%beg, bc_y%end, bc_z%beg, bc_z%end/) == -17) .or. num_bc_patches > 0) then
bc_io = .true.
end if
if (bc_x%beg == BC_PERIODIC .and. bc_x%end == BC_PERIODIC) periodic_bc(1) = .true.
if (bc_y%beg == BC_PERIODIC .and. bc_y%end == BC_PERIODIC) periodic_bc(2) = .true.
if (bc_z%beg == BC_PERIODIC .and. bc_z%end == BC_PERIODIC) periodic_bc(3) = .true.
else
call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
end if
end subroutine s_read_input_file
!> Validate that all user-provided inputs form a consistent simulation configuration
impure subroutine s_check_input_file
character(LEN=path_len) :: file_path
logical :: file_exist
file_path = trim(case_dir) // '/.'
call my_inquire(file_path, file_exist)
if (file_exist .neqv. .true.) then
call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
end if
call s_check_inputs_common(check_total_cells=.false., n_global=0_8)
call s_check_inputs()
end subroutine s_check_input_file
!> Read serial initial condition and grid data files and compute cell-width distributions
impure subroutine s_read_serial_data_files(q_cons_vf)
type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
character(LEN=path_len + 2*name_len) :: t_step_dir !< Relative path to the starting 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 the existence of the input file
integer :: i, r
if (cfl_dt) then
write (t_step_dir, '(A,I0,A,I0)') trim(case_dir) // '/p_all/p', proc_rank, '/', n_start
else
write (t_step_dir, '(A,I0,A,I0)') trim(case_dir) // '/p_all/p', proc_rank, '/', t_step_start
end if
file_path = trim(t_step_dir) // '/.'
call my_inquire(file_path, file_exist)
if (file_exist .neqv. .true.) then
call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
end if
if (bc_io) then
call s_read_serial_boundary_condition_files(t_step_dir, bc_type)
else
call s_assign_default_bc_type(bc_type)
end if
file_path = trim(t_step_dir) // '/x_cb.dat'
inquire (FILE=trim(file_path), EXIST=file_exist)
if (file_exist) then
open (2, FILE=trim(file_path), form='unformatted', ACTION='read', STATUS='old')
read (2) x_cb(-1:m); close (2)
else
call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
end if
dx(0:m) = x_cb(0:m) - x_cb(-1:m - 1)
x_cc(0:m) = x_cb(-1:m - 1) + dx(0:m)/2._wp
if (n > 0) then
file_path = trim(t_step_dir) // '/y_cb.dat'
inquire (FILE=trim(file_path), EXIST=file_exist)
if (file_exist) then
open (2, FILE=trim(file_path), form='unformatted', ACTION='read', STATUS='old')
read (2) y_cb(-1:n); close (2)
else
call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
end if
dy(0:n) = y_cb(0:n) - y_cb(-1:n - 1)
y_cc(0:n) = y_cb(-1:n - 1) + dy(0:n)/2._wp
end if
if (p > 0) then
file_path = trim(t_step_dir) // '/z_cb.dat'
inquire (FILE=trim(file_path), EXIST=file_exist)
if (file_exist) then
open (2, FILE=trim(file_path), form='unformatted', ACTION='read', STATUS='old')
read (2) z_cb(-1:p); close (2)
else
call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
end if
dz(0:p) = z_cb(0:p) - z_cb(-1:p - 1)
z_cc(0:p) = z_cb(-1:p - 1) + dz(0:p)/2._wp
end if
do i = 1, sys_size
write (file_path, '(A,I0,A)') trim(t_step_dir) // '/q_cons_vf', i, '.dat'
inquire (FILE=trim(file_path), EXIST=file_exist)
if (file_exist) then
open (2, FILE=trim(file_path), form='unformatted', ACTION='read', STATUS='old')
read (2) q_cons_vf(i)%sf(0:m,0:n,0:p); close (2)
else
call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
end if
end do
if (bubbles_euler .or. hypoelasticity) then
! Read pb and mv for non-polytropic qbmm
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'
inquire (FILE=trim(file_path), EXIST=file_exist)
if (file_exist) then
open (2, FILE=trim(file_path), form='unformatted', ACTION='read', STATUS='old')
read (2) pb_ts(1)%sf(0:m,0:n,0:p,r, i); close (2)
else
call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
end if
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'
inquire (FILE=trim(file_path), EXIST=file_exist)
if (file_exist) then
open (2, FILE=trim(file_path), form='unformatted', ACTION='read', STATUS='old')
read (2) mv_ts(1)%sf(0:m,0:n,0:p,r, i); close (2)
else
call s_mpi_abort(trim(file_path) // ' is missing. Exiting.')
end if
end do
end do
end if
end if
end subroutine s_read_serial_data_files
!> Read parallel initial condition and grid data files via MPI I/O
impure subroutine s_read_parallel_data_files(q_cons_vf)
type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
#ifdef MFC_MPI
real(wp), allocatable, dimension(:) :: x_cb_glb, y_cb_glb, z_cb_glb
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
integer(KIND=MPI_OFFSET_KIND) :: MOK
character(LEN=path_len + 2*name_len) :: file_loc
logical :: file_exist
character(len=10) :: t_step_start_string
integer :: i, j
! Downsampled data variables
integer :: m_ds, n_ds, p_ds
integer :: m_glb_ds, n_glb_ds, p_glb_ds
integer :: m_glb_read, n_glb_read, p_glb_read !< data size of read
allocate (x_cb_glb(-1:m_glb))
allocate (y_cb_glb(-1:n_glb))
allocate (z_cb_glb(-1:p_glb))
file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // 'x_cb.dat'
inquire (FILE=trim(file_loc), EXIST=file_exist)
if (down_sample) then
m_ds = int((m + 1)/3) - 1
n_ds = int((n + 1)/3) - 1
p_ds = int((p + 1)/3) - 1
m_glb_ds = int((m_glb + 1)/3) - 1
n_glb_ds = int((n_glb + 1)/3) - 1
p_glb_ds = int((p_glb + 1)/3) - 1
end if
if (file_exist) then
data_size = m_glb + 2
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
call MPI_FILE_READ(ifile, x_cb_glb, data_size, mpi_p, status, ierr)
call MPI_FILE_CLOSE(ifile, ierr)
else
call s_mpi_abort('File ' // trim(file_loc) // ' is missing. Exiting.')
end if
call s_apply_grid_from_global_dim(x_cb_glb, m_glb, m, start_idx(1), bc_x%beg, bc_x%end, buff_size, buff_size, buff_size, &
& buff_size, x_cb, x_cc, dx)
if (n > 0) then
file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // 'y_cb.dat'
inquire (FILE=trim(file_loc), EXIST=file_exist)
if (file_exist) then
data_size = n_glb + 2
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
call MPI_FILE_READ(ifile, y_cb_glb, data_size, mpi_p, status, ierr)
call MPI_FILE_CLOSE(ifile, ierr)
else
call s_mpi_abort('File ' // trim(file_loc) // ' is missing. Exiting.')
end if
call s_apply_grid_from_global_dim(y_cb_glb, n_glb, n, start_idx(2), bc_y%beg, bc_y%end, buff_size, buff_size, &
& buff_size, buff_size, y_cb, y_cc, dy)
if (p > 0) then
file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // 'z_cb.dat'
inquire (FILE=trim(file_loc), EXIST=file_exist)
if (file_exist) then
data_size = p_glb + 2
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
call MPI_FILE_READ(ifile, z_cb_glb, data_size, mpi_p, status, ierr)
call MPI_FILE_CLOSE(ifile, ierr)
else
call s_mpi_abort('File ' // trim(file_loc) // 'is missing. Exiting.')
end if
call s_apply_grid_from_global_dim(z_cb_glb, p_glb, p, start_idx(3), bc_z%beg, bc_z%end, buff_size, buff_size, &
& buff_size, buff_size, z_cb, z_cc, dz)
end if
end if
if (file_per_process) then
if (cfl_dt) then
call s_int_to_str(n_start, t_step_start_string)
write (file_loc, '(I0,A1,I7.7,A)') n_start, '_', proc_rank, '.dat'
else
call s_int_to_str(t_step_start, t_step_start_string)
write (file_loc, '(I0,A1,I7.7,A)') t_step_start, '_', proc_rank, '.dat'
end if
file_loc = trim(case_dir) // '/restart_data/lustre_' // trim(t_step_start_string) // trim(mpiiofs) // trim(file_loc)
inquire (FILE=trim(file_loc), EXIST=file_exist)
if (file_exist) then
call MPI_FILE_OPEN(MPI_COMM_SELF, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
if (down_sample) then
call s_initialize_mpi_data_ds(m_ds, n_ds, p_ds)
else
if (ib) then
call s_initialize_mpi_data(q_cons_vf, ib_markers=ib_markers, ib_mpi_data=MPI_IO_IB_DATA, &
& qbmm_pb=pb_ts(1), qbmm_mv=mv_ts(1))
else
call s_initialize_mpi_data(q_cons_vf, qbmm_pb=pb_ts(1), qbmm_mv=mv_ts(1))
end if
end if
if (down_sample) then
data_size = (m_ds + 3)*(n_ds + 3)*(p_ds + 3)
m_glb_read = m_glb_ds + 1
n_glb_read = n_glb_ds + 1
p_glb_read = p_glb_ds + 1
else
data_size = (m + 1)*(n + 1)*(p + 1)
m_glb_read = m_glb + 1
n_glb_read = n_glb + 1
p_glb_read = p_glb + 1
end if
m_MOK = int(m_glb_read + 1, MPI_OFFSET_KIND)
n_MOK = int(m_glb_read + 1, MPI_OFFSET_KIND)
p_MOK = int(m_glb_read + 1, MPI_OFFSET_KIND)
WP_MOK = int(storage_size(0._stp)/8, MPI_OFFSET_KIND)
MOK = int(1._wp, MPI_OFFSET_KIND)
if (bubbles_euler .or. hypoelasticity) then
do i = 1, sys_size
var_MOK = int(i, MPI_OFFSET_KIND)
call MPI_FILE_READ(ifile, MPI_IO_DATA%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
end do
! Read pb and mv for non-polytropic qbmm
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_READ(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
var_MOK = int(i, MPI_OFFSET_KIND)
call MPI_FILE_READ(ifile, q_cons_temp(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
end do
else
do i = 1, sys_size
var_MOK = int(i, MPI_OFFSET_KIND)
call MPI_FILE_READ(ifile, MPI_IO_DATA%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
end do
end if
end if
call s_mpi_barrier()
call MPI_FILE_CLOSE(ifile, ierr)
else
call s_mpi_abort('File ' // trim(file_loc) // ' is missing. Exiting.')
end if
else
if (cfl_dt) then
write (file_loc, '(I0,A)') n_start, '.dat'
else
write (file_loc, '(I0,A)') t_step_start, '.dat'
end if
file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // trim(file_loc)
inquire (FILE=trim(file_loc), EXIST=file_exist)
if (file_exist) then
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
if (ib) then
call s_initialize_mpi_data(q_cons_vf, ib_markers=ib_markers, ib_mpi_data=MPI_IO_IB_DATA, qbmm_pb=pb_ts(1), &
& qbmm_mv=mv_ts(1))
else
call s_initialize_mpi_data(q_cons_vf, qbmm_pb=pb_ts(1), qbmm_mv=mv_ts(1))
end if
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)
if (bubbles_euler .or. hypoelasticity) 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_io_p, MPI_IO_DATA%view(i), 'native', mpi_info_int, ierr)
call MPI_FILE_READ(ifile, MPI_IO_DATA%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
end do
! Read pb and mv for non-polytropic qbmm
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_io_p, MPI_IO_DATA%view(i), 'native', mpi_info_int, ierr)
call MPI_FILE_READ(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
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_io_p, MPI_IO_DATA%view(i), 'native', mpi_info_int, ierr)
call MPI_FILE_READ_ALL(ifile, MPI_IO_DATA%var(i)%sf, data_size*mpi_io_type, mpi_io_p, status, ierr)
end do
end if
call s_mpi_barrier()
call MPI_FILE_CLOSE(ifile, ierr)
else
call s_mpi_abort('File ' // trim(file_loc) // ' is missing. Exiting.')
end if
end if
deallocate (x_cb_glb, y_cb_glb, z_cb_glb)
if (bc_io) then
call s_read_parallel_boundary_condition_files(bc_type)
else
call s_assign_default_bc_type(bc_type)
end if
#endif
end subroutine s_read_parallel_data_files
!> Initialize internal-energy equations from phase mass, mixture momentum, and total energy
subroutine s_initialize_internal_energy_equations(v_vf)
type(scalar_field), dimension(sys_size), intent(inout) :: v_vf
real(wp) :: rho
real(wp) :: dyn_pres
real(wp) :: gamma
real(wp) :: pi_inf
real(wp) :: qv
real(wp), dimension(2) :: Re
real(wp) :: pres, T
real(wp) :: alpha_i, alpha_rho_i, e_i
integer :: i, j, k, l, c
real(wp), dimension(num_species) :: rhoYks
real(wp) :: pres_mag
pres_mag = 0._wp
T = dflt_T_guess
do j = 0, m
do k = 0, n
do l = 0, p
call s_convert_to_mixture_variables(v_vf, j, k, l, rho, gamma, pi_inf, qv, Re)
dyn_pres = 0._wp
do i = eqn_idx%mom%beg, eqn_idx%mom%end
dyn_pres = dyn_pres + 5.e-1_wp*v_vf(i)%sf(j, k, l)*v_vf(i)%sf(j, k, l)/max(rho, sgm_eps)
end do
if (chemistry) then
do c = 1, num_species
rhoYks(c) = v_vf(eqn_idx%species%beg + c - 1)%sf(j, k, l)
end do
end if
if (mhd) then
if (n == 0) then
pres_mag = 0.5_wp*(Bx0**2 + v_vf(eqn_idx%B%beg)%sf(j, k, l)**2 + v_vf(eqn_idx%B%beg + 1)%sf(j, k, l)**2)
else
pres_mag = 0.5_wp*(v_vf(eqn_idx%B%beg)%sf(j, k, l)**2 + v_vf(eqn_idx%B%beg + 1)%sf(j, k, &
& l)**2 + v_vf(eqn_idx%B%beg + 2)%sf(j, k, l)**2)
end if
end if
call s_compute_pressure(v_vf(eqn_idx%E)%sf(j, k, l), 0._stp, dyn_pres, pi_inf, gamma, rho, qv, rhoYks, pres, &
& T, pres_mag=pres_mag)
do i = 1, num_fluids
alpha_i = v_vf(i + eqn_idx%adv%beg - 1)%sf(j, k, l)
alpha_rho_i = v_vf(i + eqn_idx%cont%beg - 1)%sf(j, k, l)
call s_phase_internal_energy(pres, alpha_i, alpha_rho_i, i, e_i)
v_vf(i + eqn_idx%int_en%beg - 1)%sf(j, k, l) = e_i
end do
end do
end do
end do
end subroutine s_initialize_internal_energy_equations
!> Advance the simulation by one time step, handling CFL-based dt and time-stepper dispatch
impure subroutine s_perform_time_step(t_step, time_avg)
integer, intent(inout) :: t_step
real(wp), intent(inout) :: time_avg
integer :: i, eta_hh, eta_mm, eta_ss
real(wp) :: eta_sec
real(wp) :: dt_floor
character(len=8) :: lim_str !< Time-step limiter tag, e.g. ' (ICFL)'
if (cfl_dt) then
if (cfl_const_dt .and. t_step == 0) call s_compute_dt()
if (cfl_adap_dt) call s_compute_dt()
if (t_step == 0) dt_init = dt
! the collision restriction deliberately drops dt to collision_time/collision_temporal_resolution, so lower the
! runaway-dt abort threshold below that cap when it is enabled
dt_floor = 1.e-3_wp*dt_init
if (collision_model > 0 .and. collision_temporal_resolution > 0) then
dt_floor = min(dt_floor, 1.e-3_wp*collision_time/real(collision_temporal_resolution, wp))
end if
if (dt < dt_floor .and. cfl_adap_dt .and. proc_rank == 0) then
print *, "Delta t = ", dt
call s_mpi_abort("Delta t has become too small")
end if
end if
if (cfl_dt) then
if ((mytime + dt) >= t_stop) then
dt = t_stop - mytime
$:GPU_UPDATE(device='[dt]')
end if
else
if ((mytime + dt) >= finaltime) then
dt = finaltime - mytime
$:GPU_UPDATE(device='[dt]')
end if
end if
if (cfl_dt) then
if (proc_rank == 0 .and. mod(t_step - t_step_start, t_step_print) == 0) then
eta_sec = wall_time_avg*(t_stop - mytime)/max(dt, tiny(dt))
eta_hh = int(eta_sec)/3600
eta_mm = mod(int(eta_sec), 3600)/60
eta_ss = mod(int(eta_sec), 60)
lim_str = ''
if (cfl_adap_dt) lim_str = ' (' // dt_limiter // ')'
print '(" [", I3, "%] t = ", ES11.4, " dt = ", ES11.4, A, " @ step ", I0, " t/step ", ES9.2, "s (avg ", ES9.2, "s) ETA ", I0, ":", I2.2, ":", I2.2)', &
& int(ceiling(100._wp*(mytime/t_stop))), mytime, dt, trim(lim_str), t_step, wall_time, wall_time_avg, eta_hh, &
& eta_mm, eta_ss
end if
else
if (proc_rank == 0 .and. mod(t_step - t_step_start, t_step_print) == 0) then
eta_sec = wall_time_avg*real(t_step_stop - t_step, wp)
eta_hh = int(eta_sec)/3600
eta_mm = mod(int(eta_sec), 3600)/60
eta_ss = mod(int(eta_sec), 60)
print '(" [", I3, "%] step ", I0, " of ", I0, " (t_step ", I0, ") t/step ", ES9.2, "s (avg ", ES9.2, "s) ETA ", I0, ":", I2.2, ":", I2.2)', &
& int(ceiling(100._wp*(real(t_step - t_step_start)/(t_step_stop - t_step_start + 1)))), &
& t_step - t_step_start + 1, t_step_stop - t_step_start + 1, t_step, wall_time, wall_time_avg, eta_hh, &
& eta_mm, eta_ss
end if
end if
if (probe_wrt) then
do i = 1, sys_size
$:GPU_UPDATE(host='[q_cons_ts(1)%vf(i)%sf]')
end do
if (bubbles_euler) then
$:GPU_UPDATE(host='[ptil]')
end if
end if
! Total-variation-diminishing (TVD) Runge-Kutta (RK) time-steppers
if (any(time_stepper == (/time_stepper_rk1, time_stepper_rk2, time_stepper_rk3/))) then
call s_tvd_rk(t_step, time_avg, time_stepper)
end if
! Advance time after RK so source terms see current-step time
mytime = mytime + dt
if (relax) call s_infinite_relaxation_k(q_cons_ts(1)%vf)
! Time-stepping loop controls
t_step = t_step + 1
end subroutine s_perform_time_step
!> Collect per-process wall-clock times and write aggregate performance metrics to file
impure subroutine s_save_performance_metrics(time_avg, time_final, io_time_avg, io_time_final, proc_time, io_proc_time, &
& file_exists)
real(wp), intent(inout) :: time_avg, time_final
real(wp), intent(inout) :: io_time_avg, io_time_final
real(wp), dimension(:), intent(inout) :: proc_time
real(wp), dimension(:), intent(inout) :: io_proc_time
logical, intent(inout) :: file_exists
real(wp) :: grind_time
call s_mpi_barrier()
if (num_procs > 1) then
call mpi_bcast_time_step_values(proc_time, time_avg)
call mpi_bcast_time_step_values(io_proc_time, io_time_avg)
end if
if (proc_rank == 0) then
time_final = 0._wp
io_time_final = 0._wp
if (num_procs == 1) then
time_final = time_avg
io_time_final = io_time_avg
else
time_final = maxval(proc_time)
io_time_final = maxval(io_proc_time)
end if
grind_time = time_final*1.0e9_wp/(real(sys_size, wp)*real(maxval((/1, m_glb/)), wp)*real(maxval((/1, n_glb/)), &
& wp)*real(maxval((/1, p_glb/)), wp))
print *, "Performance:", grind_time, "ns/gp/eq/rhs"
inquire (FILE='time_data.dat', EXIST=file_exists)
if (file_exists) then
open (1, file='time_data.dat', position='append', status='old')
else
open (1, file='time_data.dat', status='new')
write (1, '(A10, A15, A15)') "Ranks", "s/step", "ns/gp/eq/rhs"
end if
write (1, '(I10, 2(F15.8))') num_procs, time_final, grind_time
close (1)
inquire (FILE='io_time_data.dat', EXIST=file_exists)
if (file_exists) then
open (1, file='io_time_data.dat', position='append', status='old')
else
open (1, file='io_time_data.dat', status='new')
write (1, '(A10, A15)') "Ranks", "s/step"
end if
write (1, '(I10, F15.8)') num_procs, io_time_final
close (1)
end if
end subroutine s_save_performance_metrics
!> Save conservative variable data to disk at the current time step
impure subroutine s_save_data(t_step, start, finish, io_time_avg, nt)
integer, intent(inout) :: t_step
real(wp), intent(inout) :: start, finish, io_time_avg
integer, intent(inout) :: nt
integer(kind=8) :: i, j, k, l
integer :: stor
integer :: save_count
if (down_sample) then
call s_populate_variables_buffers(bc_type, q_cons_ts(1)%vf)
end if
stor = 1
if (time_stepper /= time_stepper_rk1) then
$:GPU_PARALLEL_LOOP(collapse=4, copyin='[idwbuff]')
do i = 1, sys_size
do l = idwbuff(3)%beg, idwbuff(3)%end
do k = idwbuff(2)%beg, idwbuff(2)%end
do j = idwbuff(1)%beg, idwbuff(1)%end
q_cons_ts(2)%vf(i)%sf(j, k, l) = q_cons_ts(1)%vf(i)%sf(j, k, l)
end do
end do
end do
end do
$:END_GPU_PARALLEL_LOOP()
stor = 2
end if
call cpu_time(start)
call nvtxStartRange("SAVE-DATA")
do i = 1, sys_size
#ifndef FRONTIER_UNIFIED
$:GPU_UPDATE(host='[q_cons_ts(stor)%vf(i)%sf]')
#endif
do l = 0, p
do k = 0, n
do j = 0, m
if (ieee_is_nan(real(q_cons_ts(stor)%vf(i)%sf(j, k, l), kind=wp))) then
print *, "NaN(s) in timestep output.", j, k, l, i, proc_rank, t_step, m, n, p
call s_mpi_abort("NaN(s) in timestep output.")
end if
end do
end do
end do
end do
if (qbmm .and. .not. polytropic) then
$:GPU_UPDATE(host='[pb_ts(1)%sf]')
$:GPU_UPDATE(host='[mv_ts(1)%sf]')
end if
if (cfl_dt) then
save_count = int(mytime/t_save)
else
save_count = t_step
end if
if (bubbles_lagrange) then
$:GPU_UPDATE(host='[lag_id, mtn_pos, mtn_posPrev, mtn_vel, intfc_rad, intfc_vel, bub_R0, Rmax_stats, Rmin_stats, &
& bub_dphidt, gas_p, gas_mv, gas_mg, gas_betaT, gas_betaC]')
do i = 1, n_el_bubs_loc
if (ieee_is_nan(intfc_rad(i, 1)) .or. intfc_rad(i, 1) <= 0._wp) then
call s_mpi_abort("Bubble radius is negative or NaN, please reduce dt.")
end if
end do
$:GPU_UPDATE(host='[q_beta(1)%sf]')
call s_write_data_files(q_cons_ts(stor)%vf, q_T_sf, q_prim_vf, save_count, bc_type, q_beta(1))
$:GPU_UPDATE(host='[Rmax_stats, Rmin_stats, gas_p, gas_mv, intfc_vel]')
call s_write_restart_lag_bubbles(save_count) ! parallel
if (lag_params%write_bubbles_stats) call s_write_lag_bubble_stats()
else
call s_write_data_files(q_cons_ts(stor)%vf, q_T_sf, q_prim_vf, save_count, bc_type)
end if
! Write IB kinematic state for restart
if (ib) call s_write_ib_state_file(save_count)
call nvtxEndRange
call cpu_time(finish)
if (cfl_dt) then
nt = mytime/t_save
else
nt = int((t_step - t_step_start)/(t_step_save))
end if
if (nt == 1) then
io_time_avg = abs(finish - start)
else
io_time_avg = (abs(finish - start) + io_time_avg*(nt - 1))/nt
end if
end subroutine s_save_data
!> Initialize all simulation sub-modules in the required dependency order
impure subroutine s_initialize_modules
integer :: m_ds, n_ds, p_ds
integer :: i
call s_initialize_global_parameters_module()
#:if USING_AMD
#:for BC in [-5, -6, -7, -8, -9, -10, -11, -12, -13]
@:PROHIBIT(any((/bc_x%beg, bc_x%end, bc_y%beg, bc_y%end, bc_z%beg, &
& bc_z%end/) == ${BC}$) .and. eqn_idx%adv%end > 20 .and. (.not. chemistry), &
& "CBC module with AMD compiler requires eqn_idx%adv%end <= 20 when case optimization is turned off")
@:PROHIBIT(any((/bc_x%beg, bc_x%end, bc_y%beg, bc_y%end, bc_z%beg, &
& bc_z%end/) == ${BC}$) .and. sys_size > 20 .and. (chemistry), &
& "CBC module with AMD compiler and chemistry requires sys_size <= 20 when case optimization is turned off")
#:endfor
#:endif
if (bubbles_euler .or. bubbles_lagrange) then
call s_initialize_bubbles_model()
end if
call s_initialize_mpi_common_module(exchange_all_chemistry_temperatures_in=.false., use_rdma_transport_in=rdma_mpi)
call s_initialize_mpi_proxy_module()
call s_initialize_variables_conversion_module(enforce_density_floor=.true., preserve_qbmm_number=.true.)
if (grid_geometry == 3) call s_initialize_fftw_module()
if (bubbles_euler) call s_initialize_bubbles_EE_module()
if (ib) then
call s_initialize_ibm_module()
end if
if (qbmm) call s_initialize_qbmm_module()
if (acoustic_source) then
call s_initialize_acoustic_src()
end if
if (viscous .and. (.not. igr)) then
call s_initialize_viscous_module()
end if
call s_initialize_rhs_module()
if (surface_tension) call s_initialize_surface_tension_module()
if (relax) call s_initialize_phasechange_module()
call s_initialize_data_output_module()
call s_initialize_derived_variables_module()
call s_initialize_time_steppers_module()
call s_initialize_boundary_common_module(use_dirichlet_buffers=.true.)
if (down_sample) then
m_ds = int((m + 1)/3) - 1
n_ds = int((n + 1)/3) - 1
p_ds = int((p + 1)/3) - 1
allocate (q_cons_temp(1:sys_size))
do i = 1, sys_size
allocate (q_cons_temp(i)%sf(-1:m_ds + 1,-1:n_ds + 1,-1:p_ds + 1))
end do
end if
if (down_sample) then
call s_read_data_files(q_cons_temp)
call s_upsample_data(q_cons_ts(1)%vf, q_cons_temp)
do i = 1, sys_size
$:GPU_UPDATE(device='[q_cons_ts(1)%vf(i)%sf]')
end do
do i = 1, sys_size
deallocate (q_cons_temp(i)%sf)
end do
deallocate (q_cons_temp)
else
call s_read_data_files(q_cons_ts(1)%vf)
end if
block
type(int_bounds_info), dimension(3) :: grid_offsets
grid_offsets(:)%beg = buff_size
grid_offsets(:)%end = buff_size
if (n == 0) then
call s_populate_grid_variables_buffers(x_cb, x_cc, dx, grid_offsets(1), grid_offsets(2), grid_offsets(3), &
& global_bounds=glb_bounds)
else if (p == 0) then
call s_populate_grid_variables_buffers(x_cb, x_cc, dx, grid_offsets(1), grid_offsets(2), grid_offsets(3), y_cb, &
& y_cc, dy, global_bounds=glb_bounds)
else
call s_populate_grid_variables_buffers(x_cb, x_cc, dx, grid_offsets(1), grid_offsets(2), grid_offsets(3), y_cb, &
& y_cc, dy, z_cb, z_cc, dz, glb_bounds)
end if
end block
$:GPU_UPDATE(device='[glb_bounds]')
dx_min = minval(dx)
if (n > 0) dy_min = minval(dy)
if (p > 0) dz_min = minval(dz)
if (model_eqns == model_eqns_6eq) call s_initialize_internal_energy_equations(q_cons_ts(1)%vf)
if (ib) then
block
type(ib_patch_parameters), allocatable :: particle_cloud_ibs(:)
integer :: num_particle_cloud_ibs
call s_instantiate_STL_models()
call s_initialize_ib_airfoils()
call s_get_neighbor_bounds()
if (cfl_dt .and. n_start > 0) then
call s_read_ib_restart_data(n_start)
allocate (particle_cloud_ibs(0))
num_particle_cloud_ibs = 0
else if (t_step_start > 0) then
call s_read_ib_restart_data(t_step_start)
allocate (particle_cloud_ibs(0))
num_particle_cloud_ibs = 0
else
call s_generate_particle_clouds(particle_cloud_ibs, num_particle_cloud_ibs)
end if
call s_reduce_ib_patch_array(particle_cloud_ibs, num_particle_cloud_ibs)
deallocate (particle_cloud_ibs)
end block
call s_ibm_setup()
if (t_step_start == 0 .or. (cfl_dt .and. n_start == 0)) then
call s_write_ib_data_file(0)
call s_write_ib_state_file(0)
end if
end if
if (bodyForces .or. synthetic_turbulence) call s_initialize_body_forces_module()
if (acoustic_source) call s_precalculate_acoustic_spatial_sources()
! Initialize the Temperature cache.
if (chemistry) call s_compute_q_T_sf(q_T_sf, q_cons_ts(1)%vf, idwint)
! Computation of parameters, allocation of memory, association of pointers, and/or execution of any other tasks that are
! needed to properly configure the modules. The preparations below DO DEPEND on the grid being complete.
if (igr) then
call s_initialize_igr_module()
end if
if (.not. igr) then
if (recon_type == recon_type_weno) then
call s_initialize_weno_module()
else if (recon_type == recon_type_muscl) then
call s_initialize_muscl_module()
end if
call s_initialize_cbc_module()
call s_initialize_riemann_solvers_module()
end if
if (int_comp > 0) call s_initialize_thinc_module()
call s_initialize_derived_variables()
if (bubbles_lagrange) call s_initialize_bubbles_EL_module(q_cons_ts(1)%vf, bc_type)
if (hypoelasticity) call s_initialize_hypoelastic_module()
end subroutine s_initialize_modules
!> Set up the MPI execution environment, bind GPUs, and decompose the computational domain
impure subroutine s_initialize_mpi_domain
integer :: ierr
#ifdef MFC_GPU
real(wp) :: starttime, endtime
integer :: num_devices, local_size, num_nodes, ppn, my_device_num
integer :: dev, devNum, local_rank
#ifdef MFC_MPI
integer :: local_comm
#endif
#if defined(MFC_OpenACC)
integer(acc_device_kind) :: devtype
#endif
#endif
call s_mpi_initialize()
#ifdef MFC_GPU
#ifndef MFC_MPI
local_size = 1
local_rank = 0
#else
call MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, local_comm, ierr)
call MPI_Comm_size(local_comm, local_size, ierr)
call MPI_Comm_rank(local_comm, local_rank, ierr)
#endif
#if defined(MFC_OpenACC)