-
Notifications
You must be signed in to change notification settings - Fork 38
/
poly.f90
4649 lines (4649 loc) · 126 KB
/
poly.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 polynomial_mod
!
! Module that contains various functions and routines
! related to Jacobi, Legendre, and other polynomials
!
use module_kind_types
!
implicit none
#ifdef DISABLE_QP
integer, parameter :: local_qp = SP
#else
integer, parameter :: local_qp = QP
#endif
!
private
!
public :: legendre_gauss_quadrature
public :: legendre_gauss_lobatto_quadrature
public :: JacobiGL
public :: eval_jacobi_poly
public :: eval_legendre_poly
public :: eval_chebyshev_poly
public :: eval_normalized_jacobi_poly
public :: normalized_jacobi_poly
public :: grad_normalized_jacobi_poly
public :: nodes_jacobi_gauss
public :: nodes_legendre_gauss
public :: nodes_right_radau
public :: nodes_chebyshev_gauss
public :: nodes_jacobi_gauss_lobatto
public :: nodes_legendre_gauss_lobatto
public :: nodes_chebyshev_gauss_lobatto
public :: weights_jacobi_gauss
public :: weights_legendre_gauss
public :: weights_chebyshev_gauss
public :: weights_jacobi_gauss_lobatto
public :: weights_legendre_gauss_lobatto
public :: weights_right_radau
public :: weights_chebyshev_gauss_lobatto
public :: weights_dgbook_jacobi_gauss_lobatto
public :: derivative_matrix_legendre_gauss
public :: derivative_matrix_legendre_gauss_lobatto
public :: derivative_matrix_jacobi_gauss_lobatto
public :: derivative_matrix_chebyshev_gauss_lobatto
public :: eval_LagrangePoly
public :: eval_LagrangePoly1D
public :: eval_LagrangePoly2D
public :: eval_LagrangePoly3D
public :: eval_D2LagrangeDx2
public :: eval_DLagrangeDx
!
interface JacobiGL
module procedure JacobiGL_DP, &
JacobiGL_QP
end interface JacobiGL
!
interface eval_jacobi_poly
module procedure eval_jacobi_poly_DP, &
eval_jacobi_poly_QP
end interface eval_jacobi_poly
!
interface eval_legendre_poly
module procedure eval_legendre_poly_DP, &
eval_legendre_poly_QP
end interface eval_legendre_poly
!
interface eval_chebyshev_poly
module procedure eval_chebyshev_poly_DP, &
eval_chebyshev_poly_QP
end interface eval_chebyshev_poly
!
interface eval_normalized_jacobi_poly
module procedure eval_normalized_jacobi_poly_DP, &
eval_normalized_jacobi_poly_QP
end interface eval_normalized_jacobi_poly
!
interface normalized_jacobi_poly
module procedure normalized_jacobi_poly_DP, &
normalized_jacobi_poly_QP
end interface normalized_jacobi_poly
!
interface grad_normalized_jacobi_poly
module procedure grad_normalized_jacobi_poly_DP, &
grad_normalized_jacobi_poly_QP
end interface grad_normalized_jacobi_poly
!
interface nodes_jacobi_gauss
module procedure nodes_jacobi_gauss_DP, &
nodes_jacobi_gauss_QP
end interface nodes_jacobi_gauss
!
interface nodes_legendre_gauss
module procedure nodes_legendre_gauss_DP, &
nodes_legendre_gauss_QP
end interface nodes_legendre_gauss
!
interface nodes_right_radau
module procedure nodes_right_radau_DP, &
nodes_right_radau_QP
end interface nodes_right_radau
!
interface nodes_chebyshev_gauss
module procedure nodes_chebyshev_gauss_DP, &
nodes_chebyshev_gauss_QP
end interface nodes_chebyshev_gauss
!
interface nodes_jacobi_gauss_lobatto
module procedure nodes_jacobi_gauss_lobatto_DP, &
nodes_jacobi_gauss_lobatto_QP
end interface nodes_jacobi_gauss_lobatto
!
interface nodes_legendre_gauss_lobatto
module procedure nodes_legendre_gauss_lobatto_DP, &
nodes_legendre_gauss_lobatto_QP
end interface nodes_legendre_gauss_lobatto
!
interface nodes_chebyshev_gauss_lobatto
module procedure nodes_chebyshev_gauss_lobatto_DP, &
nodes_chebyshev_gauss_lobatto_QP
end interface nodes_chebyshev_gauss_lobatto
!
interface weights_jacobi_gauss
module procedure weights_jacobi_gauss_DP, &
weights_jacobi_gauss_QP
end interface weights_jacobi_gauss
!
interface weights_legendre_gauss
module procedure weights_legendre_gauss_DP, &
weights_legendre_gauss_QP
end interface weights_legendre_gauss
!
interface weights_right_radau
module procedure weights_right_radau_DP, &
weights_right_radau_QP
end interface weights_right_radau
!
interface weights_chebyshev_gauss
module procedure weights_chebyshev_gauss_DP, &
weights_chebyshev_gauss_QP
end interface weights_chebyshev_gauss
!
interface weights_jacobi_gauss_lobatto
module procedure weights_jacobi_gauss_lobatto_DP, &
weights_jacobi_gauss_lobatto_QP
end interface weights_jacobi_gauss_lobatto
!
interface weights_legendre_gauss_lobatto
module procedure weights_legendre_gauss_lobatto_DP, &
weights_legendre_gauss_lobatto_QP
end interface weights_legendre_gauss_lobatto
!
interface weights_chebyshev_gauss_lobatto
module procedure weights_chebyshev_gauss_lobatto_DP, &
weights_chebyshev_gauss_lobatto_QP
end interface weights_chebyshev_gauss_lobatto
!
interface weights_dgbook_jacobi_gauss_lobatto
module procedure weights_dgbook_jacobi_gauss_lobatto_DP, &
weights_dgbook_jacobi_gauss_lobatto_QP
end interface weights_dgbook_jacobi_gauss_lobatto
!
interface derivative_matrix_legendre_gauss
module procedure derivative_matrix_legendre_gauss_DP, &
derivative_matrix_legendre_gauss_QP
end interface derivative_matrix_legendre_gauss
!
interface derivative_matrix_legendre_gauss_lobatto
module procedure derivative_matrix_legendre_gauss_lobatto_DP, &
derivative_matrix_legendre_gauss_lobatto_QP
end interface derivative_matrix_legendre_gauss_lobatto
!
interface derivative_matrix_jacobi_gauss_lobatto
module procedure derivative_matrix_jacobi_gauss_lobatto_DP, &
derivative_matrix_jacobi_gauss_lobatto_QP
end interface derivative_matrix_jacobi_gauss_lobatto
!
interface derivative_matrix_chebyshev_gauss_lobatto
module procedure derivative_matrix_chebyshev_gauss_lobatto_DP, &
derivative_matrix_chebyshev_gauss_lobatto_QP
end interface derivative_matrix_chebyshev_gauss_lobatto
!
interface gammafun
module procedure gammafun_DP, &
gammafun_QP
end interface gammafun
!
interface log_gammafun
module procedure log_gammafun_DP, &
log_gammafun_QP
end interface log_gammafun
!
interface coefrr
module procedure coefrr_DP, &
coefrr_QP
end interface coefrr
!
interface coefle
module procedure coefle_DP, &
coefle_QP
end interface coefle
!
interface eval_LagrangePoly
module procedure eval_LagrangePoly_DP, &
eval_LagrangePoly_QP
end interface eval_LagrangePoly
!
interface eval_LagrangePoly1D
module procedure eval_LagrangePoly1D_DP, &
eval_LagrangePoly1D_QP, &
eval_LagrangePoly1D_arrays_DP, &
eval_LagrangePoly1D_arrays_QP
end interface eval_LagrangePoly1D
!
interface eval_LagrangePoly2D
module procedure eval_LagrangePoly2D_DP, &
eval_LagrangePoly2D_QP, &
eval_LagrangePoly2D_arrays_DP, &
eval_LagrangePoly2D_arrays_QP
end interface eval_LagrangePoly2D
!
interface eval_LagrangePoly3D
module procedure eval_LagrangePoly3D_DP, &
eval_LagrangePoly3D_QP, &
eval_LagrangePoly3D_arrays_DP, &
eval_LagrangePoly3D_arrays_QP
end interface eval_LagrangePoly3D
!
interface eval_D2LagrangeDx2
module procedure eval_D2LagrangeDx2_DP, &
eval_D2LagrangeDx2_QP
end interface eval_D2LagrangeDx2
!
interface eval_DLagrangeDx
module procedure eval_DLagrangeDx_DP, &
eval_DLagrangeDx_QP
end interface eval_DLagrangeDx
!
contains
!
!###############################################################################
!###############################################################################
!###############################################################################
!###############################################################################
!###############################################################################
!
! WORKING PRECISION VERSIONS OF THE POLYNOMIAL PROCEDURES
!
!###############################################################################
!###############################################################################
!###############################################################################
!###############################################################################
!###############################################################################
!
pure subroutine legendre_gauss_quadrature(xi,weights)
!
!.. Formal Arguments ..
real(wp), intent(inout) :: xi(:)
!
!.. Optional Arguments ..
real(wp), optional, intent(inout) :: weights(:)
!
!.. Local Scalars ..
integer :: npts
!
!.. Local Arrays ..
real(qp) :: pts_qp(1:size(xi))
real(qp) :: wts_qp(1:size(xi))
real(qp) :: val_qp(1:size(xi))
!
continue
!
npts = size(xi)
!
call nodes_legendre_gauss(npts,pts_qp,val_qp)
call weights_legendre_gauss(npts,pts_qp,val_qp,wts_qp)
!
xi = chop( pts_qp )
!
if (present(weights)) then
weights = chop( wts_qp )
end if
!
end subroutine legendre_gauss_quadrature
!
!###############################################################################
!
pure subroutine legendre_gauss_lobatto_quadrature(xi,weights)
!
!.. Formal Arguments ..
real(wp), intent(inout) :: xi(:)
!
!.. Optional Arguments ..
real(wp), optional, intent(inout) :: weights(:)
!
!.. Local Scalars ..
integer :: npts
!
!.. Local Arrays ..
real(qp) :: pts_qp(1:size(xi))
real(qp) :: wts_qp(1:size(xi))
real(qp) :: val_qp(1:size(xi))
!
continue
!
npts = size(xi)
!
call nodes_legendre_gauss_lobatto(npts-1,pts_qp,val_qp)
call weights_legendre_gauss_lobatto(npts-1,val_qp,wts_qp)
!
xi = chop( pts_qp )
!
if (present(weights)) then
weights = chop( wts_qp )
end if
!
end subroutine legendre_gauss_lobatto_quadrature
!
!###############################################################################
!###############################################################################
!###############################################################################
!###############################################################################
!###############################################################################
!###############################################################################
!
! PROCEDURES OF VARYING PRECISION FOR THE MODULE GENERIC INTERFACES
!
!###############################################################################
!###############################################################################
!###############################################################################
!###############################################################################
!###############################################################################
!
pure subroutine JacobiGL_DP(alpha,beta,n,xi,weights)
!
!.. Function Precision ..
integer, parameter :: lp = dp
!
!.. Formal Arguments ..
integer, intent(in) :: n
real(lp), intent(in) :: alpha
real(lp), intent(in) :: beta
real(lp), dimension(1:n+1), intent(out) :: xi
real(lp), dimension(1:n+1), intent(out) :: weights
!
!.. Local Arrays ..
real(lp), dimension(1:n+1) :: vn
!
!.. Local Constants ..
real(lp), parameter :: zero = 0.0_lp
!
continue
!
xi = zero
weights = zero
!
call nodes_jacobi_gauss_lobatto(n,alpha,beta,xi,vn)
!
call weights_dgbook_jacobi_gauss_lobatto(n,alpha,beta,xi,weights)
!
end subroutine JacobiGL_DP
!
!###############################################################################
!
pure subroutine JacobiGL_QP(alpha,beta,n,xi,weights)
!
!.. Function Precision ..
integer, parameter :: lp = local_qp
!
!.. Formal Arguments ..
integer, intent(in) :: n
real(lp), intent(in) :: alpha
real(lp), intent(in) :: beta
real(lp), dimension(1:n+1), intent(out) :: xi
real(lp), dimension(1:n+1), intent(out) :: weights
!
!.. Local Arrays ..
real(lp), dimension(1:n+1) :: vn
!
!.. Local Constants ..
real(lp), parameter :: zero = 0.0_lp
!
continue
!
xi = zero
weights = zero
!
call nodes_jacobi_gauss_lobatto(n,alpha,beta,xi,vn)
!
call weights_dgbook_jacobi_gauss_lobatto(n,alpha,beta,xi,weights)
!
end subroutine JacobiGL_QP
!
!###############################################################################
!
pure subroutine eval_jacobi_poly_DP(n,alpha,beta,x,y,dy,d2y)
!
!.. Function Precision ..
integer, parameter :: lp = dp
!
!.. Formal Arguments ..
integer, intent(in) :: n
real(lp), intent(in) :: alpha
real(lp), intent(in) :: beta
real(lp), intent(in) :: x
real(lp), intent(out) :: y
real(lp), intent(out) :: dy
real(lp), intent(out) :: d2y
!
!.. Local Scalars ..
integer :: i
real(lp) :: ab,di,c0,c1,c2,c3,c4
real(lp) :: ym,yp,dym,dyp,d2ym,d2yp
!
!.. Local Constants ..
real(lp), parameter :: zero = 0.0_lp
real(lp), parameter :: half = 0.5_lp
real(lp), parameter :: one = 1.0_lp
real(lp), parameter :: two = 2.0_lp
!
continue
!
y = one
dy = zero
d2y = zero
!
if (n > 0) then
!
ab = alpha + beta
!
y = half*(ab + two)*x + half*(alpha - beta)
dy = half*(ab + two)
d2y = zero
!
end if
!
if (n > 1) then
!
yp = one
dyp = zero
d2yp = zero
!
do i = 2,n
!
di = real(i,kind=lp)
c0 = two*di + ab
c1 = two * di * (di+ab) * (c0-two)
c2 = (c0-one) * (c0-two) * c0
c3 = (c0-one) * (alpha-beta) * ab
c4 = two * c0 * (di+alpha-one) * (di+beta-one)
!
ym = y
y = ((c2*x + c3)*y - c4*yp)/c1
yp = ym
!
dym = dy
dy = ((c2*x + c3)*dy - c4*dyp + c2*yp)/c1
dyp = dym
!
d2ym = d2y
d2y = ((c2*x + c3)*d2y - c4*d2yp + two*c2*dyp)/c1
d2yp = d2ym
!
end do
!
end if
!
end subroutine eval_jacobi_poly_DP
!
!###############################################################################
!
pure subroutine eval_jacobi_poly_QP(n,alpha,beta,x,y,dy,d2y)
!
!.. Function Precision ..
integer, parameter :: lp = local_qp
!
!.. Formal Arguments ..
integer, intent(in) :: n
real(lp), intent(in) :: alpha
real(lp), intent(in) :: beta
real(lp), intent(in) :: x
real(lp), intent(out) :: y
real(lp), intent(out) :: dy
real(lp), intent(out) :: d2y
!
!.. Local Scalars ..
integer :: i
real(lp) :: ab,di,c0,c1,c2,c3,c4
real(lp) :: ym,yp,dym,dyp,d2ym,d2yp
!
!.. Local Constants ..
real(lp), parameter :: zero = 0.0_lp
real(lp), parameter :: half = 0.5_lp
real(lp), parameter :: one = 1.0_lp
real(lp), parameter :: two = 2.0_lp
!
continue
!
y = one
dy = zero
d2y = zero
!
if (n > 0) then
!
ab = alpha + beta
!
y = half*(ab + two)*x + half*(alpha - beta)
dy = half*(ab + two)
d2y = zero
!
end if
!
if (n > 1) then
!
yp = one
dyp = zero
d2yp = zero
!
do i = 2,n
!
di = real(i,kind=lp)
c0 = two*di + ab
c1 = two * di * (di+ab) * (c0-two)
c2 = (c0-one) * (c0-two) * c0
c3 = (c0-one) * (alpha-beta) * ab
c4 = two * c0 * (di+alpha-one) * (di+beta-one)
!
ym = y
y = ((c2*x + c3)*y - c4*yp)/c1
yp = ym
!
dym = dy
dy = ((c2*x + c3)*dy - c4*dyp + c2*yp)/c1
dyp = dym
!
d2ym = d2y
d2y = ((c2*x + c3)*d2y - c4*d2yp + two*c2*dyp)/c1
d2yp = d2ym
!
end do
!
end if
!
end subroutine eval_jacobi_poly_QP
!
!###############################################################################
!
pure subroutine eval_legendre_poly_DP(n,x,y,dy,d2y)
!
!.. Function Precision ..
integer, parameter :: lp = dp
!
!.. Formal Arguments ..
integer, intent(in) :: n
real(lp), intent(in) :: x
real(lp), intent(out) :: y
real(lp), intent(out) :: dy
real(lp), intent(out) :: d2y
!
!.. Local Scalars ..
real(lp) :: alpha,beta
!
!.. Local Constants ..
real(lp), parameter :: zero = 0.0_lp
!
continue
!
alpha = zero
beta = zero
!
call eval_jacobi_poly(n,alpha,beta,x,y,dy,d2y)
!
end subroutine eval_legendre_poly_DP
!
!###############################################################################
!
pure subroutine eval_legendre_poly_QP(n,x,y,dy,d2y)
!
!.. Function Precision ..
integer, parameter :: lp = local_qp
!
!.. Formal Arguments ..
integer, intent(in) :: n
real(lp), intent(in) :: x
real(lp), intent(out) :: y
real(lp), intent(out) :: dy
real(lp), intent(out) :: d2y
!
!.. Local Scalars ..
real(lp) :: alpha,beta
!
!.. Local Constants ..
real(lp), parameter :: zero = 0.0_lp
!
continue
!
alpha = zero
beta = zero
!
call eval_jacobi_poly(n,alpha,beta,x,y,dy,d2y)
!
end subroutine eval_legendre_poly_QP
!
!###############################################################################
!
pure subroutine eval_chebyshev_poly_DP(n,x,y,dy,d2y)
!
!.. Function Precision ..
integer, parameter :: lp = dp
!
!.. Formal Arguments ..
integer, intent(in) :: n
real(lp), intent(in) :: x
real(lp), intent(out) :: y
real(lp), intent(out) :: dy
real(lp), intent(out) :: d2y
!
!.. Local Scalars ..
integer :: k
real(lp) :: yp,ym,dyp,dym,d2yp,d2ym
!
!.. Local Constants ..
real(lp), parameter :: zero = 0.0_lp
real(lp), parameter :: one = 1.0_lp
real(lp), parameter :: two = 2.0_lp
real(lp), parameter :: four = 4.0_lp
!
continue
!
y = one
dy = zero
d2y = zero
!
if (n > 0) then
y = x
dy = one
d2y = zero
end if
!
if (n > 1) then
!
yp = one
dyp = zero
d2yp = zero
!
do k = 2,n
!
ym = y
y = two*x*y - yp
yp = ym
!
dym = dy
dy = two*x*dy + two*yp - dyp
dyp = dym
!
d2ym = d2y
d2y = two*x*d2y + four*dyp - d2yp
d2yp = d2ym
!
end do
!
end if
!
end subroutine eval_chebyshev_poly_DP
!
!###############################################################################
!
pure subroutine eval_chebyshev_poly_QP(n,x,y,dy,d2y)
!
!.. Function Precision ..
integer, parameter :: lp = local_qp
!
!.. Formal Arguments ..
integer, intent(in) :: n
real(lp), intent(in) :: x
real(lp), intent(out) :: y
real(lp), intent(out) :: dy
real(lp), intent(out) :: d2y
!
!.. Local Scalars ..
integer :: k
real(lp) :: yp,ym,dyp,dym,d2yp,d2ym
!
!.. Local Constants ..
real(lp), parameter :: zero = 0.0_lp
real(lp), parameter :: one = 1.0_lp
real(lp), parameter :: two = 2.0_lp
real(lp), parameter :: four = 4.0_lp
!
continue
!
y = one
dy = zero
d2y = zero
!
if (n > 0) then
y = x
dy = one
d2y = zero
end if
!
if (n > 1) then
!
yp = one
dyp = zero
d2yp = zero
!
do k = 2,n
!
ym = y
y = two*x*y - yp
yp = ym
!
dym = dy
dy = two*x*dy + two*yp - dyp
dyp = dym
!
d2ym = d2y
d2y = two*x*d2y + four*dyp - d2yp
d2yp = d2ym
!
end do
!
end if
!
end subroutine eval_chebyshev_poly_QP
!
!###############################################################################
!
pure subroutine eval_normalized_jacobi_poly_DP(n,alpha,beta,x,y,dy)
!
!.. Function Precision ..
integer, parameter :: lp = dp
!
!.. Formal Arguments ..
integer, intent(in) :: n
real(lp), intent(in) :: alpha
real(lp), intent(in) :: beta
real(lp), intent(in) :: x
real(lp), intent(out) :: y
real(lp), intent(out) :: dy
!
!.. Local Scalars ..
integer :: n1
real(lp) :: a1,b1,ab1,rn
!
!.. Local Constants ..
real(lp), parameter :: one = 1.0_lp
!
continue
!
a1 = alpha + one
b1 = beta + one
ab1 = alpha + beta + one
rn = real(n,kind=lp)
n1 = n - 1
!
y = normalized_jacobi_poly(n,alpha,beta,x)
!
dy = sqrt(rn*(rn+ab1))*normalized_jacobi_poly(n1,a1,b1,x)
!
end subroutine eval_normalized_jacobi_poly_DP
!
!###############################################################################
!
pure subroutine eval_normalized_jacobi_poly_QP(n,alpha,beta,x,y,dy)
!
!.. Function Precision ..
integer, parameter :: lp = local_qp
!
!.. Formal Arguments ..
integer, intent(in) :: n
real(lp), intent(in) :: alpha
real(lp), intent(in) :: beta
real(lp), intent(in) :: x
real(lp), intent(out) :: y
real(lp), intent(out) :: dy
!
!.. Local Scalars ..
integer :: n1
real(lp) :: a1,b1,ab1,rn
!
!.. Local Constants ..
real(lp), parameter :: one = 1.0_lp
!
continue
!
a1 = alpha + one
b1 = beta + one
ab1 = alpha + beta + one
rn = real(n,kind=lp)
n1 = n - 1
!
y = normalized_jacobi_poly(n,alpha,beta,x)
!
dy = sqrt(rn*(rn+ab1))*normalized_jacobi_poly(n1,a1,b1,x)
!
end subroutine eval_normalized_jacobi_poly_QP
!
!###############################################################################
!
pure function normalized_jacobi_poly_DP(N,alpha,beta,x) result(return_value)
!
!.. Function Precision ..
integer, parameter :: lp = dp
!
!.. Formal Arguments ..
integer, intent(in) :: N
real(lp), intent(in) :: alpha
real(lp), intent(in) :: beta
real(lp), intent(in) :: x
!
!.. Function Result ..
real(lp) :: return_value
!
!.. Local Scalars ..
integer :: i
real(lp) :: ab,ab1,ab2,ab3,amb,a1,b1
real(lp) :: gamma0,gamma1
real(lp) :: aold,anew,bnew,h1,ri
real(lp) :: sqrt_numer,sqrt_denom
!
!.. Local Arrays ..
real(lp) :: PL(N+1)
!
!.. Local Constants ..
real(lp), parameter :: half = 0.5_lp
real(lp), parameter :: one = 1.0_lp
real(lp), parameter :: two = 2.0_lp
real(lp), parameter :: three = 3.0_lp
!
continue
!
ab = alpha + beta
amb = alpha - beta
a1 = alpha + one
b1 = beta + one
ab1 = ab + one
ab2 = ab + two
ab3 = ab + three
!
gamma0 = two**ab1 / ab1 * gammafun(a1) * gammafun(b1) / gammafun(ab1)
!
PL(1) = one/sqrt(gamma0)
!
if (N == 0) then
!
return_value = PL(1)
!
else
!
gamma1 = a1 * b1 / ab3 * gamma0
!
PL(2) = half*( ab2*x + amb ) / sqrt(gamma1)
!
aold = two / ab2 * sqrt( a1*b1/ab3 )
!
do i = 1,N-1
ri = real(i,kind=lp)
h1 = two*ri + ab
sqrt_numer = (ri+one)*(ri+ab1)*(ri+a1)*(ri+b1)
sqrt_denom = (h1+one)*(h1+three)
anew = sqrt( sqrt_numer / sqrt_denom ) * two / (h1+two)
bnew = (beta*beta - alpha*alpha) / h1 / (h1+two)
PL(i+2) = one/anew*( -aold*PL(i) + (x-bnew)*PL(i+1) )
aold = anew
end do
!
return_value = PL(N+1)
!
end if
!
end function normalized_jacobi_poly_DP
!
!###############################################################################
!
pure function normalized_jacobi_poly_QP(N,alpha,beta,x) result(return_value)
!
!.. Function Precision ..
integer, parameter :: lp = local_qp
!
!.. Formal Arguments ..
integer, intent(in) :: N
real(lp), intent(in) :: alpha
real(lp), intent(in) :: beta
real(lp), intent(in) :: x
!
!.. Function Result ..
real(lp) :: return_value
!
!.. Local Scalars ..
integer :: i
real(lp) :: ab,ab1,ab2,ab3,amb,a1,b1
real(lp) :: gamma0,gamma1
real(lp) :: aold,anew,bnew,h1,ri
real(lp) :: sqrt_numer,sqrt_denom
!
!.. Local Arrays ..
real(lp) :: PL(N+1)
!
!.. Local Constants ..
real(lp), parameter :: half = 0.5_lp
real(lp), parameter :: one = 1.0_lp
real(lp), parameter :: two = 2.0_lp
real(lp), parameter :: three = 3.0_lp
!
continue
!
ab = alpha + beta
amb = alpha - beta
a1 = alpha + one
b1 = beta + one
ab1 = ab + one
ab2 = ab + two
ab3 = ab + three
!
gamma0 = two**ab1 / ab1 * gammafun(a1) * gammafun(b1) / gammafun(ab1)
!
PL(1) = one/sqrt(gamma0)
!
if (N == 0) then
!
return_value = PL(1)
!
else
!
gamma1 = a1 * b1 / ab3 * gamma0
!
PL(2) = half*( ab2*x + amb ) / sqrt(gamma1)
!
aold = two / ab2 * sqrt( a1*b1/ab3 )
!
do i = 1,N-1
ri = real(i,kind=lp)
h1 = two*ri + ab
sqrt_numer = (ri+one)*(ri+ab1)*(ri+a1)*(ri+b1)
sqrt_denom = (h1+one)*(h1+three)
anew = sqrt( sqrt_numer / sqrt_denom ) * two / (h1+two)
bnew = (beta*beta - alpha*alpha) / h1 / (h1+two)
PL(i+2) = one/anew*( -aold*PL(i) + (x-bnew)*PL(i+1) )
aold = anew
end do
!
return_value = PL(N+1)
!
end if
!
end function normalized_jacobi_poly_QP
!
!###############################################################################
!
pure function grad_normalized_jacobi_poly_DP(n,alpha,beta,x) &
result(return_value)
!
!.. Function Precision ..
integer, parameter :: lp = dp
!
!.. Formal Arguments ..
integer, intent(in) :: n
real(lp), intent(in) :: alpha
real(lp), intent(in) :: beta
real(lp), intent(in) :: x
!
!.. Function Result ..
real(lp) :: return_value
!
!.. Local Scalars ..
real(lp) :: rn,a1,b1,ab1
!
!.. Local Constants ..
real(lp), parameter :: zero = 0.0_lp
real(lp), parameter :: one = 1.0_lp
!
continue
!
if (n == 0) then
!
return_value = zero
!
else
!
rn = real(n,kind=lp)
a1 = alpha + one
b1 = beta + one
ab1 = alpha + b1
!
return_value = sqrt(rn*(rn+ab1)) * normalized_jacobi_poly(n-1,a1,b1,x)
!
end if
!
end function grad_normalized_jacobi_poly_DP
!
!###############################################################################
!
pure function grad_normalized_jacobi_poly_QP(n,alpha,beta,x) &
result(return_value)
!
!.. Function Precision ..
integer, parameter :: lp = local_qp
!
!.. Formal Arguments ..