Exemple #1
0
def test_numpy_to_fenics_function():
    test_input = numpy.linspace(0.05, 0.95, num=10)
    mesh = fenics.UnitIntervalMesh(10)
    V = fenics.FunctionSpace(mesh, "DG", 0)
    template = fenics.Function(V)
    fenics_test_input = from_numpy(test_input, template)
    expected = fenics.interpolate(fenics.Expression("x[0]", degree=1), V)
    assert numpy.allclose(fenics_test_input.vector().get_local(),
                          expected.vector().get_local())
Exemple #2
0
def test_numpy_to_firedrake_function():
    test_input = numpy.linspace(0.05, 0.95, num=10)
    mesh = firedrake.UnitIntervalMesh(10)
    V = firedrake.FunctionSpace(mesh, "DG", 0)
    template = firedrake.Function(V)
    firedrake_test_input = from_numpy(test_input, template)
    x = firedrake.SpatialCoordinate(mesh)
    expected = firedrake.interpolate(x[0], V)
    assert numpy.allclose(firedrake_test_input.vector().get_local(),
                          expected.vector().get_local())
Exemple #3
0
def test_numpy_to_firedrake_constant(test_input, expected):
    firedrake_test_input = from_numpy(test_input, firedrake.Constant(0.0))
    assert numpy.allclose(firedrake_test_input.values(), expected.values())
def from_jax(
    jax_array: JAXArray, fem_variable: BackendVariable
) -> BackendVariable:  # noqa: C901
    """Convert numpy/jax array to FEniCS/Firedrake/pyadjoint variable"""
    return from_numpy(jax_to_fenics_numpy(jax_array, fem_variable), fem_variable)
Exemple #5
0
def test_numpy_to_fenics_constant(test_input, expected):
    fenics_test_input = from_numpy(test_input, fenics.Constant(0.0))
    assert numpy.allclose(fenics_test_input.values(), expected.values())