API Reference

This page is generated from the docstrings of the public SHTnsKit module. Optional extension methods appear when their dependencies are loaded in the calling environment.

Calling conventions

  • Allocating transforms use operation(cfg, input...).
  • In-place transforms place outputs before inputs, for example analysis!(plan, alm_out, field) and synthesis!(plan, field_out, alm).
  • analysis(CPU(), ...) and analysis(GPU(), ...) request strict typed device dispatch; ordinary calls infer the backend from array storage.
  • Dense coefficients have shape (cfg.lmax + 1, cfg.mmax + 1). Entries with l < m are unused.
  • Batch APIs add a third, field-index dimension.
  • A configuration's norm, cs_phase, real_norm, and robert_form options apply at every public transform boundary.

See Migrating to v2.0 for removed compatibility signatures and numerical changes.

Extension activation

ExtensionLoad these packages
CUDACUDA, GPUArrays, GPUArraysCore, KernelAbstractions
AMDGPUAMDGPU, GPUArrays, GPUArraysCore, KernelAbstractions
MPIMPI, PencilArrays, PencilFFTs
LoopVectorizationLoopVectorization
ForwardDiffForwardDiff
ZygoteZygote
Advanced ADChainRulesCore

Hardware-specific types such as the CUDA extension's CuFFTPlan live in their extension module and are documented in GPU Acceleration.

Public API

SHTnsKit.GPU — Type

GPU compute device.

GPU() is vendor-neutral. A concrete CUDA or AMDGPU backend is inferred from an existing device array/prototype, or selected when exactly one loaded GPU adapter is functional.

source
SHTnsKit.SHTConfig — Method
SHTConfig(; lmax, mmax, mres, nlat, nlon, θ, φ, x, w, Nlm, cphi, st,
          norm, cs_phase, real_norm, robert_form,
          nlm, li, mi, nspat,
          grid_type=:gauss, phi_scale=:auto, on_the_fly=false,
          use_plm_tables=false, plm_tables=[], dplm_tables=[],
          NP_tables=[], NdP_tables=[], norm_scale_matrix=Matrix{Float64}(undef,0,0),
          _otf_scratch_P=[], _otf_scratch_dP=[], _otf_scratch_Ps=[], _otf_scratch_Pb=[], _m_order=[],
          howmany=1, spec_dist=0, south_pole_first=false,
          allow_padding=false, nlat_padded=0, spat_dist=0) -> SHTConfig

Flat-kwargs constructor that packages the grid/normalization/tables/scratch kwargs into their respective sub-structs. Keeps the call-site syntax used by create_gauss_config, create_regular_config, copy(::SHTConfig), etc. identical to the pre-restructure behaviour.

source
SHTnsKit.SHTPlan — Type
SHTPlan

Pre-allocated working buffers and FFTW plans for zero-allocation transforms.

Thread Safety

WARNING: A single SHTPlan instance must NOT be used from multiple threads simultaneously. The internal buffers (P, dPdtheta, G, Fθk, etc.) are shared mutable state — concurrent calls to analysis! or synthesis! on the same plan will produce data races and incorrect results.

For multi-threaded use, create one SHTPlan per thread:

plans = [SHTPlan(cfg) for _ in 1:Threads.nthreads()]
Threads.@threads for i in 1:n
    plan = plans[Threads.threadid()]
    analysis!(plan, alm_out[i], fields[i])
end
source
SHTnsKit.SHTPlan — Method
SHTPlan(cfg::SHTConfig; use_rfft=false)

Create an optimized transform plan with pre-allocated buffers and FFT plans.

This constructor performs the "planning" phase: it allocates all working memory and optimizes FFTW plans for the specific grid configuration. The resulting plan can then be reused for many transforms without additional allocations.

Parameters:

  • cfg: SHTConfig defining the grid and spectral resolution
  • use_rfft: if true, use real-FFT along φ for scalar analysis!/synthesis! (halves the Fourier buffer size). Vector (sphtor) transforms on the plan still use the complex buffer. Requires cfg.mmax ≤ cfg.nlon÷2.
source
SHTnsKit.SHTRotation — Type
struct SHTRotation

Holds Euler angles and target sizes for rotation.

  • lmax, mmax: degrees/orders supported by the rotation.
  • α, β, γ: Euler angles (ZYZ by default) in radians.
  • conv: :ZYZ or :ZXZ convention.
source
SHTnsKit.SHTns37Capability — Type
SHTns37Capability

One required SHTns 3.7 mathematical capability on one execution backend. status is one of :required, :verified, or :unverified_hardware.

source
SHTnsKit.LM_cplx — Method
LM_cplx(cfg::SHTConfig, l::Integer, m::Integer) -> Int

Compatibility helper that mirrors the C macro LM_cplx for mres == 1, returning the zero-based packed complex index for coefficient (l,m).

source
SHTnsKit.LM_cplx_index — Method
LM_cplx_index(lmax::Int, mmax::Int, l::Int, m::Int) -> Int

Packed complex index for coefficient (l,m) where -min(l,mmax) ≤ m ≤ min(l,mmax). Matches SHTns LM_cplx macro (assumes mres == 1).

source
SHTnsKit.LM_index — Method
LM_index(lmax::Int, mres::Int, l::Int, m::Int) -> Int

Convert 2D spherical harmonic indices (l,m) to a 1D packed array index. This implements the SHTns packing convention for efficient memory layout.

The packing scheme groups coefficients by m-order blocks, with each block containing all valid l-degrees for that m. This enables vectorized operations on modes with the same azimuthal symmetry.

Matches SHTns C macro: LM(shtns, l, m)

source
SHTnsKit.LiM_index — Method
LiM_index(lmax::Int, mres::Int, l::Int, im::Int) -> Int

Convenience function to compute packed index using reduced m-index im. This is useful when iterating over m-modes using im = 0, 1, 2, ... instead of m = 0, mres, 2*mres, ...

Equivalent to LM_index(lmax, mres, l, im*mres). Matches SHTns macro: LiM(shtns, l, im)

source
SHTnsKit.SH_Xrotate90 — Method
SH_Xrotate90(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, Rlm::AbstractVector{<:Complex})

Rotate around X-axis by 90 degrees using ZYZ equivalence: Rz(π/2)·Ry(π/2)·Rz(-π/2).

source
SHTnsKit.SH_Yrotate — Method
SH_Yrotate(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, alpha::Real, Rlm::AbstractVector{<:Complex})

Rotate a real-field SH expansion around the Y-axis by angle alpha. Uses Wigner-d mixing per l; dispatches to the general rotation engine.

source
SHTnsKit.SH_Zrotate — Method
SH_Zrotate(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, alpha::Real, Rlm::AbstractVector{<:Complex})

