use super::*;
#[derive(Debug, Clone, Copy)]
pub struct ArrheniusRate {
pub a: f64,
pub ea: f64,
}
impl ArrheniusRate {
pub fn new(a: f64, ea: f64) -> Result<Self, KineticsError> {
if a <= 0.0 {
return Err(KineticsError::InvalidRate(format!(
"pre-exponential A must be > 0, got {a}"
)));
}
if ea < 0.0 {
return Err(KineticsError::InvalidRate(format!(
"activation energy Ea must be >= 0, got {ea}"
)));
}
Ok(Self { a, ea })
}
#[must_use]
pub fn rate_constant(&self, t: f64) -> f64 {
if t <= 0.0 {
return 0.0;
}
self.a * (-self.ea / (R_GAS * t)).exp()
}
}
impl ArrheniusRate {
pub fn with_activation_energy(
a: f64,
ea: tpt_sci_units::JoulePerMole,
) -> Result<Self, KineticsError> {
Self::new(a, ea.value())
}
#[must_use]
pub fn rate_constant_at(&self, t: tpt_sci_units::Kelvin) -> f64 {
self.rate_constant(t.value())
}
}