Octopus
gauss_legendre.F90
Go to the documentation of this file.
1!! Copyright (C) 2006 Hyllios
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22 use global_oct_m
23 use, intrinsic :: iso_fortran_env
24
25 implicit none
26
27 private
28 public :: &
31
32
33 ! 2 point
34 real(real64), target :: GL_points_2(1) = (/ &
35 -0.57735026919_real64 /)
36 real(real64), target :: GL_weights_2(1) = (/ &
37 m_one /)
38
39 ! 3 point
40 real(real64), target :: GL_points_3(2) = (/ &
41 -0.774596669241_real64, m_zero /)
42 real(real64), target :: GL_weights_3(2) = (/ &
43 0.555555555556_real64, 0.888888888889_real64 /)
44
45 ! 4 point
46 real(real64), target :: GL_points_4(2) = (/ &
47 -0.861136311594_real64, -0.339981043585_real64 /)
48 real(real64), target :: GL_weights_4(2) = (/ &
49 0.347854845137_real64, 0.652145154863_real64 /)
50
51 ! 5 point
52 real(real64), target :: GL_points_5(3) = (/ &
53 -0.906179845939_real64, -0.538469310106_real64, m_zero /)
54 real(real64), target :: GL_weights_5(3) = (/ &
55 0.236926885056_real64, 0.478628670499_real64, 0.568888888889_real64 /)
56
57 ! 6 point
58 real(real64), target :: GL_points_6(3) = (/ &
59 -0.932469514203_real64, -0.661209386466_real64, -0.238619186083_real64 /)
60 real(real64), target :: GL_weights_6(3) = (/ &
61 0.171324492379_real64, 0.360761573048_real64, 0.467913934573_real64 /)
62
63 ! 7 point
64 real(real64), target :: GL_points_7(4) = (/ &
65 -0.949107912343_real64, -0.741531185599_real64, -0.405845151377_real64, &
66 m_zero /)
67 real(real64), target :: GL_weights_7(4) = (/ &
68 0.129484966169_real64, 0.279705391489_real64, 0.381830050505_real64, &
69 0.417959183673_real64 /)
70
71 ! 8 point
72 real(real64), target :: GL_points_8(4) = (/ &
73 -0.960289856498_real64, -0.796666477414_real64, -0.525532409916_real64, &
74 -0.183434642496_real64 /)
75 real(real64), target :: GL_weights_8(4) = (/ &
76 0.10122853629_real64, 0.222381034453_real64, 0.313706645878_real64, &
77 0.362683783378_real64 /)
78
79 ! 9 point
80 real(real64), target :: GL_points_9(5) = (/ &
81 -0.968160239508_real64, -0.836031107327_real64, -0.613371432701_real64, &
82 -0.324253423404_real64, m_zero /)
83 real(real64), target :: GL_weights_9(5) = (/ &
84 0.0812743883616_real64, 0.180648160695_real64, 0.260610696403_real64, &
85 0.31234707704_real64, 0.330239355001_real64 /)
86
87 ! 10 point
88 real(real64), target :: GL_points_10(5) = (/ &
89 -0.973906528517_real64, -0.865063366689_real64, -0.679409568299_real64, &
90 -0.433395394129_real64, -0.148874338982_real64 /)
91 real(real64), target :: GL_weights_10(5) = (/ &
92 0.0666713443087_real64, 0.149451349151_real64, 0.219086362516_real64, &
93 0.26926671931_real64, 0.295524224715_real64 /)
94
95 ! 11 point
96 real(real64), target :: GL_points_11(6) = (/ &
97 -0.978228658146_real64, -0.887062599768_real64, -0.730152005574_real64, &
98 -0.519096129207_real64, -0.269543155952_real64, m_zero /)
99 real(real64), target :: GL_weights_11(6) = (/ &
100 0.0556685671162_real64, 0.125580369465_real64, 0.186290210928_real64, &
101 0.233193764592_real64, 0.26280454451_real64, 0.272925086778_real64 /)
102
103 ! 12 point
104 real(real64), target :: GL_points_12(6) = (/ &
105 -0.981560634247_real64, -0.90411725637_real64, -0.769902674194_real64, &
106 -0.587317954287_real64, -0.367831498998_real64, -0.125233408511_real64 /)
107 real(real64), target :: gl_weights_12(6) = (/ &
108 0.0471753363866_real64, 0.106939325995_real64, 0.160078328543_real64, &
109 0.203167426723_real64, 0.233492536538_real64, 0.249147045813_real64 /)
110
111contains
113 ! --------------------------------------------------------------------
117 subroutine gauss_legendre_points(n, points, weights)
118 integer, intent(in) :: n
119 real(real64), contiguous, intent(out) :: points(:)
120 real(real64), contiguous, intent(out) :: weights(:)
121
122 integer :: i
123
124 real(real64), pointer :: points_ref(:), weights_ref(:)
125
126 nullify(points_ref)
127 nullify(weights_ref)
128
129 assert(n >= 2)
130 if (n > 12) then
131 call gauss_legendre_newton(n, points, weights)
132 return
133 end if
134
135 select case (n)
136 case (2)
137 points_ref => gl_points_2
138 weights_ref => gl_weights_2
139 case (3)
140 points_ref => gl_points_3
141 weights_ref => gl_weights_3
142 case (4)
143 points_ref => gl_points_4
144 weights_ref => gl_weights_4
145 case (5)
146 points_ref => gl_points_5
147 weights_ref => gl_weights_5
148 case (6)
149 points_ref => gl_points_6
150 weights_ref => gl_weights_6
151 case (7)
152 points_ref => gl_points_7
153 weights_ref => gl_weights_7
154 case (8)
155 points_ref => gl_points_8
156 weights_ref => gl_weights_8
157 case (9)
158 points_ref => gl_points_9
159 weights_ref => gl_weights_9
160 case (10)
161 points_ref => gl_points_10
162 weights_ref => gl_weights_10
163 case (11)
164 points_ref => gl_points_11
165 weights_ref => gl_weights_11
166 case (12)
167 points_ref => gl_points_12
168 weights_ref => gl_weights_12
169 end select
170
171 do i = 1, n/2
172 points(i) = points_ref(i)
173 points(n-i+1) = -points_ref(i)
174 weights(i) = weights_ref(i)
175 weights(n-i+1) = weights_ref(i)
176 end do
177 if (mod(n, 2) == 1) then
178 points(n/2 + 1) = points_ref(n/2 + 1)
179 weights(n/2 + 1) = weights_ref(n/2 + 1)
180 end if
181
182 end subroutine gauss_legendre_points
183
184 ! --------------------------------------------------------------------
187 subroutine gauss_legendre_newton(n, points, weights)
188 integer, intent(in) :: n
189 real(real64), intent(out) :: points(:)
190 real(real64), intent(out) :: weights(:)
191
192 integer :: ii, jj, iter
193 real(real64) :: zz, p0, p1, p2, dp
194
195 assert(n >= 1)
196 do ii = 1, (n + 1)/2
197 zz = cos(m_pi*(ii - 0.25_real64)/(n + m_half))
198 do iter = 1, 100
199 p0 = m_one
200 p1 = m_zero
201 do jj = 1, n
202 p2 = p1
203 p1 = p0
204 p0 = ((2*jj - 1)*zz*p1 - (jj - 1)*p2)/jj
205 end do
206 dp = n*(zz*p0 - p1)/(zz**2 - m_one)
207 if (abs(p0/dp) < 1e-15_real64) exit
208 zz = zz - p0/dp
209 end do
210 points(ii) = -zz
211 points(n + 1 - ii) = zz
212 weights(ii) = m_two/((m_one - zz**2)*dp**2)
213 weights(n + 1 - ii) = weights(ii)
214 end do
215
216 end subroutine gauss_legendre_newton
217
218end module gauss_legendre_oct_m
219
220!! Local Variables:
221!! mode: f90
222!! coding: utf-8
223!! End:
double cos(double __x) __attribute__((__nothrow__
real(real64), dimension(6), target gl_weights_12
subroutine, public gauss_legendre_newton(n, points, weights)
Gauss-Legendre nodes and weights on [-1, 1] for arbitrary n, computed to machine precision by Newton ...
subroutine, public gauss_legendre_points(n, points, weights)
Gauss-Legendre nodes and weights on [-1, 1]. For 2 <= n <= 12 the tabulated values are returned; for ...
real(real64), parameter, public m_two
Definition: global.F90:175
real(real64), parameter, public m_zero
Definition: global.F90:173
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:171
real(real64), parameter, public m_half
Definition: global.F90:179
real(real64), parameter, public m_one
Definition: global.F90:174