Skip to content

Support for Function.assign on Submesh #4398

Open
@pbrubeck

Description

@pbrubeck

Describe the current issue
Currently Function.assign is not implemented across a Submesh and its parent.

Describe the solution you'd like
DOF-wise assignment of Functions with the same UFL element but on Submeshes should be trivial to implement by indexing.

MFE:

from firedrake import *
mesh = UnitSquareMesh(2, 2)
M = FunctionSpace(mesh, "DG", 0)
m = Function(M)
m.dat.data[0] = 1

rmesh = RelabeledMesh(mesh, [m], [100])
submesh = Submesh(rmesh, rmesh.geometric_dimension(), 100)

V = FunctionSpace(rmesh, "DG", 0)
Vsub = V.reconstruct(mesh=submesh)
u = Function(V)
usub = Function(Vsub)
usub.assign(1)

u.assign(usub, subset=rmesh.cell_subset(100))
print(u.dat.data)

Error message:

Traceback (most recent call last):
  File "/home/pbrubeck/git/dphil_thesis/static_condensation/snippets/bug_submesh_assign.py", line 16, in <module>
    u.assign(usub, subset=rmesh.cell_subset(100))
  File "petsc4py/PETSc/Log.pyx", line 188, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "petsc4py/PETSc/Log.pyx", line 189, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "/home/pbrubeck/firedrake/src/firedrake/firedrake/adjoint_utils/function.py", line 116, in wrapper
    ret = assign(self, other, *args, **kwargs)
  File "/home/pbrubeck/firedrake/src/firedrake/firedrake/function.py", line 461, in assign
    Assigner(self, expr, subset).assign()
  File "/home/pbrubeck/firedrake/src/firedrake/firedrake/assign.py", line 155, in __init__
    raise ValueError("All functions in the expression must use the same "
ValueError: All functions in the expression must use the same mesh as the assignee

Describe alternatives you've considered
Function.interpolate works with Submesh, but does redundant work by evaluating the degrees of freedom of the element on itself. This of course will fail for elements where dual evaluation is not implemented.

Additional info
Add any other information here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions