-
Notifications
You must be signed in to change notification settings - Fork 38
/
io.f90
8387 lines (8387 loc) · 269 KB
/
io.f90
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
module io_mod
!
#include <mpi_defs.h>
!
!.. Use Statements ..
use module_kind_types
use module_cgns_types
use eqn_idx, only : nec,nmb,nme,nmx,nmy,nmz,nee,ntk,ntl,nq
use ovar, only : grid_format
use ovar, only : gridfile
use ovar, only : output_dir
use ovar, only : plot3d_cutfile
use ovar, only : plot3d_bcsfile
!
implicit none
!
private
!
! ##################################
! ### Module Public Procedures ###
! ##################################
!
public :: read_input_file
public :: read_grid_file
public :: write_final_error
public :: write_parallel_cgns
public :: write_residual_file
public :: check_face_flux_point_orderings
public :: check_cell_flux_point_orderings
public :: TaylorGreen_8s_vorticity_solution
!
! ###########################
! ### Module Parameters ###
! ###########################
!
logical(lk), parameter :: check_gradients = fals
!logical(lk), parameter :: check_gradients = true
!
! ################################
! ### Module Local Variables ###
! ################################
!
!.. Output File Names ..
character(len=*), parameter :: cgns_base_fname = "solution.grid.cgns"
character(len=*), parameter :: cgns_grid_fname = "solution.grid.cgns"
character(len=*), parameter :: cgns_time_fname = "solution.time.cgns"
character(len=170), save :: cgns_dir = ""
character(len=170), save :: cgns_grid_file
character(len=170), save :: cgns_time_file
!
character(len=170), save :: cgnsfile_fmt
!
!.. CGNS Path Variables ..
integer(CBT), save :: ifile_n
integer(CBT), save :: ibase_n
integer(CBT), save :: izone_n
integer(CBT), save :: isect_n
integer(CBT), parameter :: iiter_n = 1_CBT
!
!.. CGNS Time Dependent Variables ..
integer, save :: cgns_zone_counter
!
real(sp), save, allocatable :: soltime(:)
character(len=CGLEN), save, allocatable :: solname(:)
character(len=CGLEN), save, allocatable :: solfile(:)
!
character(len=*), parameter :: base_name = "gfr_base"
character(len=*), parameter :: zone_name = "Solution"
!
!.. CGNS Parallel Point Indices ..
integer(CST), save :: n_my_output_pts
integer(CST), save :: my_pts_beg
integer(CST), save :: my_pts_end
!
integer(CST), dimension(1:3) :: zone_size
!
! DISABLE_CGNS_OUTPUT: Private module variable to disable CGNS output. It
! is currently only relevant to the Taylor-Green Vortex
! problem and is more of a temporary addition until the
! output logic/code becomes more robust.
!
logical(lk), save :: disable_cgns_output = fals
!
!.. CGNS Data Array ..
!
! NOTE: This is to ensure coordinate and solution variables
! are the same real type
!
real(CRT), allocatable, dimension(:) :: var
!
interface interpolate_for_output
module procedure interpolate_for_output_1d, &
interpolate_for_output_2d
end interface interpolate_for_output
!
integer, save :: current_cell
integer, save :: save_n1
integer, save :: save_n2
contains
!
!###############################################################################
!
subroutine read_input_file
!
!.. Local Scalars ..
integer :: i,j,ierr,input_status
integer :: command_count,command_length
character(len=1000) :: command_value
character(len=1000) :: input_fname
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "read_input_file"
character(len=*), parameter :: default_fname = "gfr.in"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Check for additional command line arguments
!
command_count = command_argument_count()
!
one_pass_loop: do i = 1,1
!
if (command_count == 1) then
!
call get_command_argument(1,input_fname,command_length,ierr)
!
call check_input_file(input_fname,input_status)
!
if (input_status == 0) exit one_pass_loop
!
else if (command_count > 1) then
!
do j = 1,command_count
!
call get_command_argument(j,command_value,command_length,ierr)
!
if (trim(adjustl(command_value)) == "-f") then
!
call get_command_argument(j+1,input_fname,command_length,ierr)
!
call check_input_file(input_fname,input_status)
!
if (input_status == 0) exit one_pass_loop
!
end if
!
end do
!
end if
!
input_fname = default_fname
!
call check_input_file(input_fname,input_status)
!
if (input_status /= 0) then
call write_nml_input_file('gfr.in.default')
write (error_message,11)
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
end if
!
end do one_pass_loop
!
call read_nml_input_file(input_fname)
!
call debug_timer(leaving_procedure,pname)
!
! Format statements
!
11 format ("ERROR FINDING A VALID INPUT FILE!")
!
end subroutine read_input_file
!
!###############################################################################
!
subroutine check_input_file(input_fname,input_status)
!
!.. Formal Arguments ..
character(len=*), intent(in) :: input_fname
integer, intent(out) :: input_status
!
!.. Local Scalars ..
integer :: ierr,inpt
logical(ldk) :: file_exists
character(len=80) :: text
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "check_input_file"
!
continue
!
call debug_timer(entering_procedure,pname)
!
input_status = -1
!
! Inquire whether the input file name exists
!
inquire (file=input_fname,exist=file_exists)
!
if (file_exists) then
!
! Try opening the input file name
!
open (newunit=inpt,file=input_fname,status="old",action="read", &
form="formatted",iostat=ierr,iomsg=error_message)
call io_error(pname,input_fname,1,__LINE__,__FILE__,ierr,error_message)
!
! Read the first line of the input file
!
read (inpt,*,iostat=ierr,err=100,end=100) text
!
close (inpt,iostat=ierr,iomsg=error_message)
call io_error(pname,input_fname,2,__LINE__,__FILE__,ierr,error_message)
!
! Check the first line for neccessary string
!
text = trim(adjustl(text))
text = uppercase( text )
!
! Change input_status to 0 if the first line
! matches the required namelist value
!
if (text(1:6) == "&INPUT") input_status = 0
!
end if
!
call debug_timer(leaving_procedure,pname)
!
return
!
! Read error continuation statements
!
100 continue
write (error_message,10) trim(adjustl(input_fname)), ierr
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
!
! Format statements
!
10 format (/," Error checking the format of the input file '",a,"'!",/, &
" IO Error = ",i0,/)
!
end subroutine check_input_file
!
!###############################################################################
!
subroutine read_nml_input_file(input_fname)
!
!.. Use Statements ..
use order_mod, only : initialize_geom_solpts
use order_mod, only : n_order,p_order,q_order,o_order,e_order
!
use geovar, only : nr,using_quadrature
!
use input_namelist_mod ! use all the variables in the input namelist
!
use ovar, only : Total_Periods,dflux_opt
use ovar, only : velref,aref,uref,Lref,time_ref
use ovar, only : Period_Timesteps,Period_Time
use ovar, only : Grid_Length
use ovar, only : LDG_beta,LDG_tau
!
use quadrature_mod, only : init_geom_quadrature_rules
use quadrature_mod, only : init_face_quadrature_rules
!
use eqn_idx, only : create_equation_indices
!
use initialization_mod, only : initialize_reference
!
use channel_mod, only : read_channel_init_file
!
use restart_mod, only : check_restart_dir
!
!.. Formal Arguments ..
character(len=*), intent(in) :: input_fname
!
!.. Local Scalars ..
integer :: i,it1,it2,ierr,ival,inpt
integer :: Period_Timesteps_X,Period_Timesteps_Y
logical(lk) :: use_qdtr_face_pts,mms_error
real(wp) :: Period_Time_X,Period_Time_Y
real(wp) :: real_Total_Periods
real(wp) :: aoa_radians
real(wp) :: cfl_sum,cfl_time
!
!.. Local Arrays ..
character(len=80), dimension(12) :: input_text
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "read_nml_input_file"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Open the input file
!
open (newunit=inpt,file=input_fname,status="old",action="read", &
form="formatted",iostat=ierr,iomsg=error_message)
call io_error(pname,input_fname,1,__LINE__,__FILE__,ierr,error_message)
!
! Read in the input file using the input namelist
!
read (inpt,nml=input)
!
! Close the input file now that we are finished reading it
!
close (inpt,iostat=ierr,iomsg=error_message)
call io_error(pname,input_fname,2,__LINE__,__FILE__,ierr,error_message)
!
! Check the lustre striping parameters
!
call check_lustre_striping
!
! Check the output directory
!
output_dir = trim(adjustl(output_dir))
call check_output_dir
!
! Check for the CGNS output directory
! NOTE: This will be done later in the post-processor
! module if continuous_output is true, so only
! do this if continuous_output is false.
!
if (.not. continuous_output) then
call check_cgns_dir
end if
!
! Check the restart output directory
!
call check_restart_dir
!
! Adjust the name of the grid file
!
gridfile = trim(adjustl(gridfile))
!
! Make sure both profile_io_restart and profile_io_cgns
! are true if profile_io_all is true
!
if (profile_io_all) then
profile_io_restart = true
profile_io_cgns = true
end if
!
! Allow for the use of the variable all_orders to make
! solution_order (n_order), projection_order (p_order),
! and quadrature_order(q_order) all the same value without
! having to explicitly specify each one individually.
!
if (all_orders >= 0) then
solution_order = all_orders
projection_order = all_orders
quadrature_order = all_orders
end if
!
! Set the order variables using the input parameters
!
n_order = solution_order
p_order = projection_order
q_order = quadrature_order
o_order = output_order
e_order = error_order
!
! Allow for the use of the variable all_points to make
! loc_solution_pts, loc_flux_pts, and loc_quadrature_pts all the same value
! without having to explicitly specify each one individually.
!
if ( any(all_points == [1,2]) ) then
loc_solution_pts = all_points
loc_flux_pts = all_points
loc_quadrature_pts = all_points
end if
!
if (loc_solution_pts /= loc_flux_pts) then
if (mypnum == 0) write (iout,101)
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__)
end if
!
if (loc_solution_pts == Legendre_Gauss_Lobatto) then
if (continuous_output) then
write (error_message,106)
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
end if
end if
!
! Disable use_bc_conflicts if Lobatto points are not being used.
!
one_pass: do i = 1,1
!
if (any(loc_solution_pts == Gauss_Lobatto)) exit one_pass
if (any(loc_flux_pts == Gauss_Lobatto)) exit one_pass
if (any(loc_quadrature_pts == Gauss_Lobatto)) exit one_pass
!
use_bc_conflicts = fals
!
end do one_pass
!
! Adjust the solution order and compute the number
! of solution points for the different cell shapes
!
n_order = max(p_order,n_order)
!
! Make sure the quadrature order is at least the same as the
! solution order and other quadrature variables are valid
!
q_order = max(n_order,q_order)
!
using_quadrature = .not. (q_order==n_order .and. &
loc_solution_pts==loc_quadrature_pts)
!
! Get the number of solution points for each of the different geometry types
! This includes quadrature and face values
!
use_qdtr_face_pts = using_quadrature .and. dflux_opt==project_derivatives
!
call initialize_geom_solpts(use_qdtr_face_pts)
!
! Now that we have the name of the grid file and the location
! of the flux and solution points, read in the grid file
!
call read_grid_file
!
call init_geom_quadrature_rules
call init_face_quadrature_rules
!
! Create the equation indices now that we know the dimension of the grid
!
call create_equation_indices(nr)
!
! Make sure the number of RK stages is correct for some RK types
!
if (Runge_Kutta_Scheme == TVD2_RK) then
num_rk_stages = 2
else if (Runge_Kutta_Scheme == TVD3_RK) then
num_rk_stages = 3
else if (Runge_Kutta_Scheme == TVD4_RK) then
num_rk_stages = 5
else if (Runge_Kutta_Scheme == CK4_RK) then
num_rk_stages = 5
end if
!
! Make sure the initialization and error locations are valid
!
if (all(loc_init_pts /= Legendre_Nodes)) loc_init_pts = loc_solution_pts
if (all(loc_error_pts /= Legendre_Nodes)) loc_error_pts = loc_solution_pts
!
! Make sure the output order is greater than or
! equal to the solution order if it is positive
!
if (o_order > 0) o_order = max(o_order,n_order+0)
!
! Make sure the error order is greater than or
! equal to the solution order if it is positive
!
if (e_order > 0) e_order = max(e_order,n_order+0)
!
! Check that the Method of Manufactured Solutions (MMS) option is valid
!
if (mms_opt /= 0) then
!
mms_error = fals
if (any(mms_opt == [1,2]) .and. nr < 2) then ! 1 and 2 are for 2D or 3D
write (error_message,21)
mms_error = true
else if (mms_opt == 3 .and. nr > 2) then ! 3 is for 1D or 2D
write (error_message,22)
mms_error = true
else if (mms_opt == 4 .and. nr /= 2) then ! 4 is for 2D only
write (error_message,23)
mms_error = true
else if (all(mms_opt /= [1,2,3,4])) then
write (error_message,24)
mms_error = true
end if
if (mms_error) then
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
end if
!
! If mms_output_solution is true, set the MMS initialization factor
! to one and set the number of time steps and final time to zero
!
if (mms_output_solution) then
mms_init = one
num_timesteps = 0
Final_Time = zero
end if
!
end if
!
if (itestcase == Channel_Flow) then
call read_channel_init_file
end if
!
! Initialize the reference conditions
!
call initialize_reference
!
! Compute periodic information for the transport problems
!
if (any(itestcase == Transport_Problems)) then
!
cfl = one
cfl_beg = one
cfl_end = one
cfl_cycles = 1
!
if (abs(velref(1)) < eps3) then
!
Period_Time_Y = Grid_Length(2) * reciprocal(velref(2)/aref)
Period_Time_Y = merge( Period_Time_Y, &
Grid_Length(2), &
Period_Time_Y > eps3 )
Period_Timesteps_Y = nint(Period_Time_Y/constant_dt)
Period_Timesteps = Period_Timesteps_Y
!
!if (mypnum == 0) then
! write (*,*) Period_Time_Y,Period_Timesteps_Y,Period_Timesteps
!end if
!
else if (abs(velref(2)) < eps3) then
!
Period_Time_X = Grid_Length(1) * reciprocal(velref(1)/aref)
Period_Time_X = merge( Period_Time_X, &
Grid_Length(1), &
Period_Time_X > eps3 )
Period_Timesteps_X = nint(Period_Time_X/constant_dt)
Period_Timesteps = Period_Timesteps_X
!
!if (mypnum == 0) then
! write (*,*) Period_Time_Y,Period_Timesteps_Y,Period_Timesteps
!end if
!
else
!
Period_Time_X = Grid_Length(1) / (velref(1)/aref)
Period_Time_Y = Grid_Length(2) / (velref(2)/aref)
!
Period_Timesteps_X = nint(Period_Time_X/constant_dt)
Period_Timesteps_Y = nint(Period_Time_Y/constant_dt)
!
if (Period_Timesteps_X == Period_Timesteps_Y) then
Period_Timesteps = Period_Timesteps_X
else
Period_Timesteps = Period_Timesteps_X * Period_Timesteps_Y &
/ mod( max(Period_Timesteps_X,Period_Timesteps_Y), &
min(Period_Timesteps_X,Period_Timesteps_Y) )
end if
!
!if (mypnum == 0) then
!write (*,*) Period_Time_X,Period_Time_Y
!write (*,*) Period_Timesteps_X,Period_Timesteps_Y
!write (*,*) Period_Timesteps
!end if
!
end if
!
Period_Time = constant_dt*real(Period_Timesteps,kind=wp)
!
! If Final_Time is negative, it is giving the total
! number of periods that the simulation will run
!
if (Final_Time < zero) then
Total_Periods = nint( abs(Final_Time) )
Final_Time = Period_Time * real(Total_Periods,kind=wp)
else
real_Total_Periods = Final_Time*reciprocal(Period_Time)
Total_Periods = nint(real_Total_Periods)
if (abs(real_Total_Periods-real(Total_Periods,kind=wp)) > ten*eps6) then
if (mypnum == 0) write (iout,103) real_Total_Periods
end if
end if
!if (mypnum == 0) write (*,*) Period_Time,Total_Periods,Final_Time
!
num_timesteps = nint( Final_Time / constant_dt )
!
else if (itestcase == Taylor_Green_Vortex) then
!
!cfl_beg = CFL
!cfl_end = CFL
!cfl_cycles = 1
!
! Set the variable time_ref to adjust our nondimension time to match
! the nondimensional time used for the Taylor-Green Vortex problem
!
time_ref = machref
!
if (Final_Time > zero) then
!
! Need to adjust the nondimensional final time which uses uref as the
! velocity for nondimensionalization and we use aref within the code
!
num_timesteps = nint( Final_Time / constant_dt )
!
!Final_Time = Final_Time * time_ref
!
end if
!
! Make sure the timestep type is global (positive)
!
Timestep_Type = abs(Timestep_Type)
!
else
!
! Set time_ref to Lref/aref for nondimensionalizing time
! NOTE: Lref is always just one
!
if (itestcase == Infinite_Cylinder) then
time_ref = machref
else
time_ref = one / aref
end if
!
if (convert_restart_to_cgns) then
!
num_timesteps = 0
!
else if (Timestep_Type == Constant_Timestep) then
!
if (cfl_cycles < 2) then
cfl_beg = CFL
cfl_end = CFL
cfl_cycles = 1
if (Final_Time > zero) then
num_timesteps = nint( Final_Time / (CFL*constant_dt*time_ref) )
end if
else
cfl_end = max(cfl_end,eps6)
cfl_beg = min(cfl_beg,cfl_end)
cfl_sum = real(cfl_cycles,kind=wp)*(cfl_beg+cfl_end)/two
cfl_time = cfl_sum*constant_dt*time_ref
if (Final_Time > zero) then
num_timesteps = cfl_cycles
if (cfl_time < Final_Time) then
num_timesteps = num_timesteps + &
nint( (Final_Time-cfl_time) / (CFL*constant_dt*time_ref) )
end if
end if
end if
!
!
else
!
if (cfl_cycles < 2) then
cfl_beg = CFL
cfl_end = CFL
cfl_cycles = 0
else
cfl_end = max(cfl_end,eps6) ! cfl_end must be >= 1.0e-6
cfl_beg = min(cfl_beg,cfl_end) ! cfl_beg must be <= cfl_end
end if
!
end if
!
end if
!
! Determine the frequency of dumping the results and solution files
!
if (any(itestcase == Transport_Problems)) then
!
if (results_interval == 0) then
results_interval = max(Period_Timesteps/500,1)
else if (results_interval < 0) then
results_interval = max(Period_Timesteps/abs(results_interval),1)
end if
!
if (output_interval == 0) then
output_interval = Period_Timesteps
else if (output_interval < 0) then
output_interval = abs(output_interval)*Period_Timesteps
end if
!
if (iter_out_interval == 0) then
iter_out_interval = Period_Timesteps
else if (iter_out_interval < 0) then
iter_out_interval = max(Period_Timesteps/abs(iter_out_interval),1)
end if
!
else
!
if (results_interval == 0) then
results_interval = num_timesteps/500
else if (results_interval < 0) then
results_interval = num_timesteps/abs(results_interval)
end if
results_interval = max(results_interval,1)
!
if (itestcase == Taylor_Green_Vortex) then
if (output_interval == 0) then
disable_cgns_output = true
end if
end if
!
if (output_interval == 0) then
output_interval = num_timesteps/50
else if (output_interval < 0) then
output_interval = num_timesteps/abs(output_interval)
end if
output_interval = max(output_interval,1)
!
if (iter_out_interval == 0) then
iter_out_interval = 1
else if (iter_out_interval < 0) then
iter_out_interval = num_timesteps/abs(iter_out_interval)
end if
iter_out_interval = max(iter_out_interval,1)
!
end if
!
if (visc_flux_method /= visc_flux_BR2) then
if (visc_flux_method == visc_flux_LDG) then
LDG_beta = half
end if
if (nr == 2) then
LDG_tau = one/ten
!LDG_tau = zero
else if (nr == 3) then
LDG_tau = one
end if
end if
!
! Now write out a copy of the input file to standard output
!
if (mypnum == 0) then
!
write (iout,104)
write (iout,nml=input)
write (iout,105)
!
end if
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
101 format (/, &
"***************************** ERROR *****************************",/, &
" THE REQUESTED LOCATIONS FOR SOLUTION POINTS AND FLUX POINTS",/, &
" DO NOT MATCH. CURRENTLY, THE PROCEDURES USED TO CREATE THE",/, &
" CORRECTION MATRICES ASSUMES THESE TWO POINTS LOCATIONS ARE",/, &
" THE SAME. THESE PROCEDURES WILL NEED TO BE UPDATED IN ORDER",/, &
" TO ALLOW FOR THIS CAPABILITY.",/, &
"***************************** ERROR *****************************",/)
103 format (/, &
" ********************* WARNING!!! *********************",/, &
" IT APPEARS THE FINAL TIME DOES NOT CORRESPOND TO THE",/, &
" EXACT END OF A PERIOD FOR THE VORTEX PROBLEM. THE",/, &
" FINAL TIME CORRESPONDS TO",f12.5," TOTAL PERIODS.",/, &
" ********************* WARNING!!! *********************",/)
104 format (/,"#######################################",/, &
"##### INPUT PARAMETERS #####",/, &
"#######################################",/)
105 format (/,"#######################################",/, &
"##### END OF INPUT PARAMETERS #####",/, &
"#######################################",/)
106 format ("Lobatto solutions points are not yet compatible with the ", &
"option to correct the output solution so that it is continuous!")
21 format ("MMS ERROR: MMS solutions 1 and 2 are allowed for 2D and 3D only!")
22 format ("MMS ERROR: MMS solution 3 is allowed for 1D and 2D only!")
23 format ("MMS ERROR: MMS solution 4 is allowed for 2D only!")
24 format ("MMS ERROR: The MMS solution chosen is invalid!")
!
end subroutine read_nml_input_file
!
!###############################################################################
!
subroutine write_nml_input_file(output_fname)
!
!.. Use Statements ..
use input_namelist_mod ! use all the variables in the input namelist
!
!.. Formal Arguments ..
character(len=*), intent(in) :: output_fname
!
!.. Local Scalars ..
integer ionml,ierr
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "write_nml_input_file"
!
continue
!
if (mypnum == 0) then
open (newunit=ionml,file=output_fname,status="new",action="write", &
delim='apostrophe', &
position="rewind",iostat=ierr,iomsg=error_message)
call io_error(pname,trim(adjustl(gridfile)),1,__LINE__,__FILE__, &
ierr,error_message)
write (ionml,nml=input)
write (iout,101) trim(output_fname)
close(ionml)
endif
!
101 format(/,"Default namelist input file written to: ",A)
!
end subroutine write_nml_input_file
!
!###############################################################################
!
subroutine check_lustre_striping
!
!.. Use Statements ..
use ovar, only : lustre_stripe_count
use ovar, only : lustre_stripe_size
use ovar, only : lustre_stripe_unit
use ovar, only : lustre_stripe_factor
!
!.. Local Scalars ..
integer :: i,j,ip,im,ierr,stripe_num
character(len=1) :: stripe_unit
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "check_lustre_striping"
character(len=*), parameter :: units = "KMG"
character(len=*), parameter :: numbers(1:10) = ["0","1","2","3","4", &
"5","6","7","8","9"]
!
integer, parameter :: max_lustre_count = 120
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Check the Lustre stripe count
!
if (mod(ncpu,lustre_stripe_count) /= 0) then
!
count_loop: do i = 1,lustre_stripe_count
ip = min( lustre_stripe_count + i , max_lustre_count )
im = max( lustre_stripe_count - i , 0 )
if (mod(ncpu,ip) == 0) then
if (ncpu/ip >= 4) then
lustre_stripe_count = ip
exit count_loop
end if
else if (mod(ncpu,im) == 0) then
lustre_stripe_count = im
exit count_loop
end if
end do count_loop
!
end if
!
! Save the stripe count for MPI
!
write (lustre_stripe_factor,4) lustre_stripe_count
!
! Check the Lustre stripe size
!
stripe_num = 0
!
lustre_stripe_size = trim(adjustl(lustre_stripe_size))
!
size_loop: do i = 1,len_trim(lustre_stripe_size)
!
if (all(lustre_stripe_size(i:i) /= numbers)) then
!
read (lustre_stripe_size(1:i-1),*,iostat=ierr) stripe_num
!
if (ierr /= 0) then
stripe_num = 0
exit size_loop
end if
!
j = i-1 + scan( uppercase(lustre_stripe_size(i:)) , units )
!
if (j /= 0) then
!
select case (uppercase(lustre_stripe_size(j:j)))
case ("K")
stripe_num = stripe_num * 1024
case ("M")
stripe_num = stripe_num * 1024 * 1024
case ("G")
stripe_num = stripe_num * 1024 * 1024 * 1024
end select
!
end if
!
exit size_loop
!
end if
!
end do size_loop
!
stripe_num = max(0,stripe_num)
! Make sure the stripe size is a multiple of 64 KB (65536 Bytes)
stripe_num = nint( real(stripe_num,kind=wp) / 65536.0_wp ) * 65536
! Save the stripe number in bytes for MPI
write (lustre_stripe_unit,4) stripe_num
! Convert the stripe size to kilobytes
stripe_num = stripe_num / 1024
stripe_unit = "k"
!
if (stripe_num == 0) then
!
if (mypnum == 0) write (iout,1)
lustre_stripe_size = "0"
!
else
!
if (stripe_num >= 1024) then
stripe_num = stripe_num / 1024
stripe_unit = "m"
end if
!
if (stripe_num >= 1024) then
stripe_num = stripe_num / 1024
stripe_unit = "g"
end if
!
write (lustre_stripe_size,2) stripe_num,stripe_unit
!
end if
!
#ifdef PBS_ENV
if (mypnum == 0) then
write (iout,3) lustre_stripe_count, &
trim(adjustl(lustre_stripe_size))
end if
#endif
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
1 format (/,20("!"),5x,"WARNING",5x,20("!"),/, &
"!!!! THE LUSTRE STRIPE SIZE WAS NOT VALID AND !!!!",/, &
"!!!! SO IT HAS BEEN RESET TO THE DEFAULT VALUE !!!!",/, &
20("!"),5x,"WARNING",5x,20("!"),/)
2 format (i0,a1)
3 format (/,"The Lustre striping command to be used is:",/, &
"lfs setstripe -c ",i0," -S ",a,1x,"[file/directory]",/)
4 format (i0)
!
end subroutine check_lustre_striping
!
!###############################################################################
!
subroutine check_output_dir
!
!.. Use Statements ..
use ovar, only : dump_fluxes
!
!.. Local Scalars ..
integer :: clen,ierr,iodir,ii
integer :: exitstat,cmndstat
character(len=200) :: test_file
character(len=200) :: test_dir
character(len=300) :: command
character(len=300) :: cmndmsg
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "check_output_dir"
!
character(len=*), parameter :: nobackup = "/nobackup/sspiegel"
character(len=*), parameter :: homedir = "/u/sspiegel"
!
logical(ldk), parameter :: wait_for_completion = .true.
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Initialize test_file and test_dir
!
test_file = " "
test_dir = " "
!
! Only perform the following tests using the root processor
! to minimize contention and prevent each MPI process from
! executing the same command.
!
root_proc_only: if (mypnum == 0) then
!
one_pass: do ii = 1,1
!
! Check for a directory "/" at the end of the input output_dir
!
clen = len_trim(output_dir)
if (output_dir(clen:clen) /= "/") then
output_dir = trim(output_dir)//"/"
end if
!
! Try to open a file in the given directory
!
test_file = trim(output_dir)//"output_dir.test_file.dat"
!
open (newunit=iodir,file=trim(test_file),status="replace", &
action="write",iostat=ierr)
!
! If the open was successful, close and delete the test file and return
!
if (ierr == 0) then
close (iodir,status="delete",iostat=ierr)
exit one_pass
end if
!
! Reset test_file
!
test_file = " "