Exemplo n.º 1
0
def test_fenics_to_numpy_function():
    # Functions in DG0 have nodes at centers of finite element cells
    mesh = fenics.UnitIntervalMesh(10)
    V = fenics.FunctionSpace(mesh, "DG", 0)
    test_input = fenics.interpolate(fenics.Expression("x[0]", degree=1), V)
    expected = numpy.linspace(0.05, 0.95, num=10)
    assert numpy.allclose(to_numpy(test_input), expected)
Exemplo n.º 2
0
def test_firedrake_to_numpy_function():
    # Functions in DG0 have nodes at centers of finite element cells
    mesh = firedrake.UnitIntervalMesh(10)
    V = firedrake.FunctionSpace(mesh, "DG", 0)
    x = firedrake.SpatialCoordinate(mesh)
    test_input = firedrake.interpolate(x[0], V)
    expected = numpy.linspace(0.05, 0.95, num=10)
    assert numpy.allclose(to_numpy(test_input), expected)
Exemplo n.º 3
0
def test_fenics_to_numpy_mixed_function():
    # Functions in DG0 have nodes at centers of finite element cells
    mesh = fenics.UnitIntervalMesh(10)
    vec_dim = 4
    V = fenics.VectorFunctionSpace(mesh, "DG", 0, dim=vec_dim)
    test_input = fenics.interpolate(
        fenics.Expression(vec_dim * ("x[0]", ), element=V.ufl_element()), V)
    expected = numpy.linspace(0.05, 0.95, num=10)
    expected = numpy.reshape(numpy.tile(expected, (4, 1)).T, V.dim())
    assert numpy.allclose(to_numpy(test_input), expected)
Exemplo n.º 4
0
def test_firedrake_to_numpy_mixed_function():
    # Functions in DG0 have nodes at centers of finite element cells
    mesh = firedrake.UnitIntervalMesh(10)
    vec_dim = 4
    V = firedrake.VectorFunctionSpace(mesh, "DG", 0, dim=vec_dim)
    x = firedrake.SpatialCoordinate(mesh)
    test_input = firedrake.interpolate(firedrake.as_vector(vec_dim * (x[0], )),
                                       V)
    expected = numpy.linspace(0.05, 0.95, num=10)
    expected = numpy.reshape(numpy.tile(expected, (4, 1)).T, V.dim())
    assert numpy.allclose(to_numpy(test_input), expected)
Exemplo n.º 5
0
def test_fenics_forward():
    numpy_output, _, _, _ = evaluate_primal(solve_fenics, templates, *inputs)
    u = solve_fenics(fa.Constant(0.5), fa.Constant(0.6))
    assert np.allclose(numpy_output, to_numpy(u))
Exemplo n.º 6
0
def test_firedrake_to_numpy_constant(test_input, expected):
    assert numpy.allclose(to_numpy(test_input), expected)
Exemplo n.º 7
0
def test_firedrake_forward():
    numpy_output, _, _, _ = evaluate_primal(solve_firedrake, templates,
                                            *inputs)
    u = solve_firedrake(firedrake.Constant(0.5), firedrake.Constant(0.6))
    assert np.allclose(numpy_output, to_numpy(u))
Exemplo n.º 8
0
def test_fenics_to_numpy_constant(test_input, expected):
    assert numpy.allclose(to_numpy(test_input), expected)