Chebyshev Derivative Operators¶
ChebyshevDerivative1D
¶
Bases: Module
1D Chebyshev derivative operator using the precomputed differentiation matrix.
Mathematical Formulation¶
For a function u(x) sampled at Chebyshev nodes xⱼ on [−L, L]:
(du/dx)ⱼ = Σₖ D_{jk} uₖ
where D is the (N+1)×(N+1) (Gauss–Lobatto) or N×N (Gauss) differentiation
matrix precomputed in :class:ChebyshevGrid1D. Higher-order derivatives
are matrix powers:
d²u/dx² = D · D · u = D² · u
Attributes¶
grid : ChebyshevGrid1D 1D Chebyshev grid carrying the differentiation matrix D.
Examples¶
Derivative of sin(πx) on [−1, 1]:
import jax.numpy as jnp grid = ChebyshevGrid1D.from_N_L(N=32, L=1.0) deriv = ChebyshevDerivative1D(grid=grid) u = jnp.sin(jnp.pi * grid.x) du_dx = deriv(u) # ≈ π cos(πx) d2u_dx2 = deriv(u, order=2) # ≈ −π² sin(πx)
Source code in spectraldiffx/_src/chebyshev/operators.py
Functions¶
__call__(u, order=1)
¶
Apply the n-th derivative Dⁿ to a nodal field.
Parameters¶
u : Float[Array, "Npts"]
Nodal values at Chebyshev nodes (Npts = N+1 for GL, N for Gauss).
order : int
Derivative order (≥ 0). order=0 returns a copy of u.
Returns¶
Float[Array, "Npts"] n-th derivative at the Chebyshev nodes.
Source code in spectraldiffx/_src/chebyshev/operators.py
gradient(u)
¶
ChebyshevDerivative2D
¶
Bases: Module
2D Chebyshev derivative operators on [−Lx, Lx] × [−Ly, Ly].
Mathematical Formulation¶
For u(x, y) on a (Nypts, Nxpts) grid with differentiation matrices Dx, Dy stored on the grid:
(∂u/∂x)[j, i] = (u · Dxᵀ)[j, i] # applied along axis 1 (x)
(∂u/∂y)[j, i] = (Dy · u)[j, i] # applied along axis 0 (y)
The scalar Laplacian and 2D divergence/curl follow directly:
∇²u = ∂²u/∂x² + ∂²u/∂y²
∇·V = ∂vₓ/∂x + ∂vᵧ/∂y
(∇×V)_z = ∂vᵧ/∂x − ∂vₓ/∂y
Attributes¶
grid : ChebyshevGrid2D 2D Chebyshev grid carrying Dx, Dy and the precomputed Dx², Dy².
Examples¶
Laplacian of u(x, y) = sin(πx)·sin(πy) on [−1, 1]²:
import jax.numpy as jnp grid = ChebyshevGrid2D.from_N_L(Nx=24, Ny=24, Lx=1.0, Ly=1.0) deriv = ChebyshevDerivative2D(grid=grid) X, Y = grid.X u = jnp.sin(jnp.pi * X) * jnp.sin(jnp.pi * Y) lap_u = deriv.laplacian(u) # ≈ −2π² u
Divergence of V = (y, −x) (should be ~0):
vx, vy = Y, -X div = deriv.divergence(vx, vy) # ≈ 0
Source code in spectraldiffx/_src/chebyshev/operators.py
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 | |
Functions¶
gradient(u)
¶
Partial derivatives (∂u/∂x, ∂u/∂y) of a 2D nodal field.
Source code in spectraldiffx/_src/chebyshev/operators.py
laplacian(u)
¶
2D Laplacian ∇²u = ∂²u/∂x² + ∂²u/∂y².
Uses precomputed Dx² and Dy² from the grid so the per-call cost is two matrix–matrix multiplies and an add (no O(N³) recomputation).
Source code in spectraldiffx/_src/chebyshev/operators.py
divergence(vx, vy)
¶
Cartesian divergence ∇·V = ∂vₓ/∂x + ∂vᵧ/∂y.
Source code in spectraldiffx/_src/chebyshev/operators.py
curl(vx, vy)
¶
Scalar curl ζ = ∂vᵧ/∂x − ∂vₓ/∂y (z-component of ∇×V).
Source code in spectraldiffx/_src/chebyshev/operators.py
advection_scalar(vx, vy, q)
¶
Scalar advection (V·∇)q = vₓ·∂q/∂x + vᵧ·∂q/∂y.