Rotate a real-field SH expansion around the Z-axis by angle alpha. Input and output are packed Qlm vectors (LM order, m ≥ 0). In-place supported if Rlm === Qlm.

source
SHTnsKit.SH_mul_mx — Method
SH_mul_mx(cfg::SHTConfig, mx::AbstractVector{<:Real}, Qlm::AbstractVector{<:Complex}, Rlm::AbstractVector{<:Complex})

Apply a nearest-neighbor-in-l operator represented by mx to Qlm and write to Rlm. Both Qlm and Rlm are length cfg.nlm packed vectors (m≥0, SHTns LM order).

Warning

Rlm must not alias Qlm. Each output couples the l-neighbors of Qlm, and those neighbors are overwritten by earlier iterations, so an in-place call (Rlm === Qlm) reads already-mutated values and gives wrong results. Use a separate output buffer.

source
SHTnsKit.SH_to_grad_point — Method
SH_to_grad_point(cfg::SHTConfig, DrSlm::AbstractVector{<:Complex}, Slm::AbstractVector{<:Complex}, cost::Real, phi::Real)
    -> vr, vt, vp

Evaluate the gradient of a scalar field at a point. DrSlm supplies the radial derivative spectrum and Slm supplies the tangential gradient.

source
SHTnsKit.SH_to_lat — Method
SH_to_lat(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, cost::Real;
          nphi::Int=cfg.nlon, ltr::Int=cfg.lmax, mtr::Int=cfg.mmax) -> Vector{<:Real}

Evaluate a real field along a latitude (fixed cosθ = cost) at nphi equispaced longitudes. Uses orthonormal harmonics and packed real coefficients Qlm (LM order).

source
SHTnsKit.SH_to_lat_cplx — Method
SH_to_lat_cplx(cfg::SHTConfig, alm_packed::AbstractVector{<:Complex}, cost::Real; nphi::Int=cfg.nlon, ltr::Int=cfg.lmax) -> Vector{<:Complex}

Evaluate a complex field along a latitude using packed LM_cplx coefficients.

source
SHTnsKit.SHqst_to_lat — Method
SHqst_to_lat(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, Slm::AbstractVector{<:Complex}, Tlm::AbstractVector{<:Complex}, cost::Real;
             nphi::Int=cfg.nlon, ltr::Int=cfg.lmax, mtr::Int=cfg.mmax) -> Vr, Vt, Vp

Evaluate 3D field along latitude (cosθ = cost) at nphi longitudes from packed real spectra. Inputs Qlm, Slm, Tlm are all packed (LM order) vectors for each component.

source
SHTnsKit.SHqst_to_point — Method
SHqst_to_point(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, Slm::AbstractVector{<:Complex}, Tlm::AbstractVector{<:Complex}, cost::Real, phi::Real)
    -> vr, vt, vp

Evaluate 3D field at a single point using packed real spectra.

source
SHTnsKit.allocate_padded_spatial — Function
allocate_padded_spatial(cfg::SHTConfig, T::Type=Float64) -> Array{T}

Allocate a spatial array with proper padding if enabled.

Returns a 2D array of size (nlatpadded, nlon) where nlatpadded >= nlat. The first nlat rows contain the actual data; remaining rows are padding.

Example

cfg = create_gauss_config(64, 66)
set_allow_padding!(cfg)
field = allocate_padded_spatial(cfg)
# field has size (nlat_padded, nlon), use field[1:cfg.nlat, :] for data
source
SHTnsKit.allocate_padded_spatial_batch — Function
allocate_padded_spatial_batch(cfg::SHTConfig, nfields::Int, T::Type=Float64) -> Array{T}

Allocate spatial arrays for batch transforms with proper padding if enabled.

Returns a 3D array of size (nlat_padded, nlon, nfields).

source
SHTnsKit.analysis! — Method
analysis!(cfg::SHTConfig, alm_out::AbstractMatrix, f::AbstractMatrix)

In-place forward transform. Writes coefficients into alm_out. alm_out must be size (lmax+1, mmax+1).

source
SHTnsKit.analysis! — Method
analysis!(plan::SHTPlan, alm_out::AbstractMatrix, f::AbstractMatrix)

In-place forward scalar SHT writing coefficients into alm_out.

source
SHTnsKit.analysis — Method
analysis(cfg::SHTConfig, f::AbstractMatrix) -> Matrix{ComplexF64}

Forward transform on Gauss-Legendre x equiangular grid. Returns coefficients alm[l+1, m+1] in the normalization, real-normalization, and phase convention configured by cfg.

Parallelizes over m-modes using static scheduling for consistent performance.

source
SHTnsKit.analysis_axisym — Method
analysis_axisym(cfg, Vr) -> Vector{ComplexF64}

Axisymmetric (m=0) transform from Gauss latitudes to degree-only coefficients. Input Vr should contain values at Gauss latitudes for a specific longitude mode. Returns coefficients Q_l for l = 0..lmax.

source
SHTnsKit.analysis_batch! — Method
analysis_batch!(cfg::SHTConfig, alm_out::AbstractArray{<:Complex,3},
                fields::AbstractArray{<:Real,3})

In-place batch forward transform.

source
SHTnsKit.analysis_batch — Method
analysis_batch(cfg::SHTConfig, fields::AbstractArray{<:Real,3}) -> Array{ComplexF64,3}

Batch forward transform for multiple scalar fields.

Arguments

  • cfg: SHTConfig with batch size configured
  • fields: 3D array of shape (nlat, nlon, nfields) containing spatial data

Returns

  • 3D array of shape (lmax+1, mmax+1, nfields) with spectral coefficients

Performance

Batch processing is more efficient than processing fields individually because:

  1. Legendre polynomials are computed once and reused across all fields
  2. FFT plans are shared
  3. Better cache utilization from contiguous memory access patterns
source
SHTnsKit.analysis_packed — Method
analysis_packed(cfg, Vr_flat::AbstractVector{<:Real}) -> Vector{ComplexF64}

Packed scalar analysis from flattened grid values (length nlat*nlon) to Qlm (LM order).

source
SHTnsKit.analysis_packed_cplx_l — Method
analysis_packed_cplx_l(cfg, z, ltr)

Analyze a complex spatial field into full LM_cplx storage while computing only degrees l ≤ ltr; entries above the limit are zero.

source
SHTnsKit.analysis_packed_l — Method
analysis_packed_l(cfg::SHTConfig, Vr::AbstractVector{<:Real}, ltr::Integer) -> Vector{ComplexF64}

Scalar analysis truncated to degrees l ≤ ltr. The returned packed coefficient vector has length cfg.nlm; coefficients with l > ltr are set to zero.

