diff --git a/firedrake/assign.py b/firedrake/assign.py index 8d5f4789d0..944c70ad4a 100644 --- a/firedrake/assign.py +++ b/firedrake/assign.py @@ -161,13 +161,15 @@ def __init__(self, assignee, expression, subset=None): if coeff.ufl_element() != assignee.ufl_element(): raise ValueError("All functions in the expression must have the same " "element as the assignee") - source_meshes.add(extract_unique_domain(coeff)) + source_meshes.add(extract_unique_domain(coeff, expand_mesh_sequence=False)) if len(source_meshes) == 0: pass elif len(source_meshes) == 1: - target_mesh = extract_unique_domain(assignee) + target_mesh = extract_unique_domain(assignee, expand_mesh_sequence=False) source_mesh, = source_meshes - if target_mesh.submesh_youngest_common_ancester(source_mesh) is None: + if target_mesh is source_mesh: + pass + elif target_mesh.submesh_youngest_common_ancester(source_mesh) is None: raise ValueError( "All functions in the expression must be defined on a single domain " "that is in the same submesh family as domain of the assignee" diff --git a/tests/firedrake/regression/test_multiple_domains.py b/tests/firedrake/regression/test_multiple_domains.py index 1a4443fc43..fb7c9bf04a 100644 --- a/tests/firedrake/regression/test_multiple_domains.py +++ b/tests/firedrake/regression/test_multiple_domains.py @@ -205,3 +205,17 @@ def test_multi_domain_assemble(): a = inner(u[0], v[0])*dx(domain=mesh1) + inner(u[1], v[1])*dx(domain=mesh2) A = assemble(a) assert A.M.values.shape == (V.dim(), V.dim()) + + +def test_multidomain_assign_function(mesh1, mesh3): + V1 = FunctionSpace(mesh1, "DG", 0) + V2 = FunctionSpace(mesh3, "CG", 1) + Z = V1 * V2 + z = Function(Z) + z.subfunctions[0].assign(42) + z.subfunctions[1].assign(67) + + w = Function(Z) + w.assign(z) + for zsub, wsub in zip(z.subfunctions, w.subfunctions): + assert np.allclose(zsub.dat.data, wsub.dat.data)