gvec.fourier#
pyGVEC postprocessing - Fourier representation
This module provides functions for computing the Fourier transform in 1D and 2D. In this context, the Fourier series is of the form \(x(\theta, \zeta) = \sum_{m, n} c_{m, n} \cos(m \theta - n \zeta) + s_{m, n} \sin(m \theta - n \zeta)\).
- gvec.fourier.eval2d(c: ndarray, s: ndarray, theta: ndarray, zeta: ndarray, deriv: str | None = None, nfp: int = 1)#
Evaluate a 2D Fourier series at given poloidal and toroidal angles.
- Parameters:
c (numpy.ndarray) – Cosine coefficients of the Fourier series.
s (numpy.ndarray) – Sine coefficients of the Fourier series.
theta (numpy.ndarray) – Poloidal angles at which to evaluate the series.
zeta (numpy.ndarray) – Toroidal angles at which to evaluate the series.
deriv (str, optional) – Derivative to evaluate, by default None. Specified as ‘theta’, ‘zeta’ or any string of ‘t’ & ‘z’, e.g. ‘t’, ‘tz’, ‘ttz’, …
nfp (int, optional) – Number of field periods, by default 1.
- Returns:
x – The values of the series at the given angles.
- Return type:
numpy.ndarray
- gvec.fourier.fft1d(x: Iterable)#
Compute the Fourier transform of a 1D array.
- Parameters:
x – Input array to transform.
- Returns:
c (ndarray) – Cosine coefficients of the Fourier series.
s (ndarray) – Sine coefficients of the Fourier series.
Notes
The function uses the real-input fast Fourier transform (rfft) from numpy.
- gvec.fourier.fft2d(x: ndarray)#
Compute the Fourier transform of a 2D array.
The Fourier series is of the form \(x(\theta, \zeta) = \sum_{m, n} c_{m, n} \cos(m \theta - n \zeta) + s_{m, n} \sin(m \theta - n \zeta)\). The coefficients are given as arrays of shape (M + 1, 2 * N + 1), where M and N are the maximum poloidal and toroidal harmonics, respectively. The coefficients with toroidal indices \(n > N\) are to be interpreted negatively, counted from the end of the array.
- Parameters:
x – Input array of shape (m, n) to transform.
- Returns:
c (ndarray) – Cosine coefficients of the double-angle Fourier series.
s (ndarray) – Sine coefficients of the double-angle Fourier series.
- gvec.fourier.fft2d_modes(M: int, N: int, grid: bool = False)#
Generate the modenumbers for a 2D FFT, as performed by fft2d.
- Parameters:
M (int) – The maximum poloidal modenumber.
N (int) – The maximum toroidal modenumber.
- Returns:
m (numpy.ndarray) – The poloidal modenumbers.
n (numpy.ndarray) – The toroidal modenumbers.
- gvec.fourier.ifft2d(c: ndarray, s: ndarray, deriv: str | None = None, nfp: int = 1) ndarray#
Inverse Fast-Fourier-Transform of a 2D Fourier series.
- Parameters:
c (numpy.ndarray) – Cosine coefficients of the Fourier series.
s (numpy.ndarray) – Sine coefficients of the Fourier series.
deriv (str, optional) – Derivative to evaluate, by default None. Specified as ‘theta’, ‘zeta’ or any string of ‘t’ & ‘z’, e.g. ‘t’, ‘tz’, ‘ttz’, …
nfp (int, optional) – Number of field periods, by default 1. Only used for derivatives, the data itself is always assumed to be in a single field period.
- Returns:
x – The values of the series at the given angles.
- Return type:
numpy.ndarray
- gvec.fourier.scale_modes2d(c, M, N)#
Scale the coefficients of a 2D Fourier series to a new maximum poloidal and toroidal harmonics.
- Parameters:
c (numpy.ndarray) – The coefficients of the original Fourier series.
M (int) – The new maximum poloidal harmonic.
N (int) – The new maximum toroidal harmonic.
- Returns:
c2 – The coefficients of the scaled Fourier series.
- Return type:
numpy.ndarray