def test_gauss4d_tri(): q = gauss4d_tri(3, 3) result = quadrature(lambda x: 1, q) np.testing.assert_almost_equal(result, 0.25) result = quadrature(lambda x: (x[:, 0] * x[:, 1] * x[:, 2] * x[:, 3])**2, q) np.testing.assert_almost_equal(result, 1.0 / (180.0**2), 10)
def test_tanh_sinh(): q = map_to(tanh_sinh(3), [0, 1]) res = quadrature(lambda x: np.log(x), q) np.testing.assert_almost_equal(res, -1.0) q = map_to(tanh_sinh(3), [0, 1]) res = quadrature(lambda x: np.cos(x), q) np.testing.assert_almost_equal(res, np.sin(1) - np.sin(0)) q = map_to(tanh_sinh(3), [0, 1]) res = quadrature(lambda x: x**2, q) np.testing.assert_almost_equal(res, 1 / 3.0)
def test_cos_a2(): f = lambda x: np.cos(x) exact = -1.48638536036015 for n in range(1, 13): q = map_to(paget(n, 2), [0, 1]) res = quadrature(f, q) np.testing.assert_almost_equal(res, exact)
def test_cos_a1(): f = lambda x: np.cos(x) exact = -0.23981174200056474 for n in range(1, 13): q = map_to(paget(n, 1), [0, 1]) res = quadrature(f, q) np.testing.assert_almost_equal(res, exact)
def test_coincident_real(): def f(p): r = np.sqrt((p[:, 0] - p[:, 2])**2 + (p[:, 1] - p[:, 3])**2) return 1.0 / r est = [quadrature(lambda p: f(p), coincident_quad(nq)) for nq in [9, 10]] np.testing.assert_almost_equal(est[0], est[1])
def test_edge_adj_real(): def f(p): y2 = -p[:, 3] r = np.sqrt((p[:, 0] - p[:, 2])**2 + (p[:, 1] - y2)**2) return 1.0 / r est = [quadrature(lambda p: f(p), edge_adj_quad(nq)) for nq in [9, 10]] np.testing.assert_almost_equal(est[0], est[1])
def check_simple(q, digits): est = quadrature(lambda p: 1.0, q) np.testing.assert_almost_equal(est, 0.25, digits) est = quadrature(lambda p: p[:, 0] * p[:, 1] * p[:, 2] * p[:, 3], q) correct = 1.0 / 576.0 np.testing.assert_almost_equal(est, correct, digits) est = quadrature(lambda p: p[:, 0]**6 * p[:, 1] * p[:, 3], q) correct = 1.0 / 3024.0 np.testing.assert_almost_equal(est, correct, digits) est = quadrature(lambda p: p[:, 0] * p[:, 1] * p[:, 3]**6, q) correct = 1.0 / 1344.0 np.testing.assert_almost_equal(est, correct, digits) est = quadrature(lambda p: p[:, 0] * p[:, 2]**6 * p[:, 3], q) correct = 1.0 / 3024.0 np.testing.assert_almost_equal(est, correct, digits)
def test_gauss2d_tri3(): q = gauss2d_tri(7) result = quadrature(lambda x: np.sin(np.exp(x[:, 0] * x[:, 1] * 5)), q) np.testing.assert_almost_equal(result, 0.426659055902, 4)
def test_gauss2d_tri2(): q = gauss2d_tri(5) result = quadrature(lambda x: x[:, 0]**3 * x[:, 1]**4, q) np.testing.assert_almost_equal(result, 1.0 / 2520.0, 12)
def test_gauss2d_tri1(): q = gauss2d_tri(2) result = quadrature(lambda x: 1, q) np.testing.assert_almost_equal(result, 0.5)
def test_gauss(): est = quadrature(lambda x: x**7, map_to(gaussxw(4), [0, 1])) exact = 1.0 / 8.0 np.testing.assert_almost_equal(est, exact)