Skip to content

Bump feectools: KroneckerStencilMatrix matmul and grouped factors - #731

Open
spossann wants to merge 4 commits into
develfrom
kron-stencil-matmul
Open

spossann wants to merge 4 commits into
develfrom
kron-stencil-matmul

Conversation

@spossann

@spossann spossann commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Points the feectools submodule to the branch of struphy-hub/feectools#100, so that the struphy test suite runs against it before that PR is merged.

struphy-hub/feectools#100 changes KroneckerStencilMatrix and KroneckerLinearSolver:

  • factors on groups of axes (e.g. 2d x 1d);
  • A @ B returns a new ComposedKroneckerStencilMatrix (operands in multiplicands, exact Kronecker factors of the product in mats);
  • ComposedLinearOperator.multiplicants → multiplicands, with a deprecated alias;
  • factor_ndims in KroneckerLinearSolver;
  • docstrings and type annotations; feectools 0.6.0.

Existing calls are unchanged, so struphy needs no code changes. struphy builds these objects in feec/preconditioner.py (MassMatrixPreconditioner) and feec/projectors.py.

multiplicants → multiplicands

  • All struphy uses (preconditioner, projectors, multigrid coarsening) now use multiplicands.
  • linop_nbytes in feec/memory.py adds up all child attributes, so a ComposedKroneckerStencilMatrix counts both its operands and the factors of the product.

Refactor of MassMatrixPreconditioner

  • The construction of the Kronecker approximation is split into module-level helpers in feec/preconditioner.py. They cover the boundary conditions, gathering array weights over MPI, the 1d weight, the 1d mass matrix and its BCs, the 1d solver, the process-local 1d factor, the block-diagonal assembly and the operator to invert.
  • MassMatrixDiagonalPreconditioner now calls these helpers instead of repeating the same ~200 lines.
  • Values and the order of MPI calls are unchanged. The copy into the process-local 1d stencil matrix is now vectorized, and the block-diagonal operators are no longer hard-coded to 3 components.
  • Docstrings, comments and type annotations.

MassMatrixPreconditioner: new option and fixes

  • New option weight_reduction="midpoint" | "average" sets how the weight is reduced to 1d in the directions other than dim_reduce. The default "midpoint" gives the same results as before, verified for M0, M1, M2, Mv, M1n and array weights, serially and on 2 ranks. "average" uses the mean over those directions: Gauss quadrature of the Derham for array weights, 16-point Gauss–Legendre for callables.
  • Array weights are reduced with a single Allreduce, instead of a subcommunicator plus Bcast.
  • The mass matrix is located in the composed operator by identity, and the approximate inverse is applied exactly there. Both preconditioners share this code (_apply_composed). Before, a mass matrix in the left-most position was applied instead of inverted.
  • FFTSolver copies its column, which was a view of the dense matrix also used for the stencil factor. It now stabilises a singular matrix once, at construction. is_circulant is vectorized.

PCG iterations (tolerance 1e-8) on HollowTorus, grid 12×16×6, degree (2,3,2), as a reference for choosing weight_reduction:

M0 M1 M2 M3 Mv M1n M2n Mvn
midpoint 13 22 22 13 31 673 600 1000 (not converged)
average 13 15 15 13 30 798 727 1000 (not converged)

On HollowCylinder both need 2 iterations for every matrix.

Tests

Run locally with the submodule branch: the MassMatrixPreconditioner tests (test_preconditioner_transpose.py, test_mass_matrices.py::test_mass_preconditioner*, the new test_reduced_weight_1d) pass serially and on 2 ranks (24 passed each). The rest is left to CI.

Don't raise the feectools pin in pyproject.toml until 0.6.0 is on PyPI. Before merging, the submodule pointer should move to the merged devel-tiny commit.

🤖 Generated with Claude Code

Points the feectools submodule to the kron-stencil-matmul branch
(KroneckerStencilMatrix @, factors on groups of axes, factor_ndims in
KroneckerLinearSolver; feectools 0.6.0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
spossann and others added 3 commits October 8, 2026 10:16
- Split the construction of the Kronecker approximation into module-level
  helpers (boundary conditions, MPI weight gathering, 1d weight, 1d mass
  matrix + bcs, 1d solver, process-local 1d factor, block-diagonal
  assembly, operator to invert); MassMatrixDiagonalPreconditioner reuses
  them instead of a copy of the same code.
- Vectorized copy into the process-local 1d stencil matrix; block-diagonal
  operators no longer hard-coded to 3 components.
- Docstrings, comments and type annotations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- New option weight_reduction="midpoint" (default, unchanged results) or
  "average" (mean of the weight over the other two directions; Gauss
  quadrature of the derham for array weights, 16-point Gauss-Legendre for
  callables). Array weights are reduced with a single Allreduce instead of
  a subcommunicator + Bcast.
- Locate the mass matrix in the composed operator by identity and apply
  the approximate inverse exactly there (shared _apply_composed for both
  preconditioners); previously a left-most mass matrix was applied instead
  of inverted.
- FFTSolver: copy the column (it was a view of the matrix used for the
  stencil factor) and stabilize a singular matrix once at construction.
- Vectorized is_circulant.
- Tests: weight_reduction in the transpose and MPI array-weight tests, new
  test of the reduced 1d weights against analytic values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Rename uses of ComposedLinearOperator.multiplicants to multiplicands
  (preconditioner, projectors, multigrid coarsening, comments).
- linop_nbytes: sum over all child attributes, so that the factors of a
  ComposedKroneckerStencilMatrix (multiplicands and mats) are counted.
- Bump feectools to the commit with ComposedKroneckerStencilMatrix.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant