Repository navigation
Allow prepared BC data in Python matrix assemblers - #4648
Draft
garth-wells wants to merge 9 commits into
Draft
garth-wells wants to merge 9 commits into
garth-wells wants to merge 9 commits into
Conversation
- Share prepared-data validation between the CSR assemblers and assemble_matrix_fn, and validate only prepared data, not data just built from boundary conditions. - Build the PETSc MatrixBCData from the private marker and diagonal records instead of flattening and repacking them on every assembly. - Cache PETSc block index sets in prepared data and in LinearProblem, rather than rebuilding them on every blocked assembly. - Attribute the diag DeprecationWarning to the caller, so it is shown under default warning filters. - Raise TypeError when prepared data for the other matrix type is passed, instead of iterating it as boundary conditions. - Check prepared diagonal rows (dtype, local range) and values (shape, scalar type), and reject a complex diag for a real scalar type. - Document the per-block diagonal value layout, including MATIS shares. - fem.LinearProblem caches prepared CSR BC data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- fem.MatrixBCData and the PETSc prepared data are frozen, slotted dataclasses rather than named tuples, so they are not sequences (and cannot be mistaken for a sequence of boundary conditions), and field order is not part of the API. - Rename the PETSc class to BlockMatrixBCData, distinct from fem.MatrixBCData. - Both derive from a private base, so the foreign-data check is a plain isinstance test rather than a named-tuple attribute probe. - Tests use dataclasses.replace, and check both cross-backend directions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repeated Python matrix assembly currently rebuilds constrained-dof markers and diagonal data from
DirichletBCobjects on every call. Allowbcsto accept either a BC sequence or reusableMatrixBCData, with publicprepare_matrix_bcsfactories for MatrixCSR and PETSc matrices. Both matrix-creation and in-place assembly overloads reuse prepared data; the CSR callback assembler also accepts its markers.BC sequences use a diagonal value of 1 by default. Explicit legacy
diagarguments remain honoured with a deprecation warning; custom diagonal values can instead be supplied during preparation. Prepared data includes PETSc/MATIS diagonal rows and sharing-adjusted values, and cannot be combined withdiag. Local validation checks function spaces, marker layouts and relevant PETSc diagonal layouts.Validation:
AI assistance: Codex assisted with the implementation, tests and PR description.