source
SHTnsKit.analysis_packed_ml — Method
analysis_packed_ml(cfg, im, Vr_m, ltr) -> Vector{<:Complex}

Transform spatial field for one stored azimuthal order to spherical harmonic coefficients. im is the zero-based stored-order index, so the physical order is m = im * cfg.mres. Vr_m contains complex spatial values for that mode. Returns coefficients Q_l for degrees l = m..ltr.

source
SHTnsKit.analysis_qst — Method
analysis_qst(cfg, Vr, Vt, Vp) -> (Qlm, Slm, Tlm)

Transform 3D spatial vector field to QST spectral coefficients. Input: radial (Vr), colatitude (Vt), and azimuthal (Vp) components.

source
SHTnsKit.analysis_qst_batch — Method
analysis_qst_batch(cfg::SHTConfig, Vr_batch::AbstractArray{<:Real,3},
                   Vt_batch::AbstractArray{<:Real,3}, Vp_batch::AbstractArray{<:Real,3})

Batch QST analysis for multiple 3D vector fields.

Returns

  • (Qlm_batch, Slm_batch, Tlm_batch): Tuple of 3D arrays with Q, S, T coefficients
source
SHTnsKit.analysis_qst_l — Method
analysis_qst_l(cfg, Vr, Vt, Vp, ltr) -> (Qlm, Slm, Tlm)

Degree-limited version of analysis_qst, computing coefficients only up to degree ltr.

source
SHTnsKit.analysis_qst_ml — Method
analysis_qst_ml(cfg, im, Vr_m, Vt_m, Vp_m, ltr) -> (Ql, Sl, Tl)

Mode-limited transform for specific azimuthal mode im.

source
SHTnsKit.analysis_sphtor! — Method
analysis_sphtor!(plan::SHTPlan, Slm_out::AbstractMatrix, Tlm_out::AbstractMatrix, Vt::AbstractMatrix, Vp::AbstractMatrix)

In-place vector analysis. Accumulates Slm/Tlm into preallocated outputs. Uses a two-pass strategy over φ FFTs to avoid extra buffers.

source
SHTnsKit.analysis_sphtor — Method
analysis_sphtor(cfg, Vt, Vp) -> (Slm, Tlm)

Transform horizontal vector field components to spheroidal/toroidal coefficients.

source
SHTnsKit.analysis_sphtor_batch — Method
analysis_sphtor_batch(cfg::SHTConfig, Vt_batch::AbstractArray{<:Real,3},
                      Vp_batch::AbstractArray{<:Real,3})

Batch spheroidal-toroidal analysis for multiple vector fields.

Arguments

  • cfg: SHTConfig
  • Vt_batch: 3D array (nlat, nlon, nfields) of theta components
  • Vp_batch: 3D array (nlat, nlon, nfields) of phi components

Returns

  • (Slm_batch, Tlm_batch): Tuple of 3D arrays (lmax+1, mmax+1, nfields) containing spheroidal and toroidal coefficients
source
SHTnsKit.analysis_sphtor_cplx — Method
analysis_sphtor_cplx(cfg, Vt, Vp) -> (Slm, Tlm)

Transform complex horizontal vector components to spheroidal/toroidal coefficients.

source
SHTnsKit.build_li_mi — Method
build_li_mi(lmax::Int, mmax::Int, mres::Int)

Build lookup arrays mapping packed indices to spherical harmonic (l,m) values. These arrays enable efficient iteration over spherical harmonic modes when working with packed coefficient arrays.

Returns (li, mi) where li[k] and mi[k] give the degree and order for the k-th packed coefficient.

source
SHTnsKit.compute_optimal_padding — Method
compute_optimal_padding(nlat::Int, nlon::Int; sizeof_real::Int=8) -> Int

Compute the optimal padding to add between latitude lines to avoid cache bank conflicts. This mimics the SHTns C library's padding strategy.

Arguments

  • nlat: Number of latitude points
  • nlon: Number of longitude points (phi)
  • sizeof_real: Size of real number in bytes (default 8 for Float64)

Returns

The number of extra elements to add per latitude line (padding amount).

Details

The padding strategy aims to:

  1. Align memory on 32-byte or 64-byte boundaries
  2. Avoid 8KB cache bank conflicts
  3. Avoid L2 cache bank/channel conflicts (especially important for AMD GPUs)

This is most beneficial for:

  • Large transforms where cache effects matter
  • Multi-threaded transforms
  • GPU computing
source
SHTnsKit.copy_from_padded! — Method
copy_from_padded!(dest::AbstractMatrix, src::AbstractMatrix, cfg::SHTConfig)

Copy data from a padded spatial array to a contiguous spatial array.

source
SHTnsKit.copy_to_padded! — Method
copy_to_padded!(dest::AbstractMatrix, src::AbstractMatrix, cfg::SHTConfig)

Copy data from a contiguous spatial array to a padded spatial array.

source
SHTnsKit.create_config — Method
create_config(lmax::Int; mmax=lmax, mres=1, nlat=lmax+2,
               nlon=max(2*lmax+1,4),
               norm::Symbol=:orthonormal, cs_phase::Bool=true,
               real_norm::Bool=false, robert_form::Bool=false,
               grid_type::Symbol=:gauss) -> SHTConfig

Compatibility wrapper for configuration creation used in some docs/snippets. Supports Gauss–Legendre (grid_type = :gauss), regular equiangular (grid_type = :regular or :regular_poles), and Driscoll-Healy (grid_type = :driscoll_healy) grids, forwarding to the appropriate creator. nlat/nlon defaults are adjusted to satisfy accuracy constraints for the chosen grid.

source
SHTnsKit.create_config — Method
create_config(::Type{T}, lmax::Int, nlat::Int, mres::Int=1; kwargs...) -> SHTConfig

Compatibility method that ignores the element type T and calls create_config. Provided to match older example signatures like create_config(Float64, 20, 22, 1).

source
SHTnsKit.create_gauss_config — Method
create_gauss_config(lmax::Int, nlat::Int; mmax::Int=lmax, nlon::Int=_default_nlon(lmax)) -> SHTConfig

Create a Gauss–Legendre based SHT configuration. Constraints:

  • nlat ≥ lmax+1 for exactness up to lmax in θ integration.
  • nlon ≥ 2*mmax+1 to resolve azimuthal orders up to mmax.
source
SHTnsKit.create_gauss_config_spf — Method
create_gauss_config_spf(lmax::Int, nlat::Int; kwargs...) -> SHTConfig

Create a Gauss-Legendre configuration with south-pole-first latitude ordering.

This is equivalent to calling create_gauss_config followed by set_south_pole_first!. All keyword arguments are passed to create_gauss_config.

Example

# Create a south-pole-first configuration
cfg = create_gauss_config_spf(32, 34)
is_south_pole_first(cfg)  # true

