-
Notifications
You must be signed in to change notification settings - Fork 0
/
quadratures.py
43 lines (30 loc) · 968 Bytes
/
quadratures.py
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
import numpy
eGLL = 'Gauss-Lobatto-Legendre'
eGL = 'Gauss-Legendre'
eGC = 'Gauss-Chebyshev'
def qType(N, type):
if type == eGLL:
N -= 1
x = numpy.cos(numpy.pi*(numpy.arange(0,N+1))/N)
P = numpy.zeros(( N+1,N+1) )
xOld = 2
while max(abs(x - xOld) > 1.e-10):
xOld = x
P[:,0] = 1
P[:,1] = x
for k in range(2,N+1):
P[:,k] = ((2.0 * float(k) - 1.0 ) * x * P[:,k-1] - float(k-1) * P[:,k-2]) / float(k)
x = xOld - (x * P[:,N] - P[:,N-1] ) / ( float(N+1) * P[:,N])
w = 2.0 / ( float(N * (N + 1.0)) * P[:,N]**2)
x *= -1.0
return x,w
elif type == eGL:
x, w = numpy.polynomial.legendre.leggauss(N)
#xx = numpy.zeros(N)
#xx[:] = -x[:]
return x, w
else:
x, w = numpy.polynomial.chebyshev.chebgauss(N)
xx = numpy.zeros(N)
xx[:] = -x[:]
return xx, w