thunder4d.grid
Simulation grid and FFT conventions (see Quickstart).
- thunder4d.grid.C0
Speed of light in vacuum [m/s].
Grid
- class thunder4d.grid.Grid(Nx, dx, Nt, lambda0, *, dt=None, lambda_min=None, lambda_max=None, Ny=None, dy=None, dtype=np.complex64, fft_backend='auto', workers=None, device='auto')[source]
\((x, y, t)\) grid centred on \(\lambda_0\).
- Parameters:
Nx (int) – number of transverse points (
Nydefaults to the same)dx (float) – transverse step [m] (
dydefaults to the same)Nt (int) – number of temporal points
lambda0 (float) – carrier wavelength [m]; defines \(\Omega = 0\) and the moving frame
dt (float) – time step [s]. Alternatively give
lambda_min(and optionallylambda_max) anddtis chosen so the spectral window covers them.dtype –
np.complex64(default, half the memory) ornp.complex128device (str) –
"auto"(GPU if CuPy and a CUDA device work, else CPU),"cpu"or"gpu"(raises if no GPU is usable). The field, propagators and mirror transfer function live on that device (grid.device,grid.xp); axes such asgrid.xandgrid.lamstay NumPy.fft_backend (str) –
"auto"(same as"scipy"),"scipy","numpy"or"fftw"(pyFFTW, CPU only; see FFTW (CPU))workers (int) – threads for the SciPy and FFTW backends (default: all cores)
Attributes
x, ycoordinates [m], FFT order
kx, kytransverse wavenumbers [rad/m], FFT order
ttime [s], FFT order
Omegaangular frequency offset \(\Omega\) [rad/s], FFT order
omegaabsolute angular frequency \(\omega_0 + \Omega\)
lamwavelength [m] for each \(\Omega\) (
infwhere \(\omega \le 0\))validboolean mask, \(\omega > 0\)
omega0, lambda0carrier
dtype, rdtypecomplex and matching real dtype
fftFFTobjectshape(Nx, Ny, Nt)X, Ybroadcastable coordinates, shapes
(Nx, 1)and(1, Ny)r2\(x^2 + y^2\), shape
(Nx, Ny)dA\(dx\,dy\)
xs, ys, ts, kxs, lams, Omegassorted versions, for plotting
FFT
- class thunder4d.grid.FFT(backend='auto', workers=None, device='cpu')[source]
Thin wrapper applying the conventions of Quickstart. With
backend="fftw", 3D complex arrays (the solvers’ fields) use planned FFTW transforms, one plan per shape, dtype and transform, made on first use with the effortFFT.fftw_effort("FFTW_MEASURE"by default;"FFTW_ESTIMATE"plans instantly,"FFTW_PATIENT"searches longer); every other array goes toscipy.fft. Each call returns a new array and leaves its input unchanged, as with SciPy.
suggest_grid
- thunder4d.grid.suggest_grid(cell, lambda0, lambda_min, lambda_max, pulse_fwhm, *, box_factor=8.0, points_per_waist=8.0, time_window_factor=8.0, **grid_kw)[source]
Choose a
Gridadapted to a cell.Box width:
box_factor× the largest mirror spot radius (atlambda_max).Step dx: the smaller of the smallest waist (at
lambda_min) divided bypoints_per_waist, and the Nyquist limit of the mirror curvature phase at the corner of the box, \(0.8\,\lambda_\text{min} R / (\sqrt 2 L)\).Time step: covers [
lambda_min,lambda_max] aroundlambda0.Point counts:
Ntcoverstime_window_factor× the input FWHM;NxandNtare rounded up to fast FFT sizes (\(2^a 3^b 5^c\)).
- Parameters:
- Returns:
Tip
Use
box_factor≥ 12–14 for top-hat, clipped or aberrated inputs: their higher-order content is much wider than the fundamental mode.
GPU and CPU helpers
- thunder4d.grid.gpu_available()
Trueif CuPy is installed and a CUDA device can run a kernel and an FFT (checked once).
- thunder4d.grid.to_host(a)
NumPy array from an array that may live on the GPU (no copy for NumPy input). The field
sim.AwandPulse.Aware device arrays on a GPU grid; the diagnostics accept either and always return NumPy arrays (they copy the field to the host once per call).
- thunder4d.kernels.numba_available()
Trueif Numba is installed: the 4D solvers then use the fused CPU kernels by default (see Numba kernels (CPU)).