Skip to content

BCs for cross-mesh interpolation#5165

Open
leo-collins wants to merge 7 commits into
mainfrom
leo/cross-mesh-bcs
Open

BCs for cross-mesh interpolation#5165
leo-collins wants to merge 7 commits into
mainfrom
leo/cross-mesh-bcs

Conversation

@leo-collins

Copy link
Copy Markdown
Contributor

Support BCs for cross-mesh interpolation matrices

@leo-collins leo-collins requested a review from pbrubeck June 11, 2026 16:02
row_mask = self._bc_mask(row_arg.function_space(), bcs)
col_mask = self._bc_mask(col_arg.function_space(), bcs)
with row_mask.dat.vec_ro as r, col_mask.dat.vec_ro as c:
mat.diagonalScale(r, c)

@pbrubeck pbrubeck Jun 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use mat.zeroRowsColumnsLocal() instead.

Comment on lines +566 to +574
def _bc_mask(self, space: WithGeometry, bcs: Iterable[DirichletBC]) -> Function:
"""Return a 0/1 mask over `space` which is zero at boundary condition nodes
"""
space = space.dual() if is_dual(space) else space
f = Function(space).assign(1.0)
for bc in bcs:
if bc.function_space() == space:
bc.zero(f)
return f

@pbrubeck pbrubeck Jun 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is reinventing the wheel. We have some functions that do similar things scattered all over the place. My recommendation is to move bcdofs from preconditioners/patch.py to bcs.py and use it instead.

if self.ufl_interpolate.is_adjoint:
I = Matrix(interpolate(TestFunction(source_space), self.target_space), res)
return assemble(action(I, self._interpolate_from_quadrature)).petscmat
res = assemble(action(I, self._interpolate_from_quadrature)).petscmat

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the right thing be to reuse the support that assemble has for bcs?

Suggested change
res = assemble(action(I, self._interpolate_from_quadrature)).petscmat
res = assemble(action(I, self._interpolate_from_quadrature), bcs=bcs).petscmat

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VomOntoVomInterpolator doesn't support BCs. I suppose we could do what this PR is doing for VomOntoVom and then it should work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the BCs that the user provided are not defined on a VOM FunctionSpace. Why do we need to support BCs for VomOntoVom?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do res = assemble(interp_expr, mat_type=mat_type, bcs=bcs).petscmat then the BCs get passed through to VomOntoVomInterpolator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a bug, we should only set BCs on the final matrix-matrix product

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants