1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use necsim_core::{
    cogs::{Habitat, MathsCore, TurnoverRate},
    landscape::Location,
};
use necsim_core_bond::{NonNegativeF64, PositiveF64};

#[derive(Clone, Debug)]
#[cfg_attr(feature = "cuda", derive(rust_cuda::lend::LendRustToCuda))]
#[allow(clippy::module_name_repetitions)]
pub struct UniformTurnoverRate {
    turnover_rate: PositiveF64,
}

impl Default for UniformTurnoverRate {
    fn default() -> Self {
        Self {
            turnover_rate: unsafe { PositiveF64::new_unchecked(0.5_f64) },
        }
    }
}

#[contract_trait]
impl<M: MathsCore, H: Habitat<M>> TurnoverRate<M, H> for UniformTurnoverRate {
    #[must_use]
    #[inline]
    fn get_turnover_rate_at_location(&self, _location: &Location, _habitat: &H) -> NonNegativeF64 {
        self.turnover_rate.into()
    }
}

impl UniformTurnoverRate {
    #[must_use]
    pub fn new(turnover_rate: PositiveF64) -> Self {
        Self { turnover_rate }
    }

    #[must_use]
    #[inline]
    pub fn get_uniform_turnover_rate(&self) -> PositiveF64 {
        self.turnover_rate
    }
}