use super::*;
#[derive(Debug, Clone, Copy)]
pub struct EleyRideal {
pub k: f64,
}
impl EleyRideal {
pub fn new(k: f64) -> Result<Self, KineticsError> {
if !k.is_finite() || k < 0.0 {
return Err(KineticsError::InvalidRate(format!(
"Eley-Rideal rate constant must be finite and >= 0, got {k}"
)));
}
Ok(Self { k })
}
#[must_use]
pub fn rate(&self, theta_adsorbed: f64, gas_phase_concentration: f64) -> f64 {
if theta_adsorbed <= 0.0 || gas_phase_concentration <= 0.0 {
return 0.0;
}
self.k * theta_adsorbed * gas_phase_concentration
}
#[must_use]
pub fn into_rate_law(
self,
theta_index: usize,
gas_index: usize,
) -> tpt_sci_reaction_network::RateLaw {
tpt_sci_reaction_network::RateLaw::custom(move |y: &[f64], _p: &[f64]| {
let theta = y.get(theta_index).copied().unwrap_or(0.0);
let gas = y.get(gas_index).copied().unwrap_or(0.0);
self.rate(theta, gas)
})
}
}