Skip to main content

hydr_structures/structures/blockage/
report.rs

1//! Base and effective geometry of each structure, derived from its definition.
2
3use super::{StructureCondition, StructureConditionKind, effective};
4use crate::structures::{CulvertBarrelShape, CulvertSide, StructureElement, StructureLaw};
5
6/// Precomputed full-area and floor-width enclosures of one culvert element.
7#[derive(Clone, Copy, Debug)]
8pub(crate) struct CulvertGeometrySummary {
9    /// Element index in the batch.
10    pub(crate) element: usize,
11    /// Unblocked barrel full area enclosure, in m².
12    pub(crate) base_full_area_m2: (f64, f64),
13    /// Open-section full area enclosure, in m².
14    pub(crate) effective_full_area_m2: (f64, f64),
15    /// Unblocked floor width enclosure, in metres.
16    pub(crate) base_floor_width_m: (f64, f64),
17    /// Effective bed/floor width enclosure, in metres.
18    pub(crate) effective_floor_width_m: (f64, f64),
19}
20
21/// Declared and effective geometry of one structure element.
22#[derive(Clone, Debug, PartialEq)]
23pub struct StructureGeometryReport {
24    /// Ordered element index.
25    pub element: usize,
26    /// Kind of the element's condition.
27    pub condition: StructureConditionKind,
28    /// Geometry as declared in the law.
29    pub base: StructureGeometry,
30    /// Geometry the law evaluates. `None` when the element is closed.
31    pub effective: Option<StructureGeometry>,
32}
33
34/// Geometry of one law that a blockage can change.
35#[non_exhaustive]
36#[derive(Clone, Debug, PartialEq)]
37pub enum StructureGeometry {
38    /// Suppressed rectangular weir.
39    Weir {
40        /// Crest length in metres.
41        crest_length_m: f64,
42    },
43    /// Submerged orifice.
44    Orifice {
45        /// Opening area in m².
46        area_m2: f64,
47    },
48    /// Hydrostatic rectangular gate.
49    Gate {
50        /// Aperture width in metres.
51        width_m: f64,
52        /// Largest admitted opening in metres.
53        maximum_opening_m: f64,
54    },
55    /// Culvert.
56    #[non_exhaustive]
57    Culvert {
58        /// Open barrel rise in metres.
59        rise_m: f64,
60        /// Enclosure of the full open-section area in m².
61        full_area_m2: (f64, f64),
62        /// Bed elevation at end A on the common datum, in metres.
63        bed_a_m: f64,
64        /// Bed elevation at end B on the common datum, in metres.
65        bed_b_m: f64,
66        /// Number of open identical barrels.
67        barrel_count: u32,
68        /// Open share of the face at ends A and B.
69        face_open_share: [f64; 2],
70        /// Enclosure of the wetted floor or sediment bed width in metres.
71        floor_width_m: (f64, f64),
72        /// Bed-to-wall Manning roughness ratio `n_bed / n_wall`, if a floor or bed is declared.
73        roughness_ratio: Option<f64>,
74    },
75    /// Pump. A pump curve has no geometry.
76    Pump,
77}
78
79/// Geometry report of every element, in element order.
80pub(crate) fn reports(
81    elements: &[StructureElement],
82    culverts: &[CulvertGeometrySummary],
83) -> Vec<StructureGeometryReport> {
84    elements
85        .iter()
86        .enumerate()
87        .map(|(index, element)| {
88            let summary = culverts.iter().find(|entry| entry.element == index);
89            let condition = element.condition.kind();
90            let effective = match condition {
91                StructureConditionKind::Closed => None,
92                StructureConditionKind::AsBuilt | StructureConditionKind::Blocked => {
93                    Some(geometry(element, &element.condition, summary, false))
94                }
95            };
96            StructureGeometryReport {
97                element: index,
98                condition,
99                base: geometry(element, &StructureCondition::AsBuilt, summary, true),
100                effective,
101            }
102        })
103        .collect()
104}
105
106fn geometry(
107    element: &StructureElement,
108    condition: &StructureCondition,
109    summary: Option<&CulvertGeometrySummary>,
110    base: bool,
111) -> StructureGeometry {
112    match &element.law {
113        StructureLaw::SuppressedRectangularWeir(parameters) => StructureGeometry::Weir {
114            crest_length_m: effective::weir_crest_length(condition, parameters),
115        },
116        StructureLaw::SubmergedOrifice(parameters) => StructureGeometry::Orifice {
117            area_m2: effective::orifice_area(condition, parameters),
118        },
119        StructureLaw::HydrostaticRectangularGate(parameters) => StructureGeometry::Gate {
120            width_m: effective::gate_width(condition, parameters),
121            maximum_opening_m: effective::gate_maximum_opening(condition, parameters),
122        },
123        StructureLaw::Culvert(parameters) => {
124            let blockage = effective::culvert_blockage(condition);
125            let barrel = parameters
126                .effective_barrel(blockage)
127                .unwrap_or_else(|_| parameters.barrel());
128            let bed_a_m = parameters
129                .bed_elevation(CulvertSide::A, blockage)
130                .unwrap_or_else(|_| parameters.invert(CulvertSide::A));
131            let bed_b_m = parameters
132                .bed_elevation(CulvertSide::B, blockage)
133                .unwrap_or_else(|_| parameters.invert(CulvertSide::B));
134            let closed_barrels = blockage.map_or(0, |b| b.closed_barrels);
135            let face_open_share = blockage.map_or([1.0, 1.0], |b| {
136                [b.face_a.open_share(), b.face_b.open_share()]
137            });
138            let default_floor = if matches!(
139                parameters.barrel().shape(),
140                CulvertBarrelShape::Box | CulvertBarrelShape::Arch
141            ) {
142                let span = parameters.barrel().span_m();
143                (span, span)
144            } else {
145                (0.0, 0.0)
146            };
147            let (full_area_m2, floor_width_m) = match (summary, base) {
148                (Some(s), true) => (s.base_full_area_m2, s.base_floor_width_m),
149                (Some(s), false) => (s.effective_full_area_m2, s.effective_floor_width_m),
150                (None, _) => ((0.0, 0.0), default_floor),
151            };
152            StructureGeometry::Culvert {
153                rise_m: barrel.open_rise_m(),
154                full_area_m2,
155                bed_a_m,
156                bed_b_m,
157                barrel_count: parameters.barrel_count().saturating_sub(closed_barrels),
158                face_open_share,
159                floor_width_m,
160                roughness_ratio: barrel.floor().map(|f| f.roughness_ratio),
161            }
162        }
163        StructureLaw::Pump(_) => StructureGeometry::Pump,
164    }
165}