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
43
44
45
46
47
48
49
50
51
use crate::common::gas::Gas;
use crate::deco::{TISSUE_COUNT, WATER_VAPOUR_PRESSURE};
use crate::gas;

/// A set of tissues for use in decompression models, comprising a set of tissues for nitrogen

/// and another set for helium.

#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "use-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Tissue {
    // Tissue states

    pub(crate) p_n2: [f64; TISSUE_COUNT],
    pub(crate) p_he: [f64; TISSUE_COUNT],
    pub(crate) p_t: [f64; TISSUE_COUNT],
}

impl Tissue {
    /// Returns a new Tissue with the given parameters.

    /// # Arguments

    /// * `p_n2` - Set of tissues for nitrogen

    /// * `p_he` - Set of tissues for nitrogen

    /// * `p_t` - Total pressure of all tissues

    pub fn new(
        p_n2: [f64; TISSUE_COUNT],
        p_he: [f64; TISSUE_COUNT],
        p_t: [f64; TISSUE_COUNT],
    ) -> Self {
        Self { p_n2, p_he, p_t }
    }

    pub fn p_n2(&self) -> [f64; TISSUE_COUNT] {
        self.p_n2
    }

    pub fn p_he(&self) -> [f64; TISSUE_COUNT] {
        self.p_n2
    }
}

impl Default for Tissue {
    /// A default value for tissues. This is the tissue loading of a diver who has been breathing

    /// air at 1 atm for a long time.

    fn default() -> Self {
        let air = gas!(21, 0);
        let adj_fr_n2 = air.fr_n2() * (1.0 - WATER_VAPOUR_PRESSURE);
        Self {
            p_n2: [adj_fr_n2; TISSUE_COUNT],
            p_he: [0.0; TISSUE_COUNT],
            p_t: [adj_fr_n2; TISSUE_COUNT],
        }
    }
}