-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathm_data_output.fpp
More file actions
1828 lines (1495 loc) · 77.5 KB
/
m_data_output.fpp
File metadata and controls
1828 lines (1495 loc) · 77.5 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
!> @brief Writes post-processed grid and flow-variable data to Silo-HDF5 or binary database files
module m_data_output
use m_derived_types ! Definitions of the derived types
use m_global_parameters ! Global parameters
use m_derived_variables !< Procedures used to compute quantities derived
use m_mpi_proxy ! Message passing interface (MPI) module proxy
use m_compile_specific
use m_helper
use m_variables_conversion
implicit none
private; public :: s_initialize_data_output_module, &
s_define_output_region, &
s_open_formatted_database_file, &
s_open_intf_data_file, &
s_open_energy_data_file, &
s_write_grid_to_formatted_database_file, &
s_write_variable_to_formatted_database_file, &
s_write_lag_bubbles_results_to_text, &
s_write_lag_bubbles_to_formatted_database_file, &
s_write_ib_state_files, &
s_write_intf_data_file, &
s_write_energy_data_file, &
s_close_formatted_database_file, &
s_close_intf_data_file, &
s_close_energy_data_file, &
s_finalize_data_output_module
! Including the Silo Fortran interface library that features the subroutines
! and parameters that are required to write in the Silo-HDF5 database format
! INCLUDE 'silo.inc'
include 'silo_f9x.inc'
! Generic storage for flow variable(s) that are to be written to formatted
! database file(s). Note that for 1D simulations, q_root_sf is employed to
! gather the flow variable(s) from all sub-domains on to the root process.
! If the run is not parallel, but serial, then q_root_sf is equal to q_sf.
real(wp), allocatable, dimension(:, :, :), public :: q_sf
real(wp), allocatable, dimension(:, :, :) :: q_root_sf
real(wp), allocatable, dimension(:, :, :) :: cyl_q_sf
! Single precision storage for flow variables
real(sp), allocatable, dimension(:, :, :), public :: q_sf_s
real(sp), allocatable, dimension(:, :, :) :: q_root_sf_s
real(sp), allocatable, dimension(:, :, :) :: cyl_q_sf_s
! The spatial and data extents array variables contain information about the
! minimum and maximum values of the grid and flow variable(s), respectively.
! The purpose of bookkeeping this information is to boost the visualization
! of the Silo-HDF5 database file(s) in VisIt.
real(wp), allocatable, dimension(:, :) :: spatial_extents
real(wp), allocatable, dimension(:, :) :: data_extents
! The size of the ghost zone layer at beginning of each coordinate direction
! (lo) and at end of each coordinate direction (hi). Adding this information
! to Silo-HDF5 database file(s) is recommended since it supplies VisIt with
! connectivity information between the sub-domains of a parallel data set.
integer, allocatable, dimension(:) :: lo_offset
integer, allocatable, dimension(:) :: hi_offset
! For Silo-HDF5 database format, this variable is used to keep track of the
! number of cell-boundaries, for the grid associated with the local process,
! in each of the active coordinate directions.
integer, allocatable, dimension(:) :: dims
! Locations of various folders in the case's directory tree, associated with
! the choice of the formatted database format. These include, in order, the
! location of the folder named after the selected formatted database format,
! and the locations of two sub-directories of the latter, the first of which
! is named after the local processor rank, while the second is named 'root'.
! The folder associated with the local processor rank contains only the data
! pertaining to the part of the domain taken care of by the local processor.
! The root directory, on the other hand, will contain either the information
! about the connectivity required to put the entire domain back together, or
! the actual data associated with the entire computational domain. This all
! depends on dimensionality and the choice of the formatted database format.
character(LEN=path_len + name_len) :: dbdir
character(LEN=path_len + 2*name_len) :: proc_rank_dir
character(LEN=path_len + 2*name_len) :: rootdir
! Handles of the formatted database master/root file, slave/local processor
! file and options list. The list of options is explicitly used in the Silo-
! HDF5 database format to provide additional details about the contents of a
! formatted database file, such as the previously described spatial and data
! extents.
integer :: dbroot
integer :: dbfile
integer :: optlist
! The total number of flow variable(s) to be stored in a formatted database
! file. Note that this is only needed when using the Binary format.
integer :: dbvars
! Generic error flags utilized in the handling, checking and the reporting
! of the input and output operations errors with a formatted database file
integer, private :: err
contains
!> @brief Allocate storage arrays, configure output directories, and count flow variables for formatted database output.
impure subroutine s_initialize_data_output_module()
! Description: Computation of parameters, allocation procedures, and/or
! any other tasks needed to properly setup the module
! Generic string used to store the location of a particular file
character(LEN=len_trim(case_dir) + 2*name_len) :: file_loc
! Generic logical used to test the existence of a particular folder
logical :: dir_check
integer :: i
! Allocating the generic storage for the flow variable(s) that are
! going to be written to the formatted database file(s). Note once
! more that the root variable is only required for 1D computations.
allocate (q_sf(-offset_x%beg:m + offset_x%end, &
-offset_y%beg:n + offset_y%end, &
-offset_z%beg:p + offset_z%end))
if (grid_geometry == 3) then
allocate (cyl_q_sf(-offset_y%beg:n + offset_y%end, &
-offset_z%beg:p + offset_z%end, &
-offset_x%beg:m + offset_x%end))
end if
if (precision == 1) then
allocate (q_sf_s(-offset_x%beg:m + offset_x%end, &
-offset_y%beg:n + offset_y%end, &
-offset_z%beg:p + offset_z%end))
if (grid_geometry == 3) then
allocate (cyl_q_sf_s(-offset_y%beg:n + offset_y%end, &
-offset_z%beg:p + offset_z%end, &
-offset_x%beg:m + offset_x%end))
end if
end if
if (n == 0) then
allocate (q_root_sf(0:m_root, 0:0, 0:0))
if (precision == 1) then
allocate (q_root_sf_s(0:m_root, 0:0, 0:0))
end if
end if
! Allocating the spatial and data extents and also the variables for
! the offsets and the one bookkeeping the number of cell-boundaries
! in each active coordinate direction. Note that all these variables
! are only needed by the Silo-HDF5 format for multidimensional data.
if (format == 1) then
allocate (data_extents(1:2, 0:num_procs - 1))
if (p > 0) then
allocate (spatial_extents(1:6, 0:num_procs - 1))
allocate (lo_offset(1:3))
allocate (hi_offset(1:3))
allocate (dims(1:3))
elseif (n > 0) then
allocate (spatial_extents(1:4, 0:num_procs - 1))
allocate (lo_offset(1:2))
allocate (hi_offset(1:2))
allocate (dims(1:2))
else
allocate (spatial_extents(1:2, 0:num_procs - 1))
allocate (lo_offset(1:1))
allocate (hi_offset(1:1))
allocate (dims(1:1))
end if
end if
! The size of the ghost zone layer in each of the active coordinate
! directions was set in the module m_mpi_proxy.f90. The results are
! now transferred to the local variables of this module when they are
! required by the Silo-HDF5 format, for multidimensional data sets.
! With the same, latter, requirements, the variables bookkeeping the
! number of cell-boundaries in each active coordinate direction are
! also set here.
if (format == 1) then
if (p > 0) then
if (grid_geometry == 3) then
lo_offset(:) = (/offset_y%beg, offset_z%beg, offset_x%beg/)
hi_offset(:) = (/offset_y%end, offset_z%end, offset_x%end/)
else
lo_offset(:) = (/offset_x%beg, offset_y%beg, offset_z%beg/)
hi_offset(:) = (/offset_x%end, offset_y%end, offset_z%end/)
end if
if (grid_geometry == 3) then
dims(:) = (/n + offset_y%beg + offset_y%end + 2, &
p + offset_z%beg + offset_z%end + 2, &
m + offset_x%beg + offset_x%end + 2/)
else
dims(:) = (/m + offset_x%beg + offset_x%end + 2, &
n + offset_y%beg + offset_y%end + 2, &
p + offset_z%beg + offset_z%end + 2/)
end if
elseif (n > 0) then
lo_offset(:) = (/offset_x%beg, offset_y%beg/)
hi_offset(:) = (/offset_x%end, offset_y%end/)
dims(:) = (/m + offset_x%beg + offset_x%end + 2, &
n + offset_y%beg + offset_y%end + 2/)
else
lo_offset(:) = (/offset_x%beg/)
hi_offset(:) = (/offset_x%end/)
dims(:) = (/m + offset_x%beg + offset_x%end + 2/)
end if
end if
! Generating Silo-HDF5 Directory Tree
if (format == 1) then
! Creating the directory associated with the local process
dbdir = trim(case_dir)//'/silo_hdf5'
write (proc_rank_dir, '(A,I0)') '/p', proc_rank
proc_rank_dir = trim(dbdir)//trim(proc_rank_dir)
file_loc = trim(proc_rank_dir)//'/.'
call my_inquire(file_loc, dir_check)
if (dir_check .neqv. .true.) then
call s_create_directory(trim(proc_rank_dir))
end if
! Creating the directory associated with the root process
if (proc_rank == 0) then
rootdir = trim(dbdir)//'/root'
file_loc = trim(rootdir)//'/.'
call my_inquire(file_loc, dir_check)
if (dir_check .neqv. .true.) then
call s_create_directory(trim(rootdir))
end if
end if
! Generating Binary Directory Tree
else
! Creating the directory associated with the local process
dbdir = trim(case_dir)//'/binary'
write (proc_rank_dir, '(A,I0)') '/p', proc_rank
proc_rank_dir = trim(dbdir)//trim(proc_rank_dir)
file_loc = trim(proc_rank_dir)//'/.'
call my_inquire(file_loc, dir_check)
if (dir_check .neqv. .true.) then
call s_create_directory(trim(proc_rank_dir))
end if
! Creating the directory associated with the root process
if (n == 0 .and. proc_rank == 0) then
rootdir = trim(dbdir)//'/root'
file_loc = trim(rootdir)//'/.'
call my_inquire(file_loc, dir_check)
if (dir_check .neqv. .true.) then
call s_create_directory(trim(rootdir))
end if
end if
end if
if (bubbles_lagrange) then !Lagrangian solver
if (lag_txt_wrt) then
dbdir = trim(case_dir)//'/lag_bubbles_post_process'
file_loc = trim(dbdir)//'/.'
call my_inquire(file_loc, dir_check)
if (dir_check .neqv. .true.) then
call s_create_directory(trim(dbdir))
end if
end if
end if
! Contrary to the Silo-HDF5 database format, handles of the Binary
! database master/root and slave/local process files are perfectly
! static throughout post-process. Hence, they are set here so that
! they do not have to be repetitively computed in later procedures.
if (format == 2) then
if (n == 0 .and. proc_rank == 0) dbroot = 2
dbfile = 1
end if
! Querying Number of Flow Variable(s) in Binary Output
if (format == 2) then
! Initializing the counter of the number of flow variable(s) to
! be written to the formatted database file(s)
dbvars = 0
! Partial densities
if ((model_eqns == 2) .or. (model_eqns == 3)) then
do i = 1, num_fluids
if (alpha_rho_wrt(i) &
.or. &
(cons_vars_wrt .or. prim_vars_wrt)) then
dbvars = dbvars + 1
end if
end do
end if
! Density
if ((rho_wrt .or. (model_eqns == 1 .and. (cons_vars_wrt .or. prim_vars_wrt))) &
.and. (.not. relativity)) then
dbvars = dbvars + 1
end if
if (relativity .and. (rho_wrt .or. prim_vars_wrt)) dbvars = dbvars + 1
if (relativity .and. (rho_wrt .or. cons_vars_wrt)) dbvars = dbvars + 1
! Momentum
do i = 1, E_idx - mom_idx%beg
if (mom_wrt(i) .or. cons_vars_wrt) dbvars = dbvars + 1
end do
! Velocity
do i = 1, E_idx - mom_idx%beg
if (vel_wrt(i) .or. prim_vars_wrt) dbvars = dbvars + 1
end do
! Flux limiter function
do i = 1, E_idx - mom_idx%beg
if (flux_wrt(i)) dbvars = dbvars + 1
end do
! Energy
if (E_wrt .or. cons_vars_wrt) dbvars = dbvars + 1
! Pressure
if (pres_wrt .or. prim_vars_wrt) dbvars = dbvars + 1
! Elastic stresses
if (hypoelasticity) dbvars = dbvars + (num_dims*(num_dims + 1))/2
! Damage state variable
if (cont_damage) dbvars = dbvars + 1
! Hyperbolic cleaning for MHD
if (hyper_cleaning) dbvars = dbvars + 1
! Magnetic field
if (mhd) then
if (n == 0) then
dbvars = dbvars + 2
else
dbvars = dbvars + 3
end if
end if
! Volume fraction(s)
if ((model_eqns == 2) .or. (model_eqns == 3)) then
do i = 1, num_fluids - 1
if (alpha_wrt(i) &
.or. &
(cons_vars_wrt .or. prim_vars_wrt)) then
dbvars = dbvars + 1
end if
end do
if (alpha_wrt(num_fluids) &
.or. &
(cons_vars_wrt .or. prim_vars_wrt)) &
then
dbvars = dbvars + 1
end if
end if
! Specific heat ratio function
if (gamma_wrt &
.or. &
(model_eqns == 1 .and. (cons_vars_wrt .or. prim_vars_wrt))) &
then
dbvars = dbvars + 1
end if
! Specific heat ratio
if (heat_ratio_wrt) dbvars = dbvars + 1
! Liquid stiffness function
if (pi_inf_wrt &
.or. &
(model_eqns == 1 .and. (cons_vars_wrt .or. prim_vars_wrt))) &
then
dbvars = dbvars + 1
end if
! Liquid stiffness
if (pres_inf_wrt) dbvars = dbvars + 1
! Speed of sound
if (c_wrt) dbvars = dbvars + 1
! Vorticity
if (p > 0) then
do i = 1, num_vels
if (omega_wrt(i)) dbvars = dbvars + 1
end do
elseif (n > 0) then
do i = 1, num_vels
if (omega_wrt(i)) dbvars = dbvars + 1
end do
end if
! Numerical Schlieren function
if (schlieren_wrt) dbvars = dbvars + 1
end if
! END: Querying Number of Flow Variable(s) in Binary Output
end subroutine s_initialize_data_output_module
!> @brief Compute the cell-index bounds for the user-specified partial output domain in each coordinate direction.
impure subroutine s_define_output_region
integer :: i
integer :: lower_bound, upper_bound
#:for X, M in [('x', 'm'), ('y', 'n'), ('z', 'p')]
if (${M}$ == 0) return ! Early return for y or z if simulation is 1D or 2D
lower_bound = -offset_${X}$%beg
upper_bound = ${M}$+offset_${X}$%end
do i = lower_bound, upper_bound
if (${X}$_cc(i) > ${X}$_output%beg) then
${X}$_output_idx%beg = i + offset_${X}$%beg
exit
end if
end do
do i = upper_bound, lower_bound, -1
if (${X}$_cc(i) < ${X}$_output%end) then
${X}$_output_idx%end = i + offset_${X}$%beg
exit
end if
end do
! If no grid points are within the output region
if ((${X}$_cc(lower_bound) > ${X}$_output%end) .or. (${X}$_cc(upper_bound) < ${X}$_output%beg)) then
${X}$_output_idx%beg = 0
${X}$_output_idx%end = 0
end if
#:endfor
end subroutine s_define_output_region
!> @brief Open (or create) the Silo-HDF5 or Binary formatted database slave and master files for a given time step.
impure subroutine s_open_formatted_database_file(t_step)
! Description: This subroutine opens a new formatted database file, or
! replaces an old one, and readies it for the data storage
! of the grid and the flow variable(s) associated with the
! current time-step, t_step. This is performed by all the
! local process(es). The root processor, in addition, must
! also generate a master formatted database file whose job
! will be to link, and thus combine, the data from all of
! the local process(es). Note that for the Binary format,
! this extra task that is assigned to the root process is
! not performed in multidimensions.
! Time-step that is currently being post-processed
integer, intent(IN) :: t_step
! Generic string used to store the location of a particular file
character(LEN=len_trim(case_dir) + 3*name_len) :: file_loc
integer :: ierr !< Generic flag used to identify and report database errors
! Silo-HDF5 Database Format
if (format == 1) then
! Generating the relative path to the formatted database slave
! file, that is to be opened for the current time-step, t_step
write (file_loc, '(A,I0,A)') '/', t_step, '.silo'
file_loc = trim(proc_rank_dir)//trim(file_loc)
! Creating formatted database slave file at the above location
! and setting up the structure of the file and its header info
ierr = DBCREATE(trim(file_loc), len_trim(file_loc), &
DB_CLOBBER, DB_LOCAL, 'MFC v3.0', 8, &
DB_HDF5, dbfile)
! Verifying that the creation and setup process of the formatted
! database slave file has been performed without errors. If this
! is not the case, the post-process exits.
if (dbfile == -1) then
call s_mpi_abort('Unable to create Silo-HDF5 database '// &
'slave file '//trim(file_loc)//'. '// &
'Exiting.')
end if
! Next, analogous steps to the ones above are carried out by the
! root process to create and setup the formatted database master
! file.
if (proc_rank == 0) then
write (file_loc, '(A,I0,A)') '/collection_', t_step, '.silo'
file_loc = trim(rootdir)//trim(file_loc)
ierr = DBCREATE(trim(file_loc), len_trim(file_loc), &
DB_CLOBBER, DB_LOCAL, 'MFC v3.0', 8, &
DB_HDF5, dbroot)
if (dbroot == -1) then
call s_mpi_abort('Unable to create Silo-HDF5 database '// &
'master file '//trim(file_loc)//'. '// &
'Exiting.')
end if
end if
! Binary Database Format
else
! Generating the relative path to the formatted database slave
! file, that is to be opened for the current time-step, t_step
write (file_loc, '(A,I0,A)') '/', t_step, '.dat'
file_loc = trim(proc_rank_dir)//trim(file_loc)
! Creating the formatted database slave file, at the previously
! precised relative path location, and setting up its structure
open (dbfile, IOSTAT=err, FILE=trim(file_loc), &
FORM='unformatted', STATUS='replace')
! Verifying that the creation and setup process of the formatted
! database slave file has been performed without errors. If this
! is not the case, the post-process exits.
if (err /= 0) then
call s_mpi_abort('Unable to create Binary database slave '// &
'file '//trim(file_loc)//'. Exiting.')
end if
! Further defining the structure of the formatted database slave
! file by describing in it the dimensionality of post-processed
! data as well as the total number of flow variable(s) that will
! eventually be stored in it
if (output_partial_domain) then
write (dbfile) x_output_idx%end - x_output_idx%beg, &
y_output_idx%end - y_output_idx%beg, &
z_output_idx%end - z_output_idx%beg, &
dbvars
else
write (dbfile) m, n, p, dbvars
end if
! Next, analogous steps to the ones above are carried out by the
! root process to create and setup the formatted database master
! file. Note that this is only done in multidimensional cases.
if (n == 0 .and. proc_rank == 0) then
write (file_loc, '(A,I0,A)') '/', t_step, '.dat'
file_loc = trim(rootdir)//trim(file_loc)
open (dbroot, IOSTAT=err, FILE=trim(file_loc), &
FORM='unformatted', STATUS='replace')
if (err /= 0) then
call s_mpi_abort('Unable to create Binary database '// &
'master file '//trim(file_loc)// &
'. Exiting.')
end if
if (output_partial_domain) then
write (dbroot) x_output_idx%end - x_output_idx%beg, 0, 0, dbvars
else
write (dbroot) m_root, 0, 0, dbvars
end if
end if
end if
end subroutine s_open_formatted_database_file
!> @brief Open the interface data file for appending extracted interface coordinates.
impure subroutine s_open_intf_data_file()
character(LEN=path_len + 3*name_len) :: file_path !<
!! Relative path to a file in the case directory
write (file_path, '(A)') '/intf_data.dat'
file_path = trim(case_dir)//trim(file_path)
! Opening the simulation data file
open (211, FILE=trim(file_path), &
FORM='formatted', &
POSITION='append', &
STATUS='unknown')
end subroutine s_open_intf_data_file
!> @brief Open the energy data file for appending volume-integrated energy budget quantities.
impure subroutine s_open_energy_data_file()
character(LEN=path_len + 3*name_len) :: file_path !<
!! Relative path to a file in the case directory
write (file_path, '(A)') '/eng_data.dat'
file_path = trim(case_dir)//trim(file_path)
! Opening the simulation data file
open (251, FILE=trim(file_path), &
FORM='formatted', &
POSITION='append', &
STATUS='unknown')
end subroutine s_open_energy_data_file
!> @brief Write the computational grid (cell-boundary coordinates) to the formatted database slave and master files.
impure subroutine s_write_grid_to_formatted_database_file(t_step)
! Description: The general objective of this subroutine is to write the
! necessary grid data to the formatted database file, for
! the current time-step, t_step. The local processor will
! write the grid data of the domain segment that it is in
! charge of to the formatted database slave file. The root
! process will additionally take care of linking that grid
! data in the formatted database master file. In the Silo-
! HDF5 database format, the spatial extents of each local
! process grid are also written to the master file. In the
! Binary format, note that no master file is maintained in
! multidimensions. Finally, in 1D, no grid data is written
! within this subroutine for the Silo-HDF5 format because
! curve objects rather than quadrilateral meshes are used.
! For curve objects, in contrast to the quadrilateral mesh
! objects, the grid data is included side by side with the
! flow variable data. Then, in this case, we take care of
! writing both the grid and the flow variable data in the
! subroutine s_write_variable_to_formatted_database_file.
! Time-step that is currently being post-processed
integer, intent(IN) :: t_step
! Bookkeeping variables storing the name and type of mesh that is
! handled by the local processor(s). Note that due to an internal
! NAG Fortran compiler problem, these two variables could not be
! allocated dynamically.
character(LEN=4*name_len), dimension(num_procs) :: meshnames
integer, dimension(num_procs) :: meshtypes
! Generic loop iterator
integer :: i
integer :: ierr !< Generic flag used to identify and report database errors
! Silo-HDF5 Database Format
if (format == 1) then
! For multidimensional data sets, the spatial extents of all of
! the grid(s) handled by the local processor(s) are recorded so
! that they may be written, by root processor, to the formatted
! database master file.
if (num_procs > 1) then
call s_mpi_gather_spatial_extents(spatial_extents)
elseif (p > 0) then
if (grid_geometry == 3) then
spatial_extents(:, 0) = (/minval(y_cb), minval(z_cb), &
minval(x_cb), maxval(y_cb), &
maxval(z_cb), maxval(x_cb)/)
else
spatial_extents(:, 0) = (/minval(x_cb), minval(y_cb), &
minval(z_cb), maxval(x_cb), &
maxval(y_cb), maxval(z_cb)/)
end if
elseif (n > 0) then
spatial_extents(:, 0) = (/minval(x_cb), minval(y_cb), &
maxval(x_cb), maxval(y_cb)/)
else
spatial_extents(:, 0) = (/minval(x_cb), maxval(x_cb)/)
end if
! Next, the root processor proceeds to record all of the spatial
! extents in the formatted database master file. In addition, it
! also records a sub-domain connectivity map so that the entire
! grid may be reassembled by looking at the master file.
if (proc_rank == 0) then
do i = 1, num_procs
write (meshnames(i), '(A,I0,A,I0,A)') '../p', i - 1, &
'/', t_step, '.silo:rectilinear_grid'
end do
meshtypes = DB_QUAD_RECT
err = DBSET2DSTRLEN(len(meshnames(1)))
err = DBMKOPTLIST(2, optlist)
err = DBADDIOPT(optlist, DBOPT_EXTENTS_SIZE, &
size(spatial_extents, 1))
err = DBADDDOPT(optlist, DBOPT_EXTENTS, spatial_extents)
err = DBPUTMMESH(dbroot, 'rectilinear_grid', 16, &
num_procs, meshnames, &
len_trim(meshnames), &
meshtypes, optlist, ierr)
err = DBFREEOPTLIST(optlist)
end if
! Finally, the local quadrilateral mesh, either 2D or 3D, along
! with its offsets that indicate the presence and size of ghost
! zone layer(s), are put in the formatted database slave file.
if (p > 0) then
err = DBMKOPTLIST(2, optlist)
err = DBADDIOPT(optlist, DBOPT_LO_OFFSET, lo_offset)
err = DBADDIOPT(optlist, DBOPT_HI_OFFSET, hi_offset)
if (grid_geometry == 3) then
err = DBPUTQM(dbfile, 'rectilinear_grid', 16, &
'x', 1, 'y', 1, 'z', 1, &
y_cb, z_cb, x_cb, dims, 3, &
DB_DOUBLE, DB_COLLINEAR, &
optlist, ierr)
else
err = DBPUTQM(dbfile, 'rectilinear_grid', 16, &
'x', 1, 'y', 1, 'z', 1, &
x_cb, y_cb, z_cb, dims, 3, &
DB_DOUBLE, DB_COLLINEAR, &
optlist, ierr)
end if
err = DBFREEOPTLIST(optlist)
elseif (n > 0) then
err = DBMKOPTLIST(2, optlist)
err = DBADDIOPT(optlist, DBOPT_LO_OFFSET, lo_offset)
err = DBADDIOPT(optlist, DBOPT_HI_OFFSET, hi_offset)
err = DBPUTQM(dbfile, 'rectilinear_grid', 16, &
'x', 1, 'y', 1, 'z', 1, &
x_cb, y_cb, DB_F77NULL, dims, 2, &
DB_DOUBLE, DB_COLLINEAR, &
optlist, ierr)
err = DBFREEOPTLIST(optlist)
else
err = DBMKOPTLIST(2, optlist)
err = DBADDIOPT(optlist, DBOPT_LO_OFFSET, lo_offset)
err = DBADDIOPT(optlist, DBOPT_HI_OFFSET, hi_offset)
err = DBPUTQM(dbfile, 'rectilinear_grid', 16, &
'x', 1, 'y', 1, 'z', 1, &
x_cb, DB_F77NULL, DB_F77NULL, dims, 1, &
DB_DOUBLE, DB_COLLINEAR, &
optlist, ierr)
err = DBFREEOPTLIST(optlist)
end if
! END: Silo-HDF5 Database Format
! Binary Database Format
elseif (format == 2) then
! Multidimensional local grid data is written to the formatted
! database slave file. Recall that no master file to maintained
! in multidimensions.
if (p > 0) then
if (precision == 1) then
write (dbfile) real(x_cb, sp), &
real(y_cb, sp), &
real(z_cb, sp)
else
if (output_partial_domain) then
write (dbfile) x_cb(x_output_idx%beg - 1:x_output_idx%end), &
y_cb(y_output_idx%beg - 1:y_output_idx%end), &
z_cb(z_output_idx%beg - 1:z_output_idx%end)
else
write (dbfile) x_cb, y_cb, z_cb
end if
end if
elseif (n > 0) then
if (precision == 1) then
write (dbfile) real(x_cb, sp), &
real(y_cb, sp)
else
if (output_partial_domain) then
write (dbfile) x_cb(x_output_idx%beg - 1:x_output_idx%end), &
y_cb(y_output_idx%beg - 1:y_output_idx%end)
else
write (dbfile) x_cb, y_cb
end if
end if
! One-dimensional local grid data is written to the formatted
! database slave file. In addition, the local grid data is put
! together by the root process and written to the master file.
else
if (precision == 1) then
write (dbfile) real(x_cb, sp)
else
if (output_partial_domain) then
write (dbfile) x_cb(x_output_idx%beg - 1:x_output_idx%end)
else
write (dbfile) x_cb
end if
end if
if (num_procs > 1) then
call s_mpi_defragment_1d_grid_variable()
else
x_root_cb(:) = x_cb(:)
end if
if (proc_rank == 0) then
if (precision == 1) then
write (dbroot) real(x_root_cb, wp)
else
if (output_partial_domain) then
write (dbroot) x_root_cb(x_output_idx%beg - 1:x_output_idx%end)
else
write (dbroot) x_root_cb
end if
end if
end if
end if
end if
end subroutine s_write_grid_to_formatted_database_file
!> @brief Write a single flow variable field to the formatted database slave and master files for a given time step.
impure subroutine s_write_variable_to_formatted_database_file(varname, t_step)
! Description: The goal of this subroutine is to write to the formatted
! database file the flow variable at the current time-step,
! t_step. The local process(es) write the part of the flow
! variable that they handle to the formatted database slave
! file. The root process, on the other hand, will also take
! care of connecting all of the flow variable data in the
! formatted database master file. In the Silo-HDF5 database
! format, the extents of each local process flow variable
! are also written to the master file. Note that in Binary
! format, no master file is maintained in multidimensions.
! Finally note that in 1D, grid data is also written within
! this subroutine for Silo-HDF5 database format since curve
! and not the quadrilateral variable objects are used, see
! description of s_write_grid_to_formatted_database_file
! for more details on this topic.
! Name of the flow variable, which will be written to the formatted
! database file at the current time-step, t_step
character(LEN=*), intent(IN) :: varname
! Time-step that is currently being post-processed
integer, intent(IN) :: t_step
! Bookkeeping variables storing the name and type of flow variable
! that is about to be handled by the local processor(s). Note that
! due to an internal NAG Fortran compiler problem, these variables
! could not be allocated dynamically.
character(LEN=4*name_len), dimension(num_procs) :: varnames
integer, dimension(num_procs) :: vartypes
! Generic loop iterator
integer :: i, j, k
integer :: ierr !< Generic flag used to identify and report database errors
! Silo-HDF5 Database Format
if (format == 1) then
! Determining the extents of the flow variable on each local
! process and gathering all this information on root process
if (num_procs > 1) then
call s_mpi_gather_data_extents(q_sf, data_extents)
else
data_extents(:, 0) = (/minval(q_sf), maxval(q_sf)/)
end if
! Next, the root process proceeds to write the gathered flow
! variable data extents to formatted database master file.
if (proc_rank == 0) then
do i = 1, num_procs
write (varnames(i), '(A,I0,A,I0,A)') '../p', i - 1, &
'/', t_step, '.silo:'//trim(varname)
end do
vartypes = DB_QUADVAR
err = DBSET2DSTRLEN(len(varnames(1)))
err = DBMKOPTLIST(2, optlist)
err = DBADDIOPT(optlist, DBOPT_EXTENTS_SIZE, 2)
err = DBADDDOPT(optlist, DBOPT_EXTENTS, data_extents)
err = DBPUTMVAR(dbroot, trim(varname), &
len_trim(varname), num_procs, &
varnames, len_trim(varnames), &
vartypes, optlist, ierr)
err = DBFREEOPTLIST(optlist)
end if
! Finally, each of the local processor(s) proceeds to write
! the flow variable data that it is responsible for to the
! formatted database slave file.
if (wp == dp) then
if (precision == 1) then
do i = -offset_x%beg, m + offset_x%end
do j = -offset_y%beg, n + offset_y%end
do k = -offset_z%beg, p + offset_z%end
q_sf_s(i, j, k) = real(q_sf(i, j, k), sp)
end do
end do
end do
if (grid_geometry == 3) then
do i = -offset_x%beg, m + offset_x%end
do j = -offset_y%beg, n + offset_y%end
do k = -offset_z%beg, p + offset_z%end
cyl_q_sf_s(j, k, i) = q_sf_s(i, j, k)
end do
end do
end do
end if
else
if (grid_geometry == 3) then
do i = -offset_x%beg, m + offset_x%end
do j = -offset_y%beg, n + offset_y%end
do k = -offset_z%beg, p + offset_z%end
cyl_q_sf(j, k, i) = q_sf(i, j, k)
end do
end do
end do
end if
end if
elseif (wp == sp) then
do i = -offset_x%beg, m + offset_x%end
do j = -offset_y%beg, n + offset_y%end
do k = -offset_z%beg, p + offset_z%end
q_sf_s(i, j, k) = q_sf(i, j, k)
end do
end do
end do
if (grid_geometry == 3) then
do i = -offset_x%beg, m + offset_x%end
do j = -offset_y%beg, n + offset_y%end
do k = -offset_z%beg, p + offset_z%end
cyl_q_sf_s(j, k, i) = q_sf_s(i, j, k)
end do
end do
end do
end if
end if
#:for PRECISION, SFX, DBT in [(1,'_s','DB_FLOAT'),(2,'',"DB_DOUBLE")]
if (precision == ${PRECISION}$) then
if (p > 0) then
if (grid_geometry == 3) then
err = DBPUTQV1(dbfile, trim(varname), &
len_trim(varname), &
'rectilinear_grid', 16, &
cyl_q_sf${SFX}$, dims - 1, 3, DB_F77NULL, &
0, ${DBT}$, DB_ZONECENT, &
DB_F77NULL, ierr)
else
err = DBPUTQV1(dbfile, trim(varname), &
len_trim(varname), &
'rectilinear_grid', 16, &
q_sf${SFX}$, dims - 1, 3, DB_F77NULL, &
0, ${DBT}$, DB_ZONECENT, &
DB_F77NULL, ierr)
end if
elseif (n > 0) then
err = DBPUTQV1(dbfile, trim(varname), &
len_trim(varname), &
'rectilinear_grid', 16, &
q_sf${SFX}$, dims - 1, 2, DB_F77NULL, &
0, ${DBT}$, DB_ZONECENT, &
DB_F77NULL, ierr)
else
err = DBPUTQV1(dbfile, trim(varname), &
len_trim(varname), &
'rectilinear_grid', 16, &