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_k
where D is the (N+1)×(N+1) [or N×N for Gauss] differentiation matrix precomputed in ChebyshevGrid1D.
Higher-order derivatives are obtained by matrix powers
d²u/dx² = D @ (D @ u) = D² @ u
grid : ChebyshevGrid1D
The 1D Chebyshev grid containing the differentiation matrix.
Source code in spectraldiffx/_src/chebyshev/operators.py
Functions¶
__call__(u, order=1)
¶
Compute the n-th derivative of a field using the differentiation matrix.
Operation
du/dx = D @ u d²u/dx² = D @ D @ u
Parameters:¶
u : Array [N+1] for GL, [N] for Gauss Physical-space field values at Chebyshev nodes. order : int Derivative order (1 = first, 2 = second, ...). Default is 1.
Returns:¶
dnu_dxn : Array [N+1] or [N] n-th derivative at 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 (Ny_pts, Nx_pts) grid:
∂u/∂x [j,i] = (u @ Dxᵀ)[j,i] (differentiation along axis 1)
∂u/∂y [j,i] = (Dy @ u)[j,i] (differentiation along axis 0)
Laplacian: ∇²u = ∂²u/∂x² + ∂²u/∂y²
grid : ChebyshevGrid2D
The 2D Chebyshev grid containing Dx and Dy matrices.
Source code in spectraldiffx/_src/chebyshev/operators.py
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 | |
Functions¶
gradient(u)
¶
Compute partial derivatives (∂u/∂x, ∂u/∂y).
Parameters:¶
u : Array [Ny_pts, Nx_pts] 2D field at Chebyshev nodes.
Returns:¶
(du_dx, du_dy) : tuple of Arrays [Ny_pts, Nx_pts]
Source code in spectraldiffx/_src/chebyshev/operators.py
laplacian(u)
¶
Compute the 2D Laplacian ∇²u = ∂²u/∂x² + ∂²u/∂y².
Uses precomputed second-derivative matrices Dx2 = Dx@Dx and Dy2 = Dy@Dy (stored on the grid) to avoid recomputing the O(N³) matrix products on every call.
Parameters:¶
u : Array [Ny_pts, Nx_pts]
Returns:¶
lap_u : Array [Ny_pts, Nx_pts]
Source code in spectraldiffx/_src/chebyshev/operators.py
divergence(vx, vy)
¶
Compute the divergence ∇·V = ∂vx/∂x + ∂vy/∂y.
Parameters:¶
vx : Array [Ny_pts, Nx_pts] x-component of the vector field. vy : Array [Ny_pts, Nx_pts] y-component of the vector field.
Returns:¶
div : Array [Ny_pts, Nx_pts]
Source code in spectraldiffx/_src/chebyshev/operators.py
curl(vx, vy)
¶
Compute the 2D scalar curl ζ = ∂vy/∂x - ∂vx/∂y.
Parameters:¶
vx : Array [Ny_pts, Nx_pts] vy : Array [Ny_pts, Nx_pts]
Returns:¶
curl : Array [Ny_pts, Nx_pts]
Source code in spectraldiffx/_src/chebyshev/operators.py
advection_scalar(vx, vy, q)
¶
Compute scalar advection (V·∇)q = vx·∂q/∂x + vy·∂q/∂y.
Parameters:¶
vx : Array [Ny_pts, Nx_pts] x-velocity. vy : Array [Ny_pts, Nx_pts] y-velocity. q : Array [Ny_pts, Nx_pts] Scalar tracer field.
Returns:¶
adv : Array [Ny_pts, Nx_pts]