Skip to content

Eliminate the same Dirichlet columns in aij and matfree EquationBC rows - #5766

Open
pbrubeck wants to merge 2 commits into
mainfrom
pbrubeck/equationbc-matfree-aij
Open

pbrubeck wants to merge 2 commits into
mainfrom
pbrubeck/equationbc-matfree-aij

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

AI assistance: Claude Code (Claude Opus 5.5) helped to write these changes and this description. The fix for the component of a nested DirichletBC and the two test cases come from #5620 by @sghelichkhani.

Summary

Fixes the second case of #5609 and supersedes #5620.

For a DirichletBC nested in an EquationBC, the aij matrix and the matrix-free operator eliminated different columns, so their mult and multTranspose differed by about 30%. Now both eliminate the columns of every DirichletBC in the bcs tree, in the domain rows and in every EquationBC row:

 assemble(a, bcs=[EquationBC(..., bcs=[dbc_nested]), dbc_top])
   domain rows
-    aij:     eliminate columns of dbc_top
-    matfree: eliminate columns of dbc_top and dbc_nested
+    eliminate columns of dbc_top and dbc_nested
   EquationBC rows
-    aij:     eliminate columns of dbc_nested
-    matfree: eliminate no columns
+    eliminate columns of dbc_top and dbc_nested

Because the EquationBC rows now eliminate the Dirichlet columns, the solver with pre_apply_bcs=False lifts the residual of each EquationBC with its own Jacobian, as it already does for the domain residual:

F_lifted(u)  = F(u)  - J(u)  r      r = u - g on the Dirichlet nodes, 0 elsewhere
G_lifted(u)  = G(u)  - J_G(u) r     for each EquationBC residual G

A second commit fixes EquationBCSplit.reconstruct, which rebuilt a nested DirichletBC on the whole space of the EquationBC. A DirichletBC on one velocity component was then applied to every component, so the matrix-free operator had identity rows where the aij matrix has EquationBC rows.

Changes for users

Before After
aij matrix, domain rows keep the columns of a DirichletBC nested in an EquationBC eliminate them
aij matrix, EquationBC rows eliminate only the columns of their own DirichletBCs eliminate the columns of every DirichletBC
matfree mult and multTranspose with nested DirichletBCs differ from aij equal to aij to round-off
assemble(a, tensor=A, bcs=bcs) keeps A.bcs sets A.bcs to bcs

Implementation details

  • A matrix stores the bcs of its top-level assembly. The EquationBC assemblers add to that matrix without zeroing it, and read the Dirichlet columns from matrix.bcs.
  • The matrix-free EquationBC actions use the input with zeroed Dirichlet entries, as the domain action does. This removes the extra copy of the input and the column masking in multTranspose.
  • EquationBCSplit.reconstruct takes new form and bcs arguments, so that _SNESContext builds each lifted EquationBC as a new object and the problem does not change.

Limitations

Evidence

test_matrixfree_action_transpose_blocks compares mult and multTranspose of the matrix-free operator, and of each field block from createSubMatrix, with the aij matrix. Two new cases:

equationbc_nested        EquationBC on side 1 with DirichletBCs on its two end points
mixed_equationbc_nested  velocity EquationBC with a DirichletBC on one velocity component
  • Before: equationbc_nested fails on main. With only the first commit, mixed_equationbc_nested fails, with a relative difference of 1.7% in mult.
    After: both pass. test_matrix_free.py passes on 1, 2 and 3 processes, and test_equation_bcs.py passes on 1 and 3 processes.

Merge Danger

Door: two-way

Blast Radius: assembly

Every aij matrix with a DirichletBC nested in an EquationBC changes. Solutions with pre_apply_bcs=True do not change. Code that reads A.bcs after assemble(a, tensor=A, bcs=...) now sees the new boundary conditions.

🤖 Generated with Claude Code

@pbrubeck pbrubeck added the LLM used An LLM was used in the production of this PR label Dec 3, 2026
@pbrubeck
pbrubeck added this pull request to stack #5768 December 3, 2026 10:11
@pbrubeck
pbrubeck requested a review from connorjward December 3, 2026 10:19
pbrubeck and others added 2 commits December 3, 2026 10:30
The aij matrix eliminated the columns of a DirichletBC that is nested in
an EquationBC only from the rows of that EquationBC, while the
matrix-free operator eliminated them only from the domain rows. So
mult and multTranspose of the two operators differed.

Eliminate the columns of every DirichletBC in the bcs tree from the
domain rows and from every EquationBC row. The matrix stores the bcs of
its top-level assembly, and the EquationBC assemblers read the Dirichlet
columns from it. The matrix-free EquationBC actions use the input with
zeroed Dirichlet entries, as the domain action does.

Because the EquationBC rows now eliminate the Dirichlet columns, the
solver lifts the residual of each EquationBC with its own Jacobian when
pre_apply_bcs=False, as it does for the domain residual. Add the form
and bcs arguments to EquationBCSplit.reconstruct, so that the lifted
EquationBC is a new object and the problem does not change.

Co-authored-by: Sia Ghelichkhan <6863057+sghelichkhani@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EquationBCSplit.reconstruct rebuilt a nested DirichletBC on the function
space of the EquationBC. A DirichletBC on one component of a vector
field was then applied to every component, so the matrix-free operator
had identity rows where the aij matrix has EquationBC rows. Rebuild the
nested DirichletBC on its own field and component, as for a nested
EquationBC.

Co-authored-by: Sia Ghelichkhan <6863057+sghelichkhani@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

LLM used An LLM was used in the production of this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant