Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 98 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,107 @@

All notable changes to this project will be documented in this file.

## [Unreleased]
## [0.4.0] - 2026-09-11

### Names and namespace

- The vocabulary is the domain's: several quantities at one set of points are **fields**, not
"channels". `Fields` now lives in the `MultiFields` submodule, with `FieldIncrement`,
`n_vector_fields`, `n_scalar_fields` and `field_dimension`.
- The package exports only its own names — the bin-edge types, the tapers and `HarmonicNodes`, the
result types, `KHM` and `midpoints`. Everything else is reached through the submodule that owns it:
`Calculations` for the entries, `StructureFunctionTypes` for the operators, `HelperFunctions` for
the geometry, `MultiFields` for `Fields`.

### Input shapes and geometry

- Arrays `(D, N)` for point lists and `(D, N, auxiliary...)` for batches over trailing axes are the
input contract; tuple-of-vector inputs are refused by name.
- Spherical geometry: `SphericalDistance(R)`, `Distances.Haversine` and `Distances.SphericalAngle`
metrics transport every pair into its geodesic frame; a point is located by `(lon, lat)` while the
velocity may carry a radial component. Degenerate (coincident, antipodal) pairs are skipped.
- Multi-fields `Fields(vectors = (u, …), scalars = (θ, …))` with the operators `ScalarSFType{P}`,
`MixedSFType{NL,NT,P}`, `VectorDotSFType(a, b)`, `ScalarDotSFType(a, b)`; a field of scalars alone
is located by its coordinates; odd scalar moments read every pair canonically, independent of the
input order.
- Pair weights: `weights` (one per point or cell) on the point entries, the gridded sweeps, the
transforms and the device engine; `cell_measure(grid)` gives a grid's cell areas.
- The transverse convention is a field of the projected operator:
`ProjectedStructureFunctionType{NL, NT}(basis)` with `CanonicalTransverseBasis()` (the right-hand rule
about `ẑ`, continued about `x̂` where `r̂ ∥ ẑ`) or `ReferenceAxisTransverseBasis(a)`; every rule's
first vector is odd under `r̂ ↦ −r̂`. The GPU batch kernel's transverse sign, which negated `T3` and
`L2T1`, is fixed.

### Grids

- `FlowGeometries` grids route by their axis types to `UniformLagSchedule`, `RectilinearLagSchedule`
(any number of uniform axes beside enumerated ones), `ZonalLagSchedule` (lat-lon, the pair frame per
lag, pole-invariant) or `ScatteredPairs`; every route is exact and the direct sweep is one
implementation for all separable schedules, with culling and threading.
- The transform engine (`FastFourierTransformSpectralBackend`) computes **every polynomial operator at
any order** on every separable schedule as cross-correlations of masked monomials: exact with missing
cells at every order, bounded directions zero-padded to `n + h_max`, multi-fields, weights, the
directional histogram over the separation angle, and the increment moment tensors
(`calculate_structure_function_tensor` on grids and the joint tensor over angle;
`StructureFunctionTensor2DSumsAndCounts`). `AutoSpectralBackend()` costs both algorithms.
- The same engine on a device (`GPUBackend`): monomial transforms through the device's `AbstractFFTs`
and one lag kernel for the binning, on every schedule.
- The harmonic route on a sphere: `HarmonicNodes` kernel-binned statistics for scalars at any order and
vectors through the spin-weighted expansion, `harmonic_spectra`, the NUFSHT extension and a direct-sum
reference; results carry floating-point kernel-weighted counts.
- A soft-binned route for scattered points by non-uniform FFT (`ScatteredModesSchedule`) with two
providers, each named by its own tag: `NonuniformFFTsSpectralBackend` (NonuniformFFTs, CPU and CUDA)
and `FINUFFTSpectralBackend` (FINUFFT, CPU and cuFINUFFT); results carry `ModeBinEdges` and are
documented as not exact.
- An exact sorted route for one-dimensional point lists (prefix sums of monomials), taken automatically
by the CPU backends for polynomial operators.
- Tensors on point lists at any order, joint in separation and angle.

### Spectra and fluxes

- `isotropic_spectrum` in one, two and three dimensions with verified constants; `gridded_spectrum`
from the whole lag space, exact on a complete periodic grid and an unbiased estimate with missing
cells, with the Blackman–Tukey estimate on bounded directions, tapers (`NoTaper`, `Bartlett`,
`GaussianTaper`) and missing-lag policies; `shell_average`, `shell_spectrum`.
- `helmholtz_spectra(L2, T2, k)` by `J₀`/`J₂`; on a sphere `isotropic_spectrum(sf, geometry, lmax)` and
`helmholtz_spectra(L2, T2, geometry, lmax; variance)` by Legendre and Wigner-d orthogonality.
- Third-order flux companions with their boundary terms: `spectral_flux` on `S3SFType`, `L3SFType`
(with `S3`) and `MixedSFType{1,0,2}`, and `enstrophy_flux` from the velocity's advective structure
function; the `J₁` route on cross-field moments.
- `covariance`, `covariance_matrix` with a positive-definiteness check.
- Regularised fits (issue #37): `SpectrumForwardModel`, `HelmholtzForwardModel`, `FluxForwardModel`;
`RegularizedLeastSquares(prior)` with a posterior covariance, `NonNegativeLeastSquares()`,
`SegmentedPowerLaw(S)` through the LsqFit extension; `fit_spectrum`, `fit_helmholtz_spectra`,
`fit_flux`, `tradeoff_curve`, `select_segments`, `independent_pair_variance`.

### Exact laws

- `KHM`: the four-fifths, four-thirds and Yaglom inversions and residuals, each on the moment it is
stated for, and the planar transverse incompressibility residual.

### Performance

- **ThreadedBackend / OhMyThreadsExt**: outer-loop chunks for O(N²) pair kernels now use
`OMT.RoundRobin()` instead of the default contiguous split. Fixes ~2× load imbalance
when `work(i) ∝ (N - i)` (structure-function and single-pass 2D paths). No API change.
- **AbstractBinEdges (O(1) Binning)**: Added high-performance bin edge wrappers (`LinearBinEdges`, `LogBinEdges`, `InfPaddedBinEdges`) to resolve $O(\log B)$ search bottlenecks in `digitize`.
- `LinearBinEdges` utilizes Fused Multiply-Add (FMA) CPU instructions and local ULP corrections to achieve 15x+ speedup on uniform grids.
- `LogBinEdges` extracts the binary floating-point exponent (IEEE 754 bitwise manipulation) and uses a precomputed lookup table to restrict the search range, bypassing the highly latent `log(x)` CPU instruction for a 5x+ speedup on logarithmic grids.
- `InfPaddedBinEdges` provides virtual infinity padding without array copying or memory allocation.
- `LinearBinEdges`, `LogBinEdges`, `InfPaddedBinEdges`: `O(1)` digitizing by fused multiply-add and
exponent lookup; squared-distance digitize plans on every pair loop.
- Cell culling (`AutoCulling`, `AlwaysCulling`, `NoCulling`) with blocked pair sweeps; the answer never
moves, the cost falls with the cutoff.
- Round-robin outer chunks on the threaded pair loops; SIMD compute/scatter split in the point kernels.
- The direct lag sweep and the transform's lag loop allocate nothing per pair or per lag.
- The device transform builds each monomial for every slab in one broadcast and transforms the slabs
in one batch, and writes the spectra in the order the binning stage reads them, so assembling its
input is a reshape. On an A100 the 720×360 lat-lon `L2` transform runs 28× the 8-thread CPU and a
stretched 256×128 grid 3.6×.
- The device binning kernel launches each slab pair over its own lag box, which a schedule reports
through `uniform_lag_box`. On a sphere the box over all row pairs does not narrow with the largest
bin edge while each row pair's does, so the kernel speeds up as the sweep narrows: 2× at a quarter
of the sphere's radius, 3× at an eighth.

### Removed

- The empty CairoMakie extension. The `UnsafeUserTransverseBasis`/`UserTransverseBasis` closure
wrappers and `CoordinateGaugeTransverseBasis` (an even rule, ill-defined on unordered pairs); a
custom convention is a subtype of `AbstractTransverseBasisConvention` with one `transverse_basis`
method.

## [0.3.0] - 2026-03-18

Expand Down
27 changes: 20 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,66 @@ Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
SpectralBackends = "289ded02-b044-41b2-8b2d-71f2a47755d1"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[weakdeps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Bessels = "0e736298-9ec6-45e8-9647-e4fc86a2fe38"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
FINUFFT = "d8beea63-0952-562e-9c6a-8e8ef7364055"
FlowGeometries = "0ccd6995-f618-4175-b01e-f437d0cb4974"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
LsqFit = "2fda8390-95c7-5789-9bda-21331edee243"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
NUFSHT = "e99b67a3-9706-455a-90e2-85b195a33206"
NonuniformFFTs = "cd96f58b-6017-4a02-bb9e-f4d81626177f"
OhMyThreads = "67456a42-1dca-4109-a031-0a68de7e3ad5"
SpectralBackends = "289ded02-b044-41b2-8b2d-71f2a47755d1"

[extensions]
StructureFunctionsCUDAExt = ["KernelAbstractions", "CUDA"]
StructureFunctionsBesselsExt = ["Bessels"]
StructureFunctionsFFTExt = ["AbstractFFTs", "SpectralBackends"]
StructureFunctionsSpectralBackendsExt = ["SpectralBackends"]
StructureFunctionsLsqFitExt = ["LsqFit"]
StructureFunctionsAbstractFFTsExt = ["AbstractFFTs"]
StructureFunctionsFlowGeometriesExt = ["FlowGeometries"]
StructureFunctionsCairoMakieExt = ["CairoMakie"]
StructureFunctionsKernelAbstractionsExt = ["KernelAbstractions"]
StructureFunctionsOhMyThreadsExt = ["OhMyThreads"]
StructureFunctionsDistributedExt = ["Distributed"]
StructureFunctionsMPIExt = ["MPI"]
StructureFunctionsNUFSHTExt = ["NUFSHT"]
StructureFunctionsAbstractFFTsKernelAbstractionsExt = ["AbstractFFTs", "KernelAbstractions"]
StructureFunctionsNonuniformFFTsExt = ["NonuniformFFTs"]
StructureFunctionsNonuniformFFTsKernelAbstractionsExt = ["NonuniformFFTs", "KernelAbstractions"]
StructureFunctionsFINUFFTExt = ["FINUFFT"]
StructureFunctionsFINUFFTKernelAbstractionsExt = ["FINUFFT", "KernelAbstractions"]


[extras]
FlowGeometries = "0ccd6995-f618-4175-b01e-f437d0cb4974"
SpectralBackends = "289ded02-b044-41b2-8b2d-71f2a47755d1"
NUFSHT = "e99b67a3-9706-455a-90e2-85b195a33206"

[sources]
ComputationalBackends = { url = "https://github.com/jbphyswx/ComputationalBackends.jl" }
FlowGeometries = { url = "https://github.com/jbphyswx/FlowGeometries.jl" }
NUFSHT = { url = "https://github.com/jbphyswx/NUFSHT.jl" }
SpectralBackends = { url = "https://github.com/jbphyswx/SpectralBackends.jl" }

[compat]
AbstractFFTs = "1"
Bessels = "0.2"
CUDA = "5, 6"
CairoMakie = "0.15"
ComputationalBackends = "0.1"
Distances = "0.10"
Distributed = "1.11"
FINUFFT = "3.5"
FlowGeometries = "0.1"
KernelAbstractions = "0.9"
LinearAlgebra = "1.11"
LsqFit = "0.15, 0.16"
MPI = "0.20"
NUFSHT = "0.1"
NonuniformFFTs = "0.9"
OhMyThreads = "0.8"
PrecompileTools = "1.3.3"
ProgressMeter = "1.9"
Expand Down
Loading
Loading