예제 #1
0
 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"))
예제 #2
0
    def f(x):
        degree = 19
        data = [
            (x[0], _f((math.sqrt(1.0 / 3.0), 3))),
            (x[1], _f2(x[6])),
            (x[2], _f2(x[7])),
            (x[3], _f2(x[8])),
            (x[4], _f2(x[9])),
            (x[5], _f11(x[10], x[11])),
        ]

        points, weights = untangle(data)
        azimuthal, polar = cartesian_to_spherical(points).T

        out = orthopy.sphere.tree_sph(
            polar, azimuthal, degree, standardization="quantum mechanic"
        )

        A = numpy.array([row for level in out for row in level])
        out = numpy.dot(A, weights)
        out[0] -= 1.0 / (2 * numpy.sqrt(numpy.pi))
        v = numpy.sqrt(out.real ** 2 + out.imag ** 2)
        norm_v = numpy.sqrt(numpy.vdot(v, v))
        print(norm_v)
        return norm_v
예제 #3
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

    # We're using the spherical harmonic iterator here; it's much less memory-intensive
    # than computing the full tree at once. Unfortunately, we cannot use
    # scheme.integrate with it, but that's okay.
    azimuthal, polar = cartesian_to_spherical(scheme.points).T
    sph_iterator = orthopy.sphere.Iterator(polar,
                                           azimuthal,
                                           standardization="quantum mechanic")
    degree = None
    for k in range(scheme.degree + 2):
        vals = next(sph_iterator)
        approximate = 4 * numpy.pi * numpy.dot(vals, scheme.weights)

        # construct exact value
        if k == 0:
            exact = [numpy.sqrt(4 * numpy.pi)]
        else:
            exact = numpy.zeros_like(approximate)

        if numpy.any(numpy.abs(approximate - exact) > tol):
            degree = k - 1
            break

    assert degree == scheme.degree, "{}  --  Observed: {}, expected: {}".format(
        scheme.name, degree, scheme.degree)
    return