def test_scheme(scheme, tol):
    # Test integration until we get to a polynomial degree `d` that can no
    # longer be integrated exactly. The scheme's degree is `d-1`.
    assert scheme.points.dtype in [numpy.float64, numpy.int64], scheme.name
    assert scheme.weights.dtype in [numpy.float64, numpy.int64], scheme.name

    def eval_orthopolys(x):
        return numpy.concatenate(
            orthopy.quadrilateral.tree(x, scheme.degree + 1, symbolic=False))

    quad = quadpy.quadrilateral.rectangle_points([-1.0, +1.0], [-1.0, +1.0])
    vals = quadpy.quadrilateral.integrate(eval_orthopolys, quad, scheme)
    # Put vals back into the tree structure:
    # len(approximate[k]) == k+1
    approximate = [
        vals[k * (k + 1) // 2:(k + 1) * (k + 2) // 2]
        for k in range(scheme.degree + 2)
    ]

    exact = [numpy.zeros(k + 1) for k in range(scheme.degree + 2)]
    exact[0][0] = 2.0

    degree = check_degree_ortho(approximate, exact, abs_tol=tol)

    assert degree >= scheme.degree, "Observed: {}, expected: {}".format(
        degree, scheme.degree)
    return
Exemple #2
0
def test_scheme(scheme, tol=1.0e-14):
    assert scheme.points.dtype == numpy.float64, scheme.name
    assert scheme.weights.dtype == numpy.float64, scheme.name

    # degree = check_degree(
    #     lambda poly: scheme.integrate(poly),
    #     integrate_monomial_over_enr2,
    #     2,
    #     scheme.degree + 1,
    #     tol=tol,
    # )
    # assert degree == scheme.degree, "{}    Observed: {}   expected: {}".format(
    #     scheme.name, degree, scheme.degree
    # )

    def eval_orthopolys(x):
        return numpy.concatenate(
            orthopy.e2r2.tree(x, scheme.degree + 1, symbolic=False))

    vals = scheme.integrate(eval_orthopolys)
    # Put vals back into the tree structure:
    # len(approximate[k]) == k+1
    approximate = [
        vals[k * (k + 1) // 2:(k + 1) * (k + 2) // 2]
        for k in range(scheme.degree + 2)
    ]

    exact = [numpy.zeros(k + 1) for k in range(scheme.degree + 2)]
    exact[0][0] = numpy.sqrt(numpy.pi)

    degree = check_degree_ortho(approximate, exact, abs_tol=tol)

    assert degree >= scheme.degree, "{} -- Observed: {}, expected: {}".format(
        scheme.name, degree, scheme.degree)
    return
Exemple #3
0
def test_scheme(scheme, tol):
    assert scheme.points.dtype in [numpy.float64, numpy.int64], scheme.name
    assert scheme.weights.dtype in [numpy.float64, numpy.int64], scheme.name

    triangle = numpy.array([[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]])

    def eval_orthopolys(x):
        bary = numpy.array([x[0], x[1], 1.0 - x[0] - x[1]])
        out = numpy.concatenate(
            orthopy.triangle.tree(bary,
                                  scheme.degree + 1,
                                  'normal',
                                  symbolic=False))
        return out

    vals = quadpy.triangle.integrate(eval_orthopolys, triangle, scheme)
    # Put vals back into the tree structure:
    # len(approximate[k]) == k+1
    approximate = [
        vals[k * (k + 1) // 2:(k + 1) * (k + 2) // 2]
        for k in range(scheme.degree + 2)
    ]

    exact = [numpy.zeros(k + 1) for k in range(scheme.degree + 2)]
    exact[0][0] = numpy.sqrt(2.0) / 2

    degree = check_degree_ortho(approximate, exact, abs_tol=tol)

    assert degree >= scheme.degree, \
        'Observed: {}, expected: {}'.format(degree, scheme.degree)
    return
Exemple #4
0
def test_scheme_cartesian(scheme, tol):
    def sph_tree_cartesian(x):
        azimuthal, polar = cartesian_to_spherical(x.T).T
        return numpy.concatenate(
            orthopy.sphere.tree_sph(polar,
                                    azimuthal,
                                    scheme.degree + 1,
                                    standardization="quantum mechanic"))

    assert scheme.points.dtype == numpy.float64, scheme.name
    assert scheme.weights.dtype == numpy.float64, scheme.name

    vals = scheme.integrate(sph_tree_cartesian,
                            center=numpy.array([0, 0, 0]),
                            radius=1)
    # Put vals back into the tree structure:
    # len(approximate[k]) == k+1
    approximate = [vals[k**2:(k + 1)**2] for k in range(scheme.degree + 2)]

    exact = [numpy.zeros(len(s)) for s in approximate]
    exact[0][0] = numpy.sqrt(4 * numpy.pi)

    degree = check_degree_ortho(approximate, exact, abs_tol=tol)

    assert degree == scheme.degree, "{}  --  Observed: {}, expected: {}".format(
        scheme.name, degree, scheme.degree)
    return
Exemple #5
0
def test_scheme(scheme):
    assert scheme.points.dtype in [numpy.float64, numpy.int64], scheme.name
    assert scheme.weights.dtype in [numpy.float64, numpy.int64], scheme.name

    print(scheme)

    n = scheme.dim
    cn_limits = [[-1.0, 1.0]] * n
    cn = quadpy.cn.ncube_points(*cn_limits)

    # degree = check_degree(
    #     lambda poly: scheme.integrate(poly, cn),
    #     lambda exp: integrate_monomial_over_cn(cn_limits, exp),
    #     n,
    #     scheme.degree + 1,
    #     tol=tol,
    # )
    # assert degree >= scheme.degree, "observed: {}, expected: {}".format(
    #     degree, scheme.degree
    # )

    def eval_orthopolys(x):
        return numpy.concatenate(
            orthopy.ncube.tree(x, scheme.degree + 1, symbolic=False))

    vals = scheme.integrate(eval_orthopolys, cn)

    # Put vals back into the tree structure:
    # len(approximate[k]) == k+1
    approximate = [
        vals[numpy.prod(range(k, k + n)) //
             math.factorial(n):numpy.prod(range(k + 1, k + 1 + n)) //
             math.factorial(n)] for k in range(scheme.degree + 2)
    ]

    exact = [numpy.zeros(len(s)) for s in approximate]
    exact[0][0] = numpy.sqrt(2.0)**n

    degree, err = check_degree_ortho(approximate,
                                     exact,
                                     abs_tol=scheme.test_tolerance)

    assert (
        degree >= scheme.degree
    ), "{} (dim={})  --  observed: {}, expected: {} (max err: {:.3e})".format(
        scheme.name, n, degree, scheme.degree, err)
Exemple #6
0
def test_scheme(scheme, print_degree=False):
    assert scheme.points.dtype in [numpy.float64, numpy.int64], scheme.name
    assert scheme.weights.dtype in [numpy.float64, numpy.int64], scheme.name

    print(scheme)

    x = [-1.0, +1.0]
    y = [-1.0, +1.0]
    z = [-1.0, +1.0]
    hexa = quadpy.c3.cube_points(x, y, z)

    # degree = check_degree(
    #     lambda poly: scheme.integrate(poly, hexa),
    #     lambda k: _integrate_exact2(k, x[0], x[1], y[0], y[1], z[0], z[1]),
    #     3,
    #     scheme.degree + 1,
    #     tol=tol,
    # )
    # if print_degree:
    #     print("Detected degree {}, scheme degree {}.".format(degree, scheme.degree))
    # assert degree == scheme.degree, scheme.name

    def eval_orthopolys(x):
        return numpy.concatenate(
            orthopy.hexahedron.tree(x, scheme.degree + 1, symbolic=False))

    vals = scheme.integrate(eval_orthopolys, hexa)
    # Put vals back into the tree structure:
    # len(approximate[k]) == k+1
    approximate = [
        vals[k * (k + 1) * (k + 2) // 6:(k + 1) * (k + 2) * (k + 3) // 6]
        for k in range(scheme.degree + 2)
    ]

    exact = [numpy.zeros(len(s)) for s in approximate]
    exact[0][0] = numpy.sqrt(2.0) * 2

    degree, err = check_degree_ortho(approximate,
                                     exact,
                                     abs_tol=scheme.test_tolerance)

    assert (degree >= scheme.degree
            ), "{} -- Observed: {}, expected: {} (max err: {:.3e})".format(
                scheme.name, degree, scheme.degree, err)
Exemple #7
0
def test_scheme_spherical(scheme, tol):
    def sph_tree(azimuthal, polar):
        return numpy.concatenate(
            orthopy.sphere.tree_sph(polar,
                                    azimuthal,
                                    scheme.degree + 1,
                                    standardization="quantum mechanic"))

    vals = scheme.integrate_spherical(sph_tree)
    # Put vals back into the tree structure:
    # len(approximate[k]) == k+1
    approximate = [vals[k**2:(k + 1)**2] for k in range(scheme.degree + 2)]

    exact = [numpy.zeros(len(s)) for s in approximate]
    exact[0][0] = numpy.sqrt(4 * numpy.pi)

    degree = check_degree_ortho(approximate, exact, abs_tol=tol)

    assert degree == scheme.degree, "Observed: {}, expected: {}".format(
        degree, scheme.degree)
    return
Exemple #8
0
def test_scheme(scheme):
    assert scheme.points.dtype == numpy.float64, scheme.name
    assert scheme.weights.dtype == numpy.float64, scheme.name

    print(scheme)

    # degree = check_degree(
    #     lambda poly: scheme.integrate(poly, [0.0, 0.0], 1.0),
    #     integrate_monomial_over_unit_nball,
    #     2,
    #     scheme.degree + 1,
    #     tol=tol,
    # )
    # assert degree == scheme.degree, "{}  -- Observed: {}   expected: {}".format(
    #     scheme.name, degree, scheme.degree
    # )

    def eval_orthopolys(x):
        return numpy.concatenate(
            orthopy.disk.tree(x, scheme.degree + 1, symbolic=False))

    vals = scheme.integrate(eval_orthopolys, [0, 0], 1)
    # Put vals back into the tree structure:
    # len(approximate[k]) == k+1
    approximate = [
        vals[k * (k + 1) // 2:(k + 1) * (k + 2) // 2]
        for k in range(scheme.degree + 2)
    ]

    exact = [numpy.zeros(k + 1) for k in range(scheme.degree + 2)]
    exact[0][0] = numpy.sqrt(numpy.pi)

    degree, err = check_degree_ortho(approximate,
                                     exact,
                                     abs_tol=scheme.test_tolerance)

    assert (degree >= scheme.degree
            ), "{} -- Observed: {}, expected: {} (max err: {:.3e})".format(
                scheme.name, degree, scheme.degree, err)