Skip to content

Commit fabcd55

Browse files
committed
Pass kwargs to Cofunction.interpolate
1 parent 1f3469f commit fabcd55

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

firedrake/cofunction.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,45 @@ def __imul__(self, expr):
308308
return self
309309
return NotImplemented
310310

311-
def interpolate(self, expression):
312-
r"""Interpolate an expression onto this :class:`Cofunction`.
313-
314-
:param expression: a UFL expression to interpolate
311+
@PETSc.Log.EventDecorator()
312+
def interpolate(
313+
self,
314+
expression,
315+
subset=None,
316+
allow_missing_dofs=False,
317+
default_missing_val=None,
318+
ad_block_tag=None
319+
):
320+
r"""Interpolate a dual expression onto this :class:`Cofunction`.
321+
322+
:param expression: a dual UFL expression to interpolate
323+
:kwarg subset: An optional :class:`pyop2.types.set.Subset` to apply the
324+
interpolation over. Cannot, at present, be used when interpolating
325+
across meshes unless the target mesh is a :func:`.VertexOnlyMesh`.
326+
:kwarg allow_missing_dofs: For interpolation across meshes: allow
327+
degrees of freedom (aka DoFs/nodes) in the target mesh that cannot be
328+
defined on the source mesh. For example, where nodes are point
329+
evaluations, points in the target mesh that are not in the source mesh.
330+
When ``False`` this raises a ``ValueError`` should this occur. When
331+
``True`` the corresponding values are set to zero or to the value
332+
``default_missing_val`` if given. Ignored if interpolating within the
333+
same mesh or onto a :func:`.VertexOnlyMesh` (the behaviour of a
334+
:func:`.VertexOnlyMesh` in this scenario is, at present, set when
335+
it is created).
336+
:kwarg default_missing_val: For interpolation across meshes: the optional
337+
value to assign to DoFs in the target mesh that are outside the source
338+
mesh. If this is not set then zero is used. Ignored if interpolating
339+
within the same mesh or onto a :func:`.VertexOnlyMesh`.
340+
:kwarg ad_block_tag: An optional string for tagging the resulting assemble block on
341+
the Pyadjoint tape.
315342
:returns: this :class:`firedrake.cofunction.Cofunction` object"""
316-
from firedrake import interpolation
317-
interp = interpolation.Interpolate(ufl_expr.Argument(self.function_space().dual(), 0), expression)
318-
return firedrake.assemble(interp, tensor=self)
343+
from firedrake import interpolate, assemble
344+
v, = self.arguments()
345+
interp = interpolate(v, expression,
346+
subset=subset,
347+
allow_missing_dofs=allow_missing_dofs,
348+
default_missing_val=default_missing_val)
349+
return assemble(interp, tensor=self, ad_block_tag=ad_block_tag)
319350

320351
@property
321352
def cell_set(self):

0 commit comments

Comments
 (0)