Skip to main content

hydr_structures/structures/blockage/
condition.rs

1//! Physical condition of a structure and its typed blockage.
2
3use super::BlockageFraction;
4use crate::structures::StructureError;
5use crate::structures::definition::text;
6
7/// Physical condition of a structure. The geometry in its law is the unblocked geometry.
8#[derive(Clone, Debug, PartialEq)]
9pub enum StructureCondition {
10    /// The law's geometry as declared.
11    AsBuilt,
12    /// A typed blockage of the declared geometry.
13    Blocked(StructureBlockage),
14    /// Fully blocked. Exact zero discharge.
15    Closed {
16        /// Evidence for the closure, such as a survey or an inspection record.
17        evidence: String,
18    },
19}
20
21/// Kind of a [`StructureCondition`], without its data.
22#[derive(Clone, Copy, Debug, PartialEq, Eq)]
23pub enum StructureConditionKind {
24    /// [`StructureCondition::AsBuilt`].
25    AsBuilt,
26    /// [`StructureCondition::Blocked`].
27    Blocked,
28    /// [`StructureCondition::Closed`].
29    Closed,
30}
31
32impl StructureCondition {
33    /// Kind of this condition.
34    pub fn kind(&self) -> StructureConditionKind {
35        match self {
36            Self::AsBuilt => StructureConditionKind::AsBuilt,
37            Self::Blocked(_) => StructureConditionKind::Blocked,
38            Self::Closed { .. } => StructureConditionKind::Closed,
39        }
40    }
41}
42
43/// Uniform sediment bed in every barrel of a culvert.
44///
45/// The bed runs along the full barrel length, parallel to the invert. The open section sits
46/// above depth `depth_m` and has rise `D - depth_m`.
47#[derive(Clone, Copy, Debug, PartialEq)]
48pub struct CulvertSediment {
49    /// Sediment depth `h` above the invert, in metres, with `0 < h < D`.
50    pub depth_m: f64,
51    /// Manning roughness `n_bed` of the sediment bed, in `s/m^(1/3)`.
52    pub bed_manning_n: f64,
53}
54
55/// Typed blockage of a culvert: entrance face fractions, uniform sediment bed, and closed barrels.
56#[derive(Clone, Copy, Debug, PartialEq)]
57pub struct CulvertBlockage {
58    /// Blocked share of the face at endpoint A. Rejected if B-to-A flow exits at A.
59    pub face_a: BlockageFraction,
60    /// Blocked share of the face at endpoint B. Rejected if A-to-B flow exits at B.
61    pub face_b: BlockageFraction,
62    /// Uniform sediment bed in every barrel, replacing any open-bottom floor roughness.
63    pub sediment: Option<CulvertSediment>,
64    /// Number of fully blocked barrels `k`, with `0 <= k < N`. `k = N` is `StructureCondition::Closed`.
65    pub closed_barrels: u32,
66}
67
68impl CulvertBlockage {
69    /// Zero face blockage, no sediment, and no closed barrels.
70    pub const NONE: Self = Self {
71        face_a: BlockageFraction::NONE,
72        face_b: BlockageFraction::NONE,
73        sediment: None,
74        closed_barrels: 0,
75    };
76}
77
78/// Blocked shares of the geometry of one law.
79#[non_exhaustive]
80#[derive(Clone, Copy, Debug, PartialEq)]
81pub enum BlockageGeometry {
82    /// Blocked share of a weir crest length.
83    Weir {
84        /// Blocked share of the crest length.
85        crest_length: BlockageFraction,
86    },
87    /// Blocked share of an orifice opening area.
88    Orifice {
89        /// Blocked share of the opening area.
90        area: BlockageFraction,
91    },
92    /// Blocked shares of a gate aperture width and opening range.
93    Gate {
94        /// Blocked share of the aperture width.
95        width: BlockageFraction,
96        /// Blocked share of the maximum opening. Every opening above the blocked limit rejects.
97        opening_range: BlockageFraction,
98    },
99    /// Blocked culvert faces, uniform sediment bed, and closed barrels.
100    Culvert(CulvertBlockage),
101}
102
103impl BlockageGeometry {
104    /// Variant name, for messages.
105    pub(crate) fn name(&self) -> &'static str {
106        match self {
107            Self::Weir { .. } => "Weir",
108            Self::Orifice { .. } => "Orifice",
109            Self::Gate { .. } => "Gate",
110            Self::Culvert(_) => "Culvert",
111        }
112    }
113}
114
115/// A typed blockage of one law's declared geometry, with its applicability evidence.
116#[derive(Clone, Debug, PartialEq)]
117pub struct StructureBlockage {
118    geometry: BlockageGeometry,
119    applicability_evidence: String,
120}
121
122impl StructureBlockage {
123    /// Blocked share of a weir crest length.
124    pub fn weir(
125        crest_length: BlockageFraction,
126        applicability_evidence: String,
127    ) -> Result<Self, StructureError> {
128        Self::new(
129            BlockageGeometry::Weir { crest_length },
130            applicability_evidence,
131        )
132    }
133
134    /// Blocked share of an orifice opening area.
135    pub fn orifice(
136        area: BlockageFraction,
137        applicability_evidence: String,
138    ) -> Result<Self, StructureError> {
139        Self::new(BlockageGeometry::Orifice { area }, applicability_evidence)
140    }
141
142    /// Blocked shares of a gate aperture width and of its maximum opening.
143    pub fn gate(
144        width: BlockageFraction,
145        opening_range: BlockageFraction,
146        applicability_evidence: String,
147    ) -> Result<Self, StructureError> {
148        Self::new(
149            BlockageGeometry::Gate {
150                width,
151                opening_range,
152            },
153            applicability_evidence,
154        )
155    }
156
157    /// Blocked culvert faces, uniform sediment bed, and closed barrels.
158    pub fn culvert(
159        blockage: CulvertBlockage,
160        applicability_evidence: String,
161    ) -> Result<Self, StructureError> {
162        Self::new(BlockageGeometry::Culvert(blockage), applicability_evidence)
163    }
164
165    fn new(
166        geometry: BlockageGeometry,
167        applicability_evidence: String,
168    ) -> Result<Self, StructureError> {
169        text(&applicability_evidence, "blockage.applicability_evidence")?;
170        Ok(Self {
171            geometry,
172            applicability_evidence,
173        })
174    }
175
176    /// Blocked shares of the law geometry.
177    pub fn geometry(&self) -> &BlockageGeometry {
178        &self.geometry
179    }
180
181    /// Evidence that the law applies to the blocked geometry.
182    pub fn applicability_evidence(&self) -> &str {
183        &self.applicability_evidence
184    }
185}