Nyx: Adaptive N-body & Hydro Code
- Nyx is a massively parallel simulation framework that integrates a symplectic N-body solver with a second-order unsplit Godunov hydrodynamic scheme on adaptive mesh grids.
- It employs a block-structured AMR framework with advanced multigrid methods to accurately model cosmological structure formation and gravitational dynamics.
- The Nyx-RT extension couples adaptive, photon-conserving ray tracing with gas and dark matter dynamics, enabling efficient radiative transfer on exascale platforms.
Nyx is a massively parallel block-structured adaptive mesh refinement (AMR) code for large-scale cosmological N-body and hydrodynamics simulations. It integrates a symplectic particle-mesh N-body solver for dark matter, a second-order unsplit Godunov Eulerian scheme for gas dynamics, and robust Poisson gravity on dynamic grids. Its architecture is built for exascale, leveraging hybrid MPI+OpenMP/GPU parallelization and the AMReX framework. Recent extensions, notably Nyx-RT, incorporate fully adaptive, photon-conserving ray tracing for radiative transfer, coupling radiation with gravitational and gas dynamics efficiently at unprecedented resolution and scale (Almgren et al., 2013, Marshak et al., 13 Dec 2025).
1. Mathematical and Algorithmic Foundations
Nyx solves cosmological structure formation by evolving dark matter and baryonic gas in an expanding universe. The comoving scale factor is advanced using the Friedmann equation:
Time integration of uses a second-order Runge–Kutta method, maintaining per step.
Gas dynamics are formulated in comoving coordinates, advancing the conservation laws for baryon density and peculiar velocity :
The dual-energy formalism evolves both total energy and internal energy for accuracy in hypersonic and low-Mach regimes, with:
The N-body module replaces the collisionless Boltzmann equation with particles, each evolved using a symplectic kick–drift–kick algorithm that naturally incorporates expansion:
1 2 3 4 |
// Pseudocode: particle update (a u_i)^{n+1/2} = (a u_i)^n + (Δt/2) g^n(x_i) x_i^{n+1} = x_i^n + (Δt / a_{n+1/2}) u_i^{n+1/2} (a u_i)^{n+1} = (a u_i)^{n+1/2} + (Δt/2) g^{n+1}(x_i^{n+1}) |
with periodic boundaries and densities deposited using the cloud-in-cell (CIC) method (Almgren et al., 2013).
2. Numerical Methods and AMR Framework
Nyx’s block-structured AMR allows spatial refinement by factors of two, utilizing the Berger–Rigoutsos clustering algorithm for grid generation, and supporting multiple subcycling policies for temporal refinement. Algorithms for mesh and multilevel synchronization include:
- Proper nesting: each fine patch contained within coarser regions with a buffer border.
- Recursive multilevel advance: gravity is solved on all levels, hydrodynamics advanced, particle update performed, and synchronization executed via refluxing and elliptic corrections.
The Eulerian hydro solver is an unsplit Godunov method, employing either a piecewise linear method (PLM) or enhanced piecewise parabolic method (PPM) for reconstruction, and an iterative two-shock (Colella–Glaz) Riemann solver for robustness in shocks.
Mass assignment and force interpolation in the particle-mesh N-body algorithm use CIC across the AMR hierarchy. Ghost and virtual particles ensure correct mass mapping at coarse–fine boundaries. The Poisson equation is discretized with a 7-point stencil and solved by geometric multigrid using red-black Gauss–Seidel smoothing.
3. Parallel Implementation and Workflow
Nyx is written in Fortran90 and C++ and leverages hybrid MPI+OpenMP parallelism (BoxLib/AMReX). Key aspects include:
- Domain decomposition: per-level “MultiFab” grids assigned via Knapsack heuristics or Morton-order (Z-curve) for load balance.
- Fine-grained data partitioning: Each MPI rank manages its particles and local mesh blocks, with no global particle structure.
- Communication: Ghost-cell halo exchange for hydro and gravity, global redistributions only on regridding or grid boundary crossing. Multigrid boundary data is communicated for solution consistency.
- I/O: Output is stored as self-describing HDF5 “plotfile” and “checkpoint” directories, with coordinated job restart and optional byte-swap or precision conversion. Built-in support exists for amrvis, VisIt, and yt visualization tools (Almgren et al., 2013).
4. Radiative Transfer: Nyx-RT Adaptive Ray Tracing
The Nyx-RT extension provides operator-split coupling of radiative transfer (RT) with gravitational and gas dynamics. Adaptive ray tracing is implemented as a sequence of AMReX particle operations, where each “ray” is a pseudo-particle carrying photon luminosity, travel distance, optical depth, and direction (parameterized on a HEALPix hierarchy). The algorithm includes:
- Initializing rays as level-0 HEALPix bundles at each source.
- Marching rays cell-by-cell using Amanatides–Woo voxel traversal.
- Depositing photoionization and photoheating rates locally, with photon-conserving flux calculation:
- Splitting rays adaptively as determined by local solid angle coverage; filtering rays based on optical depth, travel distance, or pixel depth.
Geometric overlap corrections mitigate numerical artifacts from ray–pixel mismatch, reassigning “lost” photons to neighboring cells with a conservative thresholding procedure for numerical stability (Marshak et al., 13 Dec 2025).
Source merging introduces dynamic consolidation of ionizing sources whose H II regions overlap, using a radius-detection and union-find graph algorithm. This reduces the number of rays by in late reionization, halving the total wall-time for 1024³ runs with only minimal effects () on reionization history.
5. Validation and Benchmarking
Nyx and Nyx-RT have undergone extensive code validation:
- N-body particle dynamics: Two-particle orbital tests show radius drift (coarse) and (fine), with multi-level accuracy matching single-level within .
- Cosmological N-body: Two-point correlation , halo mass functions, and NFW profiles match Gadget-2 and other AMR codes, with AMR runs (256³+2 levels) approximating uniform 1024³ grid results.
- Hydrodynamical tests: Adiabatic Santa Barbara cluster simulations recover and , and reproduce radial profiles consistent with Enzo/ART and code-averaged benchmarks, including characteristic entropy core flattening.
- Radiative transfer: Strömgren sphere solutions converge to analytic expectations; cosmological “Test 4” matches established results (Arc). Figures 4–5 in (Marshak et al., 13 Dec 2025) illustrate agreement for ionized regions and artifact suppression.
6. Performance and Scalability
Nyx is architected for exascale platforms, with demonstrated scaling to 49,152 CPU cores in MPI+OpenMP and to 4,096 GPUs with Nyx-RT. Scaling results show:
- Weak scaling with time/step increase over problem size expansion.
- At 4096³ grid and particle resolution, full RT+hydrodynamics simulations are tractable ( GPU-hours for ), with the ray-tracing pipeline GPU-dominated for memory bandwidth and throughput.
- Source merging reduces total ray count by more than threefold, dramatically accelerating late-stage reionization calculations (Almgren et al., 2013, Marshak et al., 13 Dec 2025).
7. Applications, Impact, and Future Directions
Nyx and Nyx-RT are targeted at precision studies of cosmological structure formation, the epoch of reionization, and IGM properties. Demonstrated applications include:
- Large-volume cosmological N-body/hydro with full radiative feedback at 4096³ scale.
- Accurate Ly forest flux modeling with convergence at the 10% level up to .
- Flexible AMR capabilities for multi-scale galaxy formation and cluster studies.
Ongoing and future development areas include improved photoheating models, helium radiative transfer, device-level GPU optimizations, ray merging, and full extension of adaptive RT to AMR (block-refined) grids (Marshak et al., 13 Dec 2025).
Summary Table: Key Capabilities of Nyx and Nyx-RT
| Capability | Implementation | Benchmark Highlights |
|---|---|---|
| N-body solver | Particle-mesh, CIC, symplectic KDK | , mass function, NFW |
| Hydrodynamics | Unsplit Godunov, PPM/PLM, dual-energy | Santa Barbara cluster, shocks |
| Gravity | Geometric multigrid Poisson | Scalable to > cores/GPUs |
| AMR | Block-structured, flexible subcycling | Multi-level accuracy, load balance |
| Radiative transfer (RT) | Adaptive ray tracing, source merging | Strömgren, full cosmological RT |
(Almgren et al., 2013, Marshak et al., 13 Dec 2025)