Tarang.jl

Tarang.jl

A High-Performance Spectral PDE Solver for Julia

CPU | GPU | MPI Distributed | Symbolic Equations

Build Status Documentation License: MIT


Features

Spectral Methods

  • Fourier, Chebyshev, and Legendre bases
  • Spectral accuracy for smooth solutions
  • Automatic differentiation operators

GPU Acceleration

  • Native CUDA support with cuFFT
  • KernelAbstractions.jl backend
  • Automatic CPU/GPU dispatch

MPI Parallelization

  • PencilArrays pencil decomposition
  • Scalable to thousands of cores
  • Efficient distributed FFTs

Symbolic Equations

  • Natural mathematical syntax for PDEs
  • Automatic operator construction
  • Flexible boundary conditions

Quick Start

Installation

using Pkg

# Basic installation
Pkg.add(url="https://github.com/subhk/Tarang.jl")

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

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

1D Diffusion

using Tarang

domain = PeriodicDomain(64)                     # 64-point periodic [0, 2π]
T = ScalarField(domain, "T")                    # Temperature field

problem = IVP([T])
add_parameters!(problem, kappa=0.01)
add_equation!(problem, "∂t(T) - kappa*Δ(T) = 0")

solver = InitialValueSolver(problem, RK222(); dt=0.01)
run!(solver; stop_time=1.0)                     # That's it!

2D Rayleigh-Benard Convection

using Tarang

# Channel domain: periodic in x (Fourier), bounded in z (Chebyshev)
domain = ChannelDomain(256, 64; Lx=4.0, Lz=1.0)

u = VectorField(domain, "u")                   # Velocity
T = ScalarField(domain, "T")                   # Temperature
p = ScalarField(domain, "p")                   # Pressure

problem = IVP([u, p, T])
add_parameters!(problem, Pr=1.0, Ra=2e6)
add_equation!(problem, "∂t(u) - Pr*Δ(u) + ∇(p) - Ra*Pr*T*ez = -u⋅∇(u)")
add_equation!(problem, "div(u) = 0")
add_equation!(problem, "∂t(T) - Δ(T) = -u⋅∇(T)")
add_bc!(problem, "u(z=0) = 0")
add_bc!(problem, "u(z=1) = 0")
add_bc!(problem, "T(z=0) = 1")
add_bc!(problem, "T(z=1) = 0")

solver = InitialValueSolver(problem, RK222(); dt=1e-3)
diagnose(solver)                                # Print solver summary
run!(solver; stop_time=10.0, log_interval=100)  # Run with progress
Pro Tip

Use diagnose(solver) at any time to inspect field layout, compiled RHS status, dealiasing mode, and memory usage.


GPU Example

using Tarang, CUDA

# Just add device=GPU() — everything else stays the same
domain = PeriodicDomain(512, 512; device=GPU(), dtype=Float32)
field = ScalarField(domain, "u")
forward_transform!(field)   # Uses cuFFT automatically

Scientific Applications

Fluid Dynamics

Navier-Stokes, Rayleigh-Benard convection, channel flow, jets

Turbulence

LES models (Smagorinsky, AMD), stochastic forcing, GQL approximation

Magnetohydrodynamics

MHD with magnetic fields, dynamo problems, magnetic dissipation

Geophysical Flows

Rotating shallow water, stratified turbulence, surface dynamics


Problem Types

TypeDescriptionExample
IVPInitial Value ProblemsTime-dependent Navier-Stokes
BVPBoundary Value ProblemsSteady-state solutions
EVPEigenvalue ProblemsLinear stability analysis
LBVPLinear BVPsPoisson equation
NLBVPNonlinear BVPsSteady nonlinear systems

Spectral Bases

BasisDomainUsage
RealFourierPeriodicHorizontal directions, real-valued fields
ComplexFourierPeriodicComplex-valued fields
ChebyshevTBoundedWall-bounded domains, boundary conditions
LegendreBoundedAlternative to Chebyshev

Documentation

Installation

Setup and configuration

Tutorials

Step-by-step guides

GPU Guide

CUDA acceleration

API Reference

Complete documentation


Installation Options

SetupCommandUse Case
BasicPkg.add(url="...")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 Tarang.jl in your research, please cite:

@software{tarang_jl,
  author = {Kar, Subhajit},
  title  = {Tarang.jl: A Spectral PDE Solver for Julia},
  url    = {https://github.com/subhk/Tarang.jl},
  year   = {2024}
}

License

Tarang.jl is released under the MIT License.

Made for the scientific computing community