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(fenics_to_numpy(test_input), expected)
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(fenics_to_numpy(test_input), expected)
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, fenics_to_numpy(u))
def test_fenics_to_numpy_constant(test_input, expected): assert numpy.allclose(fenics_to_numpy(test_input), expected)