-
Notifications
You must be signed in to change notification settings - Fork 38
/
time_mod.f90
1506 lines (1505 loc) · 45 KB
/
time_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 time_mod
!
use module_kind_types
use eqn_idx, only : nec,nmx,nmy,nmz,nmb,nme,nee,nq,ntk,ntl
!
implicit none
!
private
!
public :: get_dtsp
public :: rresi
public :: rupdate_Classic_RK
public :: rupdate_CK4_RK
public :: rupdate_TVD2_RK
public :: rupdate_TVD3_RK
public :: rupdate_TVD4_RK
public :: update_time_ave
public :: initialize_time_ave
!
real(wp), parameter :: o = zero
!
! Classic N stage Runge-Kutta coefficients
!
real(wp), parameter, dimension(4,4,4) :: &
alphaRK = reshape( &
! 1-Stage Coefficients
(/ONE ,o,o,o,o, o ,o,o, o ,o, o ,o, o , o , o , o , &
! 2-Stage Coefficients
HALF,o,o,o,o,ONE ,o,o, o ,o, o ,o, o , o , o , o , &
! 3-Stage Coefficients
ONE3,o,o,o,o,TWO3,o,o,ONE4,o,THREE4,o, o , o , o , o , &
! 4-Stage Coefficients
HALF,o,o,o,o,HALF,o,o, o ,o, ONE ,o,ONE6,ONE3,ONE3,ONE6/), &
(/4,4,4/) )
!
! TVD 4th-order/5-stage Runge-Kutta coefficients
!
real(wp), parameter, dimension(1:2,1:5) :: &
betaRK_TVD = reshape( (/ 0.00000000000000_wp,0.39175222700395_wp, &
0.00000000000000_wp,0.36841059262959_wp, &
0.00000000000000_wp,0.25189177424738_wp, &
0.00000000000000_wp,0.54497475021237_wp, &
0.08460416338212_wp,0.22600748319395_wp /), &
(/2,5/) )
!
real(wp), parameter, dimension(1:3,1:5) :: &
alphaRK_TVD = reshape( &
(/ 1.00000000000000_wp,0.00000000000000_wp,0.0_wp, &
0.44437049406734_wp,0.55562950593266_wp,0.0_wp, &
0.62010185138540_wp,0.37989814861460_wp,0.0_wp, &
0.17807995410773_wp,0.82192004589227_wp,0.0_wp, &
0.00683325884039_wp,0.34833675773694_wp,1.0_wp /), &
(/3,5/) )
!
real(wp), parameter, dimension(1:5) :: gammaRK_TVD = (/ 0.00000000000000_wp, &
0.51723167208978_wp, &
0.12759831133288_wp, &
0.00000000000000_wp, &
0.00000000000000_wp /)
!
character(len=100), save :: iter_out_fmt
!
real(wp), save, allocatable :: ave(:)
!
type :: time_ave_var_t
integer, allocatable :: idx(:)
end type time_ave_var_t
!
type(time_ave_var_t), save, allocatable :: time_ave_var(:)
!
contains
!
!###############################################################################
!
subroutine get_dtsp(dtmin)
!
!.. Use Statements ..
use ovar, only : Timestep_Type,time,d_t
use ovar, only : itestcase,time_ref
use ovar, only : write_TaylorGreen_8s_solution
use ovar, only : write_TaylorGreen_full_solution
use flowvar, only : dtsp
!
!.. Formal Arguments ..
real(wp), intent(out) :: dtmin
!
!.. Local Scalars ..
real(wp) :: tstar,new_tstar
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "get_dtsp"
!
continue
!
if (Timestep_Type == Constant_Timestep) then
!
call get_current_cfl
!
call get_constant_timestep(dtmin)
!
else if (abs(Timestep_Type) == Cell_Timestep) then
!
call get_current_cfl
!
call get_cell_timestep(dtmin)
!
else if (abs(Timestep_Type) == Point_Timestep) then
!
call get_current_cfl
!
call get_point_timestep(dtmin)
!
end if
!
!write (iout,1) time,dtmin,time+dtmin
!
if (itestcase == Taylor_Green_Vortex) then
!
tstar = time*time_ref
new_tstar = tstar + dtmin*time_ref
!
if (tstar < eight .and. new_tstar >= eight) then
!
dtmin = (eight - tstar) / time_ref
dtsp(:) = dtmin
write_TaylorGreen_8s_solution = true
!
else if (tstar < three .and. new_tstar >= three) then
!
dtmin = (three - tstar) / time_ref
dtsp(:) = dtmin
write_TaylorGreen_full_solution = true
!
else if (tstar < five .and. new_tstar >= five) then
!
dtmin = (five - tstar) / time_ref
dtsp(:) = dtmin
write_TaylorGreen_full_solution = true
!
else if (tstar < seven .and. new_tstar >= seven) then
!
dtmin = (seven - tstar) / time_ref
dtsp(:) = dtmin
write_TaylorGreen_full_solution = true
!
else if (tstar < nine .and. new_tstar >= nine) then
!
dtmin = (nine - tstar) / time_ref
dtsp(:) = dtmin
write_TaylorGreen_full_solution = true
!
else if (tstar < 11.0_wp .and. new_tstar >= 11.0_wp) then
!
dtmin = (11.0_wp - tstar) / time_ref
dtsp(:) = dtmin
write_TaylorGreen_full_solution = true
!
else if (tstar < 15.0_wp .and. new_tstar >= 15.0_wp) then
!
dtmin = (15.0_wp - tstar) / time_ref
dtsp(:) = dtmin
write_TaylorGreen_full_solution = true
!
end if
!
end if
!
time = time + dtmin
d_t = dtmin
!
! Format Statements
!
1 format (" Old Time = ",es14.6,"; Timestep = ",es14.6,"; New Time = ",es14.6)
!
end subroutine get_dtsp
!
!###############################################################################
!
subroutine get_current_cfl
!
!.. Use Statements ..
use ovar, only : cfl,cfl_beg,cfl_end,cfl_cycles,itcur
use ovar, only : cfl_cycle_start,cfl_cycle_end
!
!.. Local Scalars ..
real(wp) :: cycle_ratio
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "get_current_cfl"
!
continue
!
if (itcur < cfl_cycle_end) then
if (cfl_cycles < 2) then
cycle_ratio = one
else
cycle_ratio = real(itcur-cfl_cycle_start-1,kind=wp) / &
real(cfl_cycles-1,kind=wp)
end if
!
cfl = cfl_beg + (cfl_end - cfl_beg) * cycle_ratio
else
cfl = cfl_end
end if
!
end subroutine get_current_cfl
!
!###############################################################################
!
subroutine get_constant_timestep(dtmin)
!
!.. Use Statements ..
use ovar, only : constant_dt,time_ref,Final_Time,time,CFL
use ovar, only : this_is_final_timestep
use flowvar, only : dtsp
!
!.. Formal Arguments ..
real(wp), intent(out) :: dtmin
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "get_constant_timestep"
!
continue
!
call debug_timer(entering_procedure,pname)
!
dtmin = CFL * constant_dt
!
if (Final_Time > zero) then
if (time + dtmin > Final_Time/time_ref + eps9) then
dtmin = Final_Time/time_ref - time
this_is_final_timestep = true
end if
end if
!
dtsp(:) = dtmin
!
call debug_timer(leaving_procedure,pname)
!
end subroutine get_constant_timestep
!
!###############################################################################
!
subroutine get_cell_timestep(dtmin)
!
!.. Use Statements ..
use order_mod, only : n_order,maxSP,geom_solpts
!
use geovar, only : nr,nfbnd,nface
use geovar, only : face,cell
!
use ovar, only : gam,Timestep_Type,time_ref,Final_Time,time,CFL
use ovar, only : governing_equations
use ovar, only : this_is_final_timestep
!
use metrics_mod, only : geofa,metrics_dt
!
use flowvar, only : dtsp,usp
!
use interpolation_mod, only : interp
!
!.. Formal Arguments ..
real(wp), intent(out) :: dtmin
!
!.. Local Scalars ..
integer :: nf,k,m
integer :: l1,l2,npl,kl
integer :: r1,r2,npr,kr
integer :: face_geom,face_order
integer :: host_cell,host_geom,host_order
integer :: left_cell,left_geom,left_order
integer :: right_cell,right_geom,right_order
real(wp) :: ds,eigni,eignv,pp1sq
real(wp) :: dsl,vell,al,jacl,dtl,mul,hl
real(wp) :: dsr,velr,ar,jacr,dtr,mur,hr
real(wp) :: psql,psqr
!
!.. Local Arrays ..
real(wp) :: vl(1:nq),tlusp(1:maxSP,1:nq)
real(wp) :: vr(1:nq),trusp(1:maxSP,1:nq)
!
integer, parameter :: make_p_plus_one = 0
!integer, parameter :: make_p_plus_one = 1
!
logical(lk), parameter :: use_sqrt = true
!logical(lk), parameter :: use_sqrt = fals
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "get_cell_timestep"
!
continue
!
call debug_timer(entering_procedure,pname)
!
mul = zero
mur = zero
!
dtmin = huge(zero)
dtsp(:) = dtmin
!
do nf = 1,nfbnd
!
host_cell = face(nf)%left%cell ! left cell on face
!
host_geom = cell(host_cell)%geom ! host cell geometry
host_order = cell(host_cell)%order ! host cell order
!
l1 = cell(host_cell)%beg_sp ! beginning index for sol-pts in left cell
l2 = cell(host_cell)%end_sp ! ending index for sol-pts in left cell
npl = l2-l1+1 ! number of solution points in left cell
!
face_geom = face(nf)%geom ! geometry of the current face
face_order = face(nf)%order ! order of the current face
!
psql = real( (host_order+make_p_plus_one)**2 , kind=wp )
!
tlusp(1:npl,1:nq) = transpose( usp(1:nq,l1:l2) )
!
!
do k = 1,geom_solpts(face_geom,face_order)
!
kl = face(nf)%left%get_fp_idx(face_geom,face_order,k)
!
! Interpolate the conservative variables to this flux point
vl(1:nq) = interp(host_geom,host_order)% &
toFace(face_order)% &
dot_mat( kl , tlusp(1:npl,1:nq) )
!do m = 1,nq
! vl(m) = interp(host_geom,host_order)% &
! toFace(face_order)% &
! dot( kl , tlusp(1:npl,m) )
!end do
! Convert to primitive variables
vl(1:nq) = usp2v_sp( vl(1:nq) )
!
if (governing_equations == NavierStokes_Eqns) then
mul = viscosity_pv_sp( vl(1:nq) )
end if
!
ds = norm2( geofa(nf)%v(1:nr,k) )
dsl = ds * cl(host_geom) ! face length/area for left cell
!
! Normal velocity at this flux point
!
!vell = dot( vl(nmb:nme) , unit_vector(geofa(nf)%v(1:nr,k)) )
vell = selfdot( vl(nmb:nme) )
if (use_sqrt) vell = sqrt(vell)
!
! Speed of sound at this face
!
al = max( gam*vl(nee)/vl(nec) , rndoff )
if (use_sqrt) al = sqrt(al)
!
! Interpolate the jacobian to the flux point
!
jacl = interp(host_geom,host_order)% &
toFace(face_order)% &
dot( kl , metrics_dt(host_cell)%jac(:) )
!
hl = half * dsl / jacl
!
eigni = abs(vell) + al
eignv = psql * hl * mul
!
! Compute the timestep for this flux point
!
dtl = min( dtsp(l1) , CFL / (psql * hl * (eigni + eignv)) )
!
! Store the minimum timestep for this cell in the location
! of the first solution point for this cell
!
dtsp(l1:l2) = dtl
!
dtmin = min( dtmin , dtl )
!
end do
!
end do
!
do nf = nfbnd+1,nface
!
left_cell = face(nf)%left%cell ! left cell on face
right_cell = face(nf)%right%cell ! right cell on face
!
left_geom = cell(left_cell)%geom ! left cell geometry
left_order = cell(left_cell)%order ! left cell order
!
l1 = cell(left_cell)%beg_sp ! beginning index for sol-pts in left cell
l2 = cell(left_cell)%end_sp ! ending index for sol-pts in left cell
npl = l2-l1+1 ! number of solution points in left cell
!
right_geom = cell(right_cell)%geom ! right cell geometry
right_order = cell(right_cell)%order ! right cell order
!
r1 = cell(right_cell)%beg_sp ! beginning index for sol-pts in right cell
r2 = cell(right_cell)%end_sp ! ending index for sol-pts in right cell
npr = r2-r1+1 ! number of solution points in right cell
!
face_geom = face(nf)%geom ! geometry of the current face
face_order = face(nf)%order ! order of the current face
!
psql = real( (left_order +make_p_plus_one)**2 , kind=wp )
psqr = real( (right_order+make_p_plus_one)**2 , kind=wp )
!
tlusp(1:npl,1:nq) = transpose( usp(1:nq,l1:l2) )
trusp(1:npr,1:nq) = transpose( usp(1:nq,r1:r2) )
!
!
do k = 1,geom_solpts(face_geom,face_order)
!
kl = face(nf)%left%get_fp_idx(face_geom,face_order,k)
kr = face(nf)%right%get_fp_idx(face_geom,face_order,k)
!
! Interpolate the conservative variables to this flux point
vl(1:nq) = interp(left_geom,left_order)% &
toFace(face_order)% &
dot_mat( kl , tlusp(1:npl,1:nq) )
vr(1:nq) = interp(right_geom,right_order)% &
toFace(face_order)% &
dot_mat( kr , trusp(1:npr,1:nq) )
!do m = 1,nq
! vl(m) = interp(left_geom,left_order)% &
! toFace(face_order)% &
! dot( kl , tlusp(1:npl,m) )
! vr(m) = interp(right_geom,right_order)% &
! toFace(face_order)% &
! dot( kr , trusp(1:npr,m) )
!end do
! Convert to primitive variables
vl(1:nq) = usp2v_sp( vl(1:nq) )
vr(1:nq) = usp2v_sp( vr(1:nq) )
!
if (governing_equations == NavierStokes_Eqns) then
mul = viscosity_pv_sp( vl(1:nq) )
mur = viscosity_pv_sp( vr(1:nq) )
end if
!
ds = norm2( geofa(nf)%v(1:nr,k) )
dsl = ds * cl(left_geom) ! face length/area for left cell
dsr = ds * cl(right_geom) ! face length/area for right cell
!
! Normal velocity at this flux point
!
!vell = dot( vl(nmb:nme) , unit_vector(geofa(nf)%v(1:nr,k)) )
!velr = dot( vr(nmb:nme) , unit_vector(geofa(nf)%v(1:nr,k)) )
vell = selfdot( vl(nmb:nme) )
if (use_sqrt) vell = sqrt(vell)
velr = selfdot( vr(nmb:nme) )
if (use_sqrt) velr = sqrt(velr)
!
! Speed of sound at this face
!
al = max( gam*vl(nee)/vl(nec) , rndoff )
if (use_sqrt) al = sqrt(al)
ar = max( gam*vr(nee)/vr(nec) , rndoff )
if (use_sqrt) ar = sqrt(ar)
!
! Interpolate the jacobian to the flux point for the left cell
!
jacl = interp(left_geom,left_order)% &
toFace(face_order)% &
dot( kl , metrics_dt(left_cell)%jac(:) )
!
! Interpolate the jacobian to the flux point for the right cell
!
jacr = interp(right_geom,right_order)% &
toFace(face_order)% &
dot( kr , metrics_dt(right_cell)%jac(:) )
!
hl = half * dsl / jacl
hr = half * dsr / jacr
!
eigni = max( abs(vell) + al , abs(velr) + ar )
eignv = max( psql * hl * mul , psqr * hr * mur )
!
! Compute the timestep for this flux point
!
dtl = min( dtsp(l1) , CFL / (psql * hl * (eigni + eignv) ) )
dtr = min( dtsp(r1) , CFL / (psqr * hr * (eigni + eignv) ) )
!
! Store the minimum timestep for all solution points in both cells
!
dtsp(l1:l2) = dtl
dtsp(r1:r2) = dtr
!
dtmin = min( dtmin , dtl , dtr )
!
end do
!
end do
!
! Get the minimum timestep across all processors
!
if (ncpu > 1) then
call mpi_allreduce(MPI_IN_PLACE,dtmin,1_int_mpi,mpi_flttyp, &
MPI_MIN,MPI_COMM_WORLD,mpierr)
end if
!
! Limit the local timesteps if using a global timestepping
!
if (Timestep_Type == Global_Cell_Timestep) then
!
! Set all time step sizes to the global minimum timestep
!
dtsp(:) = dtmin
!
end if
!
! Make sure the timestep size doesnt make the final time exceed Final_Time
!
if (Final_Time > zero) then
if (time + dtmin > Final_Time/time_ref + eps9) then
dtsp(:) = Final_Time/time_ref - time
this_is_final_timestep = true
end if
end if
!
call debug_timer(leaving_procedure,pname)
!
end subroutine get_cell_timestep
!
!###############################################################################
!
subroutine get_point_timestep(dtmin)
!
!.. Use Statements ..
use geovar, only : nr,ncell,cell
use ovar, only : gam,time_ref,Final_Time,time,CFL,Timestep_Type
use ovar, only : this_is_final_timestep
use ovar, only : governing_equations
use metrics_mod, only : metrics_dt
use flowvar, only : usp,dtsp
!
!.. Formal Arguments ..
real(wp), intent(out) :: dtmin
!
!.. Local Scalars ..
integer :: n,nc,k,n1,n2,np
integer :: this_geom,this_order
real(wp) :: dtpt,dtc,eigni,eignv
real(wp) :: vmag,aspd,psq,visc
!
!.. Local Arrays ..
real(wp), dimension(1:nr) :: vel
real(wp), dimension(1:nq) :: pv
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "get_point_timestep"
!
!integer, parameter :: make_p_plus_one = 0
integer, parameter :: make_p_plus_one = 1
!
continue
!
call debug_timer(entering_procedure,pname)
!
dtmin = huge(zero)
!
visc = zero
!
do nc = 1,ncell
!
n1 = cell(nc)%beg_sp ! beginning index of sol-pts for this cell
n2 = cell(nc)%end_sp ! ending index of sol-pts for this cell
np = n2-n1+1 ! number of sol-pts in this cell
!
this_geom = cell(nc)%geom ! geometry type of this cell
this_order = cell(nc)%order ! solution order of this cell
!
psq = real( (this_order+make_p_plus_one)**2 , kind=wp )
!
dtc = CFL * two / psq
!
do k = 1,np
!
n = k + n1-1
!
pv(1:nq) = usp2v_sp( usp(1:nq,n) )
!
if (governing_equations == NavierStokes_Eqns) then
visc = viscosity_cv_sp( usp(1:nq,n) )
end if
!
vel(1:nr) = matmul( metrics_dt(nc)%met(k,1:nr,1:nr) , pv(nmb:nme) )
!
vmag = norm2(vel)
!
aspd = sqrt( max( gam*pv(nee)/pv(nec) , rndoff ) )
!
eigni = vmag + aspd
!
eignv = psq * visc
!
dtpt = dtc / (eigni + eignv)
!
dtmin = min( dtpt , dtmin )
!
dtsp(n) = dtpt
!
end do
!
end do
!
! Get the minimum timestep across all processors
!
if (ncpu > 1) then
call mpi_allreduce(MPI_IN_PLACE,dtmin,1_int_mpi,mpi_flttyp, &
MPI_MIN,MPI_COMM_WORLD,mpierr)
end if
!
! Limit the local timesteps if using a global timestepping
!
if (Timestep_Type == Global_Point_Timestep) then
!
! Set all time step sizes to the minimum timestep
!
dtsp(:) = dtmin
!
! Make sure the timestep size doesnt make the final time exceed Final_Time
!
if (Final_Time > zero) then
if (time + dtmin > Final_Time/time_ref + eps9) then
dtsp(:) = Final_Time/time_ref - time
this_is_final_timestep = true
end if
end if
!
end if
!
call debug_timer(leaving_procedure,pname)
!
end subroutine get_point_timestep
!
!###############################################################################
!
subroutine old_get_point_timestep(dtmin)
!
!.. Use Statements ..
use order_mod, only : n_order
use geovar, only : nr,ncell,cell
use ovar, only : gam,time_ref,Final_Time,time,CFL,Timestep_Type
use ovar, only : this_is_final_timestep
use metrics_mod, only : metrics_dt
use flowvar, only : usp,dtsp
!
!.. Formal Arguments ..
real(wp), intent(out) :: dtmin
!
!.. Local Scalars ..
integer :: k,n,nc,n1,n2
real(wp) :: dtpt,gm1,dtc,eign
real(wp) :: dxdr,dydr,dxds,dyds
real(wp) :: rho,vx,vy,pres,aspd
real(wp) :: alfa,beta,gama
!
real(wp) :: vel(1:nr)
real(wp) :: met(1:nr,1:nr)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "old_get_point_timestep"
!
continue
!
call debug_timer(entering_procedure,pname)
!
gm1 = gam - one
!
dtmin = huge(zero)
!
dtc = CFL * two / real( (n_order+1)**2 , kind=wp )
!
do nc = 1,ncell
!
n1 = cell(nc)%beg_sp
n2 = cell(nc)%end_sp
!
do n = n1,n2
!
k = n-n1+1
!
met(1:nr,1:nr) = invert_matrix(metrics_dt(nc)%met(k,1:nr,1:nr))
dxdr = met(1,1)
dydr = met(2,1)
dxds = met(1,2)
dyds = met(2,1)
!
rho = usp(nec,n)
vel = usp(nmb:nme,n)/rho
pres = gm1 * (usp(nee,n) - half*rho*selfdot(vel))
!
aspd = sqrt( max( gam*pres/rho , rndoff ) )
!
alfa = abs( vel(1)*dydr - vel(2)*dxdr )
beta = abs( vel(1)*dyds - vel(2)*dxds )
!
gama = aspd*sqrt(dxdr**2 + dydr**2 + dxds**2 + dyds**2)
!
eign = alfa + beta + gama
!
dtpt = dtc * metrics_dt(nc)%jac(k) / eign
!
dtmin = min( dtpt , dtmin )
!
dtsp(n) = dtpt
!
end do
!
end do
!
! Get the minimum timestep across all processors
!
if (ncpu > 1) then
call mpi_allreduce(MPI_IN_PLACE,dtmin,1_int_mpi,mpi_flttyp, &
MPI_MIN,MPI_COMM_WORLD,mpierr)
end if
!
! Limit the local timesteps if using a global timestepping
!
if (Timestep_Type == Global_Point_Timestep) then
!
! Set all time step sizes to the minimum timestep
!
dtsp(:) = dtmin
!
! Make sure the timestep size doesnt make the final time exceed Final_Time
!
if (Final_Time > zero) then
if (time + dtmin > Final_Time/time_ref + eps9) then
dtsp(:) = Final_Time/time_ref - time
this_is_final_timestep = true
end if
end if
!
end if
!
call debug_timer(leaving_procedure,pname)
!
end subroutine old_get_point_timestep
!
!###############################################################################
!
subroutine rresi
!
!... calculates d(utd)/dt
!
!.. Use Statements ..
use order_mod, only : p_order,n_order
use geovar, only : n_solpts,ncell,cell
use ovar, only : itestcase
use metrics_mod, only : metrics_dt
use flowvar, only : residual
use projection_mod, only : project_to_porder
!
!.. Local Scalars ..
integer :: m,n,nc,n1,n2
real(wp) :: jac_inv
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "rresi"
!
continue
!
call debug_timer(entering_procedure,pname)
!
do nc = 1,ncell
n1 = cell(nc)%beg_sp
n2 = cell(nc)%end_sp
do n = n1,n2
jac_inv = one / metrics_dt(nc)%jac(n-n1+1)
do m = 1,nq
residual(m,n) = -residual(m,n) * jac_inv
end do
end do
end do
!
! Zero out the residuals for all but the density
! equation if running the density transport test case
!
if (itestcase == Density_Transport) then
do n = 1,n_solpts
do m = nec+1,nq
residual(m,n) = residual(nec,n)
end do
end do
end if
!
if (p_order < n_order) then
call project_to_porder(cell,residual)
end if
!
call debug_timer(leaving_procedure,pname)
!
end subroutine rresi
!
!###############################################################################
!
subroutine stabilize_usp(nst,Apply_Filter,Apply_Limiter)
!
!.. Use Statements ..
use ovar, only : Limiter_Option,Filter_Option
use filter_mod, only : filter_usp
use module_limiters, only : resolution_indicator
use module_limiters, only : limit_by_projecting
!
!.. Formal Arguments ..
integer, intent(in) :: nst
logical(lk), intent(in) :: Apply_Filter
logical(lk), intent(in) :: Apply_Limiter
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "stabilize_usp"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Apply the filter
!
if (Filter_Option > 0) then
if (Apply_Filter) then
#ifdef PROFILE_ON
if (mypnum == glb_root) write (iout,1) nst
1 format (8x,"Applying Standard Filter : RK Stage = ",i0)
#endif
call filter_usp
end if
end if
!
! Apply the limiter
!
if (Limiter_Option /= 0) then
if (Apply_Limiter) then
#ifdef PROFILE_ON
if (mypnum == glb_root) write (iout,2) nst
2 format (8x,"Applying Limiter : RK Stage = ",i0)
#endif
if (Limiter_Option == -1) then
call resolution_indicator(apply_projection=true)
else if (Limiter_Option >= 1) then
call limit_by_projecting
end if
end if
end if
!
call debug_timer(leaving_procedure,pname)
!
end subroutine stabilize_usp
!
!###############################################################################
!
subroutine rupdate_Classic_RK(nst,Apply_Filter,Apply_Limiter)
!
! First, store d(utd)/dt for runge kutta time
! stepping then update usp
!
!.. Use Statements ..
use geovar, only : n_solpts
use ovar, only : num_rk_stages
use ovar, only : Limiter_Option
use ovar, only : Filter_Option
use flowvar, only : rssprk,residual,usp,uoldsp,dtsp
use filter_mod, only : filter_usp
use module_limiters, only : resolution_indicator
use module_limiters, only : limit_by_projecting
!
!.. Formal Arguments ..
integer, intent(in) :: nst
logical(lk), intent(in) :: Apply_Filter
logical(lk), intent(in) :: Apply_Limiter
!
!.. Local Scalars ..
integer :: n,m,nt
real(wp) :: temp
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "rupdate_Classic_RK"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Store the residual for this Runge-Kutta step in rssprk
!
rssprk(:,:,nst) = residual(:,:)
!
! Update usp
!
do n = 1,n_solpts
do m = 1,nq
temp = zero
do nt = 1,nst
temp = temp + alphark(nt,nst,num_rk_stages)*rssprk(m,n,nt)
end do
usp(m,n) = uoldsp(m,n) + dtsp(n)*temp
end do
end do
!
! Apply filtering or limiting to stabilize the solution
!
call stabilize_usp(nst,Apply_Filter,Apply_Limiter)
!
call debug_timer(leaving_procedure,pname)
!
end subroutine rupdate_Classic_RK
!
!###############################################################################
!
subroutine rupdate_CK4_RK(nst,Apply_Filter,Apply_Limiter)
!
!.. Use Statements ..
use geovar, only : n_solpts
use ovar, only : Limiter_Option,Filter_Option
use flowvar, only : rssprk,residual,usp,dtsp
use filter_mod, only : filter_usp
use module_limiters, only : resolution_indicator
use module_limiters, only : limit_by_projecting
!
!.. Formal Arguments ..
integer, intent(in) :: nst
logical(lk), intent(in) :: Apply_Filter
logical(lk), intent(in) :: Apply_Limiter
!
!.. Local Scalars ..
integer :: n
!
! Carpenter-Kennedy 4th-order/5-stage Runge-Kutta coefficients
!
real(wp), parameter, dimension(1:5) :: &
alfa = (/ 0.0_wp, &
-567301805773.0_wp/ 1357537059087.0_wp, &
-2404267990393.0_wp/ 2016746695238.0_wp, &
-3550918686646.0_wp/ 2091501179385.0_wp, &
-1275806237668.0_wp/ 842570457699.0_wp /)
real(wp), parameter, dimension(1:5) :: &
beta = (/ 1432997174477.0_wp/ 9575080441755.0_wp, &
5161836677717.0_wp/13612068292357.0_wp, &
1720146321549.0_wp/ 2090206949498.0_wp, &
3134564353537.0_wp/ 4481467310338.0_wp, &
2277821191437.0_wp/14882151754819.0_wp /)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "rupdate_CK4_RK"
!
continue
!
call debug_timer(entering_procedure,pname)
!
do n = 1,n_solpts
!
rssprk(:,n,1) = alfa(nst)*rssprk(:,n,1) + dtsp(n)*residual(:,n)
!
usp(:,n) = usp(:,n) + beta(nst)*rssprk(:,n,1)
!
end do
!
! Apply filtering or limiting to stabilize the solution
!
call stabilize_usp(nst,Apply_Filter,Apply_Limiter)
!
call debug_timer(leaving_procedure,pname)
!
end subroutine rupdate_CK4_RK
!
!###############################################################################
!
subroutine rupdate_TVD2_RK(nst,Apply_Filter,Apply_Limiter)
!
!.. Use Statements ..
use geovar, only : n_solpts
use ovar, only : Limiter_Option,Filter_Option
use flowvar, only : residual,usp,uoldsp,dtsp
use filter_mod, only : filter_usp
use module_limiters, only : resolution_indicator
use module_limiters, only : limit_by_projecting
!
!.. Formal Arguments ..
integer, intent(in) :: nst
logical(lk), intent(in) :: Apply_Filter
logical(lk), intent(in) :: Apply_Limiter
!
!.. Local Scalars ..
integer :: n
!
! TVD 2nd-order/2-stage Runge-Kutta Coefficients
!
real(wp), parameter, dimension(1:2) :: alfa = (/ zero,one /)
real(wp), parameter, dimension(1:2) :: beta = (/ one ,half /)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "rupdate_TVD2_RK"
!
continue
!
call debug_timer(entering_procedure,pname)
!
do n = 1,n_solpts
!
usp(:,n) = beta(nst) * (alfa(nst)*uoldsp(:,n) + &
usp(:,n) + &