How clustermontecarlo/cmc-cosmic works
1. Project purpose
- CMC-COSMIC is a high-performance astrophysical simulation code for long-term evolution of dense star clusters.
- The main execution model is a Monte Carlo/Hénon-style cluster dynamics engine coupled to stellar/binary evolution and few-body encounter handling.
2. Primary runtime boundary: the CMC simulation engine
- The core application lives under src/cmc with headers in include/cmc.
- This layer contains the cluster state evolution, relaxation, orbit averaging, I/O, MPI coordination, binary handling, stellar-evolution hooks, and encounter logic.
- It is the central subsystem that drives time evolution and coordinates all other components.
3. Parallel execution and HPC dependencies
- The code is designed for HPC clusters and uses MPI (include/cmc/cmc_mpi.h, src/cmc/cmc_mpi.c).
- Build and runtime dependencies called out in the README are MPI, HDF5, GSL, and CMake.
- The repo is organized for compiled native binaries rather than a service or library-only architecture.
4. Stellar and binary evolution integration
- src/bse_wrap and include/bse_wrap provide the bridge into the embedded COSMIC/BSE stellar evolution code.
- This is a major boundary: cluster dynamics code calls into the evolution layer to update stellar types, masses, binaries, and compact-object outcomes.
- The actual COSMIC submodule is vendored in-tree under src/bse_wrap/bse/COSMIC.
5. Few-body encounter subsystem
- src/fewbody-0.24 and include/fewbody-0.24 are a bundled third-party few-body scattering/interaction package.
- CMC uses this for close encounters such as binary-single, binary-binary, triple, and hierarchical interactions.
- This is another clear subsystem boundary: the Monte Carlo cluster model delegates rare but strong interactions to a specialized few-body solver.
6. Core physics modules inside CMC
- The src/cmc files are split by physics concern:
- relaxation and dynamics: cmc_relaxation.c, cmc_dynamics.c, cmc_core.c
- binaries and interactions: cmc_binbin.c, cmc_binsingle.c, cmc_sscollision.c, cmc_bhlosscone.c
- stellar evolution and removal: cmc_stellar_evolution.c, cmc_remove_star.c, cmc_evolution_thr.c
- numerics/search/sorting/orbits: cmc_search_grid.c, cmc_sort.c, cmc_orbit.c, cmc_nr.c
- I/O and utilities: cmc_io.c, cmc_utils.c, cmc_fits.c
- Architecturally, this is a modular C codebase with one central state model and many specialized physics handlers.
7. Data flow through the system
- Input starts from initial-condition generators or parameter files, then enters the CMC engine.
- The engine evolves cluster state over time, invoking stellar evolution and encounter solvers as needed.
- Results are written to multiple output streams and formats, including HDF5 snapshots and text logs/dat files.
- Example outputs in docs/sphinx/source/example_output show the expected artifacts: dynamical logs, binary interaction logs, BH catalogs, lagrangian radii, and snapshot files.
8. Initial-condition and preprocessing utilities
- src/utils contains standalone command-line generators and transformers:
- mkking, mkplummer, mkelson for cluster models
- setimf, setstellar, setunits, addbinaries
- FITS/ASCII conversion utilities under ascii2fits
- These are upstream tools in the workflow: they prepare cluster models before the main CMC run.
9. Analysis and Python tooling
- tools/cmc_parser.py and tools/cmctoolkit.py provide post-processing and analysis support in Python.
- These sit downstream of the simulation outputs and are likely used for parsing logs, organizing data, or producing derived measurements.
- The repo therefore includes both the compiled simulation core and a lightweight analysis layer.
10. GPU/CUDA code path
- The cuda directory is a separate CUDA implementation/support area with its own build files and common helper library.
- It appears to be an auxiliary or experimental acceleration path rather than the main code path described in the README.
- For architecture diagrams, it should be shown as an optional GPU subsystem adjacent to the core C implementation, not as the primary execution route.
11. Build and packaging structure
- The project uses CMake as the main build system, with additional CUDA makefiles and a top-level Dockerfile.
- CI is handled via GitHub Actions workflows for packaging, registry publishing, and GitHub Pages docs deployment.
- This indicates a reproducible HPC-oriented build pipeline, with container support for deployment and testing.
12. Documentation and examples as part of the repo workflow
- docs/sphinx and docs/doxygen contain the user-facing documentation sources.
- examples and ci contain runnable configuration files, input data, and test automation.
- These are not runtime subsystems, but they shape the operational flow: example input → simulation → outputs → documentation/analysis.
Main entry points: cmc_core.c Core state · cmc.c CMC runtime · cmc_io.c I/O layer · CMakeLists.txt Build system
Components 16
CMC engine
Main Monte Carlo cluster-dynamics runtime and physics handlers.
- CMC runtime · Top-level cluster evolution executable and state coordinator.
src/cmc/cmc.c - Core state · Cluster state model, time stepping, and central orchestration.
src/cmc/cmc_core.c - Dynamics · Monte Carlo relaxation, orbit averaging, and dynamical updates.
src/cmc/cmc_dynamics.c - Binary physics · Binary-single, binary-binary, collisions, and loss-cone handling.
src/cmc/cmc_binbin.c - Stellar evolution · Stellar evolution coupling, removal, and evolutionary thresholds.
src/cmc/cmc_stellar_evolution.c - I/O layer · Snapshot writing, logs, fits helpers, and runtime data output.
src/cmc/cmc_io.c - MPI layer · Parallel coordination and message-passing support.
src/cmc/cmc_mpi.c
Embedded solvers
Bundled external physics solvers used by the core engine.
- BSE bridge · Interface between CMC and the embedded COSMIC/BSE evolution code.
src/bse_wrap/bse_wrap.c - COSMIC · Vendored COSMIC stellar and binary evolution implementation.
src/bse_wrap/bse/COSMIC - Few-body solver · Bundled few-body scattering and hierarchical interaction package.
src/fewbody-0.24/fewbody.c
Workflow tools
Input generation, post-processing, documentation, and build infrastructure.
- IC generators · Standalone initial-condition and cluster model generators.
src/utils/mkking/mkking.c - Transform tools · Utilities for IMF, units, stellar settings, binaries, and FITS conversion.
src/utils/setimf/setimf.c - Python tools · Python parsing and analysis helpers for simulation outputs.
tools/cmc_parser.py - Docs · Sphinx and Doxygen documentation sources plus example outputs.
docs/sphinx/source/index.rst - Build system · CMake configuration, Dockerfile, and CI workflows for reproducible builds.
CMakeLists.txt
GPU path
Auxiliary CUDA code path and support library.
- CUDA path · Auxiliary CUDA implementation and helper library.
cuda/cmc_cuda.cu
Connections 17
- IC generators → CMC runtime: prepare inputs · Initial-condition generators produce cluster models consumed by the simulation.
- Transform tools → CMC runtime: prepare inputs · Preprocessing utilities transform tables, units, and binary populations before runtime.
- CMC runtime → Core state: drives · The executable enters the central cluster state and time-evolution loop.
- Core state → Dynamics: evolves · Core state updates invoke relaxation, orbit handling, and dynamical stepping.
- Core state → Binary physics: dispatches · Rare close encounters are routed to specialized binary and collision handlers.
- Core state → Stellar evolution: updates stars · The cluster model consults stellar evolution and removal logic as stars age or transform.
- Core state → BSE bridge: calls · CMC uses the wrapper to access COSMIC/BSE evolution routines.
- BSE bridge → COSMIC: delegates · The wrapper forwards evolution requests into the vendored COSMIC code.
- Binary physics → Few-body solver: delegates · Strong few-body interactions are solved by the bundled scattering package.
- Core state → MPI layer: parallelizes · Runtime coordination uses MPI for distributed execution.
- Core state → I/O layer: writes · Simulation state and diagnostics are persisted through the I/O layer.
- I/O layer → Docs: matches examples · Documented example outputs describe the expected files and logs.
- Python tools → I/O layer: parses · Python tools consume logs, catalogs, and snapshot outputs.
- Docs → IC generators: documents · Documentation includes input generation and example configuration workflows.
- Build system → CMC runtime: builds · CMake and related tooling assemble the main simulation binaries.
- Build system → CUDA path: builds · Separate build files support the optional CUDA path.
- CUDA path → CMC runtime: adjacent path · GPU code exists as an auxiliary implementation alongside the main C code path.