refactor(solvers): one `HelmholtzSolver(grid, bc, approximation)` module replacing nine solver classes; unify `lambda_`/`alpha` and the BC vocabulary with Chebyshev
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
The work is in solvers.py, lines 1998-2523. Start by reading the existing nine solver classes and the solve_helmholtz_* functions to understand the four calling conventions. The goal is to unify them into a single HelmholtzSolver class, deprecate the old ones, and ensure all tests pass. Check the dependencies: this issue is part of #83 and depends on an N-D kernel issue. Coordinate with #79 for Chebyshev BC vocabulary changes after it merges.
Written by the indexing model from the issue text.
Description
Part of #83. Depends on the N-D kernel issue in this epic.
Summary
There are four calling conventions for the same operation across the package:
| Class / function | Construction | Call | Notes |
|---|---|---|---|
SpectralHelmholtzSolver{1,2,3}D (solvers.py:1998-2172) |
(grid) |
.solve(f, alpha, zero_mean, spectral) |
continuous k² (= approximation="spectral"), ignores grid.dealias, periodic only |
DirichletHelmholtzSolver2D, NeumannHelmholtzSolver2D, RegularNeumannHelmholtzSolver2D, StaggeredDirichletHelmholtzSolver2D (:2180-2346) |
(dx, dy, alpha) |
(rhs) |
FD2 only, 2D only |
MixedBCHelmholtzSolver{2,3}D (:2354-2523) |
(dx, dy, bc_x, bc_y, alpha) |
(rhs, bc_x_values=...) |
FD2 only |
solve_helmholtz_* functions |
– | (rhs, dx, dy, lambda_, approximation) |
lambda_ not alpha |
ChebyshevHelmholtzSolver{1,2}D |
(grid) |
.solve(f, alpha, bc_left, bc_right, bc_type) |
different BC vocabulary |
SphericalHelmholtzSolver |
(grid) |
.solve(f, alpha, zero_mean) |
The three SpectralHelmholtzSolver* are 57 identical lines each except for K2; the four 2D wrappers are 3-field shells over one function each.
Proposed design
class HelmholtzSolver(eqx.Module):
grid: FourierGrid # N-D grid (or spacings + shape until #83's grid item lands)
bc: tuple[BCName, ...] = eqx.field(static=True) # per axis; "periodic", "dirichlet", "neumann", ("dirichlet", "neumann"), "dirichlet_staggered", ...
approximation: Literal["fd2", "spectral"] = eqx.field(static=True, default="fd2")
alpha: float | Array = 0.0 # dynamic; can be overridden per call
zero_mean: bool = eqx.field(static=True, default=True)
def solve(self, rhs, alpha=None, bc_values=None) -> Array
def eigenvalues(self) -> Array # exposed for IMEX / preconditioning
def as_lineax_operator(self) # tracked in #84
- Keep the nine existing classes as thin deprecated aliases for one release (
SpectralHelmholtzSolver2D(grid)→HelmholtzSolver(grid, bc=("periodic",)*2, approximation="spectral"), etc.). - Adopt one parameter name for the Helmholtz constant across functions and classes (
alphais used by every class and by Chebyshev/spherical; the function family useslambda_; pickalphaand acceptlambda_as a deprecated keyword). - Adopt the BC vocabulary of
solve_helmholtz_2d(bc_x="dirichlet", tuples for mixed left/right) in Chebyshev too, replacingbc_type=+bc_left/bc_right(coordinate with #79 after it merges; do not touch Chebyshev before). PoissonSolver=HelmholtzSolverwithalpha=0; do not keep separate classes.
Acceptance criteria
- All nine current classes remain importable and produce identical results (tests unchanged) with a
DeprecationWarning. -
HelmholtzSolveris jit-able as an argument (static fields),vmap-able overalpha, andgradw.r.t.alpha,rhs,bc_values(tests). - One API page documents
HelmholtzSolver; the four 2D wrapper pages are removed from the nav. -
docs/elliptic_solvers_guide.mduses onlyHelmholtzSolverandsolve_helmholtz_nd.
- Dominant language
- Python
- Stars
- 2
- Forks
- 0
- Avg merge
- 8h 13m
- Merged PRs (30d)
- 8
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from jejjohnson/spectraldiffx
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
jejjohnson/spectraldiffx#172 ·
-
epic
Difficulty 1/5 Under an hour Newbie friendliness 62/100
jejjohnson/spectraldiffx#167 · 1 comment ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
jejjohnson/spectraldiffx#113 ·
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
jejjohnson/spectraldiffx#105 ·
-
dependencies
Difficulty 4/5 3-5 days Newbie friendliness 45/100
jejjohnson/spectraldiffx#181 ·
All issues in jejjohnson/spectraldiffx
Similar issues
-
bug(operator): VolterraOperator built inside jax.jit with a concrete decay raises TracerBoolConversionErrorPossibly taken @jejjohnson claimed this today. Opentype:bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
jejjohnson/integrix#144 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
finos/ai-governance-framework#459 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
autowarefoundation/autoware_carla_scenario#2963 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
freelawproject/litigant-portal#1307 ·
Maintainers usually reply within 2 days
-
type/bug
Difficulty 1/5 Under an hour Newbie friendliness 86/100
h2oai/h2o-llmstudio#1163 ·
Maintainers usually reply within 1 day