Skip to main content

use_radiation_basic_usage/
basic_usage.rs

1use use_radiation::{
2    Dose, RadiationBeam, RadiationKind, Shield, default_radiation_weighting_factor,
3};
4
5fn main() -> Result<(), &'static str> {
6    let beam = RadiationBeam::new(10.0, 2.0).ok_or("expected valid beam")?;
7    let shield = Shield::new(core::f64::consts::LN_2, 1.0).ok_or("expected valid shield")?;
8    let dose = Dose::new(2.0).ok_or("expected valid dose")?;
9    let weighting = default_radiation_weighting_factor(RadiationKind::Gamma)
10        .ok_or("expected gamma weighting")?;
11
12    assert_eq!(beam.intensity(), Some(5.0));
13    assert_eq!(beam.photon_flux(2.0), Some(5.0));
14    assert!(
15        (shield
16            .transmitted_fraction()
17            .ok_or("expected transmitted fraction")?
18            - 0.5)
19            .abs()
20            < 1.0e-12
21    );
22    assert_eq!(dose.equivalent(weighting), Some(2.0));
23
24    Ok(())
25}