See also: create_gauss_config, set_south_pole_first!

source
SHTnsKit.create_gauss_fly_config — Method
create_gauss_fly_config(lmax::Int, nlat::Int; kwargs...) -> SHTConfig

Create a Gauss–Legendre configuration with on-the-fly Legendre polynomial computation.

This mode computes Legendre polynomials during each transform instead of using precomputed tables. Benefits:

  • Lower memory usage: No storage for P_l^m tables (saves O(lmax² × nlat) memory)
  • Better for large lmax: When lmax is large, tables become memory-intensive
  • Good cache behavior: On modern CPUs, on-the-fly computation can be faster due to better cache utilization

Trade-offs:

  • May be slower for repeated transforms with small lmax
  • No speedup from table precomputation

This mirrors the sht_gauss_fly mode in SHTns C library.

Arguments

Same as create_gauss_config.

Example

# For large lmax, on-the-fly mode saves significant memory
cfg = create_gauss_fly_config(1024, 1026)

# Performs transform computing Legendre polynomials on-the-fly
alm = analysis(cfg, field)

See also: create_gauss_config, set_on_the_fly!, set_use_tables!

source
SHTnsKit.create_regular_config — Method
create_regular_config(lmax::Int, nlat::Int; mmax::Int=lmax, mres::Int=1,
                      nlon::Int=_default_nlon(lmax), norm::Symbol=:orthonormal,
                      cs_phase::Bool=true, real_norm::Bool=false,
                      robert_form::Bool=false, include_poles::Bool=false,
                      precompute_plm::Bool=true, use_dh_weights::Bool=false) -> SHTConfig

Create an equiangular (regular) grid configuration. Regular grids use Fejér's first rule on θ = (i+0.5)π/nlat nodes by default; set include_poles=true to use pole-inclusive Clenshaw–Curtis nodes and weights. By default associated Legendre tables are precomputed, which mirrors SHTns' regular-grid behaviour and improves performance.

Driscoll-Healy Quadrature

Set use_dh_weights=true to use Driscoll-Healy quadrature for exact spherical harmonic transforms. This requires:

  • include_poles=true
  • nlat = 2*(lmax+1) for exactness up to degree lmax
  • nlat must be even

The DH grid uses θ = πj/n for j=0,...,n-1 (includes north pole, excludes south pole) and provides exact quadrature via specially computed weights.

Reference: Driscoll & Healy (1994), "Computing Fourier transforms and convolutions on the 2-sphere", Adv. Appl. Math., 15, 202-250.

source
SHTnsKit.destroy_config — Method
destroy_config(cfg::SHTConfig)

No-op placeholder for API symmetry with libraries that require explicit teardown.

source
SHTnsKit.divergence_from_spheroidal — Method
divergence_from_spheroidal(cfg, Slm) -> Matrix

Return divergence spectral coefficients δlm corresponding to spheroidal modes via δlm = −l(l+1) Slm (`δ{00} = 0`).

source
SHTnsKit.energy_scalar — Method
energy_scalar(cfg, alm; real_field=true) -> Float64

Compute the total energy of a scalar field from its spherical harmonic coefficients.

For a scalar field f(θ,φ) = Σ alm Yl^m(θ,φ), the energy is defined as: E = (1/2) ∫ |f|² dΩ = (1/2) Σ |a_lm|²

