def test_scalar_2_copy(mesh):
    (V, W) = ScalarSpaces(mesh)
    u = ScalarFunction(V)
    v = function_extend_or_restrict(u, None, W, None, weight=None, copy=True)
    assert isclose(v.vector().get_local(), 1.).all()
    assert u is not v
    assert v.vector().size() == W.dim()
def test_vector_3_weight_copy(mesh):
    (V, W) = VectorSpaces(mesh)
    u = VectorFunction(V)
    v = function_extend_or_restrict(u, None, W, None, weight=2., copy=True)
    assert isclose(v.vector().get_local(), 2.).all()
    assert u is not v
    assert v.vector().size() == W.dim()
def test_mixed_function_extension_automatic_3_weight_copy(mesh):
    (V, W) = MixedSpacesExtensionAutomatic(mesh)
    s = MixedFunctionExtensionAutomatic(V)
    extended_s = function_extend_or_restrict(s, None, W, None, weight=2., copy=True)
    assert extended_s.vector().size() == W.dim()
    (u, p) = extended_s.split(deepcopy=True)
    assert isclose(u.vector().get_local(), 2.).all()
    assert isclose(p.vector().get_local(), 0.).all()
def test_mixed_function_extension_solve_ambiguity_with_components_3_weight_copy(mesh):
    (V, W) = MixedSpacesExtensionSolveAmbiguityWithComponents(mesh)
    s = MixedFunctionExtensionSolveAmbiguityWithComponents(V)
    extended_s = function_extend_or_restrict(s, None, W, "s", weight=2., copy=True)
    assert extended_s.vector().size() == W.dim()
    (u, p) = extended_s.split(deepcopy=True)
    assert isclose(u.vector().get_local(), 2.).all()
    assert isclose(p.vector().get_local(), 0.).all()
def test_mixed_function_extension_non_ambiguous_vector_element_3_weight_copy(mesh):
    (V, W) = MixedSpacesExtensionNonAmbiguousVectorElement(mesh)
    s = MixedFunctionExtensionNonAmbiguousVectorElement(V)
    extended_s = function_extend_or_restrict(s, None, W, 0, weight=2., copy=True)
    assert extended_s.vector().size() == W.dim()
    (u, p) = extended_s.split(deepcopy=True)
    assert isclose(u.vector().get_local(), 2.).all()
    assert isclose(p.vector().get_local(), 0.).all()
def test_mixed_to_mixed_function_copy_component_to_same_location_2_int_copy(mesh):
    (V, W) = MixedToMixedSpacesCopyComponentToSameLocation(mesh)
    u = MixedToMixedFunctionCopyComponentToSameLocation(V)
    copied_u = function_extend_or_restrict(u, 0, W, 0, weight=None, copy=True)
    assert copied_u.vector().size() == W.dim()
    (copied_ux, copied_uy) = copied_u.split(deepcopy=True)
    assert isclose(copied_ux.vector().get_local(), 1.).all()
    assert isclose(copied_uy.vector().get_local(), 0.).all()
def test_mixed_to_mixed_function_copy_component_to_different_location_6_str_weight_copy(mesh):
    (V, W) = MixedToMixedSpacesCopyComponentToDifferentLocation(mesh)
    u = MixedToMixedFunctionCopyComponentToDifferentLocation(V)
    copied_u = function_extend_or_restrict(u, "ux", W, "uy", weight=2., copy=True)
    assert copied_u.vector().size() == W.dim()
    (copied_ux, copied_uy) = copied_u.split(deepcopy=True)
    assert isclose(copied_ux.vector().get_local(), 0.).all()
    assert isclose(copied_uy.vector().get_local(), 2.).all()
def test_mixed_function_extension_from_sub_element_solve_ambiguity_with_components_str_3_weight_copy(mesh):
    (V, W) = MixedSpacesExtensionFromSubElementSolveAmbiguityWithComponents(mesh, str)
    s = MixedFunctionExtensionFromSubElementSolveAmbiguityWithComponents(V)
    extended_s = function_extend_or_restrict(s, None, W, "ux", weight=2., copy=True)
    assert extended_s.vector().size() == W.dim()
    (u, p) = extended_s.split(deepcopy=True)
    (ux, uy) = u.split(deepcopy=True)
    assert isclose(ux.vector().get_local(), 2.).all()
    assert isclose(uy.vector().get_local(), 0.).all()
    assert isclose(p.vector().get_local(), 0.).all()
