Chebyshev Helmholtz Solvers¶
ChebyshevHelmholtzSolver1D
¶
Bases: Module
1D Chebyshev-collocation Helmholtz/Poisson solver with Dirichlet or Neumann BCs.
Solves the boundary-value problem on [−L, L]:
d²u/dx² − α·u = f(x), x ∈ [−L, L]
with boundary conditions selected via bc_type:
Dirichlet: u(+L) = bc_right, u(−L) = bc_left
Neumann: u'(+L) = bc_right, u'(−L) = bc_left
For α = 0 this reduces to Poisson.
Method — Boundary Elimination + Matrix Diagonalisation
On Gauss–Lobatto nodes the endpoints x[0]=+L and x[N]=−L are collocation points. Split the nodes into interior I = {1, …, N−1} and boundary B = {0, N}. Collocating D²u − αu = f at the interior nodes gives
(D²_II − α) u_I + D²_IB u_B = f_I (1)
Dirichlet: u_B = g is given, so
(D²_II − α) u_I = f_I − D²_IB g, E := D²_II
Neumann: the boundary rows D_BB u_B + D_BI u_I = g give u_B = D_BB⁻¹ (g − D_BI u_I); substituting into (1),
(E − α) u_I = f_I − D²_IB D_BB⁻¹ g, E := D²_II − D²_IB D_BB⁻¹ D_BI
In both cases E depends only on the grid, so it is diagonalised once
at construction (:class:gaussx.EigenFactorization), E = Q Λ Q⁻¹, and
every solve is
u_I = Q · diag(1 / (λ − α)) · Q⁻¹ · r O(N²)
for any α — no per-call O(N³) factorisation, and α may be a traced
JAX value (so the solve is jit/grad-compatible in α). E has
real, non-positive eigenvalues and well-conditioned eigenvectors, so
the diagonalisation is as accurate as a direct LU solve.
Pure Neumann + Poisson (α = 0) is only solvable up to a constant: the Neumann E has an exact null vector (the constant). The solver drops that eigen-component (i.e. projects out the incompatible part of f) and then fixes the gauge u[N//2] = 0. Shift the returned field by any constant if a different gauge is needed.
Gauss-node grids do not include the endpoints, so this method is
inapplicable; solve validates the grid and raises.
If the solver is constructed inside a traced function from a traced grid (so its matrices cannot be read at construction time), it falls back to an equivalent dense boundary-row solve on every call.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
ChebyshevGrid1D
|
Must use |
Examples:
Solve u″ = −π² sin(πx) with u(±1) = 0 (analytic solution u = sin(πx)):
>>> import jax.numpy as jnp
>>> grid = ChebyshevGrid1D.from_N_L(N=32, L=1.0)
>>> solver = ChebyshevHelmholtzSolver1D(grid=grid)
>>> x = grid.x
>>> f = -(jnp.pi**2) * jnp.sin(jnp.pi * x)
>>> u = solver.solve(f, alpha=0.0, bc_left=0.0, bc_right=0.0)
Neumann example — solve u″ = cos(πx) with u'(±1) = 0:
Source code in spectraldiffx/_src/chebyshev/solvers.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
Functions¶
solve(f, alpha=0.0, bc_left=0.0, bc_right=0.0, bc_type='dirichlet')
¶
Solve (d²/dx² − α) u = f on [−L, L] with Dirichlet or Neumann BCs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Num[Array, 'Npts']
|
Source term sampled at the N+1 Gauss–Lobatto nodes (ordered x[0]=+L, …, x[N]=−L). The boundary entries f[0] and f[N] are ignored (they are replaced by the BCs). |
required |
alpha
|
float or scalar Array
|
Helmholtz parameter (≥ 0). α=0 gives the Poisson equation. May be a traced value. |
0.0
|
bc_left
|
float or scalar Array
|
BC value at x = −L. Dirichlet: u(−L); Neumann: u'(−L). |
0.0
|
bc_right
|
float or scalar Array
|
BC value at x = +L. Dirichlet: u(+L); Neumann: u'(+L). |
0.0
|
bc_type
|
('dirichlet', 'neumann')
|
Boundary-condition flavour (static). |
"dirichlet"
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Npts']
|
Solution at the N+1 GL nodes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the grid uses Gauss nodes, the length of |
Source code in spectraldiffx/_src/chebyshev/solvers.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
ChebyshevPoissonSolver1D
¶
Bases: Module
1D Chebyshev Poisson solver: d²u/dx² = f on [−L, L].
Convenience wrapper around :class:ChebyshevHelmholtzSolver1D with α = 0.
The wrapped solver (and its precomputed eigendecomposition) is built
once at construction.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
ChebyshevGrid1D
|
Must use |
Examples:
>>> import jax.numpy as jnp
>>> grid = ChebyshevGrid1D.from_N_L(N=32, L=1.0)
>>> solver = ChebyshevPoissonSolver1D(grid=grid)
>>> f = -(jnp.pi**2) * jnp.sin(jnp.pi * grid.x)
>>> u = solver.solve(f) # ≈ sin(πx)
Source code in spectraldiffx/_src/chebyshev/solvers.py
Functions¶
solve(f, bc_left=0.0, bc_right=0.0, bc_type='dirichlet')
¶
Solve d²u/dx² = f with Dirichlet or Neumann BCs.
Source code in spectraldiffx/_src/chebyshev/solvers.py
ChebyshevHelmholtzSolver2D
¶
Bases: Module
2D Chebyshev-collocation Helmholtz/Poisson solver with Dirichlet BCs.
Solves on [−Lx, Lx] × [−Ly, Ly]:
∇²u − α·u = f(x, y)
with Dirichlet data on all four edges. The boundary data are provided as four 1D arrays (top, bottom, left, right), evaluated at the Gauss–Lobatto nodes along each edge.
Method — Matrix Diagonalisation (Haidvogel & Zang 1979)
With u[j, i] = u(xᵢ, yⱼ), the collocated operator is
∇²u = Dy² · u + u · Dx²ᵀ
Split each direction into interior (I) and boundary (B) nodes. The boundary values u_B are known, so the interior unknowns U = u[I, I] satisfy the Sylvester equation
Ay U + U Axᵀ − α U = R,
Ay = Dy²[I, I], Ax = Dx²[I, I],
R = f[I, I] − Dy²[I, B] u[B, I] − u[I, B] Dx²[I, B]ᵀ
(the corner values never enter). Diagonalising the 1D operators once at construction, Ay = Qy Λy Qy⁻¹ and Ax = Qx Λx Qx⁻¹, the solve is
Û = Qy⁻¹ R Qx⁻ᵀ
Û[j, i] ← Û[j, i] / (λy_j + λx_i − α)
U = Qy Û Qxᵀ
(:func:gaussx.kronecker_sum_solve), i.e. four small matrix–matrix
products: O(Nx·Ny·(Nx + Ny)) per call
for any α (vs O((Nx·Ny)³) for the dense Kronecker system), and α may
be traced. If the solver is constructed inside a traced function from
a traced grid, it falls back to the dense Kronecker solve.
Notes
• For pure-Neumann Poisson in 2D we do not provide a solver here; use a Fourier backend.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
ChebyshevGrid2D
|
Must use |
Examples:
Solve ∇²u = −2π² sin(πx) sin(πy) with homogeneous Dirichlet BCs:
>>> import jax.numpy as jnp
>>> grid = ChebyshevGrid2D.from_N_L(Nx=16, Ny=16, Lx=1.0, Ly=1.0)
>>> solver = ChebyshevHelmholtzSolver2D(grid=grid)
>>> X, Y = grid.X
>>> f = -2 * jnp.pi**2 * jnp.sin(jnp.pi * X) * jnp.sin(jnp.pi * Y)
>>> u = solver.solve(f, alpha=0.0)
Source code in spectraldiffx/_src/chebyshev/solvers.py
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 420 421 422 423 424 425 426 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 | |
Functions¶
solve(f, alpha=0.0, bc_top=0.0, bc_bottom=0.0, bc_left=0.0, bc_right=0.0)
¶
Solve (∇² − α) u = f with Dirichlet BCs on all four edges.
Boundary indexing (Gauss–Lobatto orientation):
top row is grid.y[0] (y = +Ly) at axis 0, index 0
bottom row is grid.y[-1] (y = −Ly) at axis 0, index Nᵧ
right col is grid.x[0] (x = +Lx) at axis 1, index 0
left col is grid.x[-1] (x = −Lx) at axis 1, index Nₓ
At the four corners the left/right values take precedence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Num[Array, 'Nypts Nxpts']
|
Source term at the 2D GL nodes (boundary entries are ignored). |
required |
alpha
|
float or scalar Array
|
Helmholtz parameter (≥ 0). May be a traced value. |
0.0
|
bc_top
|
float or Num[Array, 'Nxpts']
|
Dirichlet values along the top and bottom edges. Scalars broadcast. |
0.0
|
bc_bottom
|
float or Num[Array, 'Nxpts']
|
Dirichlet values along the top and bottom edges. Scalars broadcast. |
0.0
|
bc_left
|
float or Num[Array, 'Nypts']
|
Dirichlet values along the left and right edges. |
0.0
|
bc_right
|
float or Num[Array, 'Nypts']
|
Dirichlet values along the left and right edges. |
0.0
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'Nypts Nxpts']
|
Solution on the (Nᵧ+1, Nₓ+1) GL grid. |
Source code in spectraldiffx/_src/chebyshev/solvers.py
ChebyshevPoissonSolver2D
¶
Bases: Module
2D Chebyshev Poisson solver: ∇²u = f with Dirichlet BCs.
Convenience wrapper around :class:ChebyshevHelmholtzSolver2D with α = 0.
The wrapped solver (and its precomputed eigendecompositions) is built
once at construction.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
ChebyshevGrid2D
|
Must use |
Examples:
>>> import jax.numpy as jnp
>>> grid = ChebyshevGrid2D.from_N_L(Nx=16, Ny=16, Lx=1.0, Ly=1.0)
>>> solver = ChebyshevPoissonSolver2D(grid=grid)
>>> X, Y = grid.X
>>> f = -2 * jnp.pi**2 * jnp.sin(jnp.pi * X) * jnp.sin(jnp.pi * Y)
>>> u = solver.solve(f) # ≈ sin(πx) sin(πy)
Source code in spectraldiffx/_src/chebyshev/solvers.py
Functions¶
solve(f, bc_top=0.0, bc_bottom=0.0, bc_left=0.0, bc_right=0.0)
¶
Solve ∇²u = f with Dirichlet BCs on all four edges.