-
Notifications
You must be signed in to change notification settings - Fork 38
/
correction_mod.f90
1392 lines (1392 loc) · 38.5 KB
/
correction_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 correction_mod
!
!.. Use Statements ..
use module_kind_types
use generic_types_mod, only : matrix
!
implicit none
!
private
!
!
!.. Public Procedures ..
!
public :: init_correction_matrices
public :: correction_memory_usage
!
!
!
! correct : correction matrix for all combinations of cell geometry and
! and cell order that are possible in the current simulation
!
! For cell 'n' :
!
! The correction matrix (giving the contribution to each solution
! point within cell 'n' from the interface flux point 'k' that is
! currently of interest) is given by the expression
!
! correct(this_geom,this_order)%mat(:,k)
!
! Where :
!
! this_geom = cell(n)%geom
! this_order = cell(n)%order
! k = the flx-pt on a face of cell 'n' that is currently of interest
!
type(matrix), public, save, target, allocatable :: correct(:,:)
!
contains
!
!###############################################################################
!
subroutine init_correction_matrices()
!
!.. Use Statements ..
use order_mod, only : geom_solpts,geom_flxpts
use order_mod, only : n_min_geom,n_max_geom
use order_mod, only : n_min_order,n_max_order
use order_mod, only : n_order
use quadrature_mod, only : geom_is_used
use quadrature_mod, only : std_elem
!
!.. Local Scalars ..
integer :: gmin,gmax,omin,omax
integer :: this_geom,this_order
integer :: nsolpts,nflxpts,ierr
integer :: n,n1,n2,i
character(len=200) :: array_name
!
!.. Local Pointers ..
type(matrix), pointer :: this_correct
!real(wp), pointer, contiguous :: solpts(:,:)
real(wp), pointer :: solpts(:,:)
!real(wp), pointer, contiguous :: cmat(:,:)
real(wp), pointer :: cmat(:,:)
!
!.. Local Allocatable Arrays ..
real(wp), allocatable :: edgpts(:)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "init_correction_matrices"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Initialize the local pointers to disassociated
!
this_correct => null()
solpts => null()
cmat => null()
!
gmin = n_min_geom
gmax = n_max_geom
omin = n_min_order
omax = n_max_order
!
! Allocate the correct array
!
allocate ( correct(gmin:gmax,omin:omax) , stat=ierr , errmsg=error_message )
call alloc_error(pname,"correct",1,__LINE__,__FILE__,ierr,error_message)
!
geom_loop: do this_geom = gmin,gmax
!
if (.not. geom_is_used(this_geom)) cycle geom_loop
if (all(this_geom /= Geom_Valid)) cycle geom_loop
if (this_geom == Geom_Node) cycle geom_loop
!
order_loop: do this_order = omin,omax
!
! Assign local pointer as alias to simplify the code
!
this_correct => correct(this_geom,this_order)
!
! Get the number of solution points for this cell
!
nsolpts = geom_solpts(this_geom,this_order)
!
! Get the number of face/flux points for this cell
!
nflxpts = geom_flxpts(this_geom,this_order)
!
! Allocate the correction matrix
!
allocate ( this_correct%mat(1:nsolpts,1:nflxpts) , &
source=zero , stat=ierr , errmsg=error_message )
write (array_name,1) Geom_Name(this_geom),this_order
call alloc_error(pname,array_name,1,__LINE__,__FILE__,ierr,error_message)
!
! Assign local pointers to these matrices as aliases to simplify the code
!
cmat => this_correct%mat
!
! Compute the correction matrices depending on geometry type
!
select case (this_geom)
case (Geom_Edge)
!
edgpts = std_elem(this_geom,this_order)%pts(1,:) ! F2003 AUTO-REALLOC
!solpts => std_elem(this_geom,this_order)%pts
!
cmat(:,1) = CorrectionMatrix_Edge( edgpts )
!cmat(:,1) = CorrectionMatrix_Edge( solpts(1,:) )
cmat(:,2) = cmat(nsolpts:1:-1,1)
!
case (Geom_Tria)
!
solpts => std_elem(this_geom,this_order)%pts
!
cmat = CorrectionMatrix_Tria( solpts )
!
case (Geom_Quad)
!
edgpts = std_elem(Geom_Edge,this_order)%pts(1,:) ! F2003 AUTO-REALLOC
!solpts => std_elem(Geom_Edge,this_order)%pts
!
cmat = CorrectionMatrix_Quad( edgpts )
!cmat = CorrectionMatrix_Quad( solpts(1,:) )
!
case (Geom_Tetr)
!
solpts => std_elem(this_geom,this_order)%pts
!
cmat = CorrectionMatrix_Tetr( solpts )
!
case (Geom_Pyra)
!
solpts => std_elem(this_geom,this_order)%pts
!
cmat = CorrectionMatrix_Pyra( solpts )
!
case (Geom_Pris)
!
solpts => std_elem(this_geom,this_order)%pts
!
cmat = CorrectionMatrix_Pris( solpts )
!
case (Geom_Hexa)
!
edgpts = std_elem(Geom_Edge,this_order)%pts(1,:) ! F2003 AUTO-REALLOC
!solpts => std_elem(Geom_Edge,this_order)%pts
!
cmat = CorrectionMatrix_Hexa( edgpts )
!cmat = CorrectionMatrix_Hexa( solpts(1,:) )
!
case default
!
write (error_message,2)
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
!
end select
!
! Remove all associations of the local pointers before continuing
!
if (associated(this_correct)) this_correct => null()
if (associated(solpts )) solpts => null()
if (associated(cmat )) cmat => null()
!
end do order_loop
!
end do geom_loop
!
! Check for sparsity within each of the correction matrices
!
call correct%check_for_sparsity
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
1 format ("correct(",a,",",i0,")%mat")
2 format (" A grid cell of an unknown geometry type was found!")
!
end subroutine init_correction_matrices
!
!###############################################################################
!
pure function CorrectionMatrix_Edge(xi,eval_deriv) result(return_value)
!
!.. Use Statements ..
use ovar, only : correction_function
!
!.. Formal Arguments ..
real(wp), dimension(:), intent(in) :: xi
!
!.. Optional Arguments ..
logical(lk), optional, intent(in) :: eval_deriv
!
!.. Function Result ..
real(wp), dimension(1:size(xi)) :: return_value
!
!.. Local Scalars ..
integer :: n,k,j,npts,ndeg
logical(lk) :: compute_derivative
real(qp) :: cn,cnm1,cnm2
!
!.. Local Arrays ..
real(qp), dimension(1:size(xi)) :: x
real(qp), dimension(1:size(xi)) :: cmat
real(qp), dimension(0:size(xi)) :: coef_c
real(qp), dimension(0:size(xi)) :: coef_dc
!
real(qp), dimension( 0:size(xi), 1:size(xi)) :: xexp
real(qp), dimension(-1:size(xi),-1:size(xi)) :: coef_Le
real(qp), dimension( 0:size(xi), 0:size(xi)) :: coef_RR
!
continue
!
! #########################################################################
!
! THE LOOP INDICES IN THIS FUNCTION ARE USED FOR THE FOLLOWING
! SPECIFIC TASKS
!
! n : index used for looping through polynomial degrees / exponents
! k : index used for looping over the solution points
! j : index used for looping through the coefficients of a polynomial
!
! #########################################################################
!
npts = size(xi) ! number of solution points
ndeg = size(xi) ! polynomial degree of the correction function
!
compute_derivative = true
if (present(eval_deriv)) then
compute_derivative = eval_deriv
end if
!
! Initialize the function result
!
return_value(:) = zero
!
! Initialize the local arrays
!
x(:) = real( xi(:) , kind=qp )
!
cmat(:) = qzero
coef_c(:) = qzero
coef_dc(:) = qzero
coef_Le(:,:) = qzero
coef_RR(:,:) = qzero
!
! Initialize specific coefficients of Legendre polynomial
!
coef_Le(0,0) = qone
coef_Le(1,1) = qone
!
! Get the value of each nodal coordinate raised to all possible powers
! using xk = x(k), xexp(0:neg,k) contains the values of
! [ xk^0, xk^1, xk^2, ..., xk^(ndeg-1), xk^ndeg]
!
xexp(0,:) = qone
do k = 1,npts
do n = 1,ndeg
xexp(n,k) = xexp(n-1,k) * x(k)
end do
end do
!
! Get the coefficients for every Legendre polynomial up to degree ndeg
!
do n = 2,ndeg
!
cnm1 = real( 2*n-1 , kind=qp ) / real( n , kind=qp )
cnm2 = real( n-1 , kind=qp ) / real( n , kind=qp )
!
! Loop to get the coefficients for Legendre polynomial of degree n
!
do j = 0,n
coef_Le(j,n) = cnm1*coef_Le(j-1,n-1) - cnm2*coef_Le(j,n-2)
end do
!
end do
!
! Get the coefficients for every right Radau polynomial up to degree ndeg
!
do n = 1,ndeg
!
cn = qhalf * real( (-1)**n , kind=qp )
!
! Loop to get the coefficients for right Radau polynomial of degree n
!
do j = 0,n
coef_RR(j,n) = cn * (coef_Le(j,n) - coef_Le(j,n-1))
end do
!
end do
!
! Get the coefficients for the correction function
!
if (correction_function == Correction_g2) then
!
! Use the g2 correction function
!
cn = real( ndeg-1 , kind=qp ) / real( 2*ndeg-1 , kind=qp )
cnm1 = real( ndeg , kind=qp ) / real( 2*ndeg-1 , kind=qp )
!
do j = 0,ndeg
coef_c(j) = cn*coef_RR(j,ndeg) + cnm1*coef_RR(j,ndeg-1)
end do
!
else if (correction_function == Correction_gGauss) then
!
! Use the gGauss correction function
!
cn = real( ndeg-1 , kind=qp ) / real( 2*ndeg-1 , kind=qp )
cnm1 = real( ndeg , kind=qp ) / real( 2*ndeg-1 , kind=qp )
!
do j = 0,ndeg
coef_c(j) = cn*coef_RR(j,ndeg) + cnm1*coef_RR(j,ndeg-1)
end do
!
else
!
! Use the right Radau polynomial for the correction function
!
do j = 0,ndeg
coef_c(j) = coef_RR(j,ndeg)
end do
!
end if
!
if (compute_derivative) then
!
! Compute the coefficients for the derivative of the correction function
!
do j = 1,ndeg
coef_dc(j-1) = real( j , kind=qp ) * coef_c(j)
end do
!
! Finally, get the value for the derivative of the
! correction function at each 1D solution point
!
do k = 1,npts
cmat(k) = -sum( xexp(0:ndeg-1,k) * coef_dc(0:ndeg-1) )
end do
!
else
!
! Finally get the value of the correction function
! at each 1D solution point
!
do k = 1,npts
cmat(k) = sum( xexp(0:ndeg,k) * coef_c(0:ndeg) )
end do
!
end if
!
! Use the chop function to copy cmat into return_value while also
! setting any values that are less than working machine epsilon to zero.
!
return_value = chop( cmat )
!
end function CorrectionMatrix_Edge
!
!###############################################################################
!
pure function CorrectionMatrix_Quad_DG(pts1d,wts1d,eval_deriv) &
result(return_value)
!
!.. Use Statements ..
use polynomial_mod, only : eval_LagrangePoly1D
!
!.. Formal Arguments ..
real(wp), dimension(:), intent(in) :: pts1d
real(wp), dimension(:), intent(in) :: wts1d
!
!.. Optional Arguments ..
logical(lk), optional, intent(in) :: eval_deriv
!
!.. Function Result ..
real(wp), allocatable :: return_value(:,:)
!
!.. Local Scalars ..
integer :: i,j,k,nf,np,nsp,nfp,ierr
logical(lk) :: compute_derivative
!
!.. Local Allocatable Arrays ..
real(qp), allocatable :: cmat_qp(:,:)
real(qp), allocatable :: pts1d_qp(:)
real(qp), allocatable :: wts1d_qp(:)
!
continue
!
np = size(pts1d)
nsp = np*np
nfp = 4*np
!
compute_derivative = true
if (present(eval_deriv)) then
compute_derivative = eval_deriv
end if
!
! Allocate the return array containing the working
! precision correction matrix
!
allocate ( return_value(1:nsp,1:nfp) , source=zero , stat=ierr )
!
! Create the correction matrix using quad precision and make quad precision
! copies of the 1D solution points and their corresponding quadrature weights
!
allocate ( cmat_qp(1:nsp,1:nfp) , source=qzero , stat=ierr )
allocate ( pts1d_qp(1:np) , source=qzero , stat=ierr )
allocate ( wts1d_qp(1:np) , source=qzero , stat=ierr )
!
! Face 1 - bottom/south edge of quad
!
nf = 1
do i = 1,np
do j = 1,np
k = (j-1)*np + i
cmat_qp(k,nf) = eval_LagrangePoly1D(j,-qone,pts1d_qp) / wts1d_qp(j)
end do
nf = nf + 1
end do
!
! Face 2 - right/east edge of quad
!
nf = np+1
do j = 1,np
do i = np,1,-1
k = (j-1)*np + i
cmat_qp(k,nf) = eval_LagrangePoly1D(i,qone,pts1d_qp) / wts1d_qp(i)
end do
nf = nf + 1
end do
!
! Face 3 - top/north edge of quad
!
nf = 2*np+1
do i = np,1,-1
do j = np,1,-1
k = (j-1)*np + i
cmat_qp(k,nf) = eval_LagrangePoly1D(j,qone,pts1d_qp) / wts1d_qp(j)
end do
nf = nf + 1
end do
!
! Face 4 - left/west edge of quad
!
nf = 3*np+1
do j = np,1,-1
do i = 1,np
k = (j-1)*np + i
cmat_qp(k,nf) = eval_LagrangePoly1D(i,-qone,pts1d_qp) / wts1d_qp(i)
end do
nf = nf + 1
end do
!
! Use the chop function to copy cmat_qp into return_value while also
! setting any values that are less than working machine epsilon to zero.
!
return_value = chop( cmat_qp )
!
end function CorrectionMatrix_Quad_DG
!
!###############################################################################
!
pure function CorrectionMatrix_Quad(xi,eval_deriv) result(return_value)
!
!.. Formal Arguments ..
real(wp), dimension(:), intent(in) :: xi
!
!.. Optional Arguments ..
logical(lk), optional, intent(in) :: eval_deriv
!
!.. Function Result ..
real(wp), allocatable :: return_value(:,:)
!
!.. Local Scalars ..
integer :: i,j,k,np,nf,nsp,nfp,ierr
!
!.. Local Allocatable Arrays ..
real(wp), allocatable :: cmat1D(:)
!
continue
!
! ###########################################################################
! ###########################################################################
! #### NOTE: No need to use chopping function in this procedure. The ####
! #### quad correction matrix is really just the 1D correction ####
! #### matrix applied to each face/flux point of the standard ####
! #### quad element. The 1D correction matrix is obtained by the ####
! #### function CorrectionMatrix_Edge which applies the chopping ####
! #### function to its result so there is no need to repeat this ####
! #### operation again. ####
! ###########################################################################
! ###########################################################################
!
np = size(xi)
nsp = np*np
nfp = 4*np
!
! Allocate the return array containing the working
! precision correction matrix
!
allocate ( return_value(1:nsp,1:nfp) , source=zero , stat=ierr )
!
! Create the 1D correction matrix
!
allocate ( cmat1D(1:np) , source=zero , stat=ierr )
!
! 1D Correction matrix
!
cmat1D = CorrectionMatrix_Edge(xi,eval_deriv)
!
! Face 1 - y/eta min face of quad (bottom/south)
!
nf = 1
do j = 1,np
do i = 1,np
k = j + (i-1)*np
return_value(k,nf) = cmat1D(i)
end do
nf = nf + 1
end do
!
! Face 2 - x/xi max face of quad (right/east)
!
nf = np+1
do j = 1,np
do i = 1,np
k = (j-1)*np + np - i + 1
return_value(k,nf) = cmat1D(i)
end do
nf = nf + 1
end do
!
! Face 3 - y/eta max face of quad (top/north)
!
nf = 2*np+1
do j = 1,np
do i = 1,np
k = (np-i)*np + np - j + 1
return_value(k,nf) = cmat1D(i)
end do
nf = nf + 1
end do
!
! Face 4 - x/xi min face of quad (left/west)
!
nf = 3*np+1
do j = 1,np
do i = 1,np
k = (np-j)*np + i
return_value(k,nf) = cmat1D(i)
end do
nf = nf + 1
end do
!
end function CorrectionMatrix_Quad
!
!###############################################################################
!
pure function CorrectionMatrix_Tria(rs,eval_deriv) result(return_value)
!
! RS : r and s coordinates for the standard
! triangle element on the interval [-1,1]
!
!.. Use Statements ..
use vandermonde_mod, only : vand
!
!.. Formal Arguments ..
real(wp), dimension(:,:), intent(in) :: rs
!
!.. Optional Arguments ..
logical(lk), optional, intent(in) :: eval_deriv
!
!.. Function Result ..
real(wp), allocatable :: return_value(:,:)
!
!.. Local Scalars ..
integer :: i,j,n1,n2,np,nsp,nfp
integer :: this_order,ierr
logical(lk) :: compute_derivative
!
!.. Local Allocatable Arrays ..
integer, allocatable :: Fmask(:,:)
real(qp), allocatable :: cmat_qp(:,:)
real(qp), allocatable :: mmat1D_qp(:,:)
real(qp), allocatable :: vedge_qp(:,:)
real(qp), allocatable :: vtria_qp(:,:)
!
continue
!
nsp = size(rs,dim=2)
this_order = np2n(nsp)
np = this_order+1
nfp = 3*np
!
compute_derivative = true
if (present(eval_deriv)) then
compute_derivative = eval_deriv
end if
!
! Allocate the return array containing the working
! precision correction matrix
!
allocate ( return_value(1:nsp,1:nfp) , source=zero , stat=ierr )
!
! Create the correction matrix using quad precision and allocate the
! inverse mass matrix and Fmask arrays.
!
allocate ( cmat_qp(1:nsp,1:nfp) , source=qzero , stat=ierr )
allocate ( mmat1D_qp(1:np,1:np) , source=qzero , stat=ierr )
allocate ( Fmask(1:np,1:3) , source=0 , stat=ierr )
!
! Make quad precision copies of the Edge and Tria Vandermonde matrices.
!
allocate ( vedge_qp(1:np,1:np) , source=qzero , stat=ierr )
allocate ( vtria_qp(1:nsp,1:nsp) , source=qzero , stat=ierr )
!
vedge_qp = real( vand(Geom_Edge,this_order)%modal2nodal%mat , kind=qp )
vtria_qp = real( vand(Geom_Tria,this_order)%modal2nodal%mat , kind=qp )
!
! Face 1 - bottom edge of triangle
!
do i = 1,np
Fmask(i,1) = i
end do
!
! Face 2 - diagonal edge of triangle
!
j = 0
do i = 1,np
j = j + np + 1 - i
Fmask(i,2) = j
end do
!
! Face 3 - vertical edge of triangle
!
j = nsp + 1
do i = 1,np
j = j - i
Fmask(i,3) = j
end do
!
! DG Book's method for getting Fmask
!
!Fmask(:,1) = pack( (/(i,i=1,nsp)/) , abs(rs(2,:) + one ) < eps12 )
!Fmask(:,2) = pack( (/(i,i=1,nsp)/) , abs(rs(1,:) + rs(2,:)) < eps12 )
!Fmask(:,3) = pack( (/(i,i=1,nsp)/) , abs(rs(1,:) + one ) < eps12 )
!
! Compute the inverse mass matrix along an edge
!
mmat1D_qp = invert_matrix( matmul( vedge_qp , transpose(vedge_qp) ) )
!
! Face 1
!
n1 = 1 ! index of first node on this face
n2 = np ! index of last node on this face
!
cmat_qp(Fmask(:,1),n1:n2) = mmat1D_qp
!
! Face 2
!
n1 = np+1 ! index of first node on this face
n2 = 2*np ! index of last node on this face
!
cmat_qp(Fmask(:,2),n1:n2) = mmat1D_qp
!
! Face 3
!
n1 = 2*np+1 ! index of first node on this face
n2 = 3*np ! index of last node on this face
!
cmat_qp(Fmask(:,3),n1:n2) = mmat1D_qp
!
! Finally, compute the correction matrix
!
cmat_qp = matmul( transpose(vtria_qp) , cmat_qp )
cmat_qp = qtwo*matmul( vtria_qp , cmat_qp )
!
! Use the chop function to copy cmat_qp into return_value while also
! setting any values that are less than working machine epsilon to zero.
!
return_value = chop( cmat_qp )
!
end function CorrectionMatrix_Tria
!
!###############################################################################
!
pure function CorrectionMatrix_Tetr(rs,eval_deriv) result(return_value)
!
! RS : r and s coordinates for the standard
! triangle element on the interval [-1,1]
!
!.. Use Statements ..
use vandermonde_mod, only : vand
!
!.. Formal Arguments ..
real(wp), dimension(:,:), intent(in) :: rs
!
!.. Optional Arguments ..
logical(lk), optional, intent(in) :: eval_deriv
!
!.. Function Result ..
real(wp), allocatable :: return_value(:,:)
!
!.. Local Scalars ..
integer :: i,j,n1,n2,np,nsp,nfp
integer :: this_order,ierr
logical(lk) :: compute_derivative
!
!.. Local Allocatable Arrays ..
integer, allocatable :: Fmask(:,:)
real(qp), allocatable :: cmat_qp(:,:)
real(qp), allocatable :: mmat1D_qp(:,:)
real(qp), allocatable :: vedge_qp(:,:)
real(qp), allocatable :: vtria_qp(:,:)
!
continue
!
nsp = size(rs,dim=2)
this_order = np2n(nsp)
np = this_order+1
nfp = 3*np
!
compute_derivative = true
if (present(eval_deriv)) then
compute_derivative = eval_deriv
end if
!
! Allocate the return array containing the working
! precision correction matrix
!
allocate ( return_value(1:nsp,1:nfp) , source=zero , stat=ierr )
!
! Create the correction matrix using quad precision and allocate the
! inverse mass matrix and Fmask arrays.
!
allocate ( cmat_qp(1:nsp,1:nfp) , source=qzero , stat=ierr )
allocate ( mmat1D_qp(1:np,1:np) , source=qzero , stat=ierr )
allocate ( Fmask(1:np,1:3) , source=0 , stat=ierr )
!
! Make quad precision copies of the Edge and Tria Vandermonde matrices.
!
allocate ( vedge_qp(1:np,1:np) , source=qzero , stat=ierr )
allocate ( vtria_qp(1:nsp,1:nsp) , source=qzero , stat=ierr )
!
vedge_qp = real( vand(Geom_Edge,this_order)%modal2nodal%mat , kind=qp )
vtria_qp = real( vand(Geom_Tria,this_order)%modal2nodal%mat , kind=qp )
!
! Face 1 - bottom edge of triangle
!
do i = 1,np
Fmask(i,1) = i
end do
!
! Face 2 - diagonal edge of triangle
!
j = 0
do i = 1,np
j = j + np + 1 - i
Fmask(i,2) = j
end do
!
! Face 3 - vertical edge of triangle
!
j = nsp + 1
do i = 1,np
j = j - i
Fmask(i,3) = j
end do
!
! DG Book's method for getting Fmask
!
!Fmask(:,1) = pack( (/(i,i=1,nsp)/) , abs(rs(2,:) + one ) < eps12 )
!Fmask(:,2) = pack( (/(i,i=1,nsp)/) , abs(rs(1,:) + rs(2,:)) < eps12 )
!Fmask(:,3) = pack( (/(i,i=1,nsp)/) , abs(rs(1,:) + one ) < eps12 )
!
! Compute the inverse mass matrix along an edge
!
mmat1D_qp = invert_matrix( matmul( vedge_qp , transpose(vedge_qp) ) )
!
! Face 1
!
n1 = 1 ! index of first node on this face
n2 = np ! index of last node on this face
!
cmat_qp(Fmask(:,1),n1:n2) = mmat1D_qp
!
! Face 2
!
n1 = np+1 ! index of first node on this face
n2 = 2*np ! index of last node on this face
!
cmat_qp(Fmask(:,2),n1:n2) = mmat1D_qp
!
! Face 3
!
n1 = 2*np+1 ! index of first node on this face
n2 = 3*np ! index of last node on this face
!
cmat_qp(Fmask(:,3),n1:n2) = mmat1D_qp
!
! Finally, compute the correction matrix
!
cmat_qp = matmul( transpose(vtria_qp) , cmat_qp )
cmat_qp = qtwo*matmul( vtria_qp , cmat_qp )
!
! Use the chop function to copy cmat_qp into return_value while also
! setting any values that are less than working machine epsilon to zero.
!
return_value = chop( cmat_qp )
!
end function CorrectionMatrix_Tetr
!
!###############################################################################
!
pure function CorrectionMatrix_Pyra(rs,eval_deriv) result(return_value)
!
! RS : r and s coordinates for the standard
! triangle element on the interval [-1,1]
!
!.. Use Statements ..
use vandermonde_mod, only : vand
!
!.. Formal Arguments ..
real(wp), dimension(:,:), intent(in) :: rs
!
!.. Optional Arguments ..
logical(lk), optional, intent(in) :: eval_deriv
!
!.. Function Result ..
real(wp), allocatable :: return_value(:,:)
!
!.. Local Scalars ..
integer :: i,j,n1,n2,np,nsp,nfp
integer :: this_order,ierr
logical(lk) :: compute_derivative
!
!.. Local Allocatable Arrays ..
integer, allocatable :: Fmask(:,:)
real(qp), allocatable :: cmat_qp(:,:)
real(qp), allocatable :: mmat1D_qp(:,:)
real(qp), allocatable :: vedge_qp(:,:)
real(qp), allocatable :: vtria_qp(:,:)
!
continue
!
nsp = size(rs,dim=2)
this_order = np2n(nsp)
np = this_order+1
nfp = 3*np
!
compute_derivative = true
if (present(eval_deriv)) then
compute_derivative = eval_deriv
end if
!
! Allocate the return array containing the working
! precision correction matrix
!
allocate ( return_value(1:nsp,1:nfp) , source=zero , stat=ierr )
!
! Create the correction matrix using quad precision and allocate the
! inverse mass matrix and Fmask arrays.
!
allocate ( cmat_qp(1:nsp,1:nfp) , source=qzero , stat=ierr )
allocate ( mmat1D_qp(1:np,1:np) , source=qzero , stat=ierr )
allocate ( Fmask(1:np,1:3) , source=0 , stat=ierr )
!
! Make quad precision copies of the Edge and Tria Vandermonde matrices.
!
allocate ( vedge_qp(1:np,1:np) , source=qzero , stat=ierr )
allocate ( vtria_qp(1:nsp,1:nsp) , source=qzero , stat=ierr )
!
vedge_qp = real( vand(Geom_Edge,this_order)%modal2nodal%mat , kind=qp )
vtria_qp = real( vand(Geom_Tria,this_order)%modal2nodal%mat , kind=qp )
!
! Face 1 - bottom edge of triangle
!
do i = 1,np
Fmask(i,1) = i
end do
!
! Face 2 - diagonal edge of triangle
!
j = 0
do i = 1,np
j = j + np + 1 - i
Fmask(i,2) = j
end do
!
! Face 3 - vertical edge of triangle
!
j = nsp + 1
do i = 1,np
j = j - i
Fmask(i,3) = j
end do
!
! DG Book's method for getting Fmask
!
!Fmask(:,1) = pack( (/(i,i=1,nsp)/) , abs(rs(2,:) + one ) < eps12 )
!Fmask(:,2) = pack( (/(i,i=1,nsp)/) , abs(rs(1,:) + rs(2,:)) < eps12 )
!Fmask(:,3) = pack( (/(i,i=1,nsp)/) , abs(rs(1,:) + one ) < eps12 )
!
! Compute the inverse mass matrix along an edge
!
mmat1D_qp = invert_matrix( matmul( vedge_qp , transpose(vedge_qp) ) )
!
! Face 1
!
n1 = 1 ! index of first node on this face
n2 = np ! index of last node on this face
!
cmat_qp(Fmask(:,1),n1:n2) = mmat1D_qp
!
! Face 2
!
n1 = np+1 ! index of first node on this face
n2 = 2*np ! index of last node on this face
!
cmat_qp(Fmask(:,2),n1:n2) = mmat1D_qp
!
! Face 3
!
n1 = 2*np+1 ! index of first node on this face
n2 = 3*np ! index of last node on this face
!
cmat_qp(Fmask(:,3),n1:n2) = mmat1D_qp
!
! Finally, compute the correction matrix
!
cmat_qp = matmul( transpose(vtria_qp) , cmat_qp )
cmat_qp = qtwo*matmul( vtria_qp , cmat_qp )
!
! Use the chop function to copy cmat_qp into return_value while also
! setting any values that are less than working machine epsilon to zero.
!
return_value = chop( cmat_qp )
!
end function CorrectionMatrix_Pyra
!
!###############################################################################
!
pure function CorrectionMatrix_Pris(rs,eval_deriv) result(return_value)
!
! RS : r and s coordinates for the standard
! triangle element on the interval [-1,1]
!
!.. Use Statements ..
use vandermonde_mod, only : vand
!
!.. Formal Arguments ..
real(wp), dimension(:,:), intent(in) :: rs
!
!.. Optional Arguments ..
logical(lk), optional, intent(in) :: eval_deriv
!
!.. Function Result ..
real(wp), allocatable :: return_value(:,:)
!
!.. Local Scalars ..
integer :: i,j,n1,n2,np,nsp,nfp
integer :: this_order,ierr
logical(lk) :: compute_derivative
!
!.. Local Allocatable Arrays ..
integer, allocatable :: Fmask(:,:)
real(qp), allocatable :: cmat_qp(:,:)
real(qp), allocatable :: mmat1D_qp(:,:)
real(qp), allocatable :: vedge_qp(:,:)
real(qp), allocatable :: vtria_qp(:,:)
!
continue
!
nsp = size(rs,dim=2)
this_order = np2n(nsp)
np = this_order+1
nfp = 3*np