RAMSES-CPP aims to provide a functional and physically consistent alternative to the original Fortran implementation while maintaining strict bit-perfect parity in data structures and I/O.
RAMSES-CPP is designed as a modern C++17 object-oriented port of the legacy RAMSES Fortran code. It prioritizes maintainability, type safety, and modularity while maintaining bit-perfect parity with the original simulation logic.
The engine is built around several key classes that manage the simulation lifecycle, the AMR grid, and the physics solvers.
Simulation (The Orchestrator)The Simulation class is the central driver. It manages the global time-stepping, level sub-cycling, and coordinates between the grid management and the physics solvers.
src/Simulation.cpp, include/ramses/Simulation.hppParameters).Initializer).AmrGrid (The Data Structure)AmrGrid encapsulates the linked-list octree structure. In RAMSES-CPP, this is implemented as a collection of vectors (e.g., son, father, nbor), mimicking the Fortran memory layout but with C++ container management.
src/AmrGrid.cpp, include/ramses/AmrGrid.hppnbor array that stores pre-calculated neighbor pointers for every grid, enabling constant-time ($O(1)$) traversal.TreeUpdater (Grid Evolution)TreeUpdater handles the dynamic nature of AMR: refinement and de-refinement.
src/TreeUpdater.cpp, include/ramses/TreeUpdater.hppHydroSolver and MhdSolver (The Physics)These classes implement the Godunov-type solvers for fluid dynamics.
src/HydroSolver.cpp, src/MhdSolver.cppPoissonSolver (Gravity)Implements self-gravity using a Multigrid approach.
src/PoissonSolver.cpp, include/ramses/PoissonSolver.hppCoolingSolver (Thermal Physics)Handles gas cooling and heating processes.
src/CoolingSolver.cpp, include/ramses/CoolingSolver.hppRtSolver (Radiation)Implements Radiative Transfer using the M1 closure scheme.
src/RtSolver.cpp, include/ramses/RtSolver.hppRtChemistry to solve for Hydrogen/Helium ionization fractions and gas energy feedback.MpiManager and LoadBalancer (Parallelism)MpiManager: A singleton that handles MPI initialization and provides wrappers for common collective operations.LoadBalancer: Implements domain decomposition using the Hilbert Space-Filling Curve. It ensures spatial locality and provides full physical state migration (including Hydro/MHD variables) between MPI ranks.RAMSES-CPP incorporates several key optimizations to ensure high-performance execution:
nbor array within AmrGrid to store direct neighbor pointers (indices) for every grid. This mirrors the legacy pointer logic, ensuring that finding a neighbor cell across grid boundaries is a constant-time operation ($O(1)$), which is essential for efficient gradient calculation and AMR refinement.Initializer features a robust namelist parser capable of handling comma-separated lists and multi-dimensional array inputs (e.g., d_region, prad_region). It performs coordinate-accurate placement of child grids during the initial refinement phase, ensuring no mesh overlaps.qm, qp) are cached across entire AMR levels. This eliminates redundant slope calculations for shared cell interfaces, significantly improving high-order simulation performance.Simulation reads parameters and calls Initializer to set up the initial conditions on the AmrGrid. It performs an iterative refinement pass up to levelmax based on initial gradients.Simulation determines the global Courant time step dt by scanning across all active leaf cells.Simulation::amr_step is called recursively starting from levelmin.RamsesWriter periodically saves the state to disk, producing bit-perfect binary snapshots.amr_step):
TreeUpdater generates new fine grids for the current level and its children.nsubcycle factor.HydroSolver/MhdSolver) update the cell states using MUSCL-Hancock reconstruction and Riemann solvers.TreeUpdater marks cells for refinement based on relative gradients for the next time step.A critical feature of RAMSES-CPP is its ability to read and write unformatted Fortran binaries. This is handled by RamsesReader and RamsesWriter, ensuring that C++ snapshots are identical to Fortran snapshots, allowing for seamless use of the existing RAMSES ecosystem.