-
Notifications
You must be signed in to change notification settings - Fork 0
/
quadrature.py
71 lines (64 loc) · 2.31 KB
/
quadrature.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
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
import numpy as np
arr = np.array
class QuadratureException(Exception):
pass
class BadGaussOrderError(QuadratureException):
def __init__(self, order):
super().__init__("unable to give gauss points for order {}".format(order))
def tri_gauss_points_weights(order=1):
"""
Gives list of gauss points for triangles depending on order.
Quadrature rules from https://people.sc.fsu.edu/~jburkardt/datasets/quadrature_rules_tri/quadrature_rules_tri.html.
"""
if order == 1:
return arr([(1 / 3, 1 / 3)]), arr([1]) # Midpoint rule
elif order == 2:
return arr([(0.5, 0), (0.5, 0.5), (0, 0.5)]), arr([1 / 3, 1 / 3, 1 / 3])
elif order == 3:
return arr([(1 / 3, 1 / 3), (0.6, 0.2), (0.2, 0.6), (0.2, 0.2)]), arr(
[-0.5625, 1.5625 / 3, 1.5625 / 3, 1.5625 / 3]
)
elif order == 4:
return arr(
[
(0.816847572980459, 0.091576213509771),
(0.091576213509771, 0.816847572980459),
(0.091576213509771, 0.091576213509771),
(0.108103018168070, 0.445948490915965),
(0.445948490915965, 0.108103018168070),
(0.445948490915965, 0.445948490915965),
]
), arr(
[
0.109951743655322,
0.109951743655322,
0.109951743655322,
0.223381589678011,
0.223381589678011,
0.223381589678011,
]
)
elif order == 5:
return arr(
[
(0.33333333333333333, 0.33333333333333333),
(0.79742698535308720, 0.10128650732345633),
(0.10128650732345633, 0.79742698535308720),
(0.10128650732345633, 0.10128650732345633),
(0.05971587178976981, 0.47014206410511505),
(0.47014206410511505, 0.05971587178976981),
(0.47014206410511505, 0.47014206410511505),
]
), arr(
[
0.22500000000000000,
0.12593918054482717,
0.12593918054482717,
0.12593918054482717,
0.13239415278850616,
0.13239415278850616,
0.13239415278850616,
]
)
else:
raise BadGaussOrderError(order)