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
//! Reaction structure.

use crate::{access, chem::Rate};
use ndarray::Array1;

/// Reaction.
#[derive(Clone)]
pub struct Reaction {
    /// Reaction rate.
    rate: Rate,
    /// Stoichiometric coefficient map.
    coeffs: Array1<f64>,
}

impl Reaction {
    access!(coeffs, Array1<f64>);

    /// Construct a new instance.
    #[inline]
    #[must_use]
    pub fn new(rate: Rate, coeffs: Array1<f64>) -> Self {
        debug_assert!(!coeffs.is_empty());

        Self { rate, coeffs }
    }

    /// Determine the rate of change for each chemical within the system.
    #[inline]
    #[must_use]
    pub fn rate(&self, concs: &Array1<f64>) -> Array1<f64> {
        self.rate.rate(concs) * &self.coeffs
    }

    /// Separate into components.
    #[allow(clippy::missing_const_for_fn)]
    #[inline]
    #[must_use]
    pub fn components(self) -> (Rate, Array1<f64>) {
        (self.rate, self.coeffs)
    }
}