SPEED
MAKE_GL_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
26
27
28 subroutine make_gl_nw(ngp, xabsc, weig)
29
30 implicit none
31
32 INTEGER, parameter :: dbp = selected_real_kind (15,307)
33 REAL(dbp) :: newv
34 REAL(dbp) :: EPS, M_PI
35 parameter(eps=3.0d-15) !EPS is the relative precision
36 parameter(m_pi=3.141592654d0)
37
38 INTEGER*4 i, j, m
39 REAL(dbp) p1, p2, p3, pp, z, z1
40 INTEGER*4, INTENT(IN) :: ngp ! # of Gauss Points
41 REAL(dbp), INTENT(OUT) :: xabsc(ngp), weig(ngp)
42
43
44 m = (ngp + 1) / 2
45!* Roots are symmetric in the interval - so only need to find half of them */
46
47 do i = 1, m ! Loop over the desired roots */
48
49 z = cos( m_pi * (i-0.25d0) / (ngp+0.5d0) )
50!* Starting with the above approximation to the ith root,
51!* we enter the main loop of refinement by NEWTON'S method */
52
53100 p1 = 1.0d0
54 p2 = 0.0d0
55!* Loop up the recurrence relation to get the Legendre
56!* polynomial evaluated at z */
57
58 do j = 1, ngp
59 p3 = p2
60 p2 = p1
61 p1 = ((2.0d0*j-1.0d0) * z * p2 - (j-1.0d0)*p3) / j
62 enddo
63
64!* p1 is now the desired Legendre polynomial. We next compute pp,
65!* its derivative, by a standard relation involving also p2, the
66!* polynomial of one lower order. */
67 pp = ngp*(z*p1-p2)/(z*z-1.0d0)
68 z1 = z
69 z = z1 - p1/pp ! Newton's Method */
70
71 if (dabs(z-z1) .gt. eps) GOTO 100
72
73 xabsc(i) = - z ! Roots will be bewteen -1.0 & 1.0 */
74 xabsc(ngp+1-i) = + z ! and symmetric about the origin */
75 weig(i) = 2.0d0/((1.0d0-z*z)*pp*pp) ! Compute the weight and its */
76 weig(ngp+1-i) = weig(i) ! symmetric counterpart */
77
78 end do ! i loop
79
80 End subroutine make_gl_nw
81
subroutine make_gl_nw(ngp, xabsc, weig)
Makes Gauss Legendre nodes and weights.