earths 0.0.4

High-fidelity Earth simulation engine — orbit, atmosphere, geology, hydrology, biosphere, terrain, lighting, rendering, satellites, and temporal systems with full scientific coupling
Documentation
pub struct TropicalCyclone {
    pub maxsustainedwindms: f64,
    pub centralpressurehpa: f64,
    pub radiusmaxwindkm: f64,
    pub latitudedeg: f64,
}
impl TropicalCyclone {
    pub fn saffirsimpsoncategory(&self) -> u8 {
        let vkt = self.maxsustainedwindms * 1.94384;
        if vkt >= 137.0 {
            5
        } else if vkt >= 113.0 {
            4
        } else if vkt >= 96.0 {
            3
        } else if vkt >= 83.0 {
            2
        } else if vkt >= 64.0 {
            1
        } else {
            0
        }
    }
    pub fn accumulatedcycloneenergy(&self, durationhours: f64) -> f64 {
        let vkt = self.maxsustainedwindms * 1.94384;
        vkt * vkt * durationhours / 6.0 * 1e-4
    }
    pub fn potentialintensityms(sstk: f64, tropopausetempk: f64, enthalpydiff: f64) -> f64 {
        let efficiency = (sstk - tropopausetempk) / sstk;
        let ckcd = 0.9;
        (ckcd * efficiency * enthalpydiff).sqrt()
    }
    pub fn rossbydeformationradius(&self) -> f64 {
        let f = 2.0 * crate::OMEGAEARTH * (self.latitudedeg.to_radians()).sin();
        let nh = 50.0;
        if f.abs() < 1e-10 {
            return f64::INFINITY;
        }
        nh / f.abs()
    }
    pub fn windatradius(&self, rkm: f64) -> f64 {
        let rm = self.radiusmaxwindkm;
        let vm = self.maxsustainedwindms;
        vm * (rm / rkm) * (-(rkm - rm).powi(2) / (2.0 * rm * rm)).exp()
    }
}
pub fn fujitascale(windspeedms: f64) -> &'static str {
    let mph = windspeedms * 2.23694;
    if mph >= 261.0 {
        "EF5"
    } else if mph >= 201.0 {
        "EF4"
    } else if mph >= 136.0 {
        "EF3"
    } else if mph >= 111.0 {
        "EF2"
    } else if mph >= 86.0 {
        "EF1"
    } else if mph >= 65.0 {
        "EF0"
    } else {
        "Sub-EF"
    }
}
pub fn capelayer(parceltempk: f64, envtempk: f64, dz: f64) -> f64 {
    if envtempk.abs() < 1e-10 {
        return 0.0;
    }
    *crate::SURFACEGRAVITY * ((parceltempk - envtempk) / envtempk).max(0.0) * dz
}
pub fn capeintegrated(
    parceltempk: f64,
    envsurfacetempk: f64,
    envlapseratekperm: f64,
    dzm: f64,
    nlayers: u32,
) -> f64 {
    let moistlapse = 0.0065;
    let mut capetotal = 0.0;
    let mut abovelfc = false;
    for layer in 0..nlayers {
        let z = (layer as f64 + 1.0) * dzm;
        let tparcel = parceltempk - moistlapse * z;
        let tenv = envsurfacetempk - envlapseratekperm * z;
        if tparcel > tenv {
            abovelfc = true;
            capetotal += capelayer(tparcel, tenv, dzm);
        } else if abovelfc {
            break;
        }
    }
    capetotal
}