-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathrestart_mod.f90
3864 lines (3864 loc) · 128 KB
/
restart_mod.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 restart_mod
!
#include <mpi_defs.h>
!!!#define VERBOSE_RESTART
!
use module_kind_types
use eqn_idx, only : nq
!
use iso_fortran_env, only : int8,int16,int32,int64
use iso_fortran_env, only : real32,real64,real128
!
implicit none
!
private
!
!###########################
!### Public Procedures ###
!###########################
!
public :: read_restart_file
public :: write_restart_file
public :: check_restart_dir
public :: create_restart_fname_formats
!
!###########################
!### Module Parameters ###
!###########################
!
integer, parameter :: restart_gauss_nodal_solution = -Legendre_Gauss
integer, parameter :: restart_lobatto_nodal_solution = -Legendre_Gauss_Lobatto
integer, parameter :: restart_legendre_modal_solution = Legendre_Gauss
integer, parameter :: restart_monomial_modal_solution = Legendre_Gauss_Lobatto
!
character(len=*), parameter :: file_datarep = "native"
!
!#################################
!### Module Scalar Variables ###
!#################################
!
logical(lk), save :: restart_needs_initialization = true
logical(lk), save :: time_ave_needs_initialization = true
!
integer, save :: restart_solution_form
!
#ifdef PBS_ENV
_MPI_DATA_TYPE_, save :: ordered_geom_type
_MPI_DATA_TYPE_, save :: solution_type
_MPI_DATA_TYPE_, save :: sol_block_type
_MPI_DATA_TYPE_, save :: averaging_type
_MPI_DATA_TYPE_, save :: ave_block_type
#else
_MPI_DATA_TYPE_, save :: ordered_geom_type = MPI_DATATYPE_NULL
_MPI_DATA_TYPE_, save :: solution_type = MPI_DATATYPE_NULL
_MPI_DATA_TYPE_, save :: sol_block_type = MPI_DATATYPE_NULL
_MPI_DATA_TYPE_, save :: averaging_type = MPI_DATATYPE_NULL
_MPI_DATA_TYPE_, save :: ave_block_type = MPI_DATATYPE_NULL
#endif
!
character(len=170), save :: restart_dir = ""
character(len=170), save :: rstfile_fmt
character(len=170), save :: lnkcmnd_fmt
character(len=170), save :: statfile_fmt
character(len=170), save :: tafile_fmt
character(len=170), save :: talink_fmt
character(len=170), save :: tastat_fmt
character(len=170), save :: tadone_fmt
character(len=170), save :: talkdn_fmt
character(len=170), save :: rstfname_fmt
character(len=170), save :: tafname_fmt
character(len=170), save :: tadonefname_fmt
!
integer, save :: averaging_file_switch = 1
!
_MPI_DATA_TYPE_, save :: read_type
_MPI_DATA_TYPE_, save :: read_block_type
_MPI_DATA_TYPE_, save :: real_type
!
integer, save :: num_pts = 0
!
!##################################
!### Module Derived Datatypes ###
!##################################
!
type :: rstrt_cell_t
integer :: input_cell
integer :: input_beg_sp
integer :: input_end_sp
integer :: input_geom
integer :: input_order
end type rstrt_cell_t
!
type :: sp_idx_t
integer :: beg_sp
integer :: end_sp
end type sp_idx_t
!
!###################################
!### Module Allocatable Arrays ###
!###################################
!
integer, save, allocatable :: cell_output_order(:)
!
integer(INT_MPI), save, allocatable :: og_counts(:)
integer(INT_MPI), save, allocatable :: og_displs(:)
!
integer(INT_MPI), save, allocatable :: pts_counts(:)
integer(INT_MPI), save, allocatable :: pts_displs(:)
!
integer(int_mpi), save, allocatable :: pts_offset(:)
integer(int_mpi), save, allocatable :: pts_blklen(:)
!
type(sp_idx_t), save, allocatable :: host_output_order(:)
!
type(rstrt_cell_t), save, allocatable :: cell_input_data(:)
!
!############################################################################
!### Generic interfaces for subroutines to read REAL data using MPI I/O ###
!############################################################################
!
interface read_rstrt_file_r4
module procedure read_rstrt_file_r4_rank1, read_rstrt_file_r4_rank2
end interface read_rstrt_file_r4
!
interface read_rstrt_file_r8
module procedure read_rstrt_file_r8_rank1, read_rstrt_file_r8_rank2
end interface read_rstrt_file_r8
!
interface read_rstrt_file_r16
module procedure read_rstrt_file_r16_rank1, read_rstrt_file_r16_rank2
end interface read_rstrt_file_r16
!
interface read_rstrt_file_wp
module procedure read_rstrt_file_wp_rank1, read_rstrt_file_wp_rank2
end interface read_rstrt_file_wp
!
contains
!
!###############################################################################
!
subroutine read_restart_file
!
!.. Use Statements ..
use ovar, only : itrst,tmrst,dtrst,rl2mx
use ovar, only : prev_ave_time,ave_start_time
use ovar, only : restart_file,time_ave_file
use ovar, only : output_time_averaging
use ovar, only : read_time_ave_restart
use ovar, only : use_old_restart_format
use flowvar, only : usp,uavesp,time_ave_variables
!
!.. Local Scalars ..
integer :: n,ierr
character(len=150) :: fname
!
!.. Local Allocatable Arrays ..
integer(wip), allocatable :: int_header(:)
integer(wip), allocatable :: var_header(:)
real(wp), allocatable :: real_header(:)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "read_restart_file"
!
continue
!
call debug_timer(entering_procedure,pname)
!
fname = trim(adjustl(restart_file))
!
if (use_old_restart_format) then
!
call read_restart_old_format(fname,usp,sol_is_transposed=fals)
!
else
!
! Read the restart solution file
! NOTE: usp SHOULD BE ALLOCATED AT THIS POINT
!
call read_solution_file(fname,int_header,real_header,usp, &
sol_is_transposed=fals)
!
! Extract the required information from the header arrays
!
itrst = int( int_header(4) , kind=kind(itrst) )
!
tmrst = real( real_header(1) , kind=kind(tmrst) )
dtrst = real( real_header(2) , kind=kind(dtrst) )
!
if (size(real_header) >= 3) then
rl2mx = real( real_header(3) , kind=kind(rl2mx) )
end if
!
if (output_time_averaging) then
!
if (read_time_ave_restart) then
!
fname = trim(adjustl(time_ave_file))
!
! NOTE: uavesp SHOULD NOT BE ALLOCATED AT THIS POINT
!
call read_solution_file(fname,int_header,real_header,uavesp, &
var_header,sol_is_transposed=fals)
!
prev_ave_time = real( real_header(2) , kind=kind(prev_ave_time) )
ave_start_time = real( real_header(3) , kind=kind(ave_start_time) )
!
if (size(real_header) >= 4) then
rl2mx = real( real_header(4) , kind=kind(rl2mx) )
end if
!
if (int_header(4) /= itrst) then
write (error_message,1) int_header(4),itrst
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
end if
!
if (abs(real_header(1)-tmrst) > eps9) then
write (error_message,2) real_header(1),tmrst
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
end if
!
if (allocated(time_ave_variables)) then
deallocate ( time_ave_variables , stat=ierr , errmsg=error_message )
call alloc_error(pname,"time_ave_variables",2,__LINE__,__FILE__, &
ierr,error_message)
end if
!
allocate ( time_ave_variables(1:size(var_header)) , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"time_ave_variables",1,__LINE__,__FILE__, &
ierr,error_message)
!
do n = 1,size(var_header)
time_ave_variables(n) = transfer(var_header(n),time_ave_variables(n))
time_ave_variables(n) = trim(adjustl(time_ave_variables(n)))
end do
!
else
!
! Reset rl2mx since we are starting a new time averaging
!
rl2mx = -huge(zero)
!
end if
!
end if
!
end if
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
1 format("The current iteration number in the time averaging file does ", &
"not match the iteration number in the restart file: ", &
"time_ave_iter = ",i0,", restart_iter = ",i0)
2 format("The current solution time in the time averaging file does ", &
"not match the solution time in the restart file: ", &
"time_ave_time = ",es14.6,", restart_time = ",es14.6)
!
end subroutine read_restart_file
!
!###############################################################################
!
subroutine read_solution_file(file_name,int_header,real_header,solution, &
var_header,sol_is_transposed)
!
!.. Use Statements ..
use geovar, only : ncell,cell,n_solpts
use geovar, only : n_global_cell
use ovar, only : time_average_restart_files
!
!.. Formal Arguments ..
character(len=*), intent(in ) :: file_name
integer(wip), allocatable, intent( out) :: int_header(:)
real(wp), allocatable, intent( out) :: real_header(:)
real(wp), allocatable, intent(inout) :: solution(:,:)
!
!.. Optional Arguments ..
integer(wip), optional, allocatable, intent(out) :: var_header(:)
logical(lk), optional, intent(in) :: sol_is_transposed
!
!.. Local Scalars ..
integer :: l0,l1,l2,m,n,np,n0,n1,n2,ierr
integer :: sol_nq
integer :: restart_ip,restart_rp
logical(lk) :: flip_sol_indices
!
_MPI_FILE_TYPE_ :: file_handle
_MPI_INFO_TYPE_ :: file_info
!.. Need to be MPI_OFFSET_KIND integers
integer(MPI_OFFSET_KIND) :: file_disp
integer(MPI_OFFSET_KIND) :: file_offset
!
integer :: solution_errors
integer :: restart_nq,restart_ncells
integer :: n_header_int,n_header_real
!
integer :: inp_cell,inp_geom,inp_order
integer :: this_cell,this_geom,this_order
!
!.. Local Allocatable Arrays ..
integer(wip), allocatable :: ordered_geom(:)
real(wp), allocatable :: rst_sol(:,:)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "read_solution_file"
!
continue
!
call debug_timer(entering_procedure,pname)
!
flip_sol_indices = fals
if (present(sol_is_transposed)) then
flip_sol_indices = sol_is_transposed
end if
!
!
solution_errors = 0
!
! Initialize file_info to MPI_INFO_NULL
!
file_info = MPI_INFO_NULL
!
#ifdef PBS_ENV
#ifndef IGNORE_MPI_INFO
!
! Create the MPI info object for this restart file
! NOTE: For now, we will leave the MPI info object as is without any extra
! hints since this will just be for reading the restart file this one
! time before starting the simulation.
!
call mpi_info_create(file_info,mpierr)
!
#endif
#endif
!
! Open the restart file for MPI I/O
!
call mpi_file_open(MPI_COMM_WORLD,trim(adjustl(file_name)), &
MPI_MODE_RDONLY,file_info,file_handle,mpierr)
!
! Have all processors read the header section of the restart file
!
! ######################################
! ### Integer part of restart header ###
! ######################################
!
! Read the integer type for the integer part of the restart header
!
call mpi_file_read_all(file_handle,restart_ip,1_int_mpi, &
MPI_INTEGER,MPI_STATUS_IGNORE,mpierr)
!
! Read the number of integer header items
!
call mpi_file_read_all(file_handle,n_header_int,1_int_mpi, &
MPI_INTEGER,MPI_STATUS_IGNORE,mpierr)
!
! Allocate the int_header array
!
if (allocated(int_header)) then
deallocate ( int_header , stat=ierr , errmsg=error_message )
call alloc_error(pname,"int_header",2,__LINE__,__FILE__,ierr,error_message)
end if
!
allocate ( int_header(1:n_header_int) , source=0_wip , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"int_header",1,__LINE__,__FILE__,ierr,error_message)
!
! Read the integer part of the restart header
!
if (restart_ip == wip) then
call read_rstrt_file_wip(file_handle,int_header)
else
select case (restart_ip)
case (int32) ; call read_rstrt_file_i4(file_handle,int_header)
case (int64) ; call read_rstrt_file_i8(file_handle,int_header)
case (int8) ; call read_rstrt_file_i1(file_handle,int_header)
case (int16) ; call read_rstrt_file_i2(file_handle,int_header)
case default
write (error_message,20)
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
end select
end if
!
! Extract the information from the integer section of the header
!
! Extract the number of flow variables saved at each solution point
! within the restart file
!
restart_nq = int( int_header(1) , kind=kind(restart_nq) )
!
if (allocated(solution)) then
if (flip_sol_indices) then
sol_nq = size(solution,dim=2)
else
sol_nq = size(solution,dim=1)
end if
if (restart_nq /= sol_nq) then
write (error_message,10) restart_nq,sol_nq
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
end if
end if
!
! Extracted the total number of grid cells contained within the restart file
!
restart_ncells = int( int_header(2) , kind=kind(restart_ncells) )
!
if (restart_ncells /= n_global_cell) then
write (error_message,11) restart_ncells,n_global_cell
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
end if
!
! Extract the format that the solution data is in within the restart file
!
restart_solution_form = int( int_header(3) , &
kind=kind(restart_solution_form) )
!
call check_restart_solution_form(restart_solution_form)
!
! ###################################
! ### Real part of restart header ###
! ###################################
!
! Read the real type for the real part of the restart header
!
call mpi_file_read_all(file_handle,restart_rp,1_int_mpi, &
MPI_INTEGER,MPI_STATUS_IGNORE,mpierr)
!
! Read the number of real header items
!
call mpi_file_read_all(file_handle,n_header_real,1_int_mpi, &
MPI_INTEGER,MPI_STATUS_IGNORE,mpierr)
!
! Allocate the real_header array
!
if (allocated(real_header)) then
deallocate ( real_header , stat=ierr , errmsg=error_message )
call alloc_error(pname,"real_header",2,__LINE__,__FILE__,ierr,error_message)
end if
!
allocate ( real_header(1:n_header_real) , source=zero , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"real_header",1,__LINE__,__FILE__,ierr,error_message)
!
! Read the real part of the restart header
!
if (restart_rp == wp) then
call read_rstrt_file_wp(file_handle,real_header)
else
select case (restart_rp)
case (real64) ; call read_rstrt_file_r8(file_handle,real_header)
case (real32) ; call read_rstrt_file_r4(file_handle,real_header)
case (real128) ; call read_rstrt_file_r16(file_handle,real_header)
case default
write (error_message,21)
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
end select
end if
!
! #############################################
! ### Ordered_Geom part of the restart file ###
! #############################################
!
! Read the integer type for the ordered_geom array
!
call mpi_file_read_all(file_handle,restart_ip,1_int_mpi, &
MPI_INTEGER,MPI_STATUS_IGNORE,mpierr)
!
allocate ( ordered_geom(1:restart_ncells) , source=0_wip , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"ordered_geom",1,__LINE__,__FILE__,ierr, &
error_message)
!
! All processors have to read the ordered_geom data so that each
! processor can compute the data offsets for each of the cells
! within its partition.
!
if (restart_ip == wip) then
call read_rstrt_file_wip(file_handle,ordered_geom)
else
select case (restart_ip)
case (int32) ; call read_rstrt_file_i4(file_handle,ordered_geom)
case (int64) ; call read_rstrt_file_i8(file_handle,ordered_geom)
case (int8) ; call read_rstrt_file_i1(file_handle,ordered_geom)
case (int16) ; call read_rstrt_file_i2(file_handle,ordered_geom)
case default
write (error_message,22)
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
end select
end if
!
! ################################################
! ### Variable header part of the restart file ###
! ################################################
!
if (present(var_header)) then
!
! Read the real type for the solution data
!
call mpi_file_read_all(file_handle,restart_ip,1_int_mpi, &
MPI_INTEGER,MPI_STATUS_IGNORE,mpierr)
!
if (allocated(var_header)) then
deallocate ( var_header , stat=ierr , errmsg=error_message )
call alloc_error(pname,"var_header",2,__LINE__,__FILE__, &
ierr,error_message)
end if
!
allocate ( var_header(1:restart_nq) , source=0_wip , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"var_header",1,__LINE__,__FILE__,ierr,error_message)
!
! Read the variable header for the solution data
!
if (restart_ip == wip) then
call read_rstrt_file_wip(file_handle,var_header)
else
select case (restart_ip)
case (int32) ; call read_rstrt_file_i4(file_handle,var_header)
case (int64) ; call read_rstrt_file_i8(file_handle,var_header)
case (int8) ; call read_rstrt_file_i1(file_handle,var_header)
case (int16) ; call read_rstrt_file_i2(file_handle,var_header)
case default
write (error_message,24)
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
end select
end if
!
if (.not. allocated(solution)) then
if (flip_sol_indices) then
allocate ( solution(1:n_solpts,1:restart_nq) , source=zero , &
stat=ierr , errmsg=error_message )
else
allocate ( solution(1:restart_nq,1:n_solpts) , source=zero , &
stat=ierr , errmsg=error_message )
end if
call alloc_error(pname,"solution",1,__LINE__,__FILE__,ierr,error_message)
end if
!
end if
!
! #########################################
! ### Solution part of the restart file ###
! #########################################
!
! Read the real type for the solution data
!
call mpi_file_read_all(file_handle,restart_rp,1_int_mpi, &
MPI_INTEGER,MPI_STATUS_IGNORE,mpierr)
!
! Get the updated file displacement
!
call mpi_file_get_position(file_handle,file_offset,mpierr)
call mpi_file_get_byte_offset(file_handle,file_offset,file_disp,mpierr)
!
! Get the MPI derived types required to read the solution data section
! of the restart file if cell_input_data is not allocated
!
if (.not. allocated(cell_input_data)) then
!
call get_input_mpi_datatypes(restart_nq,restart_rp,real_type, &
read_block_type,read_type, &
num_pts,ordered_geom,cell_input_data)
!
end if
!
! Deallocate ordered_geom since it is no longer needed
!
if (allocated(ordered_geom)) then
deallocate ( ordered_geom , stat=ierr , errmsg=error_message )
call alloc_error(pname,"ordered_geom",2,__LINE__,__FILE__, &
ierr,error_message)
end if
!
! IF WE ARE TO MOVE THE POINT IN THE PRE-PROCESSING PHASE AT WHICH THE
! RESTART FILE IS READ, WE NEED TO MAKE SURE THAT N_SOLPTS HAS BEEN
! RECOMPUTED SO THAT IT IS LOCAL TO EACH PROCESSOR BECAUSE THIS IS NOT
! DONE WITHIN PARALLEL_MOD AFTER PARTITIONING THE GRID.
!
if (num_pts /= n_solpts) then
write (iout,12) mypnum,num_pts,n_solpts
solution_errors = 100
end if
!
! Sum up the value of solution_errors across all processors
!
call mpi_allreduce(MPI_IN_PLACE,solution_errors,1_int_mpi, &
mpi_inttyp,MPI_SUM,MPI_COMM_WORLD,mpierr)
!
if (solution_errors /= 0) then
write (error_message,13)
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
end if
!
! Set the file view to write the ordered_geom array to the restart file
!
call mpi_file_set_view(file_handle,file_disp,read_block_type, &
read_type, trim(adjustl(file_datarep)), &
file_info, mpierr)
!
! Allocate the rst_sol array to read in the solution restart data
!
allocate ( rst_sol(1:restart_nq,1:n_solpts) , source=zero , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"rst_sol",1,__LINE__,__FILE__,ierr,error_message)
!
! Read in the solution restart data
!
if (restart_rp == wp) then
call read_rstrt_file_wp(file_handle,rst_sol, &
read_block_type)
else
select case (restart_rp)
case (real64) ; call read_rstrt_file_r8(file_handle,rst_sol, &
read_block_type)
case (real32) ; call read_rstrt_file_r4(file_handle,rst_sol, &
read_block_type)
case (real128) ; call read_rstrt_file_r16(file_handle,rst_sol, &
read_block_type)
case default
write (error_message,23)
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
end select
end if
!
! Finally close the restart file
!
call mpi_file_close(file_handle,mpierr)
!
! Copy the restart solution data over into the solution array
!
solution_errors = 0
!
do this_cell = 1,ncell
!
inp_cell = cell_input_data(this_cell)%input_cell
!
l1 = cell_input_data(this_cell)%input_beg_sp
l2 = cell_input_data(this_cell)%input_end_sp
l0 = l1-1
!
inp_geom = cell_input_data(this_cell)%input_geom
inp_order = cell_input_data(this_cell)%input_order
!
n1 = cell(this_cell)%beg_sp
n2 = cell(this_cell)%end_sp
n0 = n1-1
np = n2-n0
!
this_geom = cell(this_cell)%geom
this_order = cell(this_cell)%order
!
! NEED TO ADD SOMETHING HERE TO CONVERT THE SOLUTION IF THE SOLUTION
! FORM DOESNT MATCH THE CURRENT SIMULATION. FOR NOW, JUST CREATE AN
! ERROR IF IT DOESNT MATCH THE RESTART FORM.
!
if ((inp_geom /= this_geom) .or. (inp_order /= this_order)) then
write (iout,30) mypnum, inp_cell, inp_geom, inp_order, &
this_cell,this_geom,this_order
solution_errors = solution_errors + 1
end if
!
if (flip_sol_indices) then
do n = 1,np
do m = 1,restart_nq
solution(n0+n,m) = rst_sol(m,l0+n)
end do
end do
else
do n = 1,np
do m = 1,restart_nq
solution(m,n0+n) = rst_sol(m,l0+n)
end do
end do
end if
!solution(:,n1:n2) = rst_sol(:,l1:l2)
!
end do
!
! Deallocate rst_sol since it is no longer needed
!
deallocate ( rst_sol , stat=ierr , errmsg=error_message )
call alloc_error(pname,"rst_sol",2,__LINE__,__FILE__,ierr,error_message)
!
! Sum up the value of solution_errors across all processors
!
call mpi_allreduce(MPI_IN_PLACE,solution_errors,1_int_mpi, &
mpi_inttyp,MPI_SUM,MPI_COMM_WORLD,mpierr)
!
! Stop the simulation if there were any errors copying the restart
! solution data into solution.
!
if (solution_errors > 0) then
write (error_message,31) solution_errors
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
end if
!
! Deallocate cell_input_data if we are not time-averaging a bunch of
! restart files. Also reset the variables real_type, read_type, and
! num_pts to default values in case we ever need to come back here
! and read in a new restart file.
!
if (.not. time_average_restart_files) then
!
if (allocated(cell_input_data)) then
deallocate ( cell_input_data , stat=ierr , errmsg=error_message )
call alloc_error(pname,"cell_input_data",2,__LINE__,__FILE__,ierr, &
error_message)
end if
!
real_type = MPI_DATATYPE_NULL
read_type = MPI_DATATYPE_NULL
num_pts = 0
!
end if
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
10 format("The number of variables in the restart file does not match the ", &
"number of variables in the solution array: restart_nq=",i0, &
", current_nq=",i0,".")
11 format("The number of global grid cells in the restart file does not ", &
"match the current simulation: restart_n_global_cell=",i0, &
", current_n_global_cell=",i0,".")
12 format(/," The number of solution points for the cells on CPU-",i0," ", &
"does not match the",/," number of solution points for the ", &
"corresponding cells in the restart file: ",/, &
" restart_n_solpts=",i0,/, &
" current_n_solpts=",i0)
13 format("The number of solution points for cells in the restart file ", &
"do not seem to match the corresponding cells in the current ", &
"simulation.")
!
20 format("Unknown integer type when trying to read the integer section ", &
"of the restart file header.")
21 format("Unknown real type when trying to read the real section ", &
"of the restart file header.")
22 format("Unknown integer type when trying to read the ordered_geom data ", &
"from the restart file.")
23 format("Unknown real type when trying to read the solution data ", &
"from the restart file.")
24 format("Unknown integer type when trying to read the variable header ", &
"for the solution data from the restart file.")
!
30 format(" CPU-",i0, &
": Error copying restart solution into solution array.",/, &
" restart cell: ",i0,": geom = ",i0,", order = ",i0,/, &
" current cell: ",i0,": geom = ",i0,", order = ",i0)
31 format("The geometry and structure of the solution data in the restart ", &
"file does not match the current simulation. There were ",i0," ", &
"total errors encountered across all the processors when ", &
"trying to copy the restart solution data into the current ", &
"solution array.")
!
40 format ("The number of integer header items in the restart file",/, &
"is greater than the size of the int_header array.",/, &
" n_header_int = ",i0,/, &
" size(int_header) = ",i0)
41 format ("The number of real header items in the restart file",/, &
"is greater than the size of the real_header array.",/, &
" n_header_real = ",i0,/, &
" size(real_header) = ",i0)
!
end subroutine read_solution_file
!
!###############################################################################
!
subroutine read_restart_old_format(file_name,solution,sol_is_transposed)
!
!.. Use Statements ..
use geovar, only : ncell,cell
use geovar, only : n_global_totpts
use geovar, only : global_pinc_ptr
use ovar, only : itrst,tmrst,dtrst
use flowvar, only : global_usp
use parallel_mod, only : cell_map
!
!.. Formal Arguments ..
character(len=*), intent(in) :: file_name
real(wp), intent(inout) :: solution(:,:)
!
!.. Optional Arguments ..
logical(lk), optional, intent(in) :: sol_is_transposed
!
!.. Local Scalars ..
integer :: iorst,g0,n,m,nc,np,n0,n1,n2,ierr
logical(lk) :: flip_sol_indices
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "read_restart_old_format"
!
continue
!
call debug_timer(entering_procedure,pname)
!
flip_sol_indices = fals
if (present(sol_is_transposed)) then
flip_sol_indices = sol_is_transposed
end if
!
allocate ( global_usp(1:nq,1:n_global_totpts) , source=zero , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"global_usp",1,__LINE__,__FILE__,ierr,error_message)
!
open(newunit=iorst,file=file_name,status="old",action="read", &
form="unformatted",iostat=ierr,iomsg=error_message)
call io_error(pname,file_name,1,__LINE__,__FILE__,ierr,error_message)
!
read (iorst) itrst, tmrst, dtrst
read (iorst) global_usp
!
close (iorst,iostat=ierr,iomsg=error_message)
call io_error(pname,file_name,2,__LINE__,__FILE__,ierr,error_message)
!
! Copy the solution data from only those cells
! that are local to this processor into solution
! NOTE: For a serial job, cell_map(mypnum+1)%loc_to_glb = [1,ncell]
!
do nc = 1,ncell
!
! Indices of the data for this cell in the solution array
!
n0 = cell(nc)%beg_sp - 1
np = cell(nc)%end_sp - n0
!n1 = cell(nc)%beg_sp
!n2 = cell(nc)%end_sp
!np = n2-n1+1
!
! Starting point of the data for this cell in the global_usp array
!
g0 = global_pinc_ptr( cell_map(mypnum+1)%loc_to_glb(nc) )
!
! Copy the solution data from the global_usp array for this cell
!
if (flip_sol_indices) then
do n = 1,np
do m = 1,nq
solution(n0+n,m) = global_usp(m,g0+n)
end do
end do
else
do n = 1,np
do m = 1,nq
solution(m,n0+n) = global_usp(m,g0+n)
end do
end do
end if
!solution(:,n1:n2) = global_usp(:,g0+1:g0+np)
!
end do
!
deallocate ( global_usp , stat=ierr , errmsg=error_message )
call alloc_error(pname,"global_usp",2,__LINE__,__FILE__,ierr,error_message)
!
call debug_timer(leaving_procedure,pname)
!
end subroutine read_restart_old_format
!
!###############################################################################
!
subroutine write_restart_file(itnum)
!
!.. Use Statements ..
use geovar, only : n_global_cell
use ovar, only : itcur,time,d_t,rl2mx
use ovar, only : loc_solution_pts
use ovar, only : output_time_averaging
use ovar, only : restart_output_uses_host_roots
use flowvar, only : usp
!.. Use Statements for old restart files ..
use geovar, only : n_global_totpts
use ovar, only : use_old_restart_format
use flowvar, only : global_usp
use parallel_mod, only : collect_global_solution
!
!.. Formal Arguments ..
integer, intent(in) :: itnum
!
!.. Local Scalars ..
integer :: ierr
integer :: exitstat,cmndstat
!
logical(lk) :: involved_with_output
logical(lk) :: restart_is_good_data
logical(lk) :: sol_is_transposed
!
character(len=100) :: fname
character(len=200) :: fullname
character(len=100) :: statfile
character(len=300) :: command
character(len=300) :: cmndmsg
!
_MPI_COMM_TYPE_, save :: restart_comm
!
!.. Local Arrays ..
integer(wip) :: int_header(1:4)
real(wp) :: real_header(1:3)
!
!.. Local Allocatable Arrays ..
integer(i4), allocatable :: ordered_geom(:)
real(wp), allocatable :: solution(:,:)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "write_restart_file"
!
logical(ldk), parameter :: wait_for_completion = .true.
!
continue
!
call debug_timer(entering_procedure,pname)
!
sol_is_transposed = fals
!
if (use_old_restart_format) then
!
if (itnum > 0) then
write (fullname,'("out.",i0.8,".rst")') itcur
else if (itnum == -2) then
write (fullname,'("out.",i0.8,".NaN.rst")') itcur-1
else
write (fullname,'("out.",i0.8,".done.rst")') itcur
end if
!
if (mypnum == glb_root) then
if (sol_is_transposed) then
allocate ( global_usp(1:n_global_totpts,1:nq) , source=zero , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"global_usp",1,__LINE__,__FILE__,ierr, &
error_message)
else
allocate ( global_usp(1:nq,1:n_global_totpts) , source=zero , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"global_usp",1,__LINE__,__FILE__,ierr, &
error_message)
end if
end if
!
! Collect the global solution
!
call collect_global_solution
!
! Only use the root partition to output the restart file
!
if (mypnum == glb_root) then
if (sol_is_transposed) then
global_usp = transpose(global_usp) ! F2003 AUTO-REALLOCATION
end if
call write_restart_old_format(fullname,global_usp)
end if
!
if (allocated(global_usp)) then
deallocate ( global_usp , stat=ierr , errmsg=error_message )
call alloc_error(pname,"global_usp",2,__LINE__,__FILE__,ierr, &
error_message)
end if
!
call mpi_barrier(MPI_COMM_WORLD,mpierr)
!
else
!
restart_is_good_data = true
!
! Perform some initialization tasks if the restart module has not
! been initialized yet.
!
if (restart_needs_initialization) then
!
! For now, write the nodal solution to the restart file. At some point we
! should switch so it writes the modal solution since that would give more
! flexibility regarding changes in the solution order between runs.
!
if (loc_solution_pts == Legendre_Gauss) then
restart_solution_form = restart_gauss_nodal_solution
else if (loc_solution_pts == Legendre_Gauss_Lobatto) then
restart_solution_form = restart_lobatto_nodal_solution
end if
!
! Get the MPI derived types required to read/write the restart file
!
if (restart_output_uses_host_roots) then
call get_host_output_mpi_datatypes
else
call get_output_mpi_datatypes
end if
!
#ifdef DEBUG_ON
call mpi_barrier(MPI_COMM_WORLD,mpierr)
if (mypnum == glb_root) then
write (iout,*) "After get_output_mpi_datatypes"
flush (iout)
end if
call mpi_barrier(MPI_COMM_WORLD,mpierr)
#endif
!
! Unset the restart initialization flag since this has now been done
!
restart_needs_initialization = fals
!
end if