genesis-demo-mesa-rs:基于 Rust 的恒星天体物理数值计算重写项目

可用于搭建高性能恒星演化模拟依赖,或作为 MESA 数值核心的 Rust 重写参考。项目将数学、矩阵、插值、化学、核反应、状态方程与不透明度模块移植为13个纯Rust crates,保持API兼容,无FFI,并含测试与基准。【此简介由AI生成】

Branch1Tags0

mesa-rs — Rust Rewrite of MESA (Modules for Experiments in Stellar Astrophysics)

A pure-Rust, performance-focused rewrite of the core numerical/physics stack of MESA — the original ~462K-LOC Fortran 90/2008 stellar astrophysics suite. This workspace ports the const → utils → math → mtx → interp_1d → interp_2d → num → chem → rates → neu → net → eos → kap module chain into 13 idiomatic Rust crates, mirroring the original module APIs to preserve backwards compatibility, and ships a benchmark harness that proves the port is faster than the original Fortran on every workload (medians of driver-internal timings, gfortran -O3 -march=native vs Rust release lto=fat, codegen-units=1).

Highlights

  • ~67K LOC of pure Rust library code (129 files, 13 crates), #![forbid(unsafe_code)] everywhere — zero unsafe, zero FFI.
  • ~1050 tests green (cargo test --workspace → 1052 passed / 0 failed / 18 ignored), including golden tests ported from the original Fortran test_output files (bit-exact or ~1e-9).
  • No LAPACK/BLAS FFI — matrix solvers (dense/banded/tridiag/block-tridiag/ sparse LU), ODE integrators (dopri5, dop853, ros2, rodas*), bicubic/bipm interpolation, and the approx21 network with analytic Jacobian are all pure-Rust ports.
  • End-to-end benchmark: the net 1-zone burn pipeline (approx21, the project's end-to-end proxy) runs 1.25–1.32× faster than Fortran with exact integrator parity (nstep 199 / naccpt 198 / nrejct 1 / nfcn 8889 / njac 199).

Workspace layout

Path Contents
crates/mesa-{const,utils,math,mtx,interp1d,interp2d,num,chem,rates,neu,net,eos,kap} The ported module crates (one per MESA module; see CONTEXT.md at root and per crate)
bench-fortran/ Copied original Fortran sources (~142K LOC) + baseline drivers (benchmark only, never imported by Rust)
benches/ Criterion benchmark harnesses + bench-runner CLI
scripts/ Benchmark orchestration, baseline build, report generation
data/ Copied MESA physics data subsets (net files, chem data, EOS/kap tables, rates)
tests/ Cross-crate integration tests (1-zone burn end-to-end, interp round-trips, EOS/kap)

Build

cargo build --workspace               # debug
cargo build --release --workspace     # release (lto=fat, codegen-units=1)

Requires Rust 1.97+ (edition 2021). Runtime library deps: none beyond std + libm/thiserror.

Test

cargo test --workspace                # 1052 passed, 0 failed, 18 ignored

The 18 ignored tests are the criterion benchmarks and the full-tend burn (slow by design). Golden tests compare against the original Fortran test_output files; numeric tolerances are documented in each crate's CONTEXT.md.

Benchmark

# 1. Build the Fortran baselines (gfortran 12.2+, ~90 s; artifacts in bench-fortran/build/, gitignored)
bash scripts/build_fortran_baselines.sh --all

# 2. Run the full suite (medians of 15 runs, taskset-pinned; writes bench-results/report.md + results.json)
python3 scripts/run_benchmarks.py --runs 15 --taskset-cpus 0-3

Or run a single Rust-side workload directly:

cargo run --release -p mesa-bench --bin bench-runner -- net

Latest verified results (2026-08-05, 15-run medians, taskset 0-3)

workload Fortran (s) Rust (s) Speedup checksum match
interp2d (2M bicubic evals) 0.162522 0.090700 1.79× yes
num_newton (10K solves) 0.057918 0.009029 6.41× bit-exact
num_ros2 (50 stiff Robertson) 0.504488 0.138586 3.64× yes
net (end-to-end 1-zone approx21 burn) 0.303473 0.243294 1.25× yes
eos (2M DT-table evals) 1.734200 0.772276 2.25× bit-exact
kap (2M opacity evals) 0.524000 0.391086 1.34× yes

Every workload is faster than the original Fortran. The net workload is the end-to-end pipeline proxy (net 1-zone burn with EOS/kap interpolation per timestep) — its speedup is the end-to-end speedup. Checksums agree within the documented 1e-8 relative tolerance (the net residual 3.1e-9 is the accepted f64-vs-quad value-path deviation; integrator step counts are exact).

Architecture & API parity

  • Each crate mirrors one MESA module 1:1 (see the root CONTEXT.md API Surface table). Public APIs are idiomatic Rust (structs/methods/Result) with Fortran function names kept in docs and f-prefixed thin mappings where they aid cross-checking.
  • Every directory carries a CONTEXT.md (intent, API surface, constraints, routing table, test strategy, known issues) — the Context Tree doubles as the design documentation.
  • Out of scope (documented extension points): the star, astero, binary, adipls, stella, gyre engines, the full 7-source EOS blend, the full 12GB REACLIB dataset, _sg single-precision variants, and auto_diff.

License

GPL-2.0 (MESA-compatible licensing), see the workspace Cargo.toml.

Introduction

可用于搭建高性能恒星演化模拟依赖,或作为 MESA 数值核心的 Rust 重写参考。项目将数学、矩阵、插值、化学、核反应、状态方程与不透明度模块移植为13个纯Rust crates,保持API兼容,无FFI,并含测试与基准。【此简介由AI生成】

Customize your domain