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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, ' N']
|
Right-hand side on the periodic domain. |
required |
dx
|
float
|
Grid spacing. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
|
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, ' N']
|
Right-hand side on the periodic domain. |
required |
dx
|
float
|
Grid spacing. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side on the periodic domain. |
required |
dx
|
float
|
Grid spacing in x. |
required |
dy
|
float
|
Grid spacing in y. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side on the periodic domain. |
required |
dx
|
float
|
Grid spacing in x. |
required |
dy
|
float
|
Grid spacing in y. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Nz Ny Nx']
|
Right-hand side on the triply periodic domain. |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
dz
|
float
|
Grid spacings. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Nz Ny Nx']
|
Right-hand side on the triply periodic domain. |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
dz
|
float
|
Grid spacings. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, ' N']
|
Right-hand side at interior grid points. |
required |
dx
|
float
|
Grid spacing. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, ' N']
|
Right-hand side at interior grid points. |
required |
dx
|
float
|
Grid spacing. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side at interior grid points. |
required |
dx
|
float
|
Grid spacing in x. |
required |
dy
|
float
|
Grid spacing in y. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side at interior grid points. |
required |
dx
|
float
|
Grid spacing in x. |
required |
dy
|
float
|
Grid spacing in y. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Ny Nx']
|
Solution ψ, same shape as rhs. |
Source code in spectraldiffx/_src/fourier/solvers.py
Aliases naming the transform explicitly (same functions):
solve_helmholtz_dst1 = solve_helmholtz_dst
module-attribute
¶
solve_poisson_dst1 = solve_poisson_dst
module-attribute
¶
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Nz Ny Nx']
|
Right-hand side at interior grid points. |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
dz
|
float
|
Grid spacings. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Nz Ny Nx']
|
Right-hand side at interior grid points. |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
dz
|
float
|
Grid spacings. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, ' N']
|
Right-hand side at cell-centred grid points. |
required |
dx
|
float
|
Grid spacing. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, ' N']
|
Right-hand side at cell-centred grid points. |
required |
dx
|
float
|
Grid spacing. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side at cell-centred grid points. |
required |
dx
|
float
|
Grid spacing in x. |
required |
dy
|
float
|
Grid spacing in y. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side at cell-centred grid points. |
required |
dx
|
float
|
Grid spacing in x. |
required |
dy
|
float
|
Grid spacing in y. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Nz Ny Nx']
|
Right-hand side at cell-centred grid points. |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
dz
|
float
|
Grid spacings. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Nz Ny Nx']
|
Right-hand side at cell-centred grid points. |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
dz
|
float
|
Grid spacings. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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. The DCT-I FD2 matrix is not symmetric: its left null vector is the trapezoid weight w = (1/2, 1, …, 1, 1/2), so the gauge is the trapezoid mean w·ψ = 0 (not the plain mean), and a right-hand side with w·f ≠ 0 is silently replaced by f − (w·f / w·1) (gh-92).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, ' N']
|
Right-hand side (including boundary grid points). |
required |
dx
|
float
|
Grid spacing. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, ' N']
|
Right-hand side (including boundary grid points). |
required |
dx
|
float
|
Grid spacing. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
Float[Array, ' N']
|
Solution ψ with trapezoid mean w·ψ = 0, 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 zero mode is singular (the constant null mode
of the Neumann Laplacian) and ψ̂ there is set to 0. The DCT-I FD2 matrix
is not symmetric: its left null vector is the tensor product of the 1-D
trapezoid weights w = (1/2, 1, …, 1, 1/2), so the gauge is the
trapezoid mean w·ψ = 0 (not the plain mean), and a right-hand side
with w·f ≠ 0 is silently replaced by f − (w·f / w·1) (gh-92).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side (including boundary grid points). |
required |
dx
|
float
|
Grid spacing in x. |
required |
dy
|
float
|
Grid spacing in y. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side (including boundary grid points). |
required |
dx
|
float
|
Grid spacing in x. |
required |
dy
|
float
|
Grid spacing in y. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Ny Nx']
|
Solution ψ with trapezoid mean w·ψ = 0, 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).
When lambda_ == 0 the zero mode is singular (the constant null mode
of the Neumann Laplacian) and ψ̂ there is set to 0. The DCT-I FD2 matrix
is not symmetric: its left null vector is the tensor product of the 1-D
trapezoid weights w = (1/2, 1, …, 1, 1/2), so the gauge is the
trapezoid mean w·ψ = 0 (not the plain mean), and a right-hand side
with w·f ≠ 0 is silently replaced by f − (w·f / w·1) (gh-92).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Nz Ny Nx']
|
Right-hand side (including boundary grid points). |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
dz
|
float
|
Grid spacings. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Nz Ny Nx']
|
Right-hand side (including boundary grid points). |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
dz
|
float
|
Grid spacings. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Nz Ny Nx']
|
Solution ψ with trapezoid mean w·ψ = 0, 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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, ' N']
|
Right-hand side at cell-centred grid points. |
required |
dx
|
float
|
Grid spacing. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, ' N']
|
Right-hand side at cell-centred grid points. |
required |
dx
|
float
|
Grid spacing. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side. |
required |
dx
|
float
|
Grid spacing in x. |
required |
dy
|
float
|
Grid spacing in y. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side. |
required |
dx
|
float
|
Grid spacing in x. |
required |
dy
|
float
|
Grid spacing in y. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Ny Nx']
|
Zero-mean solution ψ, same shape as rhs. |
Source code in spectraldiffx/_src/fourier/solvers.py
Aliases naming the transform explicitly (same functions):
solve_helmholtz_dct2 = solve_helmholtz_dct
module-attribute
¶
solve_poisson_dct2 = solve_poisson_dct
module-attribute
¶
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Nz Ny Nx']
|
Right-hand side at cell-centred grid points. |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
dz
|
float
|
Grid spacings. |
required |
lambda_
|
float
|
Helmholtz parameter λ. Default: 0.0 (Poisson). |
0.0
|
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Nz Ny Nx']
|
Right-hand side at cell-centred grid points. |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
dz
|
float
|
Grid spacings. |
required |
approximation
|
('fd2', 'spectral')
|
Eigenvalue type. Default: |
"fd2"
|
Returns:
| Type | Description |
|---|---|
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)¶
BoundaryCondition = SameBC | MixedBC
module-attribute
¶
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side. |
required |
dx
|
float
|
Grid spacing in x. |
required |
dy
|
float
|
Grid spacing in y. |
required |
bc_x
|
BoundaryCondition
|
Boundary condition along the x-axis (columns). |
'periodic'
|
bc_y
|
BoundaryCondition
|
Boundary condition along the y-axis (rows). |
'periodic'
|
lambda_
|
float
|
Helmholtz parameter. Default: 0.0 (Poisson). |
0.0
|
bc_x_values
|
(tuple[Array | None, Array | None], keyword - only)
|
|
(None, None)
|
bc_y_values
|
(tuple[Array | None, Array | None], keyword - only)
|
|
(None, None)
|
Returns:
| Type | Description |
|---|---|
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"))
This function always uses the FD2 eigenvalues (it has no
approximation argument), which is what the inhomogeneous BC support
requires.
Source code in spectraldiffx/_src/fourier/solvers.py
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 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 | |
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Nz Ny Nx']
|
Right-hand side. |
required |
dx
|
float
|
Grid spacing in x. |
required |
dy
|
float
|
Grid spacing in y. |
required |
dz
|
float
|
Grid spacing in z. |
required |
bc_x
|
BoundaryCondition
|
Boundary condition along the x-axis (columns). |
'periodic'
|
bc_y
|
BoundaryCondition
|
Boundary condition along the y-axis (rows). |
'periodic'
|
bc_z
|
BoundaryCondition
|
Boundary condition along the z-axis (depth). |
'periodic'
|
lambda_
|
float
|
Helmholtz parameter. Default: 0.0 (Poisson). |
0.0
|
bc_x_values
|
(tuple[Array | None, Array | None], keyword - only)
|
|
(None, None)
|
bc_y_values
|
(tuple[Array | None, Array | None], keyword - only)
|
|
(None, None)
|
bc_z_values
|
(tuple[Array | None, Array | None], keyword - only)
|
|
(None, None)
|
Returns:
| Type | Description |
|---|---|
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")
)
This function always uses the FD2 eigenvalues (it has no
approximation argument), which is what the inhomogeneous BC support
requires.
Source code in spectraldiffx/_src/fourier/solvers.py
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 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
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. It is exact on regular (vertex) grids; on staggered grids the ghost-point correction (e.g. −2a/dx² for DST-II Dirichlet) is second-order accurate, not exact (error ≈ 1.8e-3 at dx = 0.1, converging at rate 4 per halving).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, ' N']
|
Original right-hand side. |
required |
bc
|
BoundaryCondition
|
Boundary condition type. |
required |
dx
|
float
|
Grid spacing. |
required |
bc_values
|
tuple[float, float]
|
|
(0.0, 0.0)
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Original right-hand side. |
required |
bc_x
|
BoundaryCondition
|
Boundary condition types for x and y axes. |
required |
bc_y
|
BoundaryCondition
|
Boundary condition types for x and y axes. |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
bc_x_values
|
tuple[Array | None, Array | None]
|
|
(None, None)
|
bc_y_values
|
tuple[Array | None, Array | None]
|
|
(None, None)
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Ny Nx']
|
Modified RHS. |
Raises:
| Type | Description |
|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Nz Ny Nx']
|
Original right-hand side. |
required |
bc_x
|
BoundaryCondition
|
Boundary condition types for each axis. |
required |
bc_y
|
BoundaryCondition
|
Boundary condition types for each axis. |
required |
bc_z
|
BoundaryCondition
|
Boundary condition types for each axis. |
required |
dx
|
float
|
Grid spacings. |
required |
dy
|
float
|
Grid spacings. |
required |
dz
|
float
|
Grid spacings. |
required |
bc_x_values
|
tuple[Array | None, Array | None]
|
|
(None, None)
|
bc_y_values
|
tuple[Array | None, Array | None]
|
|
(None, None)
|
bc_z_values
|
tuple[Array | None, Array | None]
|
|
(None, None)
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Nz Ny Nx']
|
Modified RHS. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If non-None boundary values are provided for a periodic axis. |
Source code in spectraldiffx/_src/fourier/solvers.py
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 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
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.
These classes use the continuous wavenumbers k² (equivalent to
approximation="spectral"), while the solve_helmholtz_* functions
default to the FD2 eigenvalues (approximation="fd2"). The two agree
for well-resolved modes and differ near the grid scale (by ~7e-3
relative at 16², gh-94).
Null mode (gh-92): for α = 0 (Poisson) the k = 0 mode is singular and φ̂_0 is set to 0; for α > 0 it is solved like every other mode.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
FourierGrid1D
|
1-D Fourier grid providing wavenumbers and FFT methods. |
Source code in spectraldiffx/_src/fourier/solvers.py
2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 | |
Functions¶
solve(f, alpha=0.0, zero_mean=None, spectral=False)
¶
Solve (d²/dx² − α)φ = f.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Float[Array, 'N']
|
Source term in physical space. |
required |
alpha
|
float
|
Helmholtz parameter (α ≥ 0). Default: 0.0 (Poisson). |
0.0
|
zero_mean
|
bool or None
|
|
None
|
spectral
|
bool
|
If True, f is already in spectral space. |
False
|
Returns:
| Type | Description |
|---|---|
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.
These classes use the continuous wavenumbers k² (equivalent to
approximation="spectral"), while the solve_helmholtz_* functions
default to the FD2 eigenvalues (approximation="fd2"). The two agree
for well-resolved modes and differ near the grid scale (by ~7e-3
relative at 16², gh-94).
Null mode (gh-92): for α = 0 (Poisson) the (0,0) mode is singular and set to 0; for α > 0 it is solved like every other mode.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
FourierGrid2D
|
2-D Fourier grid providing wavenumber meshgrid and FFT methods. |
Source code in spectraldiffx/_src/fourier/solvers.py
2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 | |
Functions¶
solve(f, alpha=0.0, zero_mean=None, spectral=False)
¶
Solve (∇² − α)φ = f.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Array[Ny, Nx]
|
Source term in physical space. |
required |
alpha
|
float
|
Helmholtz parameter (α ≥ 0). Default: 0.0 (Poisson). |
0.0
|
zero_mean
|
bool or None
|
|
None
|
spectral
|
bool
|
If True, f is already in spectral space. |
False
|
Returns:
| Type | Description |
|---|---|
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.
These classes use the continuous wavenumbers k² (equivalent to
approximation="spectral"), while the solve_helmholtz_* functions
default to the FD2 eigenvalues (approximation="fd2"). The two agree
for well-resolved modes and differ near the grid scale (by ~7e-3
relative at 16², gh-94).
Null mode (gh-92): for α = 0 (Poisson) the (0,0,0) mode is singular and set to 0; for α > 0 it is solved like every other mode.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
FourierGrid3D
|
3-D Fourier grid providing wavenumber meshgrid and FFT methods. |
Source code in spectraldiffx/_src/fourier/solvers.py
2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 | |
Functions¶
solve(f, alpha=0.0, zero_mean=None, spectral=False)
¶
Solve (∇² − α)φ = f.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Array[Nz, Ny, Nx]
|
Source term in physical space. |
required |
alpha
|
float
|
Helmholtz parameter (α ≥ 0). Default: 0.0 (Poisson). |
0.0
|
zero_mean
|
bool or None
|
|
None
|
spectral
|
bool
|
If True, f is already in spectral space. |
False
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description |
|---|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side at interior grid points. |
required |
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description |
|---|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side at cell-centred grid points. |
required |
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description |
|---|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side. |
required |
Returns:
| Type | Description |
|---|---|
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).
The α = 0 gauge is the trapezoid mean w·ψ = 0; see
:func:solve_helmholtz_dct1 (gh-92).
Attributes:
| Name | Type | Description |
|---|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side (including boundary grid points). |
required |
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description |
|---|---|---|
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
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 2524 2525 2526 2527 | |
Functions¶
__call__(rhs, *, bc_x_values=(None, None), bc_y_values=(None, None))
¶
Solve (nabla^2 - alpha)psi = rhs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side. |
required |
bc_x_values
|
(tuple[Array | None, Array | None], keyword - only)
|
|
(None, None)
|
bc_y_values
|
(tuple[Array | None, Array | None], keyword - only)
|
|
(None, None)
|
Returns:
| Type | Description |
|---|---|
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:
| Name | Type | Description |
|---|---|---|
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
2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 | |
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:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Nz Ny Nx']
|
Right-hand side. |
required |
bc_x_values
|
(tuple[Array | None, Array | None], keyword - only)
|
|
(None, None)
|
bc_y_values
|
(tuple[Array | None, Array | None], keyword - only)
|
|
(None, None)
|
bc_z_values
|
(tuple[Array | None, Array | None], keyword - only)
|
|
(None, None)
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Nz Ny Nx']
|
Solution psi. |