AstroNbodySim.jl

A general-purpose, GPU-accelerated astrophysical N-body simulation library, released under the GPL-3.0 license.

AstroNbodySim.jl builds on the broader JuliaAstroSim ecosystem (PhysicalParticles, PhysicalTrees, PhysicalMeshes, AstroIC, AstroIO, AstroPlot, ParallelOperations) to provide a modular, fully unit-aware, hybrid-parallel simulation toolkit.

Galactic collision rendered with AstroNbodySim.jl

Installation

]add AstroNbodySim

or, to install from the latest main branch:

]add https://github.com/JuliaAstroSim/AstroNbodySim.jl

You might need to install NVIDIA CUDA toolkit

Package Features

  • Compute with units
  • User-friendly
    • Well documented
    • Readable programming
    • Vectorized array operations
    • Dispatch on types for various simulation settings
    • Float16, Float32, Float64, Int128, BigFloat, Measurement, etc.
  • Cross-platform: Linux, Windows, MacOS. Easy to deploy
  • Hybrid Parallelism: multi-threading, distributed parallelism, GPU acceleration
  • Modularity and Versatility: 10+ packages, designed for general purposes, highly extentable
  • Realtime visualzation (interactive)
  • Auto-test workflow

Development Guide

  1. It is highly recommended to use latest master branch of related packages (in JuliaAstroSim), first clone:
  2. dev --local [absolute path] to install packages mentioned above, for example
    pkg> dev --local /home/user/work/AstroNbodySim
  3. VS Code as well as its Julia Extension is convenient to use, and Revise.jl will update changes on the run.

First Time User Guide

  1. Read documentation of Julia: https://docs.julialang.org/en/v1/

  2. Read documentations and READMEs of related packages

  3. Try examples in AstroNbodySim/examples. First install packages used in examples by AstroNbodySim/examples/install_pkgs.jl. The default output directory of all examples is ./output. The programme would make a directory if the user-defined output path does not exist to avoid unnecessary errors.

  4. To interrupt a running simulation, create a file named stop in the output directory (same with Gadget2):

    echo > output/stop
  5. It's convenient to check out supported function arguments and keywords by help? in REPL, for example,

    help?> run
    search: run
    
      run(sim::Simulation)
    
      This function does all the work for you:
      1. `prepare` sim environment and preprocess data
      2. evaluate force, initialize timesteps, output
      3. `mainloop`

Gravity solvers at a glance

SolverMethodComplexityTypical use
DirectSumsoftened pairwise summation$\mathcal{O}(N^2)$reference solutions, $N \lesssim 10^5$
TreeBarnes–Hut octree (Gadget-2 framework)$\mathcal{O}(N \log N)$large particle counts, $N \gtrsim 10^5$
FFTspectral Poisson solver on a mesh$\mathcal{O}(N_g^3 \log N_g)$periodic boxes, 3D galaxy simulations
FDMfinite-difference Poisson solversparse/dense linear solve1D/2D verification, non-periodic boundaries
MLneural-network Poisson solver (experimental)network inferenceresearch prototype only

The particle solvers use the Gadget-2 cubic-spline softening kernel and the Gadget-2 leapfrog (kick–drift–kick) integrator, with fixed or adaptive timesteps. See the Manual for the formulas, defaults and parallel execution modes.

Relation to WaveDM.jl

AstroNbodySim.jl also provides the N-body engine used by WaveDM.jl. There the DirectSum and Tree solvers are used for collisionless baryons (bulge and stellar disk particles). In the static (:particles_static) mode the particle set is frozen and only supplies a background potential; in the dynamic (:particles_dynamic) mode the particles contribute their potential to the grid at every SPE step and the wave-DM acceleration is interpolated back to the particle positions. The baryon_mode keyword itself belongs to WaveDM.jl, not to this package. Orbit lookback and tidal-force workflows built on these solvers are demonstrated in examples/08-TrajectoryLookback.

Supporting and Citing

This software was developed as part of academic research. If you use it in research, teaching, or other activities, please follow the instructions on the CITING page.

AstroNbodySim.jl is the N-body engine of WaveDM.jl and should be cited together with the following papers:

@article{meng2026wavedmjladaptablea,
  title = {{{WaveDM}}.Jl: {{An Adaptable Simulation Framework}} for {{Dynamics}} of {{Baryonic}} and {{Wave Dark Matter}} on {{Galaxy Scales}}},
  shorttitle = {{{WaveDM}}.Jl},
  author = {Meng, Runyu and Dong, Xiaobo},
  year = 2026,
  journal = {Research in Astronomy and Astrophysics},
  issn = {1674-4527},
  doi = {10.1088/1674-4527/ae9042},
  url = {http://iopscience.iop.org/article/10.1088/1674-4527/ae9042},
  eprint = {2606.25026},
  archiveprefix = {arXiv},
  primaryclass = {astro-ph.GA},
  urldate = {2026-07-26}
}

Publications built on this code base:

@article{meng2026wavecold,
  title = {Wave {{Cold Dark Matter Can Reproduce}} the {{Radial Acceleration Relation}} in {{X}}-Ray {{Elliptical Galaxies}}},
  author = {Meng, Runyu and Dong, Xiaobo},
  year = 2026,
  journal = {Research in Astronomy and Astrophysics},
  issn = {1674-4527},
  doi = {10.1088/1674-4527/aeac08},
  url = {http://iopscience.iop.org/article/10.1088/1674-4527/aeac08},
  eprint = {2610.18969},
  archiveprefix = {arXiv},
  primaryclass = {astro-ph.GA},
  urldate = {2026-09-24}
}

Manual Outline

Contributing and citing

Issues and pull requests are always welcome — see Contributing for guidelines. If you use AstroNbodySim.jl in research, please cite the package via CITATION.bib; the same BibTeX entries are also bundled in these docs on the Citing page.