Skip to content

Refactor PCPatch code to not use PyOP2#4993

Open
connorjward wants to merge 19 commits intomainfrom
connorjward/patch-refactor
Open

Refactor PCPatch code to not use PyOP2#4993
connorjward wants to merge 19 commits intomainfrom
connorjward/patch-refactor

Conversation

@connorjward
Copy link
Copy Markdown
Contributor

@connorjward connorjward commented Mar 26, 2026

This PR:

  • Refactors the code in patch.py to not use the PyOP2 code generator and just generates C code directly instead.
  • Makes the code much more understandable (in my opinion). There is a lot of code generation/callback/struct magic going on that I have packaged more neatly together than what was already there.

The reason I have done this is because I was struggling to reproduce the level of hackery done in this file for pyop3. PCPatch requires a specific interface to the wrapper kernel which is easy enough to enforce in PyOP2 but much more difficult in pyop3 where the compiler is much more advanced and hence the generated code has a less predictable call signature.

I think it would be possible to recover this behaviour, and use pyop3 for codegen, but I would like to use this as a temporary measure because:

  • No features were harmed in this transition, everything works as it did before
  • It makes pyop3 that much closer to merging

@connorjward connorjward marked this pull request as ready for review March 30, 2026 12:50
Comment on lines -13 to -24
if interior_facets:
CHKERR(PCPatchSetComputeFunctionInteriorFacets((<PETSc.PC?>patch).pc,
<PetscPCPatchComputeFunction><uintptr_t>function,
<void *><uintptr_t>ctx))
elif exterior_facets:
CHKERR(PCPatchSetComputeFunctionExteriorFacets((<PETSc.PC?>patch).pc,
<PetscPCPatchComputeFunction><uintptr_t>function,
<void *><uintptr_t>ctx))
else:
CHKERR(PCPatchSetComputeFunction((<PETSc.PC?>patch).pc,
<PetscPCPatchComputeFunction><uintptr_t>function,
<void *><uintptr_t>ctx))
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.

These functions were never called

PetscInt *filtdofs = NULL;

PetscFunctionBeginUser;
PetscCall(ISGetSize(points, &npoints));
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.

I use the modern PetscCall calling convention, replacing ierr = ...

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.

1 participant