39 Integrate numerically over the reference tetrahedron.
41 x, y, z = sympy.symbols(
'x y z')
43 pts=scheme.transform(b)
44 weights=scheme.transform_w(b)
45 for i, w
in enumerate(weights):
46 res += w * f.subs([(x, pts[i, 0]),
47 (y, pts[i, 1]), (z, pts[i, 2])])
53 List all existing schemes for tetrahedra.
55 L = [quadpy.p3.felippa_1()] \
56 + [quadpy.p3.felippa_2()] \
57 + [quadpy.p3.felippa_3()] \
58 + [quadpy.p3.felippa_4()] \
59 + [quadpy.p3.felippa_5()] \
60 + [quadpy.p3.felippa_6()] \
61 + [quadpy.p3.felippa_7()] \
62 + [quadpy.p3.felippa_8()] \
63 + [quadpy.p3.felippa_9()] \
87 3. points inside reference pyramid:
91 pts=scheme.transform(b)
92 w=scheme.transform_w(b)
93 print(
"sum w: ", sum(w))
95 x, y, z = pts[:, 0], pts[:, 1], pts[:, 2]
96 cond_z = (z >= 0 - tol) & (z <= 1 + tol)
97 cond_x = (x >= 0 - tol) & (x <= (1 - z) + tol)
98 cond_y = (y >= 0 - tol) & (y <= (1 - z) + tol)
99 cond_inside = cond_z & cond_x & cond_y
102 math.isclose(np.sum(w), 0.3333333333333333, rel_tol=1e-10)
103 ,(relaxed
or (w >= tol).all())
109 math.isclose(np.sum(w), 0.3333333333333333, rel_tol=1e-10)
110 and (relaxed
or (w >= tol).all())
112 and cond_inside.all()
117 Picks the best scheme for a given polynomial degree, following this strategy:
118 - Tries all schemes with the same order as required.
119 - Eliminate schemes with weights that do not sum up to 1, or points that lie
120 outside the reference triangle.
121 - Among the remaining schemes, compare the integration error over all bivariate
122 monomials of inferior order.
123 - Keeps only the scheme with total integration error lower than a certain threshold.
124 - Among those, keep the one with fewer number of integration points.
125 - Finally, break ties using the integration error accumulated over the monomials.
133 for scheme
in all_schemes:
134 if scheme.degree == order
and is_valid(scheme, relaxed=relaxed):
135 N = len(scheme.weights)
142 if not math.isclose(exact - approx, 0, abs_tol=threshold):
144 error += abs(exact - approx)
146 if (min_points
is None)
or N < min_points:
150 elif N == min_points
and error < best_error:
153 return best_scheme, best_error