hydr_structures/structures/blockage/
condition.rs1use super::BlockageFraction;
4use crate::structures::StructureError;
5use crate::structures::definition::text;
6
7#[derive(Clone, Debug, PartialEq)]
9pub enum StructureCondition {
10 AsBuilt,
12 Blocked(StructureBlockage),
14 Closed {
16 evidence: String,
18 },
19}
20
21#[derive(Clone, Copy, Debug, PartialEq, Eq)]
23pub enum StructureConditionKind {
24 AsBuilt,
26 Blocked,
28 Closed,
30}
31
32impl StructureCondition {
33 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#[derive(Clone, Copy, Debug, PartialEq)]
48pub struct CulvertSediment {
49 pub depth_m: f64,
51 pub bed_manning_n: f64,
53}
54
55#[derive(Clone, Copy, Debug, PartialEq)]
57pub struct CulvertBlockage {
58 pub face_a: BlockageFraction,
60 pub face_b: BlockageFraction,
62 pub sediment: Option<CulvertSediment>,
64 pub closed_barrels: u32,
66}
67
68impl CulvertBlockage {
69 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#[non_exhaustive]
80#[derive(Clone, Copy, Debug, PartialEq)]
81pub enum BlockageGeometry {
82 Weir {
84 crest_length: BlockageFraction,
86 },
87 Orifice {
89 area: BlockageFraction,
91 },
92 Gate {
94 width: BlockageFraction,
96 opening_range: BlockageFraction,
98 },
99 Culvert(CulvertBlockage),
101}
102
103impl BlockageGeometry {
104 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#[derive(Clone, Debug, PartialEq)]
117pub struct StructureBlockage {
118 geometry: BlockageGeometry,
119 applicability_evidence: String,
120}
121
122impl StructureBlockage {
123 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 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 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 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 pub fn geometry(&self) -> &BlockageGeometry {
178 &self.geometry
179 }
180
181 pub fn applicability_evidence(&self) -> &str {
183 &self.applicability_evidence
184 }
185}