Guard cloned-space BC assembly in C++#4255
Conversation
c004515 to
00a158a
Compare
|
I narrowed the validation after CI showed that general different-degree and submesh Petrov-Galerkin assembly with BCs is supported and already covered by tests. The current check now targets only equivalent same-mesh spaces represented by distinct FunctionSpace objects, and it is bypassed for recursive MatNest sub-block assembly so existing block formulations are not rejected. |
00a158a to
bb8ae42
Compare
|
Fixed the CI issues: the BC validation helper now checks the C++ finite-element signature instead of calling the Python-only ufl_element(), and petsc.py has been formatted locally with Ruff. |
bb8ae42 to
59833d1
Compare
|
Updated again after the latest CI results. The validation is now limited to distinct spaces that share the same dofmap, which keeps the existing submesh and mixed-domain assembly tests valid. I also updated the mypy ignore for the private recursive MatNest call and verified Ruff plus the separate CI-style mypy commands locally. |
|
Could you open the PR with a clear statement of the issue, and then how the PR fixes it? I don't know what "Reject Dirichlet boundary conditions ..." means. Also, note that checks that can be performed in C++ should be done in C++ functions rather than in the Python layer. |
59833d1 to
6d8a06e
Compare
|
Thanks, updated. The PR description now starts with the concrete issue and then explains the fix. I also moved the validation from Python into the shared C++ assemble_matrix(..., bcs) path. Python now only passes check_bcs=false for PETSc block/MatNest sub-assembly, where cloned spaces are valid and diagonal handling is performed at the block level.\n\nLocally checked: clang-format, Ruff, mypy for dolfinx/demo/test, compileall, and git diff --check. |
6d8a06e to
3e1d848
Compare
|
Follow-up: fixed the docs failure by documenting the new C++ helper and pushed the amended commit. |
Issue\n\nFunctionSpace.clone() creates a distinct FunctionSpace object with a separate identity while sharing the same mesh and dofmap. This is useful for block formulations, but it is ambiguous for standalone matrix assembly with DirichletBCs.\n\nFor a bilinear form whose test and trial spaces are cloned from one another, a DirichletBC on either space is applied during row/column zeroing because the spaces share the same dofs. The diagonal insertion step, however, only runs when the test and trial FunctionSpace objects are identical. The constrained row/column can therefore be left without the expected diagonal entry.\n\nFix\n\nMove the validation into the C++ assemble_matrix(..., bcs) path. The check detects the cloned-space case only when the form is rank 2, the test and trial spaces are distinct objects, they are on the same mesh, they share the same single dofmap and element signature, and a DirichletBC belongs to either space. In that standalone assembly case, assembly now raises a clear error before producing an invalid constrained matrix.\n\nPETSc block and MatNest sub-assembly bypass this standalone check because cloned spaces are valid there and diagonal handling is performed at the block level.\n\nAdds regression coverage for both MatrixCSR and PETSc assembly.\n\nSplit out from #4249 per maintainer request.