tpt_sci_kinetics/problem.rs
1//! Kinetics problems: assembling rate laws into an ODE right-hand side.
2
3use super::*;
4
5/// A kinetics problem: a mass-action [`ReactionSystem`] whose rate constants are
6/// overwritten with Arrhenius expressions as a function of a supplied
7/// temperature.
8///
9/// [`ReactionSystem`]: tpt_sci_reaction_network::ReactionSystem
10#[derive(Debug, Clone)]
11pub struct KineticsProblem {
12 /// Per-reaction Arrhenius parameters, aligned with the reaction indices of
13 /// the system it is applied to.
14 pub rates: Vec<ArrheniusRate>,
15}
16
17impl KineticsProblem {
18 /// Construct from one [`ArrheniusRate`] per reaction index.
19 ///
20 /// # Errors
21 ///
22 /// Returns [`KineticsError::InvalidRate`] if `rates` is empty.
23 pub fn new(rates: Vec<ArrheniusRate>) -> Result<Self, KineticsError> {
24 if rates.is_empty() {
25 return Err(KineticsError::InvalidRate("no rates supplied".into()));
26 }
27 Ok(Self { rates })
28 }
29
30 /// Resolve every rate constant at temperature `t` into a vector aligned with
31 /// the reaction indices.
32 #[must_use]
33 pub fn rate_constants(&self, t: f64) -> Vec<f64> {
34 self.rates.iter().map(|r| r.rate_constant(t)).collect()
35 }
36}