Skip to content

[WIP] Implement 3D mass matrices for the implicit solver (direct deposition only) - #7181

Open
RemiLehe wants to merge 2 commits into
BLAST-WarpX:developmentfrom
RemiLehe:massmatrix-3d
Open

[WIP] Implement 3D mass matrices for the implicit solver (direct deposition only)#7181
RemiLehe wants to merge 2 commits into
BLAST-WarpX:developmentfrom
RemiLehe:massmatrix-3d

Conversation

@RemiLehe

@RemiLehe RemiLehe commented Aug 21, 2026

Copy link
Copy Markdown
Member

The full mass-matrix machinery used by the particle-suppressed JFNK solver (implicit_evolve.use_mass_matrices_jacobian) was implemented in 1D and 2D, but not in 3D.

This PR adds the 3D implementation for direct deposition, following the 1D/2D style.

Changes

  • MassMatricesDeposition.H: implement the full_mass_matrices branch of the 3D direct deposition kernel, using the same component-index convention as ApplyMassMatrices and the symmetry-reduced deposit of the diagonal blocks (only offsets with dx+dy+dz <= 1).
  • ImplicitSolver.cpp:
    • add the 3D symmetry fold in FinishMassMatrices, which copies the remaining diagonal-block components from their point-symmetric mirrors;
    • add the missing dir-2 loop in SyncMassMatricesPCAndApplyBCs and allow implicit_evolve.mass_matrices_pc_width in 3D;
    • replace the blanket 3D assert by one requiring direct deposition. The Villasenor 3D mass-matrix kernel is left as follow-up work and now aborts with a clear message.
  • ThetaImplicitEM.cpp: fix an operator-precedence bug in the 3D curl2_BC_mask setup (field_dir + 1 % AMREX_SPACEDIM evaluated to field_dir + 1).
  • MatrixPC.H: fix a wrong comment on the component-index mapping.

New CI test

test_3d_theta_implicit_jfnk_vandb: a 3D periodic uniform plasma (16^3 cells, 2x2x2 particles
per cell, 2 species, 10 steps), extending the existing 2D Villasenor and Buneman test. It uses the
theta-implicit solver with the mass-matrices Jacobian and the curl-curl MLMG preconditioner with
mass-matrices response, so it needs no PETSc. It runs in about 25 s on 2 ranks. The analysis
checks energy conservation and the Newton and GMRES iteration counts, all of which are sensitive
to mass-matrix indexing errors.

The parameters shared by the 2D and 3D vandb tests are factored into inputs_base_vandb
(included via the FILE mechanism), and the 2D and 3D analysis scripts are merged into a single
analysis_vandb_jfnk.py that reads the dimensionality and algorithm options from
warpx_used_inputs. The 2D test is unchanged (identical warpx_used_inputs dump).

Validation

  • Energy is conserved to 2e-15 (relative); Newton converges in 3 iterations per step and GMRES needs 2 iterations per Newton iteration.
  • The solution obtained with the mass-matrices Jacobian agrees with the one obtained with the matrix-free (particle-based) Jacobian to better than 6e-13 on all field quantities, i.e. at the Newton solver tolerance.
  • The existing 1D/2D implicit tests (planar pinch, vandb, symmetry) still pass their physics analyses.

🤖 Generated with Claude Code

…ition)

The full mass-matrix machinery used by the particle-suppressed JFNK
implicit solver (implicit_evolve.use_mass_matrices_jacobian) was only
implemented in 1D and 2D. This adds the 3D implementation for direct
deposition, following the 1D/2D style:

- MassMatricesDeposition.H: fill in the full_mass_matrices branch of the
  3D direct deposition kernel, with the same component-index convention
  as ApplyMassMatrices (dir-0 fastest, per-pair staggering shifts) and
  the symmetry-reduced deposit of the diagonal blocks (dx+dy+dz <= 1).
- ImplicitSolver.cpp: add the 3D symmetry fold in FinishMassMatrices
  (copy components with dx+dy+dz >= 2 from their point-symmetric
  mirrors); add the missing dir-2 loop in SyncMassMatricesPCAndApplyBCs;
  allow mass_matrices_pc_width in 3D; replace the blanket 3D assert by
  one requiring direct deposition (the Villasenor 3D mass-matrix kernel
  is left as follow-up work and now aborts with a clear message).
- ThetaImplicitEM.cpp: fix an operator-precedence bug in the 3D
  curl2_BC_mask setup (field_dir + 1 % AMREX_SPACEDIM).
- MatrixPC.H: fix a wrong comment on the component-index mapping.

Add CI test test_3d_theta_implicit_jfnk_vandb: a 3D periodic uniform
plasma (16^3 cells, 2x2x2 ppc, 10 steps, ~25 s on 2 CI ranks) using the
theta-implicit solver with the mass-matrices Jacobian and the curl-curl
MLMG preconditioner with mass-matrices response. The analysis checks
energy conservation (~2e-15) and Newton/GMRES iteration counts, both
sensitive to mass-matrix indexing errors. The mass-matrix-Jacobian
solution was verified to agree with the matrix-free (particle-based)
Jacobian solution to <= 6e-13 on all fields.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@RemiLehe RemiLehe changed the title [WIP] Implement 3D mass matrices for the implicit solver [WIP] Implement 3D mass matrices for the implicit solver (direct depositon only) Aug 21, 2026
Factor the parameters shared by the 2D and 3D theta-implicit JFNK vandb
tests into inputs_base_vandb, included from the test input files via the
FILE mechanism, as done in other tests. The 2D test is unchanged (its
warpx_used_inputs dump is identical); the 3D test only changes the
location of its reduced diagnostics files to the default paths.

Merge analysis_vandb_jfnk_2d.py and analysis_vandb_jfnk_3d.py into a
single analysis_vandb_jfnk.py, which reads the dimensionality and the
relevant algorithm options from warpx_used_inputs: the charge
conservation check runs for the charge-conserving Villasenor deposition,
and the Newton/GMRES iteration checks run when the mass matrices are
used for the Jacobian.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@RemiLehe RemiLehe changed the title [WIP] Implement 3D mass matrices for the implicit solver (direct depositon only) [WIP] Implement 3D mass matrices for the implicit solver (direct deposition only) Aug 31, 2026
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