Cleanup: remove unneeded argument for Preconditioner::Update - #7234
Merged
RemiLehe merged 9 commits intoSep 3, 2026
Conversation
Preconditioner::UpdatePreconditioner::Update
RemiLehe
commented
Sep 2, 2026
None of the preconditioners re-linearize about the vector passed to `Update()`, so the argument only suggests a dependence that does not exist. Of the three implementations, `CurlCurlMLMGPC` ignored it outright, while `JacobiPC` and `MatrixPC` used it purely for layout and index metadata, never for the field values: - `JacobiPC` read `boxArray()`/`DistributionMap()` to size the scratch MultiFabs it allocates lazily. These are now cached in `Define()`, which already receives the same vector. The allocation stays lazy: its guard is on the mass-matrix coefficients being set, not on the vector. - `MatrixPC::Assemble()` read `getDOFsObject()`. The solver vector class owns a single DOF object that lives until AMReX finalization, so this is now cached in `Define()` as a non-owning pointer as well. The state a preconditioner actually depends on reaches it through the `Ops` object and through `CurTime()`/`CurTimeStep()`, so dropping the argument makes the real data flow explicit. Should a preconditioner ever need the current iterate, it can be added back at that point. `LinearFunction::updatePreCondMat()` exists only to forward to `Update()`, so it loses its argument too, along with its call sites in `NewtonSolver`, `WarpX_PETSc` and `DarwinLinearFieldOperator`. Also drop a stale `ignore_unused(a_U)` in `MatrixPC::Define()`, whose `// a_U is not needed` comment contradicted the three uses of `a_U` immediately below it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
RemiLehe
force-pushed
the
simplify_pc_update_interface
branch
from
September 2, 2026 18:15
edc3a49 to
83b6cda
Compare
RemiLehe
commented
Sep 2, 2026
RemiLehe
commented
Sep 2, 2026
for more information, see https://pre-commit.ci
The `decltype(std::declval<const T&>().getDOFsObject().get())` alias was over-engineered: `MatrixPC` already hard-codes `FieldType::Efield_fp`, so it is not generic, and the alias was hard to read for no benefit. `Assemble()` only ever needed the DOF index maps, so cache those directly. Their type is expressible in plain AMReX terms, which removes the alias without naming `WarpXSolverDOF` or adding a NonlinearSolvers -> ImplicitSolvers include. Also drop the two DOF-count asserts. `WarpXSolverVec` owns a single static DOF object shared by every solver vector, so these compared `m_ndofs_*` against the very storage they had been copied from in `Define()` and could not fail. The separate null check is gone too: the `nDOF_local()`/`nDOF_global()` queries just above already assert that the DOF object exists. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Preconditioner::UpdatePreconditioner::Update
Preconditioner::UpdatePreconditioner::Update
`WarpXSolverVec` owns a single static DOF object shared by every solver vector, so `Assemble()` never needed an instance to reach it, and nothing needed caching in the first place. Make `getDOFsObject()` static -- it already returned static state, so the `const` member form was misleading -- and read the index maps through it directly. This removes the cached member, the `decltype(std::declval<...>())` alias that spelled its type, the caching block in `Define()`, its null-check assert, and the `<utility>` include. `MatrixPC.H` now differs from before this PR only in the `Update()`/`Assemble()` signatures and this one line. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
RemiLehe
commented
Sep 2, 2026
RemiLehe
commented
Sep 2, 2026
Co-authored-by: Remi Lehe <remi.lehe@normalesup.org>
RemiLehe
commented
Sep 2, 2026
| // Get DOF object from a_U | ||
| const auto& dofs_obj = a_U.getDOFsObject(); | ||
| const auto& dofs_mfarrvec = dofs_obj->m_array; | ||
| AMREX_ALWAYS_ASSERT(m_ndofs_l == dofs_obj->m_nDoFs_l); |
Member
Author
There was a problem hiding this comment.
This PR removes the AMREX_ALWAYS_ASSERT. On the other hand, I am not sure that this ASSERT was needed. Are there really configurations where m_ndofs_l could become different from dofs_obj->m_nDoFs_l?
Contributor
There was a problem hiding this comment.
@debog I'll let Debo answer that question. It may not be needed, but I"m not sure.
RemiLehe
commented
Sep 2, 2026
RemiLehe
commented
Sep 2, 2026
RemiLehe
commented
Sep 2, 2026
|
|
||
| // return DOFs object pointer | ||
| [[nodiscard]] inline const auto& getDOFsObject () const { return m_dofs; } | ||
| [[nodiscard]] inline static const auto& getDOFsObject () { return m_dofs; } |
Member
Author
There was a problem hiding this comment.
This function can be made static here (i.e., it can be called with WarpXSolverVec::getDOFsObject instead of requiring an instance of WarpXSolverVec) since m_dofs itself is declared as a static member (i.e. one m_dofs object per class, not per instance)
Preconditioner::UpdatePreconditioner::Update
Preconditioner::UpdatePreconditioner::Update
Preconditioner::UpdatePreconditioner::Update
RemiLehe
enabled auto-merge (squash)
September 2, 2026 23:43
RemiLehe
added a commit
to roelof-groenewald/WarpX
that referenced
this pull request
Sep 3, 2026
Adapt the Darwin MLMG preconditioner to the new Preconditioner::Update() interface from BLAST-WarpX#7234 (the WarpXSolverVec argument was removed).
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.
I found the interface of
Preconditioner::Updateconfusing, because we passa_X(aWarpXSolverVec) to it, but in practice the information froma_Xis never really used.(Instead
Updateuses other objects, stored internally in thePreconditionerobject, to update the equation it needs to solve.)This PR aims to make the interface less confusing by simply not passing
a_XtoUpdate.