def test_mixed_to_mixed_function_copy_sub_component_to_different_location_3_tuple_weight_copy(mesh):
    (V, W) = MixedToMixedSpacesCopySubComponentToDifferentLocation(mesh)
    u = MixedToMixedFunctionCopySubComponentToDifferentLocation(V)
    copied_u = function_extend_or_restrict(u, (0, 0), W, (1, 0), weight=2., copy=True)
    assert copied_u.vector().size() == W.dim()
    (copied_ux, copied_uy) = copied_u.split(deepcopy=True)
    (copied_uxx, copied_uxy) = copied_ux.split(deepcopy=True)
    (copied_uyx, copied_uyy) = copied_uy.split(deepcopy=True)
    assert isclose(copied_uxx.vector().get_local(), 0.).all()
    assert isclose(copied_uxy.vector().get_local(), 0.).all()
    assert isclose(copied_uyx.vector().get_local(), 2.).all()
    assert isclose(copied_uyy.vector().get_local(), 0.).all()
def test_mixed_to_mixed_function_copy_component_to_same_location_1_int_fail(mesh):
    (V, W) = MixedToMixedSpacesCopyComponentToSameLocation(mesh)
    u = MixedToMixedFunctionCopyComponentToSameLocation(V)
    with pytest.raises(AssertionError) as excinfo:
        function_extend_or_restrict(u, 0, W, 0, weight=None, copy=False)
    assert str(excinfo.value) == "It is not possible to extract function components without copying the vector"
def test_mixed_function_restriction_to_sub_element_solve_ambiguity_with_components_4_str_y_fail(mesh):
    (V, W) = MixedSpacesRestrictionToSubElementSolveAmbiguityWithComponents(mesh)
    up = MixedFunctionRestrictionToSubElementSolveAmbiguityWithComponents(V)
    with pytest.raises(AssertionError) as excinfo:
        function_extend_or_restrict(up, "uy", W, None, weight=None, copy=False)
    assert str(excinfo.value) == "It is not possible to extract function components without copying the vector"
def test_mixed_function_restriction_to_sub_element_solve_ambiguity_with_components_6_str_y_weight_copy(mesh):
    (V, W) = MixedSpacesRestrictionToSubElementSolveAmbiguityWithComponents(mesh)
    up = MixedFunctionRestrictionToSubElementSolveAmbiguityWithComponents(V)
    uy = function_extend_or_restrict(up, "uy", W, None, weight=2., copy=True)
    assert uy.vector().size() == W.dim()
    assert isclose(uy.vector().get_local(), 6.).all()
def test_mixed_function_restriction_to_sub_element_ambiguous_1_fail(mesh):
    (V, W) = MixedSpacesRestrictionToSubElementAmbiguous(mesh)
    up = MixedFunctionRestrictionToSubElementAmbiguous(V)
    with pytest.raises(RuntimeError) as excinfo:
        function_extend_or_restrict(up, None, W, None, weight=None, copy=False)
    assert str(excinfo.value) == "Ambiguity when querying _function_spaces_lt"
def test_mixed_function_restriction_to_sub_element_solve_ambiguity_with_components_2_tuple_x_copy(mesh):
    (V, W) = MixedSpacesRestrictionToSubElementSolveAmbiguityWithComponents(mesh)
    up = MixedFunctionRestrictionToSubElementSolveAmbiguityWithComponents(V)
    ux = function_extend_or_restrict(up, (0, 0), W, None, weight=None, copy=True)
    assert ux.vector().size() == W.dim()
    assert isclose(ux.vector().get_local(), 1.).all()
def test_mixed_function_restriction_solve_ambiguity_with_components_second_sub_element_3_str_weight_copy(mesh):
    (V, W) = MixedSpacesRestrictionSolveAmbiguityWithComponents(mesh, 1)
    up = MixedFunctionRestrictionSolveAmbiguityWithComponents(V)
    p = function_extend_or_restrict(up, "p", W, None, weight=2., copy=True)
    assert p.vector().size() == W.dim()
    assert isclose(p.vector().get_local(), 4.).all()
def test_mixed_function_extension_from_sub_element_solve_ambiguity_with_components_str_1_fail(mesh):
    (V, W) = MixedSpacesExtensionFromSubElementSolveAmbiguityWithComponents(mesh, str)
    s = MixedFunctionExtensionFromSubElementSolveAmbiguityWithComponents(V)
    with pytest.raises(AssertionError) as excinfo:
        function_extend_or_restrict(s, None, W, "ux", weight=None, copy=False)
    assert str(excinfo.value) == "It is not possible to extract function components without copying the vector"
def test_mixed_function_extension_non_ambiguous_vector_element_1_fail(mesh):
    (V, W) = MixedSpacesExtensionNonAmbiguousVectorElement(mesh)
    s = MixedFunctionExtensionNonAmbiguousVectorElement(V)
    with pytest.raises(AssertionError) as excinfo:
        function_extend_or_restrict(s, None, W, 0, weight=None, copy=False)
    assert str(excinfo.value) == "It is not possible to extract function components without copying the vector"
def test_mixed_function_restriction_automatic_first_sub_element_2_copy(mesh):
    (V, W) = MixedSpacesRestrictionAutomatic(mesh, 0)
    up = MixedFunctionRestrictionAutomatic(V)
    u = function_extend_or_restrict(up, None, W, None, weight=None, copy=True)
    assert u.vector().size() == W.dim()
    assert isclose(u.vector().get_local(), 1.).all()
def test_mixed_function_restriction_automatic_second_sub_element_1_fail(mesh):
    (V, W) = MixedSpacesRestrictionAutomatic(mesh, 1)
    up = MixedFunctionRestrictionAutomatic(V)
    with pytest.raises(AssertionError) as excinfo:
        function_extend_or_restrict(up, None, W, None, weight=None, copy=False)
    assert str(excinfo.value) == "It is not possible to restrict functions without copying the vector"
def test_vector_1(mesh):
    (V, W) = VectorSpaces(mesh)
    u = VectorFunction(V)
    v = function_extend_or_restrict(u, None, W, None, weight=None, copy=False)
    assert isclose(v.vector().get_local(), 1.).all()
    assert u is v
def test_mixed_function_extension_ambiguous_1_fail(mesh):
    (V, W) = MixedSpacesExtensionAmbiguous(mesh)
    s = MixedFunctionExtensionAmbiguous(V)
    with pytest.raises(RuntimeError) as excinfo:
        function_extend_or_restrict(s, None, W, None, weight=None, copy=False)
    assert str(excinfo.value) == "Ambiguity when querying _function_spaces_lt"
def test_mixed_function_restriction_automatic_second_sub_element_3_weight_copy(mesh):
    (V, W) = MixedSpacesRestrictionAutomatic(mesh, 1)
    up = MixedFunctionRestrictionAutomatic(V)
    p = function_extend_or_restrict(up, None, W, None, weight=2., copy=True)
    assert p.vector().size() == W.dim()
    assert isclose(p.vector().get_local(), 4.).all()
def test_mixed_function_restriction_solve_ambiguity_with_components_first_sub_element_5_str_copy(mesh):
    (V, W) = MixedSpacesRestrictionSolveAmbiguityWithComponents(mesh, 0)
    up = MixedFunctionRestrictionSolveAmbiguityWithComponents(V)
    u = function_extend_or_restrict(up, "u", W, None, weight=None, copy=True)
    assert u.vector().size() == W.dim()
    assert isclose(u.vector().get_local(), 1.).all()
def test_mixed_to_mixed_function_copy_sub_component_to_different_location_4_str_fail(mesh):
    (V, W) = MixedToMixedSpacesCopySubComponentToDifferentLocation(mesh)
    u = MixedToMixedFunctionCopySubComponentToDifferentLocation(V)
    with pytest.raises(AssertionError) as excinfo:
        function_extend_or_restrict(u, "uxx", W, "uyx", weight=None, copy=False)
    assert str(excinfo.value) == "It is not possible to extract function components without copying the vector"
def test_mixed_function_extension_automatic_1_fail(mesh):
    (V, W) = MixedSpacesExtensionAutomatic(mesh)
    s = MixedFunctionExtensionAutomatic(V)
    with pytest.raises(AssertionError) as excinfo:
        function_extend_or_restrict(s, None, W, None, weight=None, copy=False)
    assert str(excinfo.value) == "It is not possible to extend functions without copying the vector"