PCPatch: support exterior facet integrals#4878
PCPatch: support exterior facet integrals#4878miguelcoolchips wants to merge 1 commit intofiredrakeproject:mainfrom
Conversation
|
A significant proportion of the changes in this PR are just reformatting. This makes it quite difficult to identify and review the actual changes. |
You are right. Do you know if Firedrake has formatting rules? I could not see such a thing in the pyproject.toml file PS: I changed this PR to draft until the PETSc MR has been merged |
Thanks! If you run |
The formatting/linting is detailed in the contributing guide. https://www.firedrakeproject.org/contribute.html#pre-submission-checklist |
Description
This PR depends on this PETSc MR: https://gitlab.com/petsc/petsc/-/merge_requests/9024
Summary
PatchPC currently supports cell integrals (dx) and interior facet integrals (dS), but raises NotImplementedError when a form contains exterior facet integrals (ds). This PR extends PatchPC to handle exterior_facet integral types, enabling problems that involve boundary integrals -- such as DG formulations with boundary flux terms or Nitsche weak boundary conditions -- to be solved with patch-based preconditioners.
Motivation
Many finite element formulations naturally produce exterior facet integrals. For example:
Previously, any such form passed to PatchPC would fail with:
This blocked the use of
PatchPC(including Vanka relaxation in multigrid) for an important class of problems.Changes
firedrake/preconditioners/patch.pymatrix_funptrandresidual_funptr: Extended to accept"exterior_facet"as a valid integral type. Exterior facet kernels are accumulated into a newext_facet_kernelslist and returned alongside cell and interior facet kernels. When the integral type is"exterior_facet", the exterior facet local numbering dat (mesh.exterior_facets.local_facet_dat) is appended to the kernel arguments.make_c_arguments: Extended therequire_facet_numberlogic to handle"exterior_facet"integrals, usingmesh.exterior_facets.local_facet_dat._kernel_args_andmesh.exterior_facets.point2facetnumber.PatchBase.initialize: Cell, interior facet, and exterior facet kernel setup is now conditional on the respective kernel lists being non-empty, rather than assuming a cell kernel always exists. For exterior facet kernels, the method builds the C wrapper, compiles the callback function, constructs thectypesstruct (withpoint2facetfrommesh.exterior_facets.point2facetnumber), and registers the callback viaset_patch_jacobian(..., exterior_facets=True)andset_patch_residual(..., exterior_facets=True).firedrake/cython/patchimpl.pyxexterior_facets=Falseparameter toset_patch_residualandset_patch_jacobian.elif exterior_facets:branches that call the new PETSc API functionsPCPatchSetComputeOperatorExteriorFacetsandPCPatchSetComputeFunctionExteriorFacets.firedrake/cython/petschdr.pxiPCPatchSetComputeOperatorExteriorFacetsandPCPatchSetComputeFunctionExteriorFacets.tests/firedrake/regression/test_patch_pc.pytest_patch_pc_exterior_facets, parametrized over"dx_and_ds"and"dx_dS_and_ds"integral combinations. Each case solves a DG(1) problem on aUnitSquareMeshwith both a direct LU solver andPatchPC(star patches, vertex-centered), then asserts the solutions match to withinatol=1e-8.Dependencies
This PR requires a corresponding PETSc change that adds:
PCPatchSetComputeOperatorExteriorFacetsandPCPatchSetComputeFunctionExteriorFacetsAPI functionsextFacetsToPatchCellindex set in thePC_PATCHstruct for mapping exterior facets to their owning cell within each patchTest plan
test_patch_pc_exterior_facets[dx_and_ds]-- DG problem withdx + dsintegrals, PatchPC matches direct solvertest_patch_pc_exterior_facets[dx_dS_and_ds]-- DG problem withdx + dS + dsintegrals, PatchPC matches direct solvertest_jacobi_sor_equivalencetests continue to pass (cell-only and interior facet paths unchanged)The following snippet shows the feature working on a Stokes problem with Nitsche boundary conditions
Output