Spectral Elliptic Solvers¶
Helmholtz, Poisson, and Laplace solvers for rectangular domains. See the theory page for the mathematical background.
Layer 0 — Pure Functions¶
Periodic (FFT)¶
1D¶
solve_helmholtz_fft_1d(rhs, dx, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f in 1-D with periodic BCs using the FFT.
Spectral algorithm:
- Forward FFT: f̂ = FFT(f) [N]
- Eigenvalues: Λ_k (FD2 or PS, see approximation) [N]
- Spectral division: ψ̂[k] = f̂[k] / (Λ_k − λ) [N]
- Inverse FFT: ψ = Re(IFFT(ψ̂)) [N]
When lambda_ == 0 the k=0 mode has Λ_0 = 0, making the denominator
singular. This is handled by setting ψ̂[0] = 0 (zero-mean gauge).
Parameters¶
rhs : Float[Array, " N"]
Right-hand side on the periodic domain.
dx : float
Grid spacing.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
"fd2" uses finite-difference eigenvalues (exact inverse of the
3-point stencil). "spectral" uses continuous Laplacian
eigenvalues (spectral accuracy for smooth solutions).
Default: "fd2".
Returns¶
Float[Array, " N"] Solution ψ (real), same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_fft_1d(rhs, dx, *, approximation='fd2')
¶
Solve ∇²ψ = f in 1-D with periodic BCs using FFT.
Convenience wrapper around :func:solve_helmholtz_fft_1d with lambda_=0.
Parameters¶
rhs : Float[Array, " N"]
Right-hand side on the periodic domain.
dx : float
Grid spacing.
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, " N"] Zero-mean solution ψ (real), same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
2D¶
solve_helmholtz_fft(rhs, dx, dy, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f with periodic BCs using the 2-D FFT.
Spectral algorithm:
- Forward 2-D FFT: f̂ = FFT2(f) [Ny, Nx]
- Eigenvalue matrix: Λ[j,i] = Λ_j^y + Λ_i^x − λ [Ny, Nx] where Λ^x, Λ^y are FD2 or PS eigenvalues (see approximation).
- Spectral division: ψ̂[j,i] = f̂[j,i] / Λ[j,i] [Ny, Nx]
- Inverse 2-D FFT: ψ = Re(IFFT2(ψ̂)) [Ny, Nx]
When lambda_ == 0 the (0,0) mode is singular (Λ[0,0] = 0).
This is handled by setting ψ̂[0,0] = 0 (zero-mean gauge).
Parameters¶
rhs : Float[Array, "Ny Nx"]
Right-hand side on the periodic domain.
dx : float
Grid spacing in x.
dy : float
Grid spacing in y.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Ny Nx"] Solution ψ (real), same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_fft(rhs, dx, dy, *, approximation='fd2')
¶
Solve ∇²ψ = f with periodic BCs using the 2-D FFT.
Convenience wrapper around :func:solve_helmholtz_fft with lambda_=0.
Parameters¶
rhs : Float[Array, "Ny Nx"]
Right-hand side on the periodic domain.
dx : float
Grid spacing in x.
dy : float
Grid spacing in y.
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Ny Nx"] Zero-mean solution ψ (real), same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
3D¶
solve_helmholtz_fft_3d(rhs, dx, dy, dz, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f with periodic BCs using the 3-D FFT.
Parameters¶
rhs : Float[Array, "Nz Ny Nx"]
Right-hand side on the triply periodic domain.
dx, dy, dz : float
Grid spacings.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Nz Ny Nx"] Solution ψ (real), same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_fft_3d(rhs, dx, dy, dz, *, approximation='fd2')
¶
Solve ∇²ψ = f with periodic BCs using the 3-D FFT.
Parameters¶
rhs : Float[Array, "Nz Ny Nx"]
Right-hand side on the triply periodic domain.
dx, dy, dz : float
Grid spacings.
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Nz Ny Nx"] Zero-mean solution ψ (real), same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
Dirichlet, Regular Grid (DST-I)¶
1D¶
solve_helmholtz_dst1_1d(rhs, dx, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f in 1-D with Dirichlet BCs on a regular grid (DST-I).
Parameters¶
rhs : Float[Array, " N"]
Right-hand side at interior grid points.
dx : float
Grid spacing.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, " N"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_dst1_1d(rhs, dx, *, approximation='fd2')
¶
Solve ∇²ψ = f in 1-D with Dirichlet BCs on a regular grid (DST-I).
Parameters¶
rhs : Float[Array, " N"]
Right-hand side at interior grid points.
dx : float
Grid spacing.
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, " N"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
2D¶
solve_helmholtz_dst(rhs, dx, dy, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f with homogeneous Dirichlet BCs using DST-I.
The input rhs lives on the interior grid (boundary values are implicitly zero: ψ = 0 on all four edges).
Parameters¶
rhs : Float[Array, "Ny Nx"]
Right-hand side at interior grid points.
dx : float
Grid spacing in x.
dy : float
Grid spacing in y.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Ny Nx"] Solution ψ at interior grid points, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_dst(rhs, dx, dy, *, approximation='fd2')
¶
Solve ∇²ψ = f with homogeneous Dirichlet BCs using DST-I.
Convenience wrapper around :func:solve_helmholtz_dst with lambda_=0.
Parameters¶
rhs : Float[Array, "Ny Nx"]
Right-hand side at interior grid points.
dx : float
Grid spacing in x.
dy : float
Grid spacing in y.
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Ny Nx"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
3D¶
solve_helmholtz_dst1_3d(rhs, dx, dy, dz, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f with Dirichlet BCs on a regular 3-D grid (DST-I).
Parameters¶
rhs : Float[Array, "Nz Ny Nx"]
Right-hand side at interior grid points.
dx, dy, dz : float
Grid spacings.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Nz Ny Nx"] Solution ψ at interior grid points, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_dst1_3d(rhs, dx, dy, dz, *, approximation='fd2')
¶
Solve ∇²ψ = f with Dirichlet BCs on a regular 3-D grid (DST-I).
Parameters¶
rhs : Float[Array, "Nz Ny Nx"]
Right-hand side at interior grid points.
dx, dy, dz : float
Grid spacings.
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Nz Ny Nx"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
Dirichlet, Staggered Grid (DST-II)¶
1D¶
solve_helmholtz_dst2_1d(rhs, dx, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f in 1-D with Dirichlet BCs on a staggered grid (DST-II).
Parameters¶
rhs : Float[Array, " N"]
Right-hand side at cell-centred grid points.
dx : float
Grid spacing.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, " N"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_dst2_1d(rhs, dx, *, approximation='fd2')
¶
Solve ∇²ψ = f in 1-D with Dirichlet BCs on a staggered grid (DST-II).
Parameters¶
rhs : Float[Array, " N"]
Right-hand side at cell-centred grid points.
dx : float
Grid spacing.
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, " N"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
2D¶
solve_helmholtz_dst2(rhs, dx, dy, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f with Dirichlet BCs on a staggered grid (DST-II).
The input rhs lives on a cell-centred (staggered) grid; boundary values ψ = 0 are located half a grid spacing outside the first and last rows/columns.
Parameters¶
rhs : Float[Array, "Ny Nx"]
Right-hand side at cell-centred grid points.
dx : float
Grid spacing in x.
dy : float
Grid spacing in y.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Ny Nx"] Solution ψ at cell-centred grid points, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_dst2(rhs, dx, dy, *, approximation='fd2')
¶
Solve ∇²ψ = f with Dirichlet BCs on a staggered grid (DST-II).
Parameters¶
rhs : Float[Array, "Ny Nx"]
Right-hand side at cell-centred grid points.
dx : float
Grid spacing in x.
dy : float
Grid spacing in y.
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Ny Nx"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
3D¶
solve_helmholtz_dst2_3d(rhs, dx, dy, dz, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f with Dirichlet BCs on a staggered 3-D grid (DST-II).
Parameters¶
rhs : Float[Array, "Nz Ny Nx"]
Right-hand side at cell-centred grid points.
dx, dy, dz : float
Grid spacings.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Nz Ny Nx"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_dst2_3d(rhs, dx, dy, dz, *, approximation='fd2')
¶
Solve ∇²ψ = f with Dirichlet BCs on a staggered 3-D grid (DST-II).
Parameters¶
rhs : Float[Array, "Nz Ny Nx"]
Right-hand side at cell-centred grid points.
dx, dy, dz : float
Grid spacings.
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Nz Ny Nx"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
Neumann, Regular Grid (DCT-I)¶
1D¶
solve_helmholtz_dct1_1d(rhs, dx, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f in 1-D with Neumann BCs on a regular grid (DCT-I).
The k=0 eigenvalue is zero. For λ=0 (Poisson), the null mode is projected out (zero-mean gauge).
Parameters¶
rhs : Float[Array, " N"]
Right-hand side (including boundary grid points).
dx : float
Grid spacing.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, " N"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_dct1_1d(rhs, dx, *, approximation='fd2')
¶
Solve ∇²ψ = f in 1-D with Neumann BCs on a regular grid (DCT-I).
Parameters¶
rhs : Float[Array, " N"]
Right-hand side (including boundary grid points).
dx : float
Grid spacing.
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, " N"] Zero-mean solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
2D¶
solve_helmholtz_dct1(rhs, dx, dy, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f with Neumann BCs on a regular grid (DCT-I).
When lambda_ == 0 the (0,0) mode is singular (Λ[0,0] = 0,
corresponding to the constant null mode of the Neumann Laplacian).
This is handled by setting ψ̂[0,0] = 0 (zero-mean gauge).
Parameters¶
rhs : Float[Array, "Ny Nx"]
Right-hand side (including boundary grid points).
dx : float
Grid spacing in x.
dy : float
Grid spacing in y.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Ny Nx"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_dct1(rhs, dx, dy, *, approximation='fd2')
¶
Solve ∇²ψ = f with Neumann BCs on a regular grid (DCT-I).
Parameters¶
rhs : Float[Array, "Ny Nx"]
Right-hand side (including boundary grid points).
dx : float
Grid spacing in x.
dy : float
Grid spacing in y.
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Ny Nx"] Zero-mean solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
3D¶
solve_helmholtz_dct1_3d(rhs, dx, dy, dz, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f with Neumann BCs on a regular 3-D grid (DCT-I).
Parameters¶
rhs : Float[Array, "Nz Ny Nx"]
Right-hand side (including boundary grid points).
dx, dy, dz : float
Grid spacings.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Nz Ny Nx"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_dct1_3d(rhs, dx, dy, dz, *, approximation='fd2')
¶
Solve ∇²ψ = f with Neumann BCs on a regular 3-D grid (DCT-I).
Parameters¶
rhs : Float[Array, "Nz Ny Nx"]
Right-hand side (including boundary grid points).
dx, dy, dz : float
Grid spacings.
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Nz Ny Nx"] Zero-mean solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
Neumann, Staggered Grid (DCT-II)¶
1D¶
solve_helmholtz_dct2_1d(rhs, dx, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f in 1-D with Neumann BCs on a staggered grid (DCT-II).
The k=0 eigenvalue is zero. For λ=0 (Poisson), the null mode is projected out (zero-mean gauge).
Parameters¶
rhs : Float[Array, " N"]
Right-hand side at cell-centred grid points.
dx : float
Grid spacing.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, " N"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_dct2_1d(rhs, dx, *, approximation='fd2')
¶
Solve ∇²ψ = f in 1-D with Neumann BCs on a staggered grid (DCT-II).
Parameters¶
rhs : Float[Array, " N"] Right-hand side at cell-centred grid points. dx : float Grid spacing.
{"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, " N"] Zero-mean solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
2D¶
solve_helmholtz_dct(rhs, dx, dy, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f with homogeneous Neumann BCs using DCT-II.
When lambda_ == 0 the (0,0) mode is singular (Λ[0,0] = 0,
corresponding to the constant null mode of the Neumann Laplacian).
This is handled by setting ψ̂[0,0] = 0 (zero-mean gauge).
Parameters¶
rhs : Float[Array, "Ny Nx"]
Right-hand side.
dx : float
Grid spacing in x.
dy : float
Grid spacing in y.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Ny Nx"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_dct(rhs, dx, dy, *, approximation='fd2')
¶
Solve ∇²ψ = f with homogeneous Neumann BCs using DCT-II.
The Poisson problem has a one-dimensional null space (constant solutions). This function fixes the gauge by forcing the domain-mean of ψ to zero.
Parameters¶
rhs : Float[Array, "Ny Nx"]
Right-hand side.
dx : float
Grid spacing in x.
dy : float
Grid spacing in y.
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Ny Nx"] Zero-mean solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
3D¶
solve_helmholtz_dct2_3d(rhs, dx, dy, dz, lambda_=0.0, *, approximation='fd2')
¶
Solve (∇² − λ)ψ = f with Neumann BCs on a staggered 3-D grid (DCT-II).
Parameters¶
rhs : Float[Array, "Nz Ny Nx"]
Right-hand side at cell-centred grid points.
dx, dy, dz : float
Grid spacings.
lambda_ : float
Helmholtz parameter λ. Default: 0.0 (Poisson).
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Nz Ny Nx"] Solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
solve_poisson_dct2_3d(rhs, dx, dy, dz, *, approximation='fd2')
¶
Solve ∇²ψ = f with Neumann BCs on a staggered 3-D grid (DCT-II).
Parameters¶
rhs : Float[Array, "Nz Ny Nx"]
Right-hand side at cell-centred grid points.
dx, dy, dz : float
Grid spacings.
approximation : {"fd2", "spectral"}
Eigenvalue type. Default: "fd2".
Returns¶
Float[Array, "Nz Ny Nx"] Zero-mean solution ψ, same shape as rhs.
Source code in spectraldiffx/_src/fourier/solvers.py
Mixed Per-Axis BCs (2D/3D)¶
2D¶
solve_helmholtz_2d(rhs, dx, dy, bc_x='periodic', bc_y='periodic', lambda_=0.0, *, bc_x_values=(None, None), bc_y_values=(None, None))
¶
Solve (nabla^2 - lambda)psi = f in 2-D with per-axis boundary conditions.
Supports any combination of boundary conditions on each axis:
"periodic"— periodic (FFT)"dirichlet"— homogeneous Dirichlet on regular (vertex) grid (DST-I)"dirichlet_stag"— homogeneous Dirichlet on staggered (cell) grid (DST-II)"neumann"— homogeneous Neumann on regular grid (DCT-I)"neumann_stag"— homogeneous Neumann on staggered grid (DCT-II)("dirichlet_stag", "neumann_stag")— Dirichlet left + Neumann right, staggered (DST-IV)("neumann_stag", "dirichlet_stag")— Neumann left + Dirichlet right, staggered (DCT-IV)("dirichlet", "neumann")— Dirichlet left + Neumann right, regular (DST-III)("neumann", "dirichlet")— Neumann left + Dirichlet right, regular (DCT-III)
Transforms are applied as sequential 1-D transforms along each axis. When mixing FFT (complex) with DST/DCT (real), the real and imaginary parts are transformed separately along the non-periodic axis (PoisFFT approach).
Parameters¶
rhs : Float[Array, "Ny Nx"]
Right-hand side.
dx : float
Grid spacing in x.
dy : float
Grid spacing in y.
bc_x : BoundaryCondition
Boundary condition along the x-axis (columns).
bc_y : BoundaryCondition
Boundary condition along the y-axis (rows).
lambda_ : float
Helmholtz parameter. Default: 0.0 (Poisson).
bc_x_values : tuple[Array | None, Array | None], keyword-only
(left, right) inhomogeneous boundary values for x-axis.
Each is an array of shape (Ny,) or None (homogeneous).
For Dirichlet: prescribed psi values.
For Neumann: prescribed dpsi/dn (outward normal).
bc_y_values : tuple[Array | None, Array | None], keyword-only
(bottom, top) inhomogeneous boundary values for y-axis.
Each is an array of shape (Nx,) or None (homogeneous).
Returns¶
Float[Array, "Ny Nx"] Solution psi, same shape as rhs.
Notes¶
When using jax.jit, bc_x and bc_y must be marked as static
since they are Python objects used for dispatch::
solve_jit = jax.jit(solve_helmholtz_2d, static_argnames=("bc_x", "bc_y"))
Inhomogeneous BC support uses FD2 eigenvalues only (the default).
Source code in spectraldiffx/_src/fourier/solvers.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
solve_poisson_2d(rhs, dx, dy, bc_x='periodic', bc_y='periodic', *, bc_x_values=(None, None), bc_y_values=(None, None))
¶
Solve nabla^2 psi = f in 2-D with per-axis boundary conditions.
Convenience wrapper around :func:solve_helmholtz_2d with lambda_=0.
Source code in spectraldiffx/_src/fourier/solvers.py
3D¶
solve_helmholtz_3d(rhs, dx, dy, dz, bc_x='periodic', bc_y='periodic', bc_z='periodic', lambda_=0.0, *, bc_x_values=(None, None), bc_y_values=(None, None), bc_z_values=(None, None))
¶
Solve (nabla^2 - lambda)psi = f in 3-D with per-axis boundary conditions.
Supports any combination of boundary conditions on each axis:
"periodic"— periodic (FFT)"dirichlet"— homogeneous Dirichlet on regular grid (DST-I)"dirichlet_stag"— homogeneous Dirichlet on staggered grid (DST-II)"neumann"— homogeneous Neumann on regular grid (DCT-I)"neumann_stag"— homogeneous Neumann on staggered grid (DCT-II)("dirichlet_stag", "neumann_stag")— Dirichlet left + Neumann right, staggered (DST-IV)("neumann_stag", "dirichlet_stag")— Neumann left + Dirichlet right, staggered (DCT-IV)("dirichlet", "neumann")— Dirichlet left + Neumann right, regular (DST-III)("neumann", "dirichlet")— Neumann left + Dirichlet right, regular (DCT-III)
Transforms are applied as sequential 1-D transforms along each axis. Real (DST/DCT) axes are transformed first, periodic (FFT) axes last. This avoids complex intermediate handling — the IFFT on the inverse pass recovers real data before the real inverse transforms are applied.
Parameters¶
rhs : Float[Array, "Nz Ny Nx"]
Right-hand side.
dx : float
Grid spacing in x.
dy : float
Grid spacing in y.
dz : float
Grid spacing in z.
bc_x : BoundaryCondition
Boundary condition along the x-axis (columns).
bc_y : BoundaryCondition
Boundary condition along the y-axis (rows).
bc_z : BoundaryCondition
Boundary condition along the z-axis (depth).
lambda_ : float
Helmholtz parameter. Default: 0.0 (Poisson).
bc_x_values : tuple[Array | None, Array | None], keyword-only
(left, right) face arrays of shape (Nz, Ny) or None.
bc_y_values : tuple[Array | None, Array | None], keyword-only
(bottom, top) face arrays of shape (Nz, Nx) or None.
bc_z_values : tuple[Array | None, Array | None], keyword-only
(back, front) face arrays of shape (Ny, Nx) or None.
Returns¶
Float[Array, "Nz Ny Nx"] Solution psi, same shape as rhs.
Notes¶
When using jax.jit, bc_x, bc_y, and bc_z must be marked
as static since they are Python objects used for dispatch::
solve_jit = jax.jit(
solve_helmholtz_3d, static_argnames=("bc_x", "bc_y", "bc_z")
)
Inhomogeneous BC support uses FD2 eigenvalues only (the default).
Source code in spectraldiffx/_src/fourier/solvers.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 | |
solve_poisson_3d(rhs, dx, dy, dz, bc_x='periodic', bc_y='periodic', bc_z='periodic', *, bc_x_values=(None, None), bc_y_values=(None, None), bc_z_values=(None, None))
¶
Solve nabla^2 psi = f in 3-D with per-axis boundary conditions.
Convenience wrapper around :func:solve_helmholtz_3d with lambda_=0.
Source code in spectraldiffx/_src/fourier/solvers.py
Inhomogeneous BC Helpers¶
modify_rhs_1d(rhs, bc, dx, bc_values=(0.0, 0.0))
¶
Apply boundary source terms for inhomogeneous BCs to a 1-D RHS.
Modifies the right-hand side at boundary-adjacent grid points to account for non-zero boundary values. This exploits the FD2 stencil structure and must only be used with FD2 eigenvalues.
Parameters¶
rhs : Float[Array, " N"]
Original right-hand side.
bc : BoundaryCondition
Boundary condition type.
dx : float
Grid spacing.
bc_values : tuple[float, float]
(left_value, right_value). For Dirichlet BCs these are the
prescribed psi values; for Neumann BCs these are the prescribed
dpsi/dn (outward normal derivative) values.
Returns¶
Float[Array, " N"] Modified RHS with boundary source terms incorporated.
Source code in spectraldiffx/_src/fourier/solvers.py
modify_rhs_2d(rhs, bc_x, bc_y, dx, dy, bc_x_values=(None, None), bc_y_values=(None, None))
¶
Apply boundary source terms for inhomogeneous BCs to a 2-D RHS.
Parameters¶
rhs : Float[Array, "Ny Nx"]
Original right-hand side.
bc_x, bc_y : BoundaryCondition
Boundary condition types for x and y axes.
dx, dy : float
Grid spacings.
bc_x_values : tuple[Array | None, Array | None]
(left, right) boundary values for the x-axis.
Each is an array of shape (Ny,) or None (homogeneous).
bc_y_values : tuple[Array | None, Array | None]
(bottom, top) boundary values for the y-axis.
Each is an array of shape (Nx,) or None (homogeneous).
Returns¶
Float[Array, "Ny Nx"] Modified RHS.
Raises¶
ValueError If non-None boundary values are provided for a periodic axis.
Source code in spectraldiffx/_src/fourier/solvers.py
modify_rhs_3d(rhs, bc_x, bc_y, bc_z, dx, dy, dz, bc_x_values=(None, None), bc_y_values=(None, None), bc_z_values=(None, None))
¶
Apply boundary source terms for inhomogeneous BCs to a 3-D RHS.
Parameters¶
rhs : Float[Array, "Nz Ny Nx"]
Original right-hand side.
bc_x, bc_y, bc_z : BoundaryCondition
Boundary condition types for each axis.
dx, dy, dz : float
Grid spacings.
bc_x_values : tuple[Array | None, Array | None]
(left, right) face arrays of shape (Nz, Ny).
bc_y_values : tuple[Array | None, Array | None]
(bottom, top) face arrays of shape (Nz, Nx).
bc_z_values : tuple[Array | None, Array | None]
(back, front) face arrays of shape (Ny, Nx).
Returns¶
Float[Array, "Nz Ny Nx"] Modified RHS.
Raises¶
ValueError If non-None boundary values are provided for a periodic axis.
Source code in spectraldiffx/_src/fourier/solvers.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
Layer 1 — Module Classes¶
Periodic (FFT)¶
SpectralHelmholtzSolver1D
¶
Bases: Module
1D Helmholtz/Poisson solver with periodic BCs using FFT.
Solves (d²/dx² − α)φ = f on a periodic 1-D domain [0, L) using
continuous Fourier wavenumbers:
φ̂_k = −f̂_k / (k² + α)
where k = 2πm/L are the Fourier wavenumbers from grid.k.
For α = 0 (Poisson), the k=0 mode is singular; zero_mean=True
projects it out (sets φ̂_0 = 0).
Attributes¶
grid : FourierGrid1D 1-D Fourier grid providing wavenumbers and FFT methods.
Source code in spectraldiffx/_src/fourier/solvers.py
Functions¶
solve(f, alpha=0.0, zero_mean=True, spectral=False)
¶
Solve (d²/dx² − α)φ = f.
Parameters¶
f : Float[Array, "N"] Source term in physical space. alpha : float Helmholtz parameter (α ≥ 0). Default: 0.0 (Poisson). zero_mean : bool Force the mean (k=0 mode) to zero. Default: True. spectral : bool If True, f is already in spectral space.
Returns¶
Float[Array, "N"] Solution φ in physical space.
Source code in spectraldiffx/_src/fourier/solvers.py
SpectralHelmholtzSolver2D
¶
Bases: Module
2D Helmholtz/Poisson solver with periodic BCs using FFT.
Solves (∇² − α)φ = f on a doubly periodic domain using continuous
Fourier wavenumbers:
φ̂[j,i] = −f̂[j,i] / (kx_i² + ky_j² + α)
where |k|² = kx² + ky² is provided by grid.K2.
For α = 0 (Poisson), the (0,0) mode is singular; zero_mean=True
projects it out.
Attributes¶
grid : FourierGrid2D 2-D Fourier grid providing wavenumber meshgrid and FFT methods.
Source code in spectraldiffx/_src/fourier/solvers.py
Functions¶
solve(f, alpha=0.0, zero_mean=True, spectral=False)
¶
Solve (∇² − α)φ = f.
Parameters¶
f : Array [Ny, Nx] Source term in physical space. alpha : float Helmholtz parameter (α ≥ 0). Default: 0.0 (Poisson). zero_mean : bool Force the (0,0) mode to zero. Default: True. spectral : bool If True, f is already in spectral space.
Returns¶
Array [Ny, Nx] Solution φ in physical space.
Source code in spectraldiffx/_src/fourier/solvers.py
SpectralHelmholtzSolver3D
¶
Bases: Module
3D Helmholtz/Poisson solver with periodic BCs using FFT.
Solves (∇² − α)φ = f on a triply periodic domain using continuous
Fourier wavenumbers:
φ̂[l,j,i] = −f̂[l,j,i] / (kx_i² + ky_j² + kz_l² + α)
where |k|² = kx² + ky² + kz² is provided by grid.K2.
For α = 0 (Poisson), the (0,0,0) mode is singular; zero_mean=True
projects it out.
Attributes¶
grid : FourierGrid3D 3-D Fourier grid providing wavenumber meshgrid and FFT methods.
Source code in spectraldiffx/_src/fourier/solvers.py
Functions¶
solve(f, alpha=0.0, zero_mean=True, spectral=False)
¶
Solve (∇² − α)φ = f.
Parameters¶
f : Array [Nz, Ny, Nx] Source term in physical space. alpha : float Helmholtz parameter (α ≥ 0). Default: 0.0 (Poisson). zero_mean : bool Force the (0,0,0) mode to zero. Default: True. spectral : bool If True, f is already in spectral space.
Returns¶
Array [Nz, Ny, Nx] Solution φ in physical space.
Source code in spectraldiffx/_src/fourier/solvers.py
Dirichlet, Regular Grid (DST-I)¶
DirichletHelmholtzSolver2D
¶
Bases: Module
2D Helmholtz/Poisson/Laplace solver with homogeneous Dirichlet BCs.
Solves (∇² − α)ψ = f where ψ = 0 on all four edges, using the
DST-I spectral method (see :func:solve_helmholtz_dst).
The input rhs contains values at the Ny × Nx interior grid points; boundary values are implicitly zero.
With alpha=0.0 (default), solves the Poisson equation ∇²ψ = f.
Attributes¶
dx : float Grid spacing in x. dy : float Grid spacing in y. alpha : float Helmholtz parameter α ≥ 0. Default: 0.0 (Poisson/Laplace).
Source code in spectraldiffx/_src/fourier/solvers.py
Functions¶
__call__(rhs)
¶
Solve (∇² − α)ψ = rhs.
Parameters¶
rhs : Float[Array, "Ny Nx"] Right-hand side at interior grid points.
Returns¶
Float[Array, "Ny Nx"] Solution ψ at interior grid points.
Source code in spectraldiffx/_src/fourier/solvers.py
Dirichlet, Staggered Grid (DST-II)¶
StaggeredDirichletHelmholtzSolver2D
¶
Bases: Module
2D Helmholtz/Poisson solver with Dirichlet BCs on a staggered grid.
Solves (∇² − α)ψ = f where ψ = 0 at the cell edges (half a grid
spacing outside the first and last cell centres), using the DST-II
spectral method (see :func:solve_helmholtz_dst2).
Attributes¶
dx : float Grid spacing in x. dy : float Grid spacing in y. alpha : float Helmholtz parameter α ≥ 0. Default: 0.0 (Poisson).
Source code in spectraldiffx/_src/fourier/solvers.py
Functions¶
__call__(rhs)
¶
Solve (∇² − α)ψ = rhs.
Parameters¶
rhs : Float[Array, "Ny Nx"] Right-hand side at cell-centred grid points.
Returns¶
Float[Array, "Ny Nx"] Solution ψ at cell-centred grid points.
Source code in spectraldiffx/_src/fourier/solvers.py
Neumann, Staggered Grid (DCT-II)¶
NeumannHelmholtzSolver2D
¶
Bases: Module
2D Helmholtz/Poisson/Laplace solver with homogeneous Neumann BCs.
Solves (∇² − α)ψ = f where ∂ψ/∂n = 0 on all four edges, using
the DCT-II spectral method (see :func:solve_helmholtz_dct).
With alpha=0.0 (default), solves the Poisson equation ∇²ψ = f.
The Poisson null space (constant mode) is removed by enforcing
zero-mean: ψ̂[0,0] = 0.
Attributes¶
dx : float Grid spacing in x. dy : float Grid spacing in y. alpha : float Helmholtz parameter α ≥ 0. Default: 0.0 (Poisson/Laplace).
Source code in spectraldiffx/_src/fourier/solvers.py
Functions¶
__call__(rhs)
¶
Solve (∇² − α)ψ = rhs.
Parameters¶
rhs : Float[Array, "Ny Nx"] Right-hand side.
Returns¶
Float[Array, "Ny Nx"] Solution ψ (zero-mean gauge when α = 0).
Source code in spectraldiffx/_src/fourier/solvers.py
Neumann, Regular Grid (DCT-I)¶
RegularNeumannHelmholtzSolver2D
¶
Bases: Module
2D Helmholtz/Poisson solver with Neumann BCs on a regular grid.
Solves (∇² − α)ψ = f where ∂ψ/∂n = 0 on all four edges, using
the DCT-I spectral method (see :func:solve_helmholtz_dct1).
Attributes¶
dx : float Grid spacing in x. dy : float Grid spacing in y. alpha : float Helmholtz parameter α ≥ 0. Default: 0.0 (Poisson).
Source code in spectraldiffx/_src/fourier/solvers.py
Functions¶
__call__(rhs)
¶
Solve (∇² − α)ψ = rhs.
Parameters¶
rhs : Float[Array, "Ny Nx"] Right-hand side (including boundary grid points).
Returns¶
Float[Array, "Ny Nx"] Solution ψ (zero-mean gauge when α = 0).
Source code in spectraldiffx/_src/fourier/solvers.py
Mixed Per-Axis BCs¶
MixedBCHelmholtzSolver2D
¶
Bases: Module
2D Helmholtz/Poisson solver with per-axis boundary conditions.
Solves (nabla^2 - alpha)psi = f where each axis can have a different
boundary condition type (see :func:solve_helmholtz_2d).
Examples¶
Channel flow (periodic in x, Dirichlet walls in y)::
solver = MixedBCHelmholtzSolver2D(
dx=0.1,
dy=0.1,
bc_x="periodic",
bc_y="dirichlet",
)
psi = solver(rhs)
Attributes¶
dx : float Grid spacing in x. dy : float Grid spacing in y. bc_x : BoundaryCondition Boundary condition along the x-axis. bc_y : BoundaryCondition Boundary condition along the y-axis. alpha : float Helmholtz parameter. Default: 0.0 (Poisson).
Source code in spectraldiffx/_src/fourier/solvers.py
2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 | |
Functions¶
__call__(rhs, *, bc_x_values=(None, None), bc_y_values=(None, None))
¶
Solve (nabla^2 - alpha)psi = rhs.
Parameters¶
rhs : Float[Array, "Ny Nx"]
Right-hand side.
bc_x_values : tuple[Array | None, Array | None], keyword-only
(left, right) inhomogeneous boundary values for x-axis.
bc_y_values : tuple[Array | None, Array | None], keyword-only
(bottom, top) inhomogeneous boundary values for y-axis.
Returns¶
Float[Array, "Ny Nx"] Solution psi.
Source code in spectraldiffx/_src/fourier/solvers.py
MixedBCHelmholtzSolver3D
¶
Bases: Module
3D Helmholtz/Poisson solver with per-axis boundary conditions.
Solves (nabla^2 - alpha)psi = f where each axis can have a different
boundary condition type (see :func:solve_helmholtz_3d).
Examples¶
Atmospheric boundary layer (periodic x/y, Neumann z)::
solver = MixedBCHelmholtzSolver3D(
dx=1000.0,
dy=1000.0,
dz=50.0,
bc_x="periodic",
bc_y="periodic",
bc_z="neumann_stag",
)
psi = solver(rhs)
Attributes¶
dx : float Grid spacing in x. dy : float Grid spacing in y. dz : float Grid spacing in z. bc_x : BoundaryCondition Boundary condition along the x-axis. bc_y : BoundaryCondition Boundary condition along the y-axis. bc_z : BoundaryCondition Boundary condition along the z-axis. alpha : float Helmholtz parameter. Default: 0.0 (Poisson).
Source code in spectraldiffx/_src/fourier/solvers.py
2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 | |
Functions¶
__call__(rhs, *, bc_x_values=(None, None), bc_y_values=(None, None), bc_z_values=(None, None))
¶
Solve (nabla^2 - alpha)psi = rhs.
Parameters¶
rhs : Float[Array, "Nz Ny Nx"]
Right-hand side.
bc_x_values : tuple[Array | None, Array | None], keyword-only
(left, right) face arrays of shape (Nz, Ny).
bc_y_values : tuple[Array | None, Array | None], keyword-only
(bottom, top) face arrays of shape (Nz, Nx).
bc_z_values : tuple[Array | None, Array | None], keyword-only
(back, front) face arrays of shape (Ny, Nx).
Returns¶
Float[Array, "Nz Ny Nx"] Solution psi.