-
Notifications
You must be signed in to change notification settings - Fork 38
/
generic.f90
1461 lines (1461 loc) · 46.6 KB
/
generic.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 generic_mod
!
use module_kind_types
use eqn_idx, only : nec,nmb,nme,nmx,nmy,nmz,nee,nq,ntk,ntl
!
implicit none
!
private
!
public :: init_generic_mod
public :: write_iter_stats
public :: getmaxent
public :: compute_residual_error
public :: compute_TaylorGreen_KEDR
public :: generic_memory_usage
!
character(len=100), save :: iter_out_fmt
!
real(wp), save :: Density_Maximum_Residual = -huge(zero)
logical(lk), save :: vortex_has_collapsed = fals
integer, save :: final_countdown = 0
!!
!real(wp), save :: rl2mx = -huge(zero)
!
! TGV_KEDR : array used for the Taylor-Green vortex problem that
! contains the temporal evolution of various integrated
! quantities relating to the kinetic energy
!
integer, save :: iotg
real(wp), save, allocatable :: tgv_kedr(:,:)
real(wp), save, allocatable :: sum_kedr(:,:)
real(wp), save :: tgv_dimen(1:7) = zero
!
contains
!
!###############################################################################
!
subroutine compute_residual_error()
!
!.. Use Statements ..
use order_mod, only : maxEP
use geovar, only : nr,ncell,cell
use ovar, only : total_volume,itestcase
use ovar, only : uverr
use parallel_mod, only : cell_map
use interpolation_mod, only : outerp
!
!.. Local Scalars ..
integer :: this_cell,n1,n2,np,k,m,n
integer :: this_geom,this_order,l1,l2,l3
real(wp) :: sn,se
!
!.. Local Arrays ..
real(wp), dimension(1:maxEP) :: wtdjac
real(wp), dimension(1:nq,1:maxEP) :: uold,vold
real(wp), dimension(1:nq,1:maxEP) :: unew,vnew
real(wp), dimension(1:nr,1:maxEP) :: xyz_err
real(wp), dimension(1:nq+1,1:2) :: ett
real(wp), dimension(1:nq+1,1:2,1:5+nr) :: error
real(wp), dimension(1:nq+1,1:2,1:5+nr,1:ncpu) :: all_error
!
! error(1:nq+1,:,:) = error value for each flow equation + extra variable
! error(:,1,:) = error for conserved variables [rho,rho(u,v,..),rhoe,entropy]
! error(:,2,:) = error for primitive variables [rho,u,v,..,pressure,vel mag]
! error(:,:,1) = L1 norm of total error for all solution points
! error(:,:,2) = L2% norm of total error for all solution points
! error(:,:,3) = L-inf norm (max value) of error for all solution points
! error(:,:,4) = ID of grid cell containing maximum value of error
! error(:,:,5) = ID of solution point with maximum value of error
! error(:,:,6) = x-coordinate of sol-pt with max value of error
! error(:,:,7) = y-coordinate of sol-pt with max value of error (if 2D or 3D)
! error(:,:,8) = z-coordinate of sol-pt with max value of error (if 3D
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "compute_residual_error"
!
continue
!
l1 = 1
l2 = min(2,nr)
l3 = min(3,nr)
!
#ifdef DEBUG_ON
call debug_timer(entering_procedure,pname)
#endif
!
error(:,:,:) = zero ! intialize everything to zero
error(:,:,3) = -eps6 ! make this slightly negative in case all error is zero
!
do this_cell = 1,ncell
!
n1 = cell(this_cell)%beg_sp
n2 = cell(this_cell)%end_sp
np = n2-n1+1
!
this_geom = cell(this_cell)%geom
this_order = cell(this_cell)%order
!
if (allocated(outerp(this_geom,this_order)%error)) then
if (allocated(outerp(this_geom,this_order)%error%mat)) then
np = size(outerp(this_geom,this_order)%error%mat,dim=1)
end if
end if
!
call collect_error_arrays(this_cell,unew(1:nq,1:np),uold(1:nq,1:np), &
wtdjac(1:np),xyz_err(1:nr,1:np), &
vnew(1:nq,1:np),vold(1:nq,1:np))
!
! Now loop through the solution points of this cell to compute the
! error between the solutions of the current and previous time steps
!
do k = 1,np
!
! Write out an error to stdout if density or pressure is negative
!
if (any([unew(nec,k),vnew(nee,k)] <= zero)) then
write (iout,1) mypnum,cell_map(mypnum+1)%loc_to_glb(this_cell),k, &
unew(nec,k),vnew(nee,k),vnew(nec,k)
end if
!
! Error for conserved variables at the current solution point
!
if (itestcase == Inviscid_Gaussian_Bump) then
sn = entropy_cv_sp( unew(:,k) , log_opt=fals , use_pref_nd=true )
se = one
else
sn = entropy_cv_sp( unew(:,k) )
se = entropy_cv_sp( uold(:,k) )
end if
!
ett(1:nq,1) = abs( unew(:,k) - uold(:,k) )
ett(nq+1,1) = sn - se
!
! Error for primitive variables at the current solution point
!
ett(1:nq,2) = abs( vnew(:,k) - vold(:,k) )
ett(nq+1,2) = norm2( ett(nmb:nme,2) )
!
! Now add the error for all variables at the current solution
! point to the running integral sum for the L1 and L2 error norms
!
error(:,:,1) = error(:,:,1) + wtdjac(k)*ett(:,:)
error(:,:,2) = error(:,:,2) + wtdjac(k)*ett(:,:)*ett(:,:)
!
! If any of these errors are greater than the previous maximum
! values, save the error value and record this location
!
where (abs(ett(:,:)) > error(:,:,3))
error(:,:,3) = abs(ett(:,:))
error(:,:,4) = real(cell_map(mypnum+1)%loc_to_glb(this_cell),kind=wp)
error(:,:,5) = real(k,kind=wp)
error(:,:,5+l1) = xyz_err(l1,k)
error(:,:,5+l2) = xyz_err(l2,k)
error(:,:,5+l3) = xyz_err(l3,k)
end where
!
end do
!
end do
!
! Collect the error information from all processors
!
if (ncpu > 1) then
call mpi_allgather(error, size(error,kind=int_mpi),mpi_flttyp, &
all_error,size(error,kind=int_mpi),mpi_flttyp, &
MPI_COMM_WORLD,mpierr)
else
all_error(:,:,:,1) = error(:,:,:)
end if
!
! Finish computing the various global norms for all variables
!
do n = 1,2
!
! n : 1 => conserved variables + entropy
! 2 => primitive variables (temp,vel,pres) + velocity magnitude
!
!! L1 norm for the current set of variables
!uverr(:,1,n) = sum(all_error(:,n,1,:),dim=2) / total_volume
!! L2 norm for the current set of variables
!uverr(:,2,n) = sqrt( sum(all_error(:,n,2,:),dim=2) / total_volume )
!! Infinity norm for the current set of variables
!uverr(:,3,n) = maxval(all_error(:,n,3,:),dim=2)
!
do m = 1,nq+1
!
! L1 norm for the current variable
uverr(m,1,n) = sum(all_error(m,n,1,:)) / total_volume
! L2 norm for the current variable
uverr(m,2,n) = sqrt( sum(all_error(m,n,2,:)) / total_volume )
! Infinity norm for the current variable
uverr(m,3,n) = maxval(all_error(m,n,3,:))
!
! Processor with max inf norm for the current variable
k = maxloc(all_error(m,n,3,:),dim=1)
! ID of grid cell with max inf norm for the current variable
uverr(m,4,n) = all_error(m,n,4,k)
! ID of sol point with max inf norm for the current variable
uverr(m,5,n) = all_error(m,n,5,k)
! Coordinates of sol point with max inf norm for the current variable
uverr(m,6:5+nr,n) = all_error(m,n,6:5+nr,k)
!
end do
!
end do
!
#ifdef DEBUG_ON
call debug_timer(leaving_procedure,pname)
#endif
!
! Format Statements
!
1 format ("ERROR DETECTED! CPU #",i0," => cell=",i0,", SP=",i0," :",/, &
8x,"rho=",es13.6,", pres=",es13.6,", temp=",es13.6)
!
end subroutine compute_residual_error
!
!###############################################################################
!
subroutine write_iter_stats(walltime_expiring,exit_main_loop)
!
!.. Use Statements ..
use geovar, only : global_pinc_ptr
use ovar, only : itcur,d_t,cfl,time,minimum_timesteps,time_ref
use ovar, only : convergence_reached,itestcase,Period_Timesteps
use ovar, only : convergence_order_max_res,convergence_order_abs_res
use ovar, only : rl2mx,uverr,this_is_final_timestep,iter_out_interval
use ovar, only : output_time_averaging,time_scaling_factor,ave_start_time
!
use pbs_mod, only : pbs_remaining_walltime
!
!.. Formal Arguments ..
logical(lk), intent(inout) :: walltime_expiring
logical(lk), intent( out) :: exit_main_loop
!
!.. Local Scalars ..
integer :: hrs_left,min_left,sec_left
integer :: nloc,kloc
real(wp) :: xentmax,yentmax
real(wp) :: entL2
real(wp) :: wall_time_left,out_time
real(wp) :: orders_converged,output_L2val
real(wp) :: rltwo
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "write_iter_stats"
!
continue
!
exit_main_loop = fals
!
#ifdef DEBUG_ON
call debug_timer(entering_procedure,pname)
#endif
!
! Get the density and entropy residual stats from uverr
!
rltwo = uverr(nec,2,1)
entL2 = uverr(nq+1,2,1)
!
nloc = nint( uverr(nec,4,1) )
kloc = nint( uverr(nec,5,1) )
!
! Coordinates Location of the max inf norm for entropy
xentmax = uverr(nq+1,6,1)
yentmax = uverr(nq+1,7,1)
!
! Maximum L2 norm of density for the current simulation
rl2mx = max( rltwo , rl2mx )
!
if (any(itestcase == Transport_Problems)) then
!
output_L2val = entL2
convergence_reached = fals
!
! Check for a collapse of the vortex, or update the final
! countdown if a collapse has already been detected
!
if (vortex_has_collapsed) then
!
! Need to subtract from final_countdown the number of time steps
! that have been completed since the last call to write_iter_stats
!
final_countdown = max(final_countdown - iter_out_interval,0)
!
else if (rltwo > zero) then
!
if (log10(rltwo) > Density_Maximum_Residual) then
Density_Maximum_Residual = log10(rltwo)
end if
if (Density_Maximum_Residual > -two) then
vortex_has_collapsed = true
final_countdown = 26*Period_Timesteps - mod(itcur,Period_Timesteps)
end if
!
end if
!
else
!
orders_converged = log10(max(rl2mx,eps17)) - log10(max(rltwo,eps17))
output_L2val = orders_converged
!
! Check for convergence
!
if (itcur > minimum_timesteps) then
convergence_reached = (-orders_converged <= convergence_order_max_res) &
.or. (log10(rltwo) <= convergence_order_abs_res)
if (itestcase == Taylor_Green_Vortex) then
convergence_reached = fals
end if
end if
!
end if
!
! Output the results for the current time step
!
call pbs_remaining_walltime(walltime_expiring,wall_time_left)
!
if (mypnum == glb_root) then
!
out_time = time*time_ref*time_scaling_factor
if (output_time_averaging) then
out_time = out_time - ave_start_time*time_ref*time_scaling_factor
end if
#ifdef PBS_ENV
!
sec_left = abs(nint(wall_time_left))
!
hrs_left = sec_left/3600
min_left = (sec_left - hrs_left*3600)/60
sec_left = sec_left - hrs_left*3600 - min_left*60
! Make hrs_left negative if wall_time_left happens to be negative
hrs_left = sign(hrs_left,int(wall_time_left))
!
!write (iout,iter_out_fmt) itcur,d_t*time_ref,time*time_ref, &
write (iout,iter_out_fmt) itcur,d_t,out_time, &
cfl,rltwo,output_L2val,nloc, &
global_pinc_ptr(nloc)+kloc, &
xentmax,yentmax, &
hrs_left,min_left,sec_left
!
#else
!
!write (iout,iter_out_fmt) itcur,d_t*time_ref,time*time_ref, &
write (iout,iter_out_fmt) itcur,d_t,out_time, &
cfl,rltwo,output_L2val,nloc, &
global_pinc_ptr(nloc)+kloc, &
xentmax,yentmax
!
!
#endif
!
if (convergence_reached) then
if (-orders_converged <= convergence_order_max_res) write (iout,3)
if (log10(rltwo) <= convergence_order_abs_res) write (iout,4)
end if
!
if (walltime_expiring) write (iout,2)
!
if (this_is_final_timestep) write (iout,5)
!
end if
!
! If a vortex collapse has been detected and final_countdown has reached 0,
! activate convergence_reached so that the main_loop can be exited when
! we return from this subroutine to the main program.
!
if (vortex_has_collapsed .and. final_countdown==0) then
if (mypnum == glb_root) write (iout,6)
convergence_reached = true
end if
!
if (convergence_reached) exit_main_loop = true
if (this_is_final_timestep) exit_main_loop = true
if (walltime_expiring) exit_main_loop = true
!
#ifdef DEBUG_ON
call debug_timer(leaving_procedure,pname)
#endif
!
! Format Statements
!
2 format (/,"*******************************************************",/, &
" THE SIMULATION WALL TIME REQUESTED IS EXPIRING SOON!",/, &
" STOPPING EXECUTION AND DUMPING THE FINAL RESULTS!",/, &
"*******************************************************",/)
3 format (/,"*******************************************************",/, &
" THE CONVERGENCE CRITERION FOR THE ORDERS OF",/, &
" MAGNITUDE REDUCTION OF THE RESIDUAL ERROR",/, &
" RELATIVE TO THE MAXIMUM RESIDUAL ERROR HAS BEEN MET!",/, &
"*******************************************************",/)
4 format (/,"*******************************************************",/, &
" THE CONVERGENCE CRITERION FOR THE ORDER OF MAGNITUDE",/, &
" REDUCTION OF THE ABSOLUTE RESIDUAL ERROR HAS BEEN MET!",/, &
"*******************************************************",/)
5 format (/,"*******************************************************",/, &
" THE SIMULATION HAS REACHED THE REQUESTED FINAL TIME!",/, &
"*******************************************************",/)
6 format (/,"******************************************************",/, &
" VORTEX HAS APPEARED TO COLLAPSE! THE SIMULATION WAS",/, &
" RUN ANOTHER 25 PERIODS PAST THE POINT OF COLLAPSE!",/, &
" STOPPING EXECUTION AND DUMPING THE FINAL RESULTS!",/, &
"******************************************************",/)
!
end subroutine write_iter_stats
!
!###############################################################################
!
subroutine init_generic_mod
!
!.. Use Statements ..
use geovar, only : nr,n_global_cell,n_global_solpts
use ovar, only : itcur,num_timesteps,itestcase
use ovar, only : uverr,output_time_averaging
!
use pbs_mod, only : pbs_remaining_walltime
!
!.. Local Scalars ..
integer :: ierr
integer :: final_iter_digits
integer :: max_cell_digits
integer :: max_solpt_digits
integer :: hrs_left,min_left,sec_left
logical(lk) :: walltime_expiring
real(wp) :: wall_time_left
character(len=100) :: char_num
character(len=1000) :: iter_header
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "init_generic_mod"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Allocate the error array
!
if (.not. allocated(uverr)) then
allocate ( uverr(1:nq+1,1:5+nr,1:2) , source=zero , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"uverr",1,__LINE__,__FILE__,ierr, &
error_message,skip_alloc_pause)
end if
!
write (char_num,1) itcur + num_timesteps
final_iter_digits = max(4,len_trim(adjustl(char_num)))
!
write (char_num,1) n_global_cell
max_cell_digits = max(4,len_trim(adjustl(char_num)))
!
write (char_num,1) n_global_solpts
max_solpt_digits = max(5,len_trim(adjustl(char_num)))
!
!if (output_time_averaging) then
! write (iter_out_fmt,101) final_iter_digits
!else
write (iter_out_fmt,100) final_iter_digits,max_cell_digits,max_solpt_digits
!end if
!
! Add on the remaining simulation time to the output if
! running in the PBS environment
!
#ifdef PBS_ENV
iter_out_fmt = iter_out_fmt(1:len_trim(iter_out_fmt)) // ',1x,i3,2(":",i2.2)'
#endif
!
! Put the last ')' onto iter_out_fmt
!
iter_out_fmt = iter_out_fmt(1:len_trim(iter_out_fmt)) // ")"
!
! Now get the format for the header
!
if (any(itestcase == Transport_Problems)) then
write (iter_header,200) final_iter_digits-3, &
max_cell_digits-2, &
max_solpt_digits-3
else if (itestcase == Laminar_BndLyr) then
write (iter_header,201) final_iter_digits-3, &
max_cell_digits-2, &
max_solpt_digits-3
else if (itestcase == Taylor_Green_Vortex) then
!write (iter_header,203) final_iter_digits-3, &
write (iter_header,202) final_iter_digits-3, &
max_cell_digits-2, &
max_solpt_digits-3
!else if (output_time_averaging) then
! write (iter_header,204) final_iter_digits-3
else
write (iter_header,202) final_iter_digits-3, &
max_cell_digits-2, &
max_solpt_digits-3
end if
!
#ifdef PBS_ENV
iter_header = iter_header(1:len_trim(iter_header)) // ",4x,'Time Left'"
!
! Get the remaining wall time before the solver begins
!
call pbs_remaining_walltime(walltime_expiring,wall_time_left)
!
sec_left = abs(nint(wall_time_left))
!
hrs_left = sec_left/3600
min_left = (sec_left - hrs_left*3600)/60
sec_left = sec_left - hrs_left*3600 - min_left*60
! Make hrs_left negative if wall_time_left happens to be negative
hrs_left = sign(hrs_left,int(wall_time_left))
!
if (mypnum == 0) write (iout,2) hrs_left,min_left,sec_left
!
#endif
!
! Put the last ')' onto iter_header
!
iter_header = iter_header(1:len_trim(iter_header)) // ")"
!
! Write the header for the terminal output
!
if (mypnum == 0) write (iout,iter_header)
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
1 format (i0)
2 format (/," After Pre-Processor and Initializations =>", &
" Wall Time Remaining = ",i3,2(":",i2.2))
100 format ("(1x,i",i0,",5es12.4,2x,i",i0,",2x,i",i0,",2es9.1")
101 format ("(1x,i",i0,",8es12.4")
200 format ("(/,",i0,"x,'iter',5x,'d_t',8x,'Time',6x,'L2-Density',2x,", &
"'L2-Entropy',",i0,"x,'Cell',",i0,"x,'Solpt',5x,'x',8x,'y'")
201 format ("(/,",i0,"x,'iter',5x,'d_t',8x,'Time',6x,'L2-X-Mmntm',2x,", &
"'OrdersDrop',2x,'Max-DensL2',",i0,"x,'Cell',",i0, &
"x,'Solpt',5x,'x',8x,'y'")
!202 format ("(/,",i0,"x,'iter',5x,'d_t',8x,'Time',10x,'CFL',5x,", &
202 format ("(/,",i0,"x,'iter',3x,'d_t* (ND)',3x,'Time (s)',7x,'CFL',5x,", &
"'L2-Density',2x,'Max-DensL2',",i0,"x,'Cell',",i0, &
"x,'Solpt',5x,'x',8x,'y'")
!202 format ("(/,",i0,"x,'iter',5x,'d_t',8x,'Time',6x,'L2-Density',2x,", &
! "'OrdersDrop',2x,'Max-DensL2',",i0,"x,'Cell',",i0, &
! "x,'Solpt',5x,'x',8x,'y'")
203 format ("(/,",i0,"x,'iter',5x,'dt*',8x,'Time*',5x,'L2-Density',2x,", &
"'OrdersDrop',2x,'Max-DensL2',",i0,"x,'Cell',",i0, &
"x,'Solpt',5x,'x',8x,'y'")
204 format ("(/,",i0,"x,'iter',5x,'dt*',8x,'Time*',5x,'L2-Density',4x,", &
"'L2-Vx',7x,'L2-Vy',7x,'L2-Vz',7x,'L2-Pres'")
!
end subroutine init_generic_mod
!
!###############################################################################
!
subroutine getmaxent
!
!.. Use Statements ..
use ovar, only : uverr
!
!.. Local Scalars ..
integer :: nentmax,kentmax
real(wp) :: xentmax,yentmax,zentmax
real(wp) :: entmax,entL1,entL2
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "getmaxent"
!
continue
!
call debug_timer(entering_procedure,pname)
!
entL1 = uverr(nq+1,1,1)
entL2 = uverr(nq+1,2,1)
entmax = uverr(nq+1,3,1)
nentmax = nint( uverr(nq+1,4,1) )
kentmax = nint( uverr(nq+1,5,1) )
xentmax = uverr(nq+1,6,1)
if (size(uverr,dim=2) >= 7) &
yentmax = uverr(nq+1,7,1)
if (size(uverr,dim=2) == 8) &
zentmax = uverr(nq+1,8,1)
!
call debug_timer(leaving_procedure,pname)
!
end subroutine getmaxent
!
!###############################################################################
!
subroutine collect_error_arrays(this_cell,unew,uold,wtdjac,xyz_err,vnew,vold)
!
!.. Use Statements ..
use order_mod, only : maxSP
use geovar, only : nr,cell,xyz
use ovar, only : mms_opt,itestcase,bc_in
use ovar, only : itcur,itrst,read_time_ave_restart
use ovar, only : prev_ave_time,saved_ave_time,ave_start_time
use ovar, only : output_time_averaging
use flowvar, only : usp,uoldsp,uavesp
use interpolation_mod, only : outerp
use quadrature_mod, only : std_elem
use metrics_mod, only : metrics_dt
use mms_mod, only : mms_solution_at_xyz
!
!.. Formal Arguments ..
integer, intent(in) :: this_cell
real(wp), dimension(:,:), intent(inout) :: unew
real(wp), dimension(:,:), intent(inout) :: uold
real(wp), dimension(:,:), intent(inout) :: xyz_err
real(wp), dimension(:), intent(inout) :: wtdjac
!
!.. Optional Arguments ..
real(wp), optional, intent(inout) :: vnew(:,:)
real(wp), optional, intent(inout) :: vold(:,:)
!
!.. Local Scalars ..
integer :: m,l,k,n1,n2,np,nep
integer :: this_geom,this_order
real(wp) :: a,b
logical(lk) :: use_error_matrix
!
!.. Local Arrays ..
real(wp) :: xyz_offset(1:nr,1:maxSP)
real(wp) :: uprev(1:nq,1:maxSP)
real(wp) :: vprev(1:nq,1:maxSP)
real(wp) :: ucurr(1:nq,1:maxSP)
real(wp) :: vcurr(1:nq,1:maxSP)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "collect_error_arrays"
!
continue
!
!call debug_timer(entering_procedure,pname)
!
this_geom = cell(this_cell)%geom
this_order = cell(this_cell)%order
!
n1 = cell(this_cell)%beg_sp
n2 = cell(this_cell)%end_sp
np = n2-n1+1
!
! Determine if we will be using the error matrix or not
!
use_error_matrix = fals
!
if (allocated(outerp(this_geom,this_order)%error)) then
if (allocated(outerp(this_geom,this_order)%error%mat)) then
use_error_matrix = true
end if
end if
!
! Get the number of error points
!
if (use_error_matrix) then
nep = size(outerp(this_geom,this_order)%error%mat,dim=1)
else
nep = np
end if
!
! #######
! ## 1 ##
! #######
!
! Get the conserved variables of the current solution at the error points
!
if (output_time_averaging) then
ucurr(1:nq,1:np) = uavesp(1:nq,n1:n2)
else
ucurr(1:nq,1:np) = usp(1:nq,n1:n2)
end if
!
if (use_error_matrix) then
!
do m = 1,nq
unew(m,1:nep) = outerp(this_geom,this_order)% &
error% &
mv_mult( ucurr(m,1:np) )
end do
!
else
!
unew(1:nq,1:nep) = ucurr(1:nq,1:np)
!
end if
!
! Get the primitive variables of the current solution at the error points
!
if (present(vnew)) then
!
if (output_time_averaging) then
vcurr(1:nq,1:np) = uavesp(nq+1:2*nq,n1:n2)
else
vcurr(1:nq,1:np) = usp2v( usp(1:nq,n1:n2) , swap_t_for_rho=true )
end if
!
if (use_error_matrix) then
!
do m = 1,nq
vnew(m,1:nep) = outerp(this_geom,this_order)% &
error% &
mv_mult( vcurr(m,1:np) )
end do
!
else
!
vnew(1:nq,1:nep) = vcurr(1:nq,1:np)
!
end if
!
end if
!
! #######
! ## 2 ##
! #######
!
! Get the value of the metric jacobians multiplied
! by the quadrature weights at the error points
!
if (use_error_matrix) then
!
wtdjac(1:nep) = outerp(this_geom,this_order)% &
error% &
mv_mult( metrics_dt(this_cell)%jac(:) )
!
wtdjac(1:nep) = wtdjac(1:nep) * outerp(this_geom,this_order)%err_wts
!
else
!
wtdjac(1:nep) = metrics_dt(this_cell)%jac(:) * &
std_elem(this_geom,this_order)%wts
!
end if
!
! #######
! ## 3 ##
! #######
!
! Get the coordinates of the error points
!
if (use_error_matrix) then
!
do l = 1,nr
xyz_err(l,1:nep) = outerp(this_geom,this_order)% &
error% &
mv_mult( xyz(l,n1:n2) )
end do
!
else
!
xyz_err(1:nr,1:nep) = xyz(1:nr,n1:n2)
!
end if
!
! #######
! ## 4 ##
! #######
!
! Get either
! (a) the exact analytical solution or
! (b) solution from the previous time step
! at the error points.
!
if (mms_opt /= 0) then
!
! Evaluate the exact analytical MMS solution at the error points
!
do k = 1,nep
uold(1:nq,k) = mms_solution_at_xyz( xyz_err(1:nr,k), &
return_nondim=true, &
return_cv=true )
end do
!
if (present(vold)) then
vold(1:nq,1:nep) = usp2v( uold(1:nq,1:nep) , swap_t_for_rho=true )
end if
!
else if (any(itestcase == Transport_Problems)) then
!
! Evaluate the exact analytical solution to the vortex transport problem
!
xyz_offset(1:nr,1:nep) = vortex_offset( xyz_err(1:nr,1:nep) )
!
do k = 1,nep
uold(1:nq,k) = vortex_solution( xyz_offset(1:nr,k) )
end do
!
if (present(vold)) then
vold(1:nq,1:nep) = usp2v( uold(1:nq,1:nep) , swap_t_for_rho=true )
end if
!
else if (itestcase == Freestream_Preservation) then
!
do k = 1,nep
uold(1:nq,k) = bc_in(0)%cv(1:nq)
end do
!
if (present(vold)) then
do k = 1,nep
vold(1:nq,k) = bc_in(0)%pv(1:nq)
end do
end if
!
else
!
if (output_time_averaging) then
! Compute uavesp at the previous averaging time
if (any(saved_ave_time == [zero,ave_start_time]) .or. &
(.not. read_time_ave_restart .and. itcur-itrst < 100)) then
uprev(1:nq,1:np) = uoldsp(1:nq,n1:n2)
else
a = (prev_ave_time-saved_ave_time) / (saved_ave_time-ave_start_time)
b = one - a
uprev(1:nq,1:np) = b * uavesp(1:nq,n1:n2) - a * usp(1:nq,n1:n2)
!if (any(uprev(nec,1:np) <= zero)) then
! uprev(1:nq,1:np) = uoldsp(1:nq,n1:n2)
!else if (any(pressure_cv(uprev(1:nq,1:np)) <= zero)) then
! uprev(1:nq,1:np) = uoldsp(1:nq,n1:n2)
!end if
end if
else
uprev(1:nq,1:np) = uoldsp(1:nq,n1:n2)
end if
!
if (use_error_matrix) then
!
! Get the solution from the previous time step at the error points
!
do m = 1,nq
uold(m,1:nep) = outerp(this_geom,this_order)% &
error% &
mv_mult( uprev(m,1:np) )
end do
!
else
!
! Use the solution from the previous time step
!
uold(1:nq,1:nep) = uprev(1:nq,1:np)
!
end if
!
if (present(vold)) then
!
if (output_time_averaging) then
! Compute uavesp at the previous averaging time
if (any(saved_ave_time == [zero,ave_start_time]) .or. &
(.not. read_time_ave_restart .and. itcur-itrst < 100)) then
vprev(1:nq,1:np) = usp2v( uoldsp(1:nq,n1:n2) , swap_t_for_rho=true )
else
! a and b were already computed above, no need to do it again
vprev(1:nq,1:np) = b * uavesp(nq+1:2*nq,n1:n2) - &
a * usp2v( usp(1:nq,n1:n2) , swap_t_for_rho=true )
end if
else
vprev(1:nq,1:np) = usp2v( uoldsp(1:nq,n1:n2) , swap_t_for_rho=true )
end if
!
if (use_error_matrix) then
!
! Get the solution from the previous time step at the error points
!
do m = 1,nq
vold(m,1:nep) = outerp(this_geom,this_order)% &
error% &
mv_mult( vprev(m,1:np) )
end do
!
else
!
! Use the solution from the previous time step
!
vold(1:nq,1:nep) = vprev(1:nq,1:np)
!
end if
!
end if
!
end if
!
!call debug_timer(leaving_procedure,pname)
!
end subroutine collect_error_arrays
!
!###############################################################################
!
subroutine compute_TaylorGreen_KEDR(iter,dtmin)
!
!.. Use Statements ..
use order_mod, only : maxpts,n_order
use geovar, only : nr,ncell,cell
use ovar, only : muref_nd,total_volume
use ovar, only : time,time_ref
use ovar, only : VortexGrid_DOF
use ovar, only : iter_out_interval
use flowvar, only : usp,dusp
use interpolation_mod, only : outerp
use quadrature_mod, only : std_elem
use metrics_mod, only : metrics_dt
!
!.. Formal Arguments ..
integer, intent(in) :: iter
real(wp), intent(in) :: dtmin
!
!.. Local Scalars ..
integer :: k,l,m,n,nc,nep,n1,n2,tgv_idx
integer :: ierr,nke,ndt,nmin,nmax,nbeg,nend
integer :: this_cell,this_geom,this_order
!
logical(lk) :: first_output,final_output
logical(lk) :: this_is_output_iter
!
real(wp) :: kem,kec,kep,dtm,dtp
real(wp) :: solution_time
real(wp) :: div_vel,muref_star
!
!.. Local Saved Scalars ..
logical(lk), save :: completed_first_output = fals
logical(lk), save :: needs_initialization = true
!
!.. Local Arrays ..
real(wp) :: vort(1:nr)
real(wp) :: wtdjac(1:maxpts)
real(wp) :: strain(1:nr,1:nr)
real(wp) :: vsp(1:nq,1:maxpts)
real(wp) :: dcvdx(1:nr,1:nq,1:maxpts)
real(wp) :: dpvdx(1:nr,1:nq,1:maxpts)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "compute_TaylorGreen_KEDR"
character(len=*), parameter :: fname = "TaylorGreen_KEDR.dat"
!
continue
!
call debug_timer(entering_procedure,pname)
!
nke = 5
ndt = 7
!
nmin = 1
nmax = iter_out_interval
!
! Get the current index value for the kedr array
! NOTE: tgv_idx will be zero if iter is 0, otherwise it will
! take a value between 1 and iter_out_interval
!
tgv_idx = mod( abs(iter)-1 , nmax ) + 1
!
! Create some logical variables to help readability
!
final_output = (iter < 0)
first_output = (iter == nmax) .or. &
(final_output .and. .not. completed_first_output)
this_is_output_iter = ((tgv_idx == nmax .or. final_output) .and. (iter /= 0))
!
#ifdef DEBUG_ON
!if (mypnum == 0) then
! if (first_output) then
! write (iout,13) "FIRST",iter,tgv_idx
! end if
! if (final_output) then
! write (iout,13) "FINAL",iter,tgv_idx
! end if
!end if
!13 format (/," THIS IS THE ",a," TGV-KEDR OUTPUT!",/, &
! " niter=",i0,", tgv_idx=",i0,/)
#endif
!
!####################################################
!####################################################
!####################################################
!########## ##########
!########## INITIALIZATION SECTION ##########
!########## ##########
!####################################################
!####################################################
!####################################################
!
! If this is before the first iteration, initialize everything needed
! for this subroutine
!
if (needs_initialization) then
!
! Reset tgv_idx to 0 for the first time through this subroutine
!
tgv_idx = 0
!
! NOTE: tgv_kedr(ndt,-1) will store the solution time for the last
! output of the TGV results so initializing tgv_kedr to zero
! is exactly what we need to start
!
allocate ( tgv_kedr(1:7,-1:nmax) , source=zero , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"tgv_kedr",1,__LINE__,__FILE__,ierr, &
error_message,skip_alloc_pause)
!
allocate ( sum_kedr(1:4,0:nmax) , source=zero , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"sum_kedr",1,__LINE__,__FILE__,ierr, &
error_message,skip_alloc_pause)
!
! Initialize the array to adjust the nondimensionalization of the
! integrated results
! NOTE: The comments above each value indicate the reason for