Internals
These functions and types are not part of the public API (they are not exported), but are documented here for contributors. They may change without notice.
Execution-backend helpers
The execution-axis introspection helpers (local_backend, is_distributed, resolve_backend) are provided by ComputationalBackends.jl and used internally and by the distribution extensions. The default AutoBackend resolves through the internal _resolve_execution (Threaded when OhMyThreads is loaded and Threads.nthreads() > 1, else Serial); ComputationalBackends' own resolve_backend(::AutoBackend) raises.
FlowFieldSpectra._backend_nthreads — Function
_backend_nthreads(exec) -> IntThread count for a library plan built under exec: Threads.nthreads() on a threaded backend, 1 otherwise. Every library plan FFS builds itself receives this explicit count, since FINUFFT reads 0 as every core on the machine. A host NUFSHT plan takes execution = exec and sets the same count from it; a device one, built over device nodes, takes this count.
FlowFieldSpectra._to_host — Function
_to_host(a) -> Arraya as a host Array, returning it unchanged when it already is one. copyto! covers every KA / GPUArrays device array, so this is device-generic.
Plans
FlowFieldSpectra.DirectSumCartesianPlan — Type
DirectSumCartesianPlan{FT}Reusable Cartesian direct-sum plan: the per-axis dense DFT matrices, the working arrays the contraction walks through, the wavenumber axes, the modes held at zero, and the quadrature-scaled field buffer, all built once for a fixed grid, ms, iflag and batch shape. Execute with calculate_spectrum!(coeffs, plan, field), which runs on the plan's execution backend.
FlowFieldSpectra.DirectSumSphericalPlan — Type
DirectSumSphericalPlan{FT}Reusable spherical direct-sum plan: the grid's materialized nodes (or its ring table, or its longitude DFT matrix and latitude quadrature — whichever its layout reads), the Legendre recurrence tables, and the (lmax+1, nrings, B) longitude buffer, all built once for a fixed grid, lmax and batch shape. For a complex element type T the plan also holds the exp(+imλ) longitude transform's matrix and buffer. Execute with calculate_spectrum!(coeffs, plan, field), which runs on the plan's execution backend.
FlowFieldSpectra.DirectSumSynthesisPlan — Type
DirectSumSynthesisPlan{FT}Reusable direct-sum synthesis: the grid, resolution, sign and batch shape the series is fixed by, so synthesize! writes into the caller's array and allocates nothing of its own.
The plan holds what the synthesis reads from the grid (DirectSum.synth_setup): on a tensor grid the per-axis tables and the working arrays their contraction walks through, on a Cartesian point set the positions and wavenumbers, and on a sphere the nodes and Legendre tables.
FlowFieldSpectra.HybridPlan — Type
HybridPlan{T,D,R}Reusable plan for a Cartesian grid uniform in some directions and stretched in others, on the host or a device: the FFT over the uniform axes (RegionFFT), one 1-D type-1 NUFFT per stretched axis, the length(sdims) + 1 working arrays the passes write through, the last in the coefficients' layout, and the per-point weights the field is staged with. R marks a real field. Execute with calculate_spectrum!(coeffs, plan, field); close! releases the NUFFT library plans.
FlowFieldSpectra.RegionFFT — Type
RegionFFT{P,S,O}The hybrid composite's FFT over its uniform axes, planned once on the execution backend's arrays. A real field takes an rfft, which shortens axis 1 to n₁÷2+1. conj_in conjugates a complex input, carrying iflag = -1 through the composite. The field is staged into scratch with its quadrature weights, so the caller's array is never mutated.
FlowFieldSpectra._hybrid_plan — Function
_hybrid_plan(nufft, exec, grid, ::Type{T}, ms; batch, iflag, eps, measure = true, kwargs...)A HybridPlan on exec, a host or a device backend, for a grid uniform in some directions and stretched in others. measure selects FFTW's measured planning for the uniform axes; the one-shot transform passes false.
FlowFieldSpectra._hybrid_derive — Function
_hybrid_derive(grid, ::Type{Tr}, ms, ::Type{T}, iflag, eps) -> NamedTupleEverything the hybrid composite needs before any transform runs: the stretched axes, every axis's origin and Fourier length, which dims the FFT takes and which the NUFFT takes (tuples whose lengths the grid's axis types fix), the coefficient box, the coefficients' extents, its sign, and the wavenumber axes.
FlowFieldSpectra.HybridSynthesisPlan — Type
HybridSynthesisPlan{T,D,R}Reusable synthesis for a Cartesian grid uniform in some directions and stretched in others, the counterpart of HybridPlan on the host or a device: one 1-D type-2 NUFFT per stretched axis, the backward FFT over the uniform axes (c2r for a real field), the working arrays the passes write through, and on a device the field buffer a host array is filled from. R marks a real field. Execute with synthesize!(out, plan, coeffs); close! releases the NUFFT library plans.
FlowFieldSpectra._hybrid_synthesis_plan — Function
_hybrid_synthesis_plan(nufft, exec, grid, ::Type{T}, ms; batch, iflag, eps, measure = true, kwargs...)A HybridSynthesisPlan on exec, a host or a device backend, for a grid uniform in some directions and stretched in others, T the field's element type. measure selects FFTW's measured planning for the uniform axes; a one-shot synthesis passes false.
FlowFieldSpectra.Plans.SplitFFTPlan — Type
SplitFFTPlanReusable Fourier transform of one field held in FlowGeometries blocks, including trailing batch axes. Each axis transforms on a split that holds that axis whole. The coefficient fields use a Cartesian index grid; wavenumbers gives their physical mode coordinates. Consecutive stages on the same block layout share a coefficient field.
NUFFT plans
The NUFFT plans run FlowTransformBindings' library plans in FFTModes order and publish the packed layout from them: a point set's type 1 and type 2, and a nonuniform tensor grid's separable passes in both directions. A line pass of the separable plans and the hybrid composite asks NonuniformFFTs for m_d modes and reads, or writes, the mode +m_d/2 of a widened axis in each line's oversampled spectrum; it asks FINUFFT for the box's m_d + 1 modes.
FlowFieldSpectra.NUFFTPointPlan — Type
NUFFTPointPlan{T,D,R}Reusable type-1 NUFFT over a Cartesian point set (a node cloud or a curvilinear grid's cells): the FlowTransformBindings plan with C transforms per execution, its strength and spectrum buffers, and the tables that publish the coefficient box. R marks a real field. Execute with calculate_spectrum!(coeffs, plan, field); close! releases the library plan.
FlowFieldSpectra.NUFFTSeparablePlan — Type
NUFFTSeparablePlan{T,D,R}Reusable separable NUFFT over a nonuniform tensor-product Cartesian grid: one NUFFTAxisPass per axis, the working arrays the passes write through, and the per-point weights the field is staged with. Execute with calculate_spectrum!(coeffs, plan, field); close! releases the library plans.
FlowFieldSpectra.NUFFTSeparableSynthesisPlan — Type
NUFFTSeparableSynthesisPlan{T,D,R}Reusable synthesis on a nonuniform tensor-product Cartesian grid, the counterpart of NUFFTSeparablePlan: one type-2 NUFFTAxisPass per axis in sdims order, the working arrays the passes write through, and a real field's axis-1 row weights. Execute with synthesize!(out, plan, coeffs); close! releases the library plans.
FlowFieldSpectra.NUFFTAxisPass — Type
NUFFTAxisPassOne grid axis's 1-D NUFFT over C lines per execution. On the host its executions are split over lanes, one task each, every lane with a single-threaded library plan, its own strength and spectrum buffers and line offsets: a library plan threaded over a few short lines costs more than the lines. On a device, one plan and the staging for the axis-to-front permutation.
A line's m output modes are the library's spectrum rows 1:kept in order, rows past gap one row on, and on a NonuniformFFTs pass whose output widens to ms_d + 1 modes the row +ms_d/2 between them, held in each line's oversampled spectrum (_LinePlus).
FlowFieldSpectra._axis_pass — Function
_axis_pass(library, exec, ::Type{LT}, insize, d, axis, n, b, rng, off, tol, batch_chunk; iflag)The NUFFTAxisPass along dim d of a working array of size insize on its points side, whose lines have element type LT: an n-mode transform whose coefficient box holds b modes on this axis (n or n + 1), written to b output modes for a complex line and the half b ÷ 2 + 1 for a real one. iflag is FlowTransformBindings' sign.
FlowFieldSpectra._LinePlus — Type
_LinePlusWhere a NonuniformFFTs line plan of n modes holds the mode +n/2 of an output widened to n + 1 modes (active): output row pos[1], entry idx[1] of each line's oversampled spectrum, which the type 1 reads times read[1] = normfactor / ϕ̂(n/2) and the type 2 writes times write[1] = 1 / ϕ̂(n/2) (FlowTransformBindings.oversampled_spectra). The tables live in the plan's memory, where the device gathers read them.
FlowFieldSpectra._half_row_weights — Function
_half_row_weights(library, ::Type{T}, m1, b1) -> Vector{T}The weight each row k₁ = 0 … b1÷2 of a real field's packed half enters the axis-1 type 2 with, m1 the transform's and b1 the coefficient box's axis-1 mode count, so the pass sums the whole box. NonuniformFFTs' real-data plan counts each row past k₁ = 0 with its mirror: 1/2 on a Nyquist row the box does not widen, 1 elsewhere. FINUFFT's complex plan reads no mirror: the row's fold weight, 2 past k₁ = 0 but on that Nyquist row.
FlowFieldSpectra.NUFFTSynthesisPlan — Type
NUFFTSynthesisPlan{T,D,R}Reusable type-2 NUFFT synthesis onto a Cartesian grid's points: the plan with C transforms per execution, its spectrum and value buffers, how it reads the coefficients (_synthesis_reader), and on a device the coefficient and field buffers a host array passes through. Execute with synthesize!(out, plan, coeffs); close! releases the library plan.
FlowFieldSpectra._packed_src — Function
_packed_src(ms, box, dims, ::Type{T}; mirror = true) -> Vector{Int}For each coefficient of the box box of an ms-mode transform of a field of element type T, axis 1 halved for a real T, where one transform's spectrum of shape dims in FFTModes order holds it: i > 0 at entry i, i < 0 as the conjugate of entry -i, 0 nowhere. A computed mode is read at its frequency, dims holding at least the computed modes on every axis. A mode at +ms_d/2 on a widened axis is read at its frequency where dims[d] > ms[d] on each such axis, as the conjugate at -k where mirror is set and -k is computed (dims then holding -k₁ on axis 1), and is 0 otherwise; with -ms_e/2 on another widened axis it is 0.
FlowFieldSpectra._oversampled_table — Function
_oversampled_table(Tr, ms, box, ovdims, phis, scale) -> (pos, src, fac)The coefficients of a real field's packed box box at +ms_d/2 on a widened axis that hold a value, and where a real-data NonuniformFFTs plan of ms modes holds them in its oversampled spectrum of shape ovdims (FlowTransformBindings.oversampled_spectra): coefficient pos[i] is entry src[i] times fac[i] = scale / Π_d phis[d]. The forward reads them at scale = normfactor / M, the factor the plan's own modes take with FFS's 1/M; the synthesis writes them at scale = 1 and divides (FlowTransformBindings.oversampled_type2!).
FlowFieldSpectra._gather_packed! — Function
_gather_packed!(dst, doff, src, soff, sstride, idx, scale, n, ntr, neg)For i ≤ n and each of ntr transforms c, dst[doff + (c-1)·n + i] is scale times the entry idx[i] names (_packed_src) of transform c's spectrum, soff + (c-1)·sstride into src, or zero where it names none, conjugated where neg. The device method is the KernelAbstractions extension's, one launch for all ntr.
FlowFieldSpectra._scatter_each! — Function
_scatter_each!(dst, doff, n, srcs, ntr, pos, idx, fac, neg)For each of ntr transforms c, n coefficients apart in dst from doff, the coefficient pos[i] is srcs[c][idx[i]] · fac[i], conjugated where neg. The device method is the KernelAbstractions extension's, one launch for all ntr.
FlowFieldSpectra._inject_each! — Function
_inject_each!(spectra, src, soff, sstride, ntr, pos, idx, fac, neg)The reverse of _scatter_each!: for each of ntr transforms c, entry idx[i] of spectra[c] is fac[i] times coefficient pos[i] of transform c, soff + (c-1)·sstride into src, the coefficient conjugated where neg. The device method is the KernelAbstractions extension's, one launch for all ntr.
FlowFieldSpectra._mode_src — Function
_mode_src(T, ms, box) -> (src, w)For each mode of a real-data plan over ms modes, its packed half in FFTModes order, the entry src of one field's packed half over the coefficient box box holding the same frequency, and the weight w it enters with: 1/2 on the row k₁ = ms₁/2 of an even axis 1 the box does not widen, a Nyquist row the plan's type 2 counts with a mirror it does not have, 1 elsewhere.
FlowFieldSpectra._synthesis_reader — Function
_synthesis_reader(library, exec, ::Type{TT}, ::Type{T}, plan, ms, box, ns, M, ntrans, C, iflag)How a synthesis of a field of element type TT reads its coefficients: nothing for a complex field, whose coefficients are the series; a _RealHalf for a real field on NonuniformFFTs; a _ComplexSeries for a real field on FINUFFT.
The direct sum's setup / run split
Both direct-sum plans are a setup the grid fixes plus a run over a field, and each one-shot composes the same pair. On a Cartesian grid the setup holds the per-axis dense DFT matrices, the working arrays the contraction walks through and the modes a real field's coefficient box holds at zero; a structured grid contracts axis by axis through AxisPass, and a point cloud sums directly.
FlowFieldSpectra.DirectSum.phase_geometry — Function
phase_geometry(grid, ::Type{FT}, ms, ::Type{T}, box = nothing) -> (xs, ks)The positions x - x₀ and the wavenumber axes a Cartesian direct sum over grid reads, over the coefficient box of an ms-mode transform (Grids.mode_box) of a field of element type T, halved for a real T. box holds a whole grid's origins and Fourier lengths when grid is part of it (see Grids.axis_geometry).
FlowFieldSpectra.DirectSum.cart_setup — Function
cart_setup(layout, grid, T, ms, batch, iflag; box = nothing) -> NamedTupleEverything a Cartesian direct sum reads from grid: the wavenumber axes of the coefficient box, the modes of a real field's packed half that hold zero (FlowTransformBindings.outside_modes), and for a tensor layout the per-axis DFT matrices and the working arrays their contraction walks through. T is the field's element type, whose realness fixes the packed layout; box is as in phase_geometry.
Run it against a field with cart_run!, or the threaded run of the OhMyThreads extension; DirectSumCartesianPlan holds it across executions.
FlowFieldSpectra.DirectSum.cart_run! — Function
cart_run!(coeffs, layout, setup, field) -> ksFill coeffs with the Cartesian spectrum of field against a cart_setup result, the modes outside the computed box and its mirror at zero, and return the wavenumber axes.
field arrives already scaled by the grid's quadrature factor. A tensor layout contracts axis by axis, a point cloud sums directly, and both write only into coeffs and the setup's own buffers.
FlowFieldSpectra.DirectSum.synth_setup — Function
synth_setup(layout, grid, T, ms, batch, iflag; box = nothing)Everything a Cartesian direct-sum synthesis over grid reads, for a field of element type T. On a tensor grid, the native_table a real field's packed half is read through, and the per-axis tables E_d[p, a] = exp(+iflag·i·k_a·x_p) with the working arrays their contraction walks through from the series of Grids.series_modes (…, batch…) to the field (size(grid)…, batch…). On a point set, the positions and the wavenumbers of the coefficient box its direct sum reads (phase_geometry). box is as in phase_geometry.
FlowFieldSpectra.DirectSum.native_table — Function
native_table(ms, box) -> (src, wt)How the complex series in FFT order whose real part is the series of a real field's packed half over box reads that half, box the coefficient box of an ms-mode transform (Grids.mode_box). The series has (box[1], ms[2:D]…) modes. Mode i (linear) is entry src[i] of one field's half, or the conjugate of entry -src[i] where src[i] < 0 (k₁ < 0), times wt[i]. The weight is two where -k is not a mode of the series (k_d = -ms[d]/2 on an axis d ≥ 2 that box widens) and one elsewhere, so the real part sums k and -k alike.
FlowFieldSpectra.DirectSum.native_coefficients! — Function
native_coefficients!(full, half, src, wt) -> fullThe series full (modes…, batch…) of each field's packed half in half (packed…, batch…), through the native_table (src, wt). The device method is the KernelAbstractions extension's.
FlowFieldSpectra.DirectSum.AxisPass — Type
AxisPass{FT, ND, M, A}One axis's contraction: its dense DFT matrix, the two matrix aliases the matmul reads and writes, and — for an axis past the first — the staging buffers and the permutation bringing it to the front and back, all built once. Run it with _axis_pass!.
FlowFieldSpectra.DirectSum.sph_setup — Function
sph_setup(layout, grid, T, lmax, B; sampling, weights) -> NamedTupleEverything a spherical direct sum reads from grid: its materialized nodes, or its ring table, or its longitude DFT matrix and latitude quadrature — whichever its layout uses — plus the Legendre recurrence tables and the longitude buffer. T is the coefficient element type; a complex one adds the exp(+imλ) partner transform.
Run it against a field with sph_run!. DirectSumSphericalPlan holds it across executions.
FlowFieldSpectra.DirectSum.sph_run! — Function
sph_run!(coeffs, layout, setup, field, lmax, B) -> ksFill coeffs (lmax+1, 2lmax+1, B) with the spherical spectrum of field against a sph_setup result, and return (0:lmax, -lmax:lmax).
A tensor layout runs one longitude DFT for every latitude, a ring layout one per ring, and a point cloud projects per node; all three then contract over θ against the Legendre tables.
FlowFieldSpectra.DirectSum._order_starts — Function
_order_starts(θ, tables, lmax) -> (ys, ks)Every order's start d^m_{m0} = y·2^{Kk} at every row's colatitude θ[j], ys[m+1, j] and ks[m+1, j], by SphericalKernels.legendre_start_step from d^0_{00} = 1.
FlowFieldSpectra.DirectSum._sph_order_accumulate! — Function
_sph_order_accumulate!(coeffs, fhat, fhat2, θ, wθ, ys, ks, tables, orders, lmax, B, P) -> coeffsThe θ contraction for the orders orders: order m adds to its columns ±m of coeffs (lmax+1, 2lmax+1, B), over every row j, the row's longitude bin times wθ[j] s(m) P̄_ℓ^m(cos θ_j) for ℓ = m … lmax, the degrees run by SphericalKernels.legendre_order! into P from the starts ys, ks. Each order owns its columns, so orders split across tasks write disjoint coefficients.
FlowFieldSpectra.DirectSum.sph_synth_setup — Function
sph_synth_setup(grid, ::Type{FT}, lmax) -> NamedTupleEverything the spherical inverse reads from grid: its nodes, the Legendre recurrence tables and the per-node Plm scratch. Synthesis carries no quadrature, so this is the node list only.
Run it against coefficients with sph_synth_run!; DirectSumSynthesisPlan holds it.
FlowFieldSpectra.DirectSum.sph_synth_run! — Function
sph_synth_run!(out, setup, coeffs, lmax) -> outEvaluate the spherical harmonic sum at the setup's nodes, writing out (N, batch…).
Grids
FlowFieldSpectra builds on FlowGeometries' grid/geometry types and reads them through FlowGeometries' own accessors. The grid-related internals are the spectral wavenumber grid, the field-shape and point-list readers, the spherical (θ, φ) / quadrature-weight bridge (FlowGeometries stores (λ, φ_lat); the transforms want (θ = colatitude, φ = longitude)), the spherical layout traits that select an algorithm, and the mask/measure queries.
FlowFieldSpectra.Grids.physical_wavenumbers — Function
physical_wavenumbers(Ls, box, ::Type{T}) -> NTuple
physical_wavenumbers(grid, ms, ::Type{T}) -> NTuplePacked native-order wavenumber axes matching the packed coefficient layout of a field of element type T: for a real T axis 1 is a nonnegative rfft axis (FlowTransformBindings.RFFTAxis, length box[1]÷2+1) and axes 2:D are full fft axes (FlowTransformBindings.FFTAxis); for a complex T every axis is a full fft axis. box[d] is the coefficient box's mode count along d, which on grid is the mode_box of an ms-mode transform. A Fourier length of zero takes the spacing of unit length.
FlowFieldSpectra.Grids.PointwiseCartesian — Type
PointwiseCartesianCartesian grids whose coordinates are stored per point: a node cloud, and a curvilinear grid, whose coordinate arrays hold one value per cell. Both index linearly in the field's own order. A tensor grid has its own, more specific, factorized methods.
FlowFieldSpectra.Grids.SphericalHarmonicGeometry — Type
SphericalHarmonicGeometryGeometries whose points are addressed by a direction, so a spherical-harmonic transform applies to a field sampled on them: a sphere, and a spheroid.
A spheroid node's direction is its geocentric one, which _colatitude gives, and the transform returns the field's surface expansion over those directions.
FlowFieldSpectra.Grids.field_batch_shape — Function
field_batch_shape(grid, field) -> TupleTrailing batch sizes of field on grid: the dims after the leading ndims(grid) spatial ones, per the (spatial…, batch…) contract Problem states. ndims(grid) is 1 for a node cloud and N for a grid that indexes as an N-D array.
FlowFieldSpectra.Grids.point_coordinates — Function
point_coordinates(::Type{FT}, grid, ::Val{D}) -> (coords::NTuple{D}, spatial::Tuple)The D per-point coordinate vectors of grid in the field's own column-major order, and the spatial shape a field on it carries. Read from FlowGeometries.Grids.materialize, which allocates D·n numbers on a tensor grid; a repeated caller holds the result in a plan.
FlowFieldSpectra.Grids.axis_geometry — Function
axis_geometry(::Type{FT}, grid, ::Val{D}) -> (offsets::NTuple{D,FT}, ranges::NTuple{D,FT})Per-axis origin and Fourier length: offsets[d] is the smallest coordinate along direction d, the x₀ every phase is measured from, and ranges[d] the axis_range of direction d.
FlowFieldSpectra.Grids.axis_range — Function
axis_range(FT, grid, d) -> FTDirection d's Fourier length: the length FlowGeometries.Grids.domain_length gives the cells along d, which is the period where d wraps. A transform weights each sample by its measure, and the measure integrates over those cells, so the Fourier modes are periodic over the same length.
FlowFieldSpectra.Grids.relative_coordinates — Function
relative_coordinates(grid, offsets) -> NTupleEach direction's coordinates less its origin, x - x₀: the positions a phase e^{-ik·(x - x₀)} reads.
FlowFieldSpectra.Grids._sph_points — Function
_sph_points(grid) -> (θ, φ)Per-point colatitude/longitude lists for any spherical grid, in the transform's (θ = colatitude, φ = longitude) convention and the field's column-major order (longitude fastest on a structured (nlon, nlat) grid). The nodes come from FlowGeometries.Grids.materialize, so a pixelization yields its pixel centres.
FlowFieldSpectra.Grids._colatitude — Function
_colatitude(geometry, φ) -> FTColatitude of the direction the surface point at latitude φ lies in: π/2 less its Geometry.geocentric_latitude, which is φ on a sphere and the direction of the geodetic φ's point on a spheroid. Longitude does not enter, so a latitude row is one iso-latitude ring.
FlowFieldSpectra.Grids._longitude_axis — Function
_longitude_axis(grid, ::Type{FT}) -> (λ₀, s)The origin λ₀ and step sign s of a structured sphere's longitude axis, which a longitude FFT reads only as a FlowGeometries.Axes.PeriodicUniformAxis: nlon samples 2π/nlon apart around the circle. With λ_j = λ₀ + s·2πj/nlon, Σ_j f_j e^{-imλ_j} is e^{-imλ₀} times the FFT's bin s·m.
FlowFieldSpectra.Grids._colocated — Function
_colocated(a, v) -> AbstractArrayv, an array the grid holds on the host, placed where an array like a lives: v itself beside a host array, a dense copy in device memory beside a device array.
Spherical layout routing
FlowFieldSpectra.Grids._sph_layout — Function
_sph_layout(grid) -> FlowGeometries.Grids.AbstractRingStructureWhich spherical transform grid takes, named by FlowGeometries.Grids.ring_structure: TensorRings() is the tensor path, one longitude matrix shared by complete latitude rows under a sphere's latitude quadrature; IsoLatitudeRings() the ring path, a longitude sum per ring; NoRings() the per-point projection. A tensor grid with a mask, whose rows are incomplete, or on a spheroid, whose latitudes are geodetic, takes the ring path.
FlowFieldSpectra.Grids._ring_table — Function
_ring_table(grid, ::Type{FT}; lmax=nothing, sampling=nothing, weights=nothing) -> (; ranges, θ, λ, wpt)Per iso-latitude ring: its slice of the flattened point vector and its colatitude, read at the ring's first point; plus every point's longitude and quadrature weight. The weights are _sph_point_weights(grid, FT; sampling, weights), the ones the per-point projection reads, so the ring transform is that projection reassociated for every quadrature a caller can state.
Quadrature, band limit, masks
FlowFieldSpectra.Grids._sht_weights — Function
_sht_weights(grid, nlat; sampling=nothing, weights=nothing, lmax=nothing) -> VectorPer-colatitude quadrature weights for a structured spherical grid, from its own node-set recipe FlowGeometries.Grids.sampling(grid) via SphericalSampling.latitude_weights (Σw = 2, carrying the sinθ Jacobian). weights or sampling override it; lmax is checked against the band limit.
Coordinates alone do not fix the quadrature, so a grid built from raw axes, which records no recipe, raises unless the caller states one.
FlowFieldSpectra.Grids._sph_point_weights — Function
_sph_point_weights(grid[, mask], ::Type{FT}; sampling=nothing, weights=nothing) -> AbstractVector{FT}Per-point quadrature weights of a spherical grid in the field's column-major order, a point mask (the grid's own by default) leaves out at zero: on a structured sphere the latitude rule of _sht_weights times 2π/nlon, and on every other grid the per-node weights of _sph_node_weights. Both total 4π over an unmasked grid. sampling and weights override the grid's own rule as those two state, so weights holds one value per latitude on a structured sphere and one per node elsewhere.
FlowFieldSpectra.Grids._sph_node_weights — Function
_sph_node_weights(grid, mask, ::Type{FT}, N, weights) -> Vector{FT}Per-node quadrature weights for a scattered spherical grid, from its own per-node measure rescaled to sum to 4π — the transform's convention, the same total the structured path's latitude_weights ⊗ 2π/nlon carries. weights overrides it, one per node, a node mask leaves out still at zero. Only the relative measures matter, so a grid of true dual-cell areas integrates exactly and a grid of equal-area nodes gives 4π/N.
FlowFieldSpectra.Grids.quadrature_scale — Function
quadrature_scale(grid, ::Type{FT}, N) -> Union{Nothing, AbstractVector}Per-node factor α_j = N·w_j/Σw taking a node-count-normalized transform to the measure-weighted quadrature over grid, or nothing where the measure's type makes it constant (a rectilinear grid's SeparableMeasure of Axes.ConstantVector factors, every axis uniform) and α_j is exactly one. N is the number of spatial samples the field carries; the result is flat, of length N, in the field's column-major point order.
Read from FlowGeometries.Grids.measure, which keeps a rectilinear grid's SeparableMeasure and a ring layout's RingwiseVector compact, so the result is lazy on such a grid.
FlowFieldSpectra.quadrature_weighted — Function
quadrature_weighted(grid, field) -> fieldfield scaled by the grid's per-node quadrature factor (see Grids.quadrature_scale), so a backend's node-count normalization becomes the measure-weighted quadrature over grid. Returns field itself where the measure is constant: every uniform grid, and every scattered grid whose nodes carry equal weight.
FlowFieldSpectra.Grids._warn_bandlimit — Function
_warn_bandlimit(sampling, nlat, lmax)Warn, once per logger, when degree lmax exceeds what nlat latitude samples of sampling resolve; the coefficients are still returned. The relation is the sampling's own SphericalSampling.bandlimit: nlat÷2 − 1 for Driscoll–Healy, nlat − 1 for Gauss–Legendre and Fejér's first rule. A sampling with no such relation (SphericalSampling.has_bandlimit false: a lat–lon grid, an equal-area pixelization) has nothing to check against.
FlowFieldSpectra.Grids._warn_longitude_bandlimit — Function
_warn_longitude_bandlimit(nlon, lmax)Warn when nlon longitudes cannot separate the orders |m| ≤ lmax. The trigonometric polynomials of degree lmax span 2lmax + 1 dimensions, so on fewer longitudes one of them vanishes at every node and the orders alias; on equispaced longitudes cos(mλ) and cos((nlon − m)λ) take the same samples. Warned, as _warn_bandlimit warns for the latitudes.
FlowFieldSpectra.Grids._zeroed_inactive — Function
_zeroed_inactive(field, grid) -> AbstractArrayfield with its inactive cells set to zero, or field itself where every cell is active.
A transform consuming complete longitude rows (a library SHT on its own grid, a longitude rfft) is linear in the field, so a zeroed datum drops out of its sum exactly, and a NaN under the mask is cleared. The weights stay the sampling's own.
FlowFieldSpectra.Grids._inactive_scale — Function
_inactive_scale(inactive, grid, ::Type{FT}; sampling = nothing, weights = nothing) -> FTThe factor on a spherical quadrature over grid under inactive: one under ZeroFill or with every cell active, and under Exclude the total of the grid's weights unmasked over the total of its active cells' (_sph_point_weights).
FlowFieldSpectra.Grids._inactive_weights — Function
_inactive_weights(inactive, grid, ::Type{FT}; sampling = nothing, weights = nothing) -> weightsThe weights a spherical quadrature over grid reads under inactive: weights itself under ZeroFill or with every cell active, and under Exclude on a masked grid the grid's weights times _inactive_scale, per latitude on a structured sphere and per node elsewhere, as weights is read there.
FlowFieldSpectra.Grids._analysis_weights — Function
_analysis_weights(analysis, inactive, grid, ::Type{FT}; sampling = nothing, weights = nothing) -> weightsThe per-point weights analysis reads over a spherical grid under inactive, in the field's column-major order: those of _sph_point_weights under _inactive_weights, an inactive point at zero; for a LeastSquares fit under ZeroFill, which holds every node, each node's weight on the grid with every cell active.
FlowFieldSpectra.Grids._transform_nodes — Function
_transform_nodes(inactive, grid, analysis) -> (act, live)The nodes a spherical transform over grid holds under inactive, act their indices (nothing for every node), and which of them read the field, live a flag per held node (nothing where every one does). A quadrature gives an inactive node no weight, so it holds the active nodes. A least-squares fit holds every node under ZeroFill, an inactive one reading zero, and the active nodes under Exclude.
Transform selection
FlowFieldSpectra._sht_applicable — Function
_sht_applicable(grid, ms) -> BoolWhether the FastSphericalHarmonics analysis applies to grid at ms. Its transform is addressed by array position on FastTransforms' own Clenshaw–Curtis nodes, so only that grid at the matching size qualifies; the extension owns the check and answers false until it loads.
Packed spectral layout
FlowFieldSpectra.Grids.mode_box — Function
mode_box(grid, ms, ::Type{T}) -> NTupleThe extents of the coefficient box an ms-mode Cartesian transform on grid of a field of element type T fills. For a real T, an even ms[d] on an axis whose samples tell +ms[d]/2 from -ms[d]/2 apart widens to ms[d] + 1 (FlowTransformBindings.box_size), so that the packed half reaches every conjugate partner; a uniform axis of a structured grid transformed at its own length samples the two as one mode and keeps ms[d]. A complex T's box is ms.
FlowFieldSpectra.Grids.series_modes — Function
series_modes(grid, ms, ::Type{T}) -> NTupleThe mode counts, in FFT order, of the complex series an ms-mode synthesis on grid evaluates for a field of element type T: for a real T, mode_box(grid, ms, T)[1] on axis 1 and ms on the others, whose real part, with the coefficients DirectSum.native_coefficients! writes, is the series of the packed half over the whole coefficient box; ms for a complex T.
The packed layout and the widened axes are FlowTransformBindings' (box_size, outside_modes). The NUFFT and hybrid plans publish the half over the coefficient box from a library's FFTModes output through one index table (FlowFieldSpectra._packed_src) of direct and conjugate reads. A NonuniformFFTs plan asked for ms_d modes reads the modes at +ms_d/2 a widened axis adds from its oversampled spectra, and its synthesis writes them there: a real-data point plan through FlowFieldSpectra._oversampled_table, a line pass through FlowFieldSpectra._LinePlus, on the host and on a device alike.
Transform problem & layout
FlowFieldSpectra.Problem.spatial_shape — Function
spatial_shape(prob) — the leading spatial array sizes (N_1, …).
FlowFieldSpectra.Problem.batch_shape — Function
batch_shape(prob) — the trailing batch sizes (() if none).
FlowFieldSpectra.Problem.n_batch — Function
n_batch(prob) — number of trailing batch dims.
FlowFieldSpectra.Problem.batch_length — Function
batch_length(prob) — total batch slices, prod(batch) (1 if no batch axes).
FlowFieldSpectra.Problem.coeff_output_size — Function
coeff_output_size(spectral::Tuple, prob) -> NTupleShape of the coefficient array: (spectral…, batch…).
FlowFieldSpectra.Problem.stack_fields — Function
stack_fields(fields::Tuple) -> AbstractArrayConvenience for the multi-field call form: stack equal-shaped field arrays along a new trailing batch axis ((spatial…, batch…, NU)). This materializes a combined array — pass a single (spatial…, batch…) array to avoid the copy.
FlowFieldSpectra.Problem.check_same_shape — Function
check_same_shape(fields::Tuple) -> fieldsRaises unless there is at least one field and every field has the first one's shape.
Process backends
FlowFieldSpectra._point_partition — Function
_point_partition(transform, grid, kwargs) -> BoolWhether a transform divided among processes splits the points of grid (each share's coefficients weighted by _partition_weight and summed) or its batch columns (each share transforming whole fields). The points split where the transform is additive over them and the grid is a point set; a NUFSHT solve couples every point, so it splits the batch.
FlowFieldSpectra._partition_weight — Function
_partition_weight(grid, idx, weights) -> RealThe weight the coefficients of the points idx carry in C = Σ_w α_w C_w over a disjoint point partition. A transform on those points normalizes by their own measure total W_w (the Cartesian quadrature Σ wⱼfⱼe^{-ik·x}/Σw, the spherical weights rescaled to 4π), so α_w = W_w/W. With explicit per-node weights nothing is normalized and α_w = 1.
Preprocessing helpers
FlowFieldSpectra.Preprocessing.window_value — Function
window_value(win::AbstractWindow, t::T) -> TThe taper win at the fractional position t ∈ [0, 1] along an axis, 0 and 1 its two ends: Hann ½(1 − cos 2πt), Hamming 0.54 − 0.46 cos 2πt, Blackman 0.42 − ½cos 2πt + 0.08 cos 4πt, and Tukey(α) a Hann edge over t < α/2 and t > 1 − α/2, one between.
FlowFieldSpectra.Preprocessing.window_function — Function
window_function(win::AbstractWindow, n::Integer, ::Type{T}=Float64) -> Vector{T}Allocate and return the length-n taper win.
FlowFieldSpectra.Preprocessing.window_function! — Function
window_function!(w::AbstractVector, win::AbstractWindow) -> wFill w (length n) in place with the taper win at the n evenly spaced positions t = (i − 1)/(n − 1); a single sample takes one.
FlowFieldSpectra.Preprocessing.window_correction — Function
window_correction(w::AbstractVector) -> (S1, S2)Coherent-gain factor S1 = (Σ w)/n and power factor S2 = (Σ w²)/n. Amplitude spectra divide by S1; power/energy spectra divide by S2 to preserve variance.
FlowFieldSpectra.Preprocessing.detrend! — Function
detrend!(x::AbstractVector, d::AbstractDetrend) -> xDetrend x in place according to d.
FlowFieldSpectra.Preprocessing.is_identity — Function
is_identity(spec) — whether spec leaves a field untouched, so the transform reads it directly.
FlowFieldSpectra.Preprocessing.axis_taper — Function
axis_taper(::Type{FT}, window, n) -> Vector{FT}Length-n taper for one axis, scaled to unit mean square (Σw²/n == 1).
Under that scaling Parseval holds on the tapered coefficients: with C_w(k) = (1/N) Σ w f e^{-ikx}, the folded sum Σ_k |C_w|² is mean|w·f|², which returns mean|f|² when Σw²/n = 1 on every axis (the tensor product's mean square is the product of the axes'). NoWindow is an exact no-op.
FlowFieldSpectra.Preprocessing.point_window — Function
point_window(::Type{FT}, window, xs, w) -> Vector{FT}The window at points with coordinates xs (one vector per direction, one entry per point): the product over directions of window_value at t_d = (x_d − min x_d)/(max x_d − min x_d), scaled to unit mean square under the point weights w, Σ w τ² / Σ w = 1. On a uniform lattice of equal weights this is the tensor product of the axis_tapers.
FlowFieldSpectra.Preprocessing.apply_window! — Function
apply_window!(field, τ, nsp)Multiply every batch slice of field point by point by the window τ of point_window, one entry per spatial point of the leading nsp dims in column-major order.
FlowFieldSpectra.Preprocessing.detrend_spatial! — Function
detrend_spatial!(field, ::Demean, nsp, w)
detrend_spatial!(field, ::LinearDetrend, nsp, w, xs)Detrend the leading nsp spatial dims of field in place, per batch slice, under the point weights w (one per spatial point in column-major order). A point of zero weight is left out of every fit, the NaN masked data commonly holds included.
Demean subtracts the weighted mean Σ w f / Σ w. LinearDetrend subtracts the weighted least-squares fit a + Σ_d b_d x_d in the point coordinates xs (one vector per direction), which leaves the residual orthogonal under w to the constant and to every coordinate.
Radial-bin helpers
FlowFieldSpectra.Reductions._shell_values! — Function
_shell_values!(E, nmodes, dk, ks, estimator) -> EThe bins' values from the energy E (bins first, batch after) they accumulated over nmodes native modes each. Normalization.ShellSum keeps the sum; Normalization.ModeAverage scales bin b by V_D ((b·dk)ᴰ − ((b−1)·dk)ᴰ) / ∏Δk_d / nmodes[b].
FlowFieldSpectra.Reductions._requested_bins — Function
_requested_bins(k_bins, num_bins, ks, T, cutoff) -> IntThe bin count up to k_max of an in-place radial reduction. Under cutoff it is length(k_bins). With cutoff = false it is num_bins (or the default), and those bins plus the ones appended up to the mode box's corner must number length(k_bins).
FlowFieldSpectra.Reductions._split_sum! — Function
_split_sum!(f!, exec, accs, n) -> accsf!(parts, r) adds the work of the indices r into the arrays parts, over ranges r partitioning 1:n. On SerialBackend that is f!(accs, 1:n). On ThreadedBackend (the OhMyThreads extension) each task adds its contiguous range into zeroed copies of accs, which are then added into accs; with accs = () the tasks write disjoint results themselves.
FlowFieldSpectra.Reductions._foreach_radial — Function
_foreach_radial(f, ks, sz, dk, k_top, cut, nb, rows)f(bin, i1, off, Irest) for every mode of the rows rows (linear indices over axes 2:D) of a spectral box of size sz that has a radial bin (_mode_bin): i1 its index on axis 1, off the linear index before its row and Irest the row's indices on the other axes.
FlowFieldSpectra.Reductions._radial_accumulate! — Function
_radial_accumulate!(exec, E, nmodes, val, A, ks, dk, k_top, cut) -> EAdd val(n, A[I, b]) to E[bin, b] and n to nmodes[bin] for every mode I of A (ms…, batch…), n its fold weight and bin the radial bin of width dk holding |k(I)|; cut leaves out |k| > k_top. The rows are split on exec (_split_sum!). The GPUArraysCore extension runs a device A on its device, E and nmodes staying on the host.
FlowFieldSpectra.Reductions._sector_accumulate! — Function
_sector_accumulate!(exec, E, nmodes, P, ks, dk, dθ, k_max) -> EAdd ½ P[I, b] to E[ik, iθ, b] and one to nmodes[ik, iθ] for every mode I of the 2D power P up to k_max, (ik, iθ) the bin of its magnitude and angle; a halved-axis mode's partner at −k lands in the opposite angle, and k = 0 is spread evenly over the angles of the first bin. The rows are split on exec (_split_sum!). The GPUArraysCore extension runs a device P on its device.
FlowFieldSpectra.Reductions._transect_accumulate! — Function
_transect_accumulate!(exec, E_reduced, ks, coeffs, dims) -> E_reducedAdd ½|C|² of every entry of coeffs to the entry of E_reduced its kept indices name, with the fold weights and partners of a halved axis. The columns of coeffs along axis 1, one per index of dims 2…N, are split on exec (_split_sum!). The GPUArraysCore extension runs a device coeffs on its device.
FlowFieldSpectra.Averaging._welch_accumulate! — Function
_welch_accumulate!(exec, E_k, nmodes, coeffs, ks, dk, k_top, cut) -> E_kAdd to E_k[bin] the mean over the realizations (the batch of coeffs) of ½ n |C|² over the modes in radial bin bin, n a mode's fold weight, and n to nmodes[bin] once per mode; cut leaves out |k| > k_top. The rows are split on exec (Reductions._split_sum!). The GPUArraysCore extension runs a device coeffs on its device.
FlowFieldSpectra.Averaging._coherence_accumulate! — Function
_coherence_accumulate!(exec, Sff, Sgg, Sfg, cf, cg, ks, dk, k_max) -> SfgAdd to bin bin of Sff, Sgg and Sfg the sums over the realizations and the modes up to k_max in that radial bin of n|a|², n|b|² and x + (n − 1) conj(x), a, b the two coefficients, x = a conj(b) and n the mode's fold weight: the missing negative half of a halved axis folded in, inert on a full layout. The rows are split on exec (Reductions._split_sum!). The GPUArraysCore extension runs device coefficients on their device, with every sum halved, which the coherence and phase do not read.
Spherical-harmonic kernels
FlowFieldSpectra.SphericalKernels.LegendreTables — Type
LegendreTables{FT}The step coefficients of d^ℓ_{m0} up to degree lmax from FTB.wigner_d_coeffs, α, c = c₊ and γ at [ℓ+1, m+1] (c₋ = −c₊ at n = 0), the normalizations nrm[ℓ+1] = √((2ℓ+1)/4π), and the order factors f[m] = √((2m−1)/(2m)). Built once per transform by legendre_tables and read by fill_legendre! and the device table.
FlowFieldSpectra.SphericalKernels.legendre_tables — Function
legendre_tables(::Type{FT}, lmax::Int) -> LegendreTables{FT}The step coefficients, normalizations and order factors up to degree lmax, in FT.
FlowFieldSpectra.SphericalKernels.fill_legendre! — Function
fill_legendre!(Plm::AbstractMatrix, t::LegendreTables, x, s, lmax)Fill Plm[l+1, m+1] = \bar P_\ell^m(x) for m = 0:lmax, l = m:lmax at a single point with x = cosθ, s = sinθ, reusing the precomputed coefficients in t. Entries with l < m are left untouched (the projection never reads them).
FlowFieldSpectra.SphericalKernels.legendre_start_step — Function
legendre_start_step(y, k, g) -> (y, k)The next order's start from d^{m−1}_{m−1,0} = y·2^{Kk}: its product by g = −sin θ f[m], held again as y·2^{Kk} with 2^{−K/2} < |y| ≤ 1, or (0, k) where it vanishes. Starting from (1, 0) at m = 0.
FlowFieldSpectra.SphericalKernels.legendre_order! — Function
legendre_order!(P, ix, α, c, γ, nrm, m, lmax, y, k, pos, u) -> PP[ix(ℓ)] = P̄_ℓ^m for ℓ = m … lmax at one node, from the start d^m_{m0} = y·2^{Kk} (legendre_start_step), on the side pos = cos θ ≥ 0 with u = 1 − |cos θ|, the coefficient tables of LegendreTables. The host fill and the device table both run it.
FlowFieldSpectra.SphericalKernels.legendre_index — Function
legendre_index(l, m, lmax) -> IntRow of P̄_ℓ^m (0 ≤ m ≤ ℓ ≤ lmax) in a packed Legendre table, which stores each order's degrees ℓ = m:lmax in turn: m(lmax + 1) − m(m − 1)/2 + (ℓ − m) + 1.
FlowFieldSpectra.SphericalKernels.legendre_count — Function
legendre_count(lmax) -> IntRows of a packed Legendre table, (lmax + 1)(lmax + 2)/2.
FlowFieldSpectra.SphericalKernels.device_legendre_table — Function
device_legendre_table(backend, ::Type{FT}, lmax, θ) -> AbstractMatrix{FT}The packed table P[legendre_index(ℓ, m, lmax), j] = P̄_ℓ^m(cos θ_j) on the KernelAbstractions device backend, computed there in FT: one thread per node forms the starts by legendre_start_step, one thread per order and node runs legendre_order!. The KernelAbstractions extension defines it.
FlowFieldSpectra.SphericalKernels.normalized_legendre — Function
normalized_legendre(l, m, x, s) -> FTSingle normalized associated Legendre value $\bar P_\ell^m(x)$ (m ≥ 0), x = cos θ, s = sin θ, by the recurrences of fill_legendre! for one order.