-
Notifications
You must be signed in to change notification settings - Fork 38
/
interpolation_mod.f90
3981 lines (3981 loc) · 117 KB
/
interpolation_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 interpolation_mod
!
!.. Use Statements ..
use module_kind_types
use generic_types_mod, only : matrix
!
implicit none
!
private
!
!
!.. Public Procedures ..
!
public :: init_interpolation_matrices
public :: init_outerpolation_matrices
public :: interpolation_memory_usage
!
!
!
! interpolation_matrix : derived type that stores the matrices for
! interpolating a polynomial quantity within a
! cell to a face point or cell point for a given
! combination of cell geometry and cell order
!
type, public :: interpolation_matrix
type(matrix), allocatable :: toFace(:) ! interpolate to a face point
type(matrix), allocatable :: toCell(:) ! interpolate to a cell point
type(matrix), allocatable :: toEdge(:) ! interpolate to a edge point
type(matrix), allocatable :: toNode ! interpolate to a node
end type interpolation_matrix
!
! interp : interpolation matrix for all combinations of cell geometry
! and cell order that are possible in the current simulation
!
! For cell 'n' :
!
! The interpolation matrix (giving the contribution of each solution
! point within cell 'n' to the solution point 'k' that is currently
! of interest) is given by the expression
!
! interp(this_geom,this_order)%toFace(to_order)%mat(:,k)
! interp(this_geom,this_order)%toCell(to_order)%mat(:,k)
!
! Where :
!
! this_geom = cell(n)%geom
! this_order = cell(n)%order
! to_order = order of face or cell to which we are interpolating
! k = if using toFace, the face solution point we are interpolating to
! if using toCell, the cell solution point we are interpolating to
!
type(interpolation_matrix), public, save, target, allocatable :: interp(:,:)
!
! outerpolation_matrix : derived type that stores the "outerpolation" matrices
! (short for "interpolation for output") which
! interpolate the cell solution to specific quadrature
! points.
!
type, public :: outerpolation_matrix
! output : Interpolation matrix from solution points to quadrature points
! used to output the solution for post-processing
type(matrix), allocatable :: output
! init : Interpolation matrix from solution points to quadrature points
! used to compute initial conditions
type(matrix), allocatable :: init
! error : Interpolation matrix from solution points to quadrature points
! used for error computations
type(matrix), allocatable :: error
! err_wts : Array containing the quadrature weights
! for the error computations
real(wp), allocatable :: err_wts(:)
end type outerpolation_matrix
!
! outerp : "outerpolation" matrix for all combinations of cell geometry
! and cell order that are possible in the current simulation.
! These matrices interpolate the solution from the cell solution
! points to a set of nodal points only meant for output and to
! visualize the solution.
!
type(outerpolation_matrix), public, save, target, allocatable :: outerp(:,:)
!
type :: spanning_vectors_t
logical(lk) :: found = fals
integer :: idx1
integer :: idx2
integer :: idx3
end type spanning_vectors_t
!
type(spanning_vectors_t), save, allocatable :: ref_vectors(:,:)
!
contains
!
!###############################################################################
!
subroutine interpolate_restart_solution(nc,xyz_pt,return_value)
!
!.. Use Statements ..
use order_mod, only : maxSP
use order_mod, only : n_min_geom,n_min_order
use order_mod, only : n_max_geom,n_max_order
use geovar, only : nr,cell,xyz
use flowvar, only : usp
use quadrature_mod, only : std_elem,solpts_edge
!
!.. Formal Arguments ..
integer, intent(in) :: nc
real(wp), intent(in) :: xyz_pt(:)
real(wp), intent(inout) :: return_value(:)
!
!.. Local Scalars ..
integer :: l,m,n,n1,n2,np,ierr
integer :: idx0,idx1,idx2,idx3
integer :: this_geom,this_order
real(wp) :: errmag
!
!.. Local Arrays ..
real(wp) :: xyz_cell(1:nr,1:maxSP)
real(wp) :: phys_a(1:nr),comp_a(1:nr)
real(wp) :: phys_b(1:nr),comp_b(1:nr)
real(wp) :: phys_c(1:nr),comp_c(1:nr)
real(wp) :: phys_r(1:nr),comp_r(1:nr)
real(wp) :: del_abc(1:nr)
real(wp) :: interp_mat(1:maxSP)
!
!.. Local Pointers ..
real(wp), pointer, contiguous :: solpts(:,:)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "interpolate_restart_solution"
!
integer, parameter :: max_iterations = 10
!
continue
!
! Initialize the local pointers to disassociated
!
solpts => null()
!
! Information for the current cell
!
n1 = cell(nc)%beg_sp
n2 = cell(nc)%end_sp
np = n2-n1+1
!
this_geom = cell(nc)%geom
this_order = cell(nc)%order
!
if (.not. allocated(ref_vectors)) then
allocate ( ref_vectors(n_min_geom:n_max_geom,n_min_order:n_max_order) , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"ref_vectors",1,__LINE__,__FILE__,ierr,error_message)
end if
!
! Get the indices for the reference points for this combination of
! geometry/solution-order if it hasnt been done yet
!
if (.not. ref_vectors(this_geom,this_order)%found) then
ref_vectors(this_geom,this_order) = find_ref_vectors(this_geom,this_order)
end if
!
! Get the indices of the points to use in this cell to create the
! reference vectors that will used to find the computational space
! coordinates corresponding to the physical space coordinates xyz_pt
!
idx0 = 1
idx1 = ref_vectors(this_geom,this_order)%idx1
idx2 = ref_vectors(this_geom,this_order)%idx2
idx3 = ref_vectors(this_geom,this_order)%idx3
!
! Create a local copy of the physical space coordinates
! of the solution points for this cell
!
xyz_cell(1:nr,1:maxSP) = xyz(1:nr,n1:n2)
!
! Get the physical space vector for the first point 'a'
!
phys_a(:) = xyz_cell(:,idx1) - xyz_cell(:,idx0)
!
! Get the computational space vector for the first point 'a'
!
comp_a(:) = std_elem(this_geom,this_order)%pts(:,idx1) &
- std_elem(this_geom,this_order)%pts(:,idx0)
!
! Get the physical space vector for the second point 'b'
!
phys_b(:) = xyz_cell(:,idx2) - xyz_cell(:,idx0)
!
! Get the computational space vector for the second point 'b'
!
comp_b(:) = std_elem(this_geom,this_order)%pts(:,idx2) &
- std_elem(this_geom,this_order)%pts(:,idx0)
!
if (nr == 3) then
!
! If this is 3D, get the physical space vector for the third points 'c'
!
phys_c(:) = xyz_cell(:,idx3) - xyz_cell(:,idx0)
!
! If this is 3D, get the computational space vector for the third point 'c'
!
comp_c(:) = std_elem(this_geom,this_order)%pts(:,idx3) &
- std_elem(this_geom,this_order)%pts(:,idx0)
!
end if
!
! Compute the physical space vector from the "origin" location
! to the location to which we want to interpolate
!
phys_r(:) = xyz_pt(:) - xyz_cell(:,idx0)
!
! Initialize the location of xyz_pt in computational space to the
! "origin" location used to create the other computational space vectors
!
comp_r(:) = std_elem(this_geom,this_order)%pts(:,idx0)
!
!
iter_loop: do n = 1,max_iterations
!
del_abc(:) = interpolate_vector_solve(phys_r,phys_a,phys_b,phys_c)
!
if (nr == 3) then
!
comp_r(1) = comp_r(1) + del_abc(1)*comp_a(1) &
+ del_abc(2)*comp_b(1) &
+ del_abc(3)*comp_c(1)
!
comp_r(2) = comp_r(2) + del_abc(1)*comp_a(2) &
+ del_abc(2)*comp_b(2) &
+ del_abc(3)*comp_c(2)
!
comp_r(3) = comp_r(3) + del_abc(1)*comp_a(3) &
+ del_abc(2)*comp_b(3) &
+ del_abc(3)*comp_c(3)
!
else
!
comp_r(1) = comp_r(1) + del_abc(1)*comp_a(1) + del_abc(2)*comp_b(1)
comp_r(2) = comp_r(2) + del_abc(1)*comp_a(2) + del_abc(2)*comp_b(2)
!
end if
!
! Create a new interpolation matrix for the
! updated computational space coordinates in comp_r
!
select case (this_geom)
!
case (Geom_Edge)
!
interp_mat(1:np) = InterpToPoint_Edge(solpts_edge,comp_r)
!
case (Geom_Tria)
!
solpts => std_elem(this_geom,this_order)%pts
!
interp_mat(1:np) = InterpToPoint_Tria(solpts,comp_r)
!
if (associated(solpts)) solpts => null()
!
case (Geom_Quad)
!
interp_mat(1:np) = InterpToPoint_Quad(solpts_edge,comp_r)
!
case (Geom_Tetr)
!
solpts => std_elem(this_geom,this_order)%pts
!
interp_mat(1:np) = InterpToPoint_Tetr(solpts,comp_r)
!
if (associated(solpts)) solpts => null()
!
case (Geom_Pyra)
!
solpts => std_elem(this_geom,this_order)%pts
!
interp_mat(1:np) = InterpToPoint_Pyra(solpts,comp_r)
!
if (associated(solpts)) solpts => null()
!
case (Geom_Pris)
!
solpts => std_elem(this_geom,this_order)%pts
!
interp_mat(1:np) = InterpToPoint_Pris(solpts,comp_r)
!
if (associated(solpts)) solpts => null()
!
case (Geom_Hexa)
!
interp_mat(1:np) = InterpToPoint_Hexa(solpts_edge,comp_r)
!
end select
!
! Find the physical space coordinates corresponding to the
! updated computational space coordinates in comp_r using
! this new interpolation matrix
!
do l = 1,nr
phys_r(l) = xyz_pt(l) - dot( interp_mat(1:np) , xyz_cell(l,1:np) )
end do
!
! Check to see if we have converged
!
errmag = norm2( phys_r(1:nr) )
!
if (errmag < eps3) then
exit iter_loop
end if
!
end do iter_loop
!
! Use the last interpolation matrix that was created to interpolate
! the solution in the current cell to the input point
!
do m = 1,size(usp,dim=1)
return_value(m) = dot( interp_mat(1:np) , usp(m,n1:n2) )
end do
!
end subroutine interpolate_restart_solution
!
!###############################################################################
!
pure function find_ref_vectors(this_geom,this_order) result(return_value)
!
!.. Use Statements ..
use order_mod, only : geom_solpts
!
!.. Formal Arguments ..
integer, intent(in) :: this_geom
integer, intent(in) :: this_order
!
!.. Function Result ..
type(spanning_vectors_t) :: return_value
!
!.. Local Scalars ..
integer :: np_edge,np_tria,np_quad
!
!.. Local Parameters ..
!logical(lk), parameter :: use_short_vectors = fals
logical(lk), parameter :: use_short_vectors = true
!
continue
!
np_edge = geom_solpts(Geom_Edge,this_order)
np_tria = geom_solpts(Geom_Tria,this_order)
np_quad = geom_solpts(Geom_Quad,this_order)
!
if (use_short_vectors) then
!
select case (this_geom)
!
case (Geom_Tria)
!
return_value%idx1 = 2
return_value%idx2 = np_edge+1
return_value%idx3 = 0
!
case (Geom_Quad)
!
return_value%idx1 = 2
return_value%idx2 = np_edge+1
return_value%idx3 = 0
!
case (Geom_Tetr)
!
return_value%idx1 = 2
return_value%idx2 = np_edge+1
return_value%idx3 = np_tria+1
!
case (Geom_Pyra)
!
return_value%idx1 = 2
return_value%idx2 = np_edge+1
return_value%idx3 = np_quad+1
!
case (Geom_Pris)
!
return_value%idx1 = 2
return_value%idx2 = np_edge+1
return_value%idx3 = np_tria+1
!
case (Geom_Hexa)
!
return_value%idx1 = 2
return_value%idx2 = np_edge+1
return_value%idx3 = np_quad+1
!
case default
!
return_value%idx1 = 2
return_value%idx2 = 0
return_value%idx3 = 0
!
end select
!
else
!
select case (this_geom)
!
case (Geom_Tria)
!
return_value%idx1 = np_edge
return_value%idx2 = np_tria
return_value%idx3 = 0
!
case (Geom_Quad)
!
return_value%idx1 = np_edge
return_value%idx2 = np_edge*(np_edge-1) + 1
return_value%idx3 = 0
!
case (Geom_Tetr)
!
return_value%idx1 = np_edge
return_value%idx2 = np_tria
return_value%idx3 = geom_solpts(Geom_Tetr,this_order)
!
case (Geom_Pyra)
!
return_value%idx1 = np_edge
return_value%idx2 = np_edge*(np_edge-1) + 1
return_value%idx3 = geom_solpts(Geom_Pyra,this_order)
!
case (Geom_Pris)
!
return_value%idx1 = np_edge
return_value%idx2 = np_tria
return_value%idx3 = np_tria*(np_edge-1) + 1
!
case (Geom_Hexa)
!
return_value%idx1 = np_edge
return_value%idx2 = np_edge*(np_edge-1) + 1
return_value%idx3 = np_quad*(np_edge-1) + 1
!
case default
!
return_value%idx1 = np_edge
return_value%idx2 = 0
return_value%idx3 = 0
!
end select
!
end if
!
return_value%found = true
!
end function find_ref_vectors
!
!###############################################################################
!
pure function interpolate_vector_solve(r,a,b,c) result(return_value)
!
! This function finds the coefficients that make a linear combination of
! some reference vectors equivalent to the vector r.
!
! For 3D: three reference vectors a, b, and c, the solution for these
! coefficients becomes a linear equation of the form
!
! coeff_a * ax + coeff_b * bx + coeff_c * cx = rx
! coeff_a * ay + coeff_b * by + coeff_c * cy = ry
! coeff_a * az + coeff_b * bz + coeff_c * cz = rz
!
! or in matrix form:
!
! | ax bx cx | | coeff_a | | rx |
! | ay by cy | X | coeff_b | = | ry |
! | az bz cz | | coeff_c | | rz |
!
! For 2D: two reference vectors a and b, the solution for these
! coefficients becomes a linear equation of the form:
!
! coeff_a * ax + coeff_b * bx = rx
! coeff_a * ay + coeff_b * by = ry
!
! or in matrix form:
!
! | ax bx | | coeff_a | | rx |
! | | X | | = | |
! | ay by | | coeff_b | | ry |
!
!.. Formal Arguments ..
real(wp), intent(in) :: r(:)
real(wp), intent(in) :: a(:)
real(wp), intent(in) :: b(:)
real(wp), intent(in) :: c(:)
!
!.. Function Result ..
real(wp) :: return_value(1:size(r))
!
!.. Local Scalars ..
integer :: nr
real(wp) :: ax,ay,az,bx,by,bz,cx,cy,cz,rx,ry,rz
real(wp) :: m11,m12,m13,m21,m22,m23,m31,m32,m33
real(wp) :: det
!
continue
!
nr = size(r)
!
return_value(:) = zero
!
if (nr == 3) then
!
ax = a(1) ; ay = a(2) ; az = a(3)
bx = b(1) ; by = b(2) ; bz = b(3)
cx = c(1) ; cy = c(2) ; cz = c(3)
rx = r(1) ; ry = r(2) ; rz = r(3)
!
m11 = by*cz - bz*cy
m12 = bz*cx - bx*cz
m13 = bx*cy - by*cx
!
m21 = az*cy - ay*cz
m22 = ax*cz - az*cx
m23 = ay*cx - ax*cy
!
m31 = ay*bz - az*by
m32 = az*bx - ax*bz
m33 = ax*by - ay*bx
!
det = ax*m11 + ay*m12 + az*m13
!
if (abs(det) > eps6) then
!
return_value(1) = rx*m11 + ry*m12 + rz*m13
return_value(2) = rx*m21 + ry*m22 + rz*m23
return_value(3) = rx*m31 + ry*m32 + rz*m33
!
return_value(1) = return_value(1) / det
return_value(2) = return_value(2) / det
return_value(3) = return_value(3) / det
!
end if
!
else
!
ax = a(1) ; ay = a(2)
bx = b(1) ; by = b(2)
rx = r(1) ; ry = r(2)
!
m11 = -by
m12 = bx
!
m21 = ay
m22 = -ax
!
det = ax*m11 + ay*m12
!
if (abs(det) > eps6) then
!
return_value(1) = rx*m11 + ry*m12
return_value(2) = rx*m21 + ry*m22
!
return_value(1) = return_value(1) / det
return_value(2) = return_value(2) / det
!
end if
!
end if
!
end function interpolate_vector_solve
!
!###############################################################################
!
pure function InterpToPoint_Edge(xi_sp,xi_pt) result(return_value)
!
!.. Use Statements ..
use polynomial_mod, only : eval_LagrangePoly
!
!.. Formal Arguments ..
real(wp), intent(in) :: xi_sp(:)
real(wp), intent(in) :: xi_pt(:)
!
!.. Function Result ..
real(wp) :: return_value(1:size(xi_sp))
!
!.. Local Scalars ..
integer :: i
!
continue
!
do i = 1,size(xi_sp)
return_value(i) = eval_LagrangePoly( [i] , xi_pt , xi_sp )
end do
!
end function InterpToPoint_Edge
!
!###############################################################################
!
pure function InterpToPoint_Quad(xi_sp,xi_pt) result(return_value)
!
!.. Use Statements ..
use polynomial_mod, only : eval_LagrangePoly
!
!.. Formal Arguments ..
real(wp), intent(in) :: xi_sp(:)
real(wp), intent(in) :: xi_pt(:)
!
!.. Function Result ..
real(wp) :: return_value(1:size(xi_sp)**2)
!
!.. Local Scalars ..
integer :: i,j,n,nsp
!
continue
!
nsp = size(xi_sp)
!
! Get the coefficients for interpolating a polynomial from the solution
! points to the input point. These coefficients are simply the value of
! the 2D Lagrange polynomial for a specified solution point evaluated at
! the coordinates of the input point.
!
! Get the value of the Lagrange polynomial for the
! input point at each of the interior solution points
!
n = 0
do j = 1,nsp
do i = 1,nsp
n = n + 1
return_value(n) = eval_LagrangePoly( [i,j] , xi_pt , xi_sp )
end do
end do
!
end function InterpToPoint_Quad
!
!###############################################################################
!
pure function InterpToPoint_Tria(rs_sp,rs_pt) result(return_value)
!
!.. Formal Arguments ..
real(wp), intent(in) :: rs_sp(:,:)
real(wp), intent(in) :: rs_pt(:)
!
!.. Function Result ..
real(wp) :: return_value(1:size(rs_sp,dim=2))
!
!.. Local Scalars ..
integer :: np,nfp
!
continue
!
!np = size(rs_sp,dim=2)
!nfp = np2n( np ) + 1
!
return_value(:) = zero
!
return_value(1) = one
!
end function InterpToPoint_Tria
!
!###############################################################################
!
pure function InterpToPoint_Tetr(rs_sp,rs_pt) result(return_value)
!
!.. Formal Arguments ..
real(wp), intent(in) :: rs_sp(:,:)
real(wp), intent(in) :: rs_pt(:)
!
!.. Function Result ..
real(wp) :: return_value(1:size(rs_sp,dim=2))
!
!.. Local Scalars ..
integer :: i,n,nsp3d,nfp3d,nep3d
!
continue
!
nsp3d = size(rs_sp,dim=2)
!
return_value(:) = zero
!
return_value(1) = one
!
! Find the order for this tetrahedra
!
n = -1
do i = 0,256
if (Tetr_Solpts(i) == nsp3d) then
n = i
exit
end if
end do
!
! If n is still -1, return with the interpolation matrix still being zero
!
if (n == -1) return
!
nfp3d = Cell_Flxpts(Geom_Tetr,n)
nep3d = n + 1
!
end function InterpToPoint_Tetr
!
!###############################################################################
!
pure function InterpToPoint_Pyra(rs_sp,rs_pt) result(return_value)
!
!.. Formal Arguments ..
real(wp), intent(in) :: rs_sp(:,:)
real(wp), intent(in) :: rs_pt(:)
!
!.. Function Result ..
real(wp) :: return_value(1:size(rs_sp,dim=2))
!
!.. Local Scalars ..
integer :: i,n,nfp3d,nsp3d,ierr
!
continue
!
nsp3d = size(rs_sp,dim=2)
!
return_value(:) = zero
!
return_value(1) = one
!
! Find the order for this tetrahedra
!
n = -1
do i = 0,256
if (Pyra_Solpts(i) == nsp3d) then
n = i
exit
end if
end do
!
nfp3d = Cell_Flxpts(Geom_Pyra,n)
!
! If n is still -1, return with the interpolation matrix still being zero
!
if (n == -1) return
!
end function InterpToPoint_Pyra
!
!###############################################################################
!
pure function InterpToPoint_Pris(rs_sp,rs_pt) result(return_value)
!
!.. Formal Arguments ..
real(wp), intent(in) :: rs_sp(:,:)
real(wp), intent(in) :: rs_pt(:)
!
!.. Function Result ..
real(wp) :: return_value(1:size(rs_sp,dim=2))
!
!.. Local Scalars ..
integer :: i,n,nfp3d,nsp3d,ierr
!
continue
!
nsp3d = size(rs_sp,dim=2)
!
return_value(:) = zero
!
return_value(1) = one
!
! Find the order for this tetrahedra
!
n = -1
do i = 0,256
if (Pris_Solpts(i) == nsp3d) then
n = i
exit
end if
end do
!
nfp3d = Cell_Flxpts(Geom_Pris,n)
!
! If n is still -1, return with the interpolation matrix still being zero
!
if (n == -1) return
!
end function InterpToPoint_Pris
!
!###############################################################################
!
pure function InterpToPoint_Hexa(xi_sp,xi_pt) result(return_value)
!
!.. Use Statements ..
use polynomial_mod, only : eval_LagrangePoly
!
!.. Formal Arguments ..
real(wp), intent(in) :: xi_sp(:)
real(wp), intent(in) :: xi_pt(:)
!
!.. Function Result ..
real(wp) :: return_value(1:size(xi_sp)**3)
!
!.. Local Scalars ..
integer :: i,j,k,n,nsp
!
continue
!
nsp = size(xi_sp)
!
! Get the coefficients for interpolating a polynomial from the solution
! points to the input point. These coefficients are simply the value of
! the 3D Lagrange polynomial for a specified solution point evaluated at
! the coordinates of the input point.
!
! Get the value of the Lagrange polynomial for the
! current point at each of the interior solution points
!
n = 0
do k = 1,nsp
do j = 1,nsp
do i = 1,nsp
n = n + 1
return_value(n) = eval_LagrangePoly( [i,j,k] , xi_pt , xi_sp )
end do
end do
end do
!
end function InterpToPoint_Hexa
!
!###############################################################################
!
subroutine init_interpolation_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 : geom_mio,geom_edgpts
use quadrature_mod, only : geom_is_used
use quadrature_mod, only : std_elem,face_elem
!
!.. Local Scalars ..
integer :: gmin,gmax,omin,omax,ierr
integer :: this_omin,this_omax
integer :: nsolpts,this_order,this_geom
integer :: nflxpts,face_order
integer :: nedgpts,edge_order
integer :: nnodpts,node_order
character(len=200) :: array_name
!
!.. Local Pointers ..
type(interpolation_matrix), pointer :: this_interp
type(matrix), pointer :: this_face
type(matrix), pointer :: this_edge
type(matrix), pointer :: this_node
!real(wp), pointer, contiguous :: solpts(:,:)
real(wp), pointer :: solpts(:,:)
!real(wp), pointer, contiguous :: flxpts(:,:)
!real(wp), pointer :: flxpts(:,:)
!
!.. Local Allocatable Arrays ..
real(wp), allocatable :: edgpts(:)
real(wp), allocatable :: flxpts(:)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "init_interpolation_matrices"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Initialize the local pointers to disassociated
!
this_interp => null()
this_face => null()
this_edge => null()
this_node => null()
solpts => null()
!flxpts => null()
!
gmin = n_min_geom
gmax = n_max_geom
omin = n_min_order
omax = n_max_order
!
! Allocate the interp array
!
allocate ( interp(gmin:gmax,omin:omax) , stat=ierr , errmsg=error_message )
call alloc_error(pname,"interp",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_interp => interp(this_geom,this_order)
!
! Get the number of solution points for this cell
!
nsolpts = geom_solpts(this_geom,this_order)
!
! Get the minimum and maximum interpolation order for
! this combination of cell geometry and cell order
!
this_omin = this_order
this_omax = geom_mio(this_geom,this_order)
!
! this_omax should not be smaller than this_omin. If for some reason
! it is, cycle to the next order for this geometry. The array geom_mio
! was initialized to -1 so this should also account for geometries that
! were never found while creating the array.
!
if (this_omax < this_omin) cycle order_loop
!
! Allocate the interp%toFace component of interp
!
allocate ( this_interp%toFace(this_omin:this_omax) , &
stat=ierr , errmsg=error_message )
write (array_name,1) Geom_Name(this_geom),this_order,"toFace"
call alloc_error(pname,array_name,1,__LINE__,__FILE__,ierr,error_message)
!
! Loop through all the interpolation orders for this combo
! and compute the corresponding interpolation matrices
!
face_order_loop: do face_order = this_omin,this_omax
!
! Assign local pointers to these matrices
! as aliases to simplify the code
!
this_face => this_interp%toFace(face_order)
!
! Get the number of face/flux points for this face order
!
nflxpts = geom_flxpts(this_geom,face_order)
!
! Allocate the interpolation matrix for this face order
!
allocate ( this_face%mat(1:nsolpts,1:nflxpts) , &
source=zero , stat=ierr , errmsg=error_message )
write (array_name,1) Geom_Name(this_geom),this_order,"toFace",face_order
call alloc_error(pname,array_name,1,__LINE__,__FILE__,ierr, &
error_message)
!
! Compute the interpolation matrices depending on geometry type
!
select case (this_geom)
case (Geom_Edge)
!
edgpts = std_elem(this_geom,this_order)%pts(1,:) ! F03 AUTO-REALLOC
!solpts => std_elem(this_geom,this_order)%pts
!
this_face%mat = InterpToFace_Edge( edgpts )
!this_face%mat = InterpToFace_Edge( solpts(1,:) )
!
case (Geom_Tria)
!
solpts => std_elem(this_geom,this_order)%pts
!
this_face%mat = InterpToFace_Tria( solpts )
!
case (Geom_Quad)
!
edgpts = std_elem(Geom_Edge,this_order)%pts(1,:) ! F03 AUTO-REALLOC
!solpts => std_elem(Geom_Edge,this_order)%pts
flxpts = face_elem(Geom_Edge,face_order)%pts(1,:) ! F03 AUTO-REALLOC
!flxpts => face_elem(Geom_Edge,face_order)%pts
!
this_face%mat = InterpToFace_Quad( edgpts , flxpts )
!this_face%mat = InterpToFace_Quad( solpts(1,:) , flxpts(1,:) )
!
case (Geom_Tetr)
!
solpts => std_elem(this_geom,this_order)%pts
!
this_face%mat = InterpToFace_Tetr( solpts )
!
case (Geom_Pyra)
!
solpts => std_elem(this_geom,this_order)%pts
!
this_face%mat = InterpToFace_Pyra( solpts )
!
case (Geom_Pris)
!
solpts => std_elem(this_geom,this_order)%pts
!
this_face%mat = InterpToFace_Pris( solpts )
!
case (Geom_Hexa)
!
edgpts = std_elem(Geom_Edge,this_order)%pts(1,:) ! F03 AUTO-REALLOC
!solpts => std_elem(Geom_Edge,this_order)%pts
flxpts = face_elem(Geom_Edge,face_order)%pts(1,:) ! F03 AUTO-REALLOC
!flxpts => face_elem(Geom_Edge,face_order)%pts
!
this_face%mat = InterpToFace_Hexa( edgpts , flxpts )
!this_face%mat = InterpToFace_Hexa( solpts(1,:) , flxpts(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_face)) this_face => null()
if (associated(solpts )) solpts => null()
!if (associated(flxpts )) flxpts => null()
!