cosmology: a rust crate for cosmology
An early-in-development crate intended to eventually include lots of utilities commonly used in cosmology, including
Current Features
- Solves the Friedmann equations to get the scale factor for a given cosmology over time.
- On-the-fly: supply some
dtand you are able tostep_forward(dt). This is what I will be using in my quantum solver since thedttaken by the solver at some n-th step is not known at compile time. - In advance: supply some
dtspacing and a final time or scale_factor and get aBox<[T]>time series foraanddadt
- On-the-fly: supply some
Planned Features
- Power spectra
P(k)and correlation functionξ(r)using transfer function from (Eisenstein & Hu '98). - Cosmological initial condition generators.
- Linear theory predictions for the kNN distributions of matter and its tracers (e.g. haloes, galaxies).
Sample Usage
use ;
// Specify cosmological parameters
let params = CosmologicalParameters ;
// Specify initial redshift
let z0 = 9.0;
let a0 = 1.0 / ;
// Specify max dloga
let max_dloga = 0.01;
// Expectation (analytic solution of the Friedmann equation)
// For a matter dominated universe, this is a(t) = (t / (2/3/H0))^(2/3)
let hubble = 0.7 * LITTLE_H_TO_BIG_H;
let age_of_universe = 2.0 / 3.0 / hubble;
let expected = ;
// Initialize ScaleFactor
let mut scale_factor = new;
// On-the-fly
// Initialize vectors which collect values
let mut a = vec!;
let mut dadt = vec!;
let mut t = vec!;
let dt = 100.0;
let mut a_expected = vec!;
while a.last.unwrap < &1.0
// Calculate the avg of L1 loss between the calculated values and the expected values
let avg_diff = a
.iter
.zip
.map
.
/ a.len as f64;
// If --nocapture, print value
println!;
// Check that the avg of the L1 loss between the calculated values and the expected values
// is under this threshold
const ERROR_TOLERANCE: f64 = 1e-10;
assert!;
I work on a lot of things including non-equilibrium fluid dynamics, cosmology (large scale structure and scalar field dark matter), machine learning, distributed systems, smart contracts, (financial) derivatives. I am a Rust zealot and was surprised to see that there is a gap to be filled in the astrophysics/cosmology crate space. This is a crate that I am looking forward to developing.
I first began to look for a crate like this one because I needed to solve the Friedmann equations for a cosmological scalar field solver I've been working on. I found no such crate. So, here I am building it. This is presently in a very early stage but I look very forward to adding features over time. Feel free to submit PRs or suggestions for new features.