def test_solve_spherical_system():
    # a PDE system that can be decoupled into 2 Laplacian equations :math:`\\nabla^2 u = 0` and :math:`\\nabla^2 v = 0`
    pde_system = lambda u, v, r, theta, phi: [
        laplacian_spherical(u, r, theta, phi) + laplacian_spherical(
            v, r, theta, phi),
        laplacian_spherical(u, r, theta, phi) - laplacian_spherical(
            v, r, theta, phi),
    ]

    # constant boundary conditions for u and v; solution should be u = 0 identically and v = 1 identically
    conditions = [
        DirichletBVPSpherical(r_0=0.,
                              f=lambda phi, theta: 0.,
                              r_1=1.,
                              g=lambda phi, theta: 0.),
        DirichletBVPSpherical(r_0=0.,
                              f=lambda phi, theta: 1.,
                              r_1=1.,
                              g=lambda phi, theta: 1.),
    ]

    with pytest.warns(FutureWarning):
        solution, _ = solve_spherical_system(pde_system,
                                             conditions,
                                             0.0,
                                             1.0,
                                             max_epochs=2,
                                             return_best=True)
    assert isinstance(solution, SolutionSpherical)
Example #2
0
def test_solve_spherical_system():
    # a PDE system that can be decoupled into 2 Laplacian equations :math:`\\nabla^2 u = 0` and :math:`\\nabla^2 v = 0`
    pde_system = lambda u, v, r, theta, phi: [
        laplacian_spherical(u, r, theta, phi) + laplacian_spherical(
            v, r, theta, phi),
        laplacian_spherical(u, r, theta, phi) - laplacian_spherical(
            v, r, theta, phi),
    ]

    # constant boundary conditions for u and v; solution should be u = 0 identically and v = 1 identically
    conditions = [
        DirichletBVPSpherical(r_0=0.,
                              f=lambda phi, theta: 0.,
                              r_1=1.,
                              g=lambda phi, theta: 0.),
        DirichletBVPSpherical(r_0=0.,
                              f=lambda phi, theta: 1.,
                              r_1=1.,
                              g=lambda phi, theta: 1.),
    ]

    solution, loss_history = solve_spherical_system(pde_system,
                                                    conditions,
                                                    0.0,
                                                    1.0,
                                                    max_epochs=2,
                                                    return_best=True)
    generator = GeneratorSpherical(512, r_min=0., r_max=1.)
    rs, thetas, phis = generator.get_examples()
    us, vs = solution(rs, thetas, phis, as_type='np')
Example #3
0
def test_solve_spherical_system():
    # a PDE system that can be decoupled into 2 Laplacian equations :math:`\\nabla^2 u = 0` and :math:`\\nabla^2 v = 0`
    pde_system = lambda u, v, r, theta, phi: [
        laplacian_spherical(u, r, theta, phi) + laplacian_spherical(
            v, r, theta, phi),
        laplacian_spherical(u, r, theta, phi) - laplacian_spherical(
            v, r, theta, phi),
    ]

    # constant boundary conditions for u and v; solution should be u = 0 identically and v = 1 identically
    conditions = [
        DirichletBVPSpherical(r_0=0.,
                              f=lambda phi, theta: 0.,
                              r_1=1.,
                              g=lambda phi, theta: 0.),
        DirichletBVPSpherical(r_0=0.,
                              f=lambda phi, theta: 1.,
                              r_1=1.,
                              g=lambda phi, theta: 1.),
    ]

    solution, loss_history = solve_spherical_system(pde_system,
                                                    conditions,
                                                    0.0,
                                                    1.0,
                                                    max_epochs=500,
                                                    return_best=True)
    generator = ExampleGeneratorSpherical(512, r_min=0., r_max=1.)
    rs, thetas, phis = generator.get_examples()
    us, vs = solution(rs, thetas, phis, as_type='np')

    assert np.isclose(us, np.zeros(512),
                      atol=0.005).all(), f"Solution u is not straight 0s: {us}"
    assert np.isclose(vs, np.ones(512),
                      atol=0.005).all(), f"Solution v is not straight 1s: {vs}"

    print("solve_spherical_system tests passed")