This represents the L² norm of the field, which is conserved under orthonormal spherical harmonic transforms (Parseval's identity).

source
SHTnsKit.energy_scalar_l_spectrum — Method
energy_scalar_l_spectrum(cfg, alm; real_field=true) -> Vector{Float64}

Compute energy spectrum as a function of spherical harmonic degree l. Returns E(l) = Σₘ |a_lm|² for each l = 0..lmax.

source
SHTnsKit.energy_scalar_lm — Method
energy_scalar_lm(cfg, alm; real_field=true) -> Matrix{Float64}

Compute per-mode energy distribution Elm = |alm|² for each (l,m) mode. Returns matrix of size (lmax+1, mmax+1) with energy contributions.

source
SHTnsKit.energy_scalar_m_spectrum — Method
energy_scalar_m_spectrum(cfg, alm; real_field=true) -> Vector{Float64}

Compute energy spectrum as a function of spherical harmonic order m. Returns E(m) = Σₗ |a_lm|² for each m = 0..mmax.

source
SHTnsKit.energy_vector — Method
energy_vector(cfg, Slm, Tlm; real_field=true) -> Float64

Compute the total kinetic energy of a vector field from spheroidal/toroidal coefficients.

For a vector field V = ∇×(T Yl^m êᵣ) + ∇ₕ(S Yl^m), the kinetic energy is: KE = (1/2) ∫ |V|² dΩ = (1/2) Σ [l(l+1)|Slm|² + l(l+1)|Tlm|²]

source
SHTnsKit.energy_vector_l_spectrum — Method
energy_vector_l_spectrum(cfg, Slm, Tlm; real_field=true) -> Vector{Float64}

Compute kinetic energy spectrum by degree l for vector fields. Returns KE(l) = Σₘ l(l+1)[|Slm|² + |Tlm|²] for each l = 1..lmax.

source
SHTnsKit.energy_vector_lm — Method
energy_vector_lm(cfg, Slm, Tlm; real_field=true) -> Matrix{Float64}

Compute per-mode kinetic energy KElm = l(l+1)[|Slm|² + |T_lm|²] for vector fields. Returns matrix of size (lmax+1, mmax+1) with energy contributions.

source
SHTnsKit.energy_vector_m_spectrum — Method
energy_vector_m_spectrum(cfg, Slm, Tlm; real_field=true) -> Vector{Float64}

Compute kinetic energy spectrum by order m for vector fields. Returns KE(m) = Σₗ l(l+1)[|Slm|² + |Tlm|²] for each m = 0..mmax.

source
SHTnsKit.energy_vector_packed — Method
energy_vector_packed(cfg, Spacked, Tpacked; real_field=true) -> Float64

Compute vector field kinetic energy from packed S and T coefficients.

source
SHTnsKit.enstrophy — Method
enstrophy(cfg, Tlm; real_field=true) -> Float64

Compute the enstrophy (kinetic energy of vorticity) from toroidal coefficients.

For a toroidal field with coefficients Tlm, the enstrophy is: Z = (1/2) ∫ |∇×V|² dΩ = (1/2) Σ l²(l+1)²|Tlm|²

This is a measure of the small-scale intensity of rotational motion.

source
SHTnsKit.enstrophy_l_spectrum — Method
enstrophy_l_spectrum(cfg, Tlm; real_field=true) -> Vector{Float64}

Compute enstrophy spectrum as a function of degree l. Returns Z(l) = Σₘ l²(l+1)²|T_lm|² for each l = 1..lmax.

source
SHTnsKit.enstrophy_lm — Method
enstrophy_lm(cfg, Tlm; real_field=true) -> Matrix{Float64}

Compute per-mode enstrophy Zlm = l²(l+1)²|Tlm|² for each (l,m) mode. Returns matrix of size (lmax+1, mmax+1) with enstrophy contributions.

source
SHTnsKit.enstrophy_m_spectrum — Method
enstrophy_m_spectrum(cfg, Tlm; real_field=true) -> Vector{Float64}

Compute enstrophy spectrum as a function of order m. Returns Z(m) = Σₗ l²(l+1)²|T_lm|² for each m = 0..mmax.

source
SHTnsKit.estimate_table_memory — Method
estimate_table_memory(lmax::Int, mmax::Int, nlat::Int) -> Int

Estimate memory usage (in bytes) for precomputed Legendre polynomial tables.

Returns the approximate memory needed for both Pl^m and dPl^m/dx tables.

source
SHTnsKit.get_nlat_padded — Method
get_nlat_padded(cfg::SHTConfig) -> Int

Get the padded latitude dimension. Returns cfg.nlat if padding is disabled, or cfg.nlat_padded if padding is enabled.

This is the stride between successive phi (longitude) values in padded spatial arrays.

source
SHTnsKit.get_spat_dist — Method
get_spat_dist(cfg::SHTConfig) -> Int

Get the distance between spatial arrays in batch mode. Returns cfg.nspat if padding is disabled, or the padded spatial distance if enabled.

source
SHTnsKit.gpu_analysis_sphtor — Method
gpu_analysis_sphtor(cfg, Vt, Vp; device=GPU(), prototype=nothing)

Compatibility wrapper for the historical host-returning GPU vector API. Ordinary analysis_sphtor(GPU(), ...) remains device-resident; this legacy entry point deliberately copies its two results back to CPU storage.

source
SHTnsKit.gpu_synthesis_sphtor — Method
gpu_synthesis_sphtor(cfg, S, T; device=GPU(), real_output=true,
                     prototype=nothing)

Compatibility wrapper for the historical host-returning GPU vector API.

source
SHTnsKit.grad_energy_scalar_alm — Method
grad_energy_scalar_alm(cfg, alm; real_field=true) -> Matrix

Compute gradient of scalar field energy with respect to spectral coefficients. Returns ∂E/∂a_lm for use in optimization problems.

source
SHTnsKit.grad_energy_vector_Slm_Tlm — Method
grad_energy_vector_Slm_Tlm(cfg, Slm, Tlm; real_field=true) -> (grad_S, grad_T)

Compute gradients of vector field kinetic energy with respect to S and T coefficients.

source
SHTnsKit.grad_enstrophy_Tlm — Method
grad_enstrophy_Tlm(cfg, Tlm; real_field=true) -> Matrix

Compute gradient of enstrophy with respect to toroidal coefficients. Returns ∂Z/∂Tlm = l²(l+1)² Tlm for optimization applications.

source
SHTnsKit.grad_grid_enstrophy_zeta — Method
grad_grid_enstrophy_zeta(cfg, ζ) -> Matrix

Compute gradient of grid-based enstrophy with respect to vorticity field values. Returns ∂Z/∂ζ for each grid point.

source
SHTnsKit.grad_loss_vorticity_Tlm — Method
grad_loss_vorticity_Tlm(cfg, Tlm, ζ_target) -> Matrix

Compute gradient of vorticity loss with respect to toroidal coefficients. Uses adjoint method for efficient computation.

source
SHTnsKit.grid_energy_scalar — Method
grid_energy_scalar(cfg, f) -> Float64

Compute energy of a scalar field directly from its spatial representation. Uses Gauss-Legendre quadrature for accurate integration.

source
SHTnsKit.grid_enstrophy — Method
grid_enstrophy(cfg, ζ) -> Float64

Compute enstrophy directly from gridded vorticity field using quadrature. Z = (1/2) ∫ ζ² dΩ using Gauss-Legendre integration.

source
SHTnsKit.im_from_lm — Method
im_from_lm(lm::Int, lmax::Int, mres::Int) -> Int

Inverse operation: determine the reduced m-index (im = m/mres) from a packed index. This function searches through the m-blocks to find which block contains the given packed index.

Useful for algorithms that need to determine the azimuthal symmetry of a coefficient from its packed storage location.

source
SHTnsKit.inside — Method
inside(a; buff=1)

Return CartesianIndices range excluding buff layers of cells on all boundaries. Useful for iterating over interior points while respecting boundary conditions.

source
SHTnsKit.is_on_the_fly — Method
is_on_the_fly(cfg::SHTConfig) -> Bool

Check if configuration is set to on-the-fly Legendre computation mode.

source
SHTnsKit.is_south_pole_first — Method
is_south_pole_first(cfg::SHTConfig) -> Bool

Check if the configuration uses south-pole-first latitude ordering.

Returns true if latitude data starts at the south pole (θ=π), false if it starts at the north pole (θ=0, the default).

source
SHTnsKit.local_range — Method
local_range(arr)

Return CartesianIndices for iterating over the local portion of an array. For PencilArrays, this iterates over parent(arr) dimensions. For regular arrays, this is equivalent to CartesianIndices(arr).

Example

# With PencilArray (MPI-distributed)
@sht_loop local_data[I] = value over I ∈ local_range(pencil_arr)

# With regular array
@sht_loop field[I] = value over I ∈ local_range(regular_arr)
source
SHTnsKit.local_size — Method
local_size(arr)

Return the size of the local portion of an array. For PencilArrays, returns size(parent(arr)). For regular arrays, returns size(arr).

source
SHTnsKit.loss_and_grad_vorticity_Tlm — Method
loss_and_grad_vorticity_Tlm(cfg, Tlm, ζ_target) -> (loss, grad)

Combined computation of loss and gradient for vorticity optimization. More efficient than separate computations due to shared forward pass.

source
SHTnsKit.loss_vorticity_grid — Method
loss_vorticity_grid(cfg, Tlm, ζ_target) -> Float64

Compute loss function for vorticity matching problem. L = (1/2) ∫ [ζ(Tlm) - ζ_target]² dΩ where ζ(Tlm) is computed vorticity.

source
SHTnsKit.mode_range — Method
mode_range(mmax)

Return a range for iterating over azimuthal modes (0 to mmax). Storage index: m+1 for m ∈ 0:mmax

source
SHTnsKit.nlm_calc — Method
nlm_calc(lmax::Integer, mmax::Integer, mres::Integer) -> Int

Calculate the total number of packed spectral coefficients for a real scalar field. Real fields only need m ≥ 0 modes due to Hermitian symmetry: Yl^{-m} = (-1)^m (Yl^m)*

The packing scheme groups modes by m-order, then by l-degree within each m block. This layout is optimized for vectorized operations and cache efficiency.

source
SHTnsKit.nlm_cplx_calc — Method
nlm_cplx_calc(lmax::Integer, mmax::Integer, mres::Integer) -> Int

Calculate the total number of spectral coefficients for a complex field. Complex fields require both positive and negative m modes, unlike real fields which use Hermitian symmetry to store only m ≥ 0 modes.

This is used for complex-valued spherical harmonic expansions where no symmetry assumptions can be made about the coefficients.

source
SHTnsKit.prepare_plm_tables! — Method
prepare_plm_tables!(cfg::SHTConfig)

Precompute associated Legendre tables Pl^m(xi) for all i and m, stored as cfg.plm_tables[m+1][l+1, i]. Enables faster scalar transforms on regular grids.

source
SHTnsKit.scratch_fft — Function
scratch_fft(cfg::SHTConfig, T::Type=ComplexF64) -> Matrix{T}

Allocate a complex buffer sized for φ-FFTs (nlat, nlon). Reuse this across analysis!/synthesis! calls via the fft_scratch keyword to avoid per-call allocations.

source
SHTnsKit.scratch_spatial — Function
scratch_spatial(cfg::SHTConfig, T::Type=Float64) -> Matrix{T}

Allocate a spatial grid buffer of size (nlat, nlon).

source
SHTnsKit.set_allow_padding! — Method
set_allow_padding!(cfg::SHTConfig; auto_compute::Bool=true)

Enable memory padding for cache optimization. When enabled, spatial arrays can have extra padding between latitude lines to avoid cache bank conflicts.

This can improve performance by 1-50% depending on the problem size and hardware, especially for multi-threaded and GPU transforms.

Arguments

  • cfg: SHTConfig to modify
  • auto_compute: If true, automatically compute optimal padding. If false, you must set cfg.nlat_padded manually.

Example

cfg = create_gauss_config(64, 66)
set_allow_padding!(cfg)
println("Padded nlat: $(cfg.nlat_padded)")  # May be > 66

See also: disable_padding!, is_padding_enabled, get_nlat_padded

source
SHTnsKit.set_batch_size! — Method
set_batch_size!(cfg::SHTConfig, howmany::Int; spec_dist::Int=0)

Configure batch processing for multiple fields. After calling this function, batch transform functions (analysis_batch, synthesis_batch, etc.) will process howmany fields simultaneously.

Arguments

  • cfg: SHTConfig to modify
  • howmany: Number of fields to process in each batch (≥1)
  • spec_dist: Distance between spectral coefficient arrays in memory. If 0, arrays are assumed contiguous. Otherwise, this is the stride between the start of successive spectral arrays.

Returns

  • The configured batch size (always ≥1)

Example

cfg = create_gauss_config(32, 34)
set_batch_size!(cfg, 4)  # Process 4 fields at once

# Now use batch transforms
fields = rand(cfg.nlat, cfg.nlon, 4)
alms = analysis_batch(cfg, fields)
source
SHTnsKit.set_fft_plan_cache! — Function
set_fft_plan_cache!(flag::Bool; clear::Bool=true)

Enable or disable caching of distributed FFT plans. When disabling and clear=true, cached plans are freed.

source
SHTnsKit.set_loop_backend — Method
set_loop_backend(backend::String)

Set the loop backend preference. Valid values:

  • "auto": Automatically detect from array type (default) - uses GPU when arrays are on GPU
  • "SIMD": Force CPU SIMD path (useful for debugging or when GPU is not desired)
source
SHTnsKit.set_north_pole_first! — Method
set_north_pole_first!(cfg::SHTConfig)

Enable north-pole-first latitude ordering (the default). In this mode, latitude data starts at the north pole (θ=0).

This reverses the internal grid arrays if the configuration was previously in south-pole-first mode, and recalculates any precomputed Legendre tables.

Example

cfg = create_gauss_config(32, 34)
set_south_pole_first!(cfg)  # Data starts at south pole
set_north_pole_first!(cfg)  # Back to default (north pole first)

See also: set_south_pole_first!, is_south_pole_first

source
SHTnsKit.set_on_the_fly! — Method
set_on_the_fly!(cfg::SHTConfig)

Enable on-the-fly Legendre polynomial computation mode. This disables precomputed tables and computes P_l^m(x) during each transform.

Benefits:

  • Lower memory usage (no table storage)
  • Better for large lmax values
  • Can be faster on modern CPUs due to cache effects

See also: set_use_tables!, create_gauss_fly_config

source
SHTnsKit.set_south_pole_first! — Method
set_south_pole_first!(cfg::SHTConfig)

Enable south-pole-first latitude ordering. In this mode, latitude data starts at the south pole (θ=π) instead of the default north pole (θ=0).

This reverses the internal grid arrays (θ, x, w, st) and recalculates any precomputed Legendre tables if necessary.

Example

cfg = create_gauss_config(32, 34)
set_south_pole_first!(cfg)  # Data now starts at south pole

See also: set_north_pole_first!, is_south_pole_first

source
SHTnsKit.set_use_tables! — Method
set_use_tables!(cfg::SHTConfig)

Enable precomputed Legendre polynomial tables. This precomputes Pl^m(xi) for all grid points and stores them for reuse.

Benefits:

  • Faster for repeated transforms with same grid
  • No redundant computation of Legendre polynomials

Trade-offs:

  • Higher memory usage: O(lmax × mmax × nlat)
  • Initial table computation overhead

See also: set_on_the_fly!, prepare_plm_tables!

source
SHTnsKit.shtns37_capabilities — Method
shtns37_capabilities() -> Vector{SHTns37Capability}

Return a copy of the executable SHTns 3.7 mathematical capability matrix. CPU and MPI/CPU cells remain :required until an immutable CI artifact is recorded for their named runner. A successful local parity gate is readiness evidence, not certification. Accelerator cells remain :unverified_hardware until their named runner has passed on physical hardware and its immutable CI artifact has been recorded.

source
SHTnsKit.shtns_rotation_apply_real — Method
shtns_rotation_apply_real(r::SHTRotation, Qlm::AbstractVector{<:Complex}, Rlm::AbstractVector{<:Complex})

Apply rotation to real-field SH coefficients in packed LM layout (m ≥ 0). Requires mres==1.

source
SHTnsKit.shtns_rotation_set_angle_axis — Method
shtns_rotation_set_angle_axis(r::SHTRotation, theta::Real, Vx::Real, Vy::Real, Vz::Real)

Define rotation from angle-axis (theta around vector V). Angles are set in ZYZ convention.

source
SHTnsKit.shtns_rotation_wigner_d_matrix — Method
shtns_rotation_wigner_d_matrix(r::SHTRotation, l::Integer, mx::AbstractVector{<:Real}) -> Int

Fill mx (length ≥ (2l+1)^2) with d^l in row-major order. Returns size 2l+1.

source
SHTnsKit.spectral_range — Method
spectral_range(lmax, mmax)

Return a CartesianIndices range for iterating over valid (l,m) coefficient pairs. Note: Returns range for 1-based indexing of storage array, so iterate as: for idx ∈ spectral_range(lmax, mmax) l, m = idx[1] - 1, idx[2] - 1 # Convert to 0-based degree/order # ... work with alm[l+1, m+1] end

source
SHTnsKit.st_dt_matrix — Method
st_dt_matrix(cfg::SHTConfig, mx::AbstractVector{<:Real})

Fill mx with coupling coefficients for sinθ ∂θ operator: sinθ ∂θ Yl^m = l bl^m Y{l+1}^m - (l+1) al^m Y_{l-1}^m.

source
SHTnsKit.suggest_pencil_grid — Function
suggest_pencil_grid(comm_or_nprocs, nlat, nlon; prefer_square=true, allow_one_dim=true)

Return a suggested MPI pencil decomposition (p_theta, p_phi) for a grid of size nlat x nlon. The base package provides a (1,1) fallback so the function is always defined; when SHTnsKitParallelExt is loaded the callback is replaced with an MPI-aware heuristic that favours balanced 2D decompositions.

source
SHTnsKit.synthesis! — Method
synthesis!(cfg::SHTConfig, f_out::AbstractMatrix, alm::AbstractMatrix; real_output::Bool=true)

In-place inverse transform. Writes the spatial field into f_out.

source
SHTnsKit.synthesis! — Method
synthesis!(plan::SHTPlan, f_out::AbstractMatrix, alm::AbstractMatrix; real_output=true)

In-place inverse scalar SHT writing spatial field into f_out. Streams m→k directly without building a (θ×m) intermediate.

source
SHTnsKit.synthesis — Method
synthesis(cfg::SHTConfig, alm::AbstractMatrix; real_output::Bool=true) -> Matrix

Inverse transform back to a grid (nlat, nlon). If real_output=true, Hermitian symmetry is enforced before IFFT.

source
SHTnsKit.synthesis_axisym — Method
synthesis_axisym(cfg, Qlm) -> Vector{Float64}

Axisymmetric synthesis from degree-only coefficients to Gauss latitudes. Input Qlm should contain coefficients Q_l for l = 0..lmax. Returns spatial values at Gauss latitudes.

source
SHTnsKit.synthesis_batch! — Method
synthesis_batch!(cfg::SHTConfig, f_out::AbstractArray,
                 alm_batch::AbstractArray{<:Complex,3}; real_output::Bool=true)

In-place batch inverse transform.

source
SHTnsKit.synthesis_batch — Method
synthesis_batch(cfg::SHTConfig, alm_batch::AbstractArray{<:Complex,3};
                real_output::Bool=true) -> Array

Batch inverse transform for multiple spectral coefficient sets.

Arguments

  • cfg: SHTConfig with batch size configured
  • alm_batch: 3D array of shape (lmax+1, mmax+1, nfields) with spectral coefficients
  • real_output: If true, return real spatial fields; otherwise complex

Returns

  • 3D array of shape (nlat, nlon, nfields) with spatial data
source
SHTnsKit.synthesis_batch_cplx — Method
synthesis_batch_cplx(cfg::SHTConfig, alm_batch::AbstractArray{<:Complex,3}) -> Array{ComplexF64,3}

Complex-output batch inverse transform. Equivalent to synthesis_batch(cfg, alm_batch; real_output=false) with a concrete return type for inference-sensitive callers.

source
SHTnsKit.synthesis_cplx — Method
synthesis_cplx(cfg::SHTConfig, alm::AbstractMatrix) -> Matrix{<:Complex}

Complex-output inverse scalar transform. This is equivalent to synthesis(cfg, alm; real_output=false) but dispatches through a compile-time output mode so callers can rely on a concrete return type.

source
SHTnsKit.synthesis_grad — Method
synthesis_grad(cfg::SHTConfig, Slm::AbstractMatrix; real_output::Bool=true)

Gradient synthesis alias for compatibility with SHTns.

source
SHTnsKit.synthesis_grad_l — Method
synthesis_grad_l(cfg::SHTConfig, Slm::AbstractMatrix, ltr::Int; real_output::Bool=true)

Degree-limited gradient synthesis alias.

source
SHTnsKit.synthesis_grad_ml — Method
synthesis_grad_ml(cfg::SHTConfig, im::Int, Sl::AbstractVector{<:Complex}, ltr::Int)

Mode-limited gradient synthesis alias.

source
SHTnsKit.synthesis_packed — Method
synthesis_packed(cfg, Qlm::AbstractVector{<:Complex}) -> Vector{Float64}

Packed scalar synthesis from Qlm (LM order) to flattened real grid (length nlat*nlon).

source
SHTnsKit.synthesis_packed_cplx_l — Method
synthesis_packed_cplx_l(cfg, alm_packed, ltr)

Synthesize a complex spatial field from the LM_cplx coefficients with degrees l > ltr ignored. The input retains the full packed storage shape.

source
SHTnsKit.synthesis_packed_l — Method
synthesis_packed_l(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, ltr::Integer) -> Vector{Float64}

Scalar synthesis truncated to degrees l ≤ ltr. Contributions from higher degrees are ignored.

source
SHTnsKit.synthesis_packed_ml — Method
synthesis_packed_ml(cfg, im, Ql, ltr) -> Vector{<:Complex}

Transform spherical harmonic coefficients for specific mode m to spatial field. im is the zero-based stored-order index (m = im * cfg.mres); Ql contains coefficients for degrees l = m..ltr. Returns complex spatial values for that azimuthal mode.

source
SHTnsKit.synthesis_point_cplx — Method
synthesis_point_cplx(cfg::SHTConfig, alm::AbstractVector{<:Complex}, cost::Real, phi::Real) -> Complex

Evaluate a complex field represented by packed alm at a single point.

source
SHTnsKit.synthesis_qst — Method
synthesis_qst(cfg, Qlm, Slm, Tlm; real_output=true, use_rfft=false) -> (Vr, Vt, Vp)

Transform QST spectral coefficients to 3D spatial vector field components. Returns radial (Vr), colatitude (Vt), and azimuthal (Vp) components.

source
SHTnsKit.synthesis_qst_batch — Method
synthesis_qst_batch(cfg::SHTConfig, Qlm_batch::AbstractArray{<:Complex,3},
                    Slm_batch::AbstractArray{<:Complex,3}, Tlm_batch::AbstractArray{<:Complex,3};
                    real_output::Bool=true)

Batch QST synthesis for multiple 3D vector fields.

Returns

  • (Vr_batch, Vt_batch, Vp_batch): Tuple of 3D arrays with spatial components
source
SHTnsKit.synthesis_qst_cplx — Method
synthesis_qst_cplx(cfg, Qlm, Slm, Tlm) -> (Vr, Vt, Vp)

Complex version of QST to spatial transform, preserving complex values.

source
SHTnsKit.synthesis_qst_l — Method
synthesis_qst_l(cfg, Qlm, Slm, Tlm, ltr; real_output=true) -> (Vr, Vt, Vp)

Degree-limited version of synthesis_qst, using coefficients only up to degree ltr.

source
SHTnsKit.synthesis_qst_ml — Method
synthesis_qst_ml(cfg, im, Ql, Sl, Tl, ltr) -> (Vr_m, Vt_m, Vp_m)

Mode-limited synthesis for specific azimuthal mode im.

source
SHTnsKit.synthesis_sph — Method
synthesis_sph(cfg, Slm; real_output=true) -> (Vt, Vp)

Transform only spheroidal component to spatial vector field (Tlm = 0).

source
SHTnsKit.synthesis_sph_cplx — Method
synthesis_sph_cplx(cfg, Slm) -> (Vt, Vp)

Complex-output spheroidal-only synthesis without allocating a dense zero toroidal spectrum.

source
SHTnsKit.synthesis_sph_ml — Method
synthesis_sph_ml(cfg::SHTConfig, im::Int, Sl::AbstractVector{<:Complex}, ltr::Int)

Mode-limited spheroidal-only synthesis wrapper.

source
SHTnsKit.synthesis_sphtor! — Method
synthesis_sphtor!(plan::SHTPlan, Vt_out::AbstractMatrix, Vp_out::AbstractMatrix, Slm::AbstractMatrix, Tlm::AbstractMatrix; real_output=true)

In-place vector synthesis. Streams m→k without forming (θ×m) intermediates; inverse FFT Vt then Vp.

source
SHTnsKit.synthesis_sphtor — Method
synthesis_sphtor(cfg, Slm, Tlm; real_output=true) -> (Vt, Vp)

Transform spheroidal/toroidal coefficients to horizontal vector field components. Returns colatitude (Vt) and azimuthal (Vp) components on the spatial grid.

source
SHTnsKit.synthesis_sphtor_batch — Method
synthesis_sphtor_batch(cfg::SHTConfig, Slm_batch::AbstractArray{<:Complex,3},
                       Tlm_batch::AbstractArray{<:Complex,3}; real_output::Bool=true)

Batch spheroidal-toroidal synthesis for multiple vector fields.

Returns

  • (Vt_batch, Vp_batch): Tuple of 3D arrays (nlat, nlon, nfields) containing theta and phi components
source
SHTnsKit.synthesis_sphtor_ml — Method
synthesis_sphtor_ml(cfg, mval, Sl, Tl, ltr) -> (Vt_m, Vp_m)

Mode-limited synthesis for a single azimuthal order mval: Vθ = ∂S/∂θ - (i·mval/sinθ) * T Vφ = (i·mval/sinθ) * S + ∂T/∂θ

The order argument is named mval, NOT im: a binding called im shadows Julia's imaginary unit, and 1.0im is juxtaposition (1.0 * im), so the coupling terms above silently became real. Do not rename it back.

source
SHTnsKit.synthesis_tor — Method
synthesis_tor(cfg, Tlm; real_output=true) -> (Vt, Vp)

Transform only toroidal component to spatial vector field (Slm = 0).

source
SHTnsKit.synthesis_tor_cplx — Method
synthesis_tor_cplx(cfg, Tlm) -> (Vt, Vp)

Complex-output toroidal-only synthesis without allocating a dense zero spheroidal spectrum.

source
SHTnsKit.synthesis_tor_ml — Method
synthesis_tor_ml(cfg::SHTConfig, im::Int, Tl::AbstractVector{<:Complex}, ltr::Int)

Mode-limited toroidal-only synthesis wrapper.

source
SHTnsKit.vorticity_grid — Method
vorticity_grid(cfg, Tlm) -> Matrix

Transform toroidal coefficients to vorticity on the spatial grid. This combines spectral vorticity calculation with spherical harmonic synthesis.

source
SHTnsKit.vorticity_spectral — Method
vorticity_spectral(cfg, Tlm) -> Matrix{ComplexF64}

Compute vorticity coefficients ζlm from toroidal stream function coefficients Tlm. Relationship: ζlm = -l(l+1) Tlm

source
SHTnsKit.δ — Method
δ(i, N::Int)
δ(i, I::CartesianIndex{N})

Return a CartesianIndex of dimension N which is one at index i and zero elsewhere. Useful for offsetting indices in a specific direction.

Example

δ(1, CartesianIndex(2,3))  # Returns CartesianIndex(1,0)
source
SHTnsKit.@sht_inside — Macro
@sht_inside <arr[I] = expr>

Convenience macro to loop over interior points of an array, excluding boundaries. Automatically determines the loop range from the array size.

Example

@sht_inside field[I] = 0.5 * (field_old[I+δ(1,I)] + field_old[I-δ(1,I)])
source
SHTnsKit.@sht_loop — Macro
@sht_loop <expr> over <I ∈ R>

Macro to automate fast loops using @simd when running on CPU, or KernelAbstractions when running on GPU (requires GPU extension).

The macro extracts all symbols from the expression, creates kernel functions for both CPU and GPU paths, and dispatches based on the array backend at runtime.

Examples

# Loop over 2D Cartesian range
@sht_loop dest[i, j] = src[i, j] * scale over (i, j) ∈ CartesianIndices((n, m))

# Loop with accumulation pattern
@sht_loop alm[l+1, m+1] += weights[i] * Plm[i, l+1, m+1] * Fm[i, m+1] over i ∈ 1:nlat

Notes

  • Detects CPU vs GPU from the first array in the expression
  • GPU path requires GPU extension (CUDA.jl + KernelAbstractions)
  • CPU path uses @simd @fastmath @inbounds for vectorization
  • Set SHTnsKit.set_loop_backend("SIMD") to force CPU path

Field accesses in the body (e.g. cfg.scale) are supported: the expression is evaluated once at the call site and passed in under a hygienic name, so it can never pick up an unrelated caller local that happens to share the field name.

source

Configuration lifecycle

SHTConfig is managed by Julia's garbage collector. destroy_config(cfg) is a no-op retained for API symmetry; callers do not need a try/finally teardown pattern.