SHTnsKit.jl

SHTnsKit.jl

High-Performance Spherical Harmonic Transforms for Julia

CPU | GPU | MPI Distributed | Auto-Differentiation

Build Status Documentation License: GPL v3


Features

Core Transforms

  • Forward & backward spherical harmonic transforms
  • Scalar, vector, and complex field support
  • In-place operations for memory efficiency

GPU Acceleration

  • CUDA/cuFFT for NVIDIA GPUs
  • KernelAbstractions.jl backend
  • Automatic CPU fallback

MPI Distributed

  • PencilArrays domain decomposition
  • Scalable to thousands of cores
  • Efficient communication patterns

Analysis Tools

  • Power spectrum analysis
  • Energy diagnostics
  • Wigner D-matrix rotations

Quick Start

Installation

using Pkg

# Basic installation
Pkg.add("SHTnsKit")

# With GPU support
Pkg.add(["SHTnsKit", "CUDA", "KernelAbstractions"])

# With MPI support
Pkg.add(["SHTnsKit", "MPI", "PencilArrays", "PencilFFTs"])

Hello World

using SHTnsKit

# Create configuration for lmax=16
cfg = create_gauss_config(16, 18)

# Create a test pattern on the sphere
spatial = zeros(cfg.nlat, cfg.nlon)
for i in 1:cfg.nlat
    x = cfg.x[i]  # cos(θ)
    spatial[i, :] .= (3*x^2 - 1)/2  # Y_2^0 pattern
end

# Transform: spatial → spectral → spatial
Alm = analysis(cfg, spatial)
recovered = synthesis(cfg, Alm)

# Verify roundtrip accuracy
println("Error: ", maximum(abs.(spatial - recovered)))  # ~1e-14
Pro Tip

For large problems (lmax > 64), use GPU acceleration with gpu_analysis() and gpu_synthesis() for significant speedup.


GPU Example

using SHTnsKit, CUDA

cfg = create_gauss_config(128, 130)
spatial = rand(cfg.nlat, cfg.nlon)

# GPU-accelerated transforms
Alm = gpu_analysis(cfg, spatial)
recovered = gpu_synthesis(cfg, Alm)

# Safe version with automatic CPU fallback
Alm_safe = gpu_analysis_safe(cfg, spatial)

Scientific Applications

Climate Science

Atmospheric dynamics, weather prediction, ocean circulation

Geophysics

Gravitational fields, magnetic anomalies, Earth surface modeling

Astrophysics

CMB analysis, stellar dynamics, gravitational waves

Fluid Dynamics

Vorticity-divergence decomposition, turbulence on spheres


Documentation

Quick Start

Get started in minutes

GPU Guide

CUDA acceleration

Distributed

MPI parallelization

API Reference

Complete documentation


Installation Options

SetupCommandUse Case
BasicPkg.add("SHTnsKit")Single CPU, getting started
GPU+ CUDA, KernelAbstractionsNVIDIA GPU acceleration
MPI+ MPI, PencilArrays, PencilFFTsCluster computing
FullAll of the aboveMaximum flexibility
Requirements
  • Julia 1.10 or later
  • For GPU: NVIDIA GPU with CUDA support
  • For MPI: OpenMPI or MPICH installed

Contributing

We welcome contributions! See our GitHub repository for:

  • Bug reports and feature requests
  • Documentation improvements
  • Pull requests

Citation

If you use SHTnsKit.jl in your research, please cite:

@software{shtnskit,
  author = {Kar, Subhajit},
  title = {SHTnsKit.jl: High-Performance Spherical Harmonic Transforms},
  url = {https://github.com/subhk/SHTnsKit.jl},
  year = {2024}
}

License

SHTnsKit.jl is released under the GNU General Public License v3.0.

Made for the scientific computing community