SPEED
MAKE_LGL_NW.f90
Go to the documentation of this file.
1! Copyright (C) 2012 The SPEED FOUNDATION
2! Author: Ilario Mazzieri
3!
4! This file is part of SPEED.
5!
6! SPEED is free software; you can redistribute it and/or modify it
7! under the terms of the GNU Affero General Public License as
8! published by the Free Software Foundation, either version 3 of the
9! License, or (at your option) any later version.
10!
11! SPEED is distributed in the hope that it will be useful, but
12! WITHOUT ANY WARRANTY; without even the implied warranty of
13! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14! Affero General Public License for more details.
15!
16! You should have received a copy of the GNU Affero General Public License
17! along with SPEED. If not, see <http://www.gnu.org/licenses/>.
18
27
28 subroutine make_lgl_nw(nb_pnt, xq, wq, dd)
29
30 implicit real*8 (a-h,o-z)
31
32 parameter(nstep = 1000, acc = 1.d-15)
33
34
35 integer*4, intent(inout) :: nb_pnt
36 real*8, dimension(nb_pnt) :: xq, wq
37 real*8, dimension(nb_pnt) :: dd(nb_pnt,nb_pnt)
38
39 n = nb_pnt-1
40 xq(1) = -1.d0
41 xq(nb_pnt) = 1.d0
42 n2=idint(0.5d0*nb_pnt)
43 dx=2.d0/dfloat(nstep)
44
45 x = -1.d0
46 iroot = 1
47
48 call get_legendre_value(p2,a1,p1,p1der,n,x)
49
50 do while (iroot .lt. n2)
51 x = x + dx
52 call get_legendre_value(p2,a2,p1,p1der,n,x)
53
54 if (dabs(a2) .le. acc) then
55 iroot = iroot + 1
56 xq(iroot) = a2
57 else
58 aa = a1 * a2
59 if (aa .lt. 0.d0) then
60 iroot = iroot + 1
61 xq(iroot) = find_root_pol(x-dx,x,acc,n)
62 endif
63 endif
64
65 a1 = a2
66 enddo
67
68 n_filt = 2*n2
69 if (n_filt .ne. nb_pnt) then ! nb_pnt odd
70 xq(n2+1) = 0.d0
71 do i = 1, n2-1
72 xq(nb_pnt-i) = -xq(i+1)
73 enddo
74 else ! nb_pnt even
75 do i = 1, n2-1
76 xq(nb_pnt-i) = -xq(i+1)
77 enddo
78 endif
79
80
81 xn = dfloat(n)
82 acost = 2.d0/(xn*(xn+1.d0))
83
84 do j = 1,nb_pnt
85 call get_legendre_value(p2,p2der,p1,p1der,n,xq(j))
86 den = p2*p2
87 wq(j) = acost/den
88
89 do i = 1, nb_pnt
90 if (i .ne. j) then
91 call get_legendre_value(pnum,p2der,p1,p1der,n,xq(i))
92 den = p2 * (xq(i)-xq(j))
93 dd(i,j) = pnum / den
94 endif
95 enddo
96
97 enddo
98
99 do j = 2, nb_pnt-1
100 dd(j,j) = 0.d0
101 enddo
102
103 dd(1,1) = -0.25d0 * xn * (xn+1.d0)
104 dd(nb_pnt,nb_pnt) = 0.25d0 * xn * (xn+1.d0)
105
106
107 return
108
109 end subroutine make_lgl_nw
real *8 function find_root_pol(x1, x2, xacc, n)
Find a root of a polynomial of degree n.
subroutine get_legendre_value(p2, p2der, p1, p1der, n, x)
Computes Legendre polynomial and its derivative on a given point x.
subroutine make_lgl_nw(nb_pnt, xq, wq, dd)
Makes Gauss-Legendre-Lobatto nodes, weigths and spectral derivatives.