callistos 0.0.3

Callisto celestial simulation crate for the MilkyWay SolarSystem workspace
Documentation
use sciforge::hub::prelude::constants::elements::atomic_mass;

pub struct ExosphereSpecies {
    pub name: &'static str,
    pub symbol: &'static str,
    pub molar_mass_kg_mol: f64,
    pub column_density_m2: f64,
    pub scale_height_m: f64,
}

pub struct ExosphereEndpoint {
    pub body_radius_m: f64,
    pub species: Vec<ExosphereSpecies>,
}

fn co2_molar() -> f64 {
    (atomic_mass(6) + 2.0 * atomic_mass(8)) * 1e-3
}
fn o2_molar() -> f64 {
    2.0 * atomic_mass(8) * 1e-3
}
fn h2o_molar() -> f64 {
    (2.0 * atomic_mass(1) + atomic_mass(8)) * 1e-3
}

impl ExosphereEndpoint {
    pub fn callisto() -> Self {
        Self {
            body_radius_m: crate::CALLISTO_RADIUS_M,
            species: vec![
                ExosphereSpecies {
                    name: "Carbon dioxide",
                    symbol: "CO2",
                    molar_mass_kg_mol: co2_molar(),
                    column_density_m2: 1e19,
                    scale_height_m: 60_000.0,
                },
                ExosphereSpecies {
                    name: "Molecular oxygen",
                    symbol: "O2",
                    molar_mass_kg_mol: o2_molar(),
                    column_density_m2: 1e18,
                    scale_height_m: 90_000.0,
                },
                ExosphereSpecies {
                    name: "Water vapor",
                    symbol: "H2O",
                    molar_mass_kg_mol: h2o_molar(),
                    column_density_m2: 1e15,
                    scale_height_m: 20_000.0,
                },
            ],
        }
    }

    pub fn density_at_altitude(&self, species_symbol: &str, altitude_m: f64) -> f64 {
        self.species
            .iter()
            .find(|s| s.symbol == species_symbol)
            .map(|s| {
                let n_surface = s.column_density_m2 / s.scale_height_m;
                n_surface * (-altitude_m / s.scale_height_m).exp()
            })
            .unwrap_or(0.0)
    }

    pub fn total_column_density(&self) -> f64 {
        self.species.iter().map(|s| s.column_density_m2).sum()
    }
}