Skip to main content

hydr_structures/structures/culvert/inlet/
row.rs

1//! One inlet-control row: barrel, inlet, signed barrel slope, gravity and face blockage.
2
3use super::CulvertInlet;
4use crate::structures::{BlockageFraction, CulvertBarrel, StructureError};
5
6/// Barrel, inlet, slope, gravity and face blockage of one inlet-control row.
7#[derive(Clone, Copy, Debug, PartialEq)]
8pub struct CulvertInletRow {
9    /// Barrel the inlet leads into. A barrel with a floor takes its inlet coefficients on the
10    /// open section: open rise `D'`, open full area, critical head of the open section, and
11    /// headwater above the bed.
12    pub barrel: CulvertBarrel,
13    /// HDS-5 inlet definition.
14    pub inlet: CulvertInlet,
15    /// Signed barrel slope `S` in metres per metre, positive when the barrel falls away from the
16    /// inlet. It enters the slope term `Ks S`.
17    pub slope: f64,
18    /// Gravity in metres per second squared, for the form-1 critical head.
19    pub gravity_m_per_s2: f64,
20    /// Blocked share `f` of the inlet face. The inlet passes `(1 - f)` times its unblocked
21    /// discharge at each headwater. This rule is a hydr definition.
22    pub face_blockage: BlockageFraction,
23}
24
25impl CulvertInletRow {
26    /// Rejects a nonfinite slope, a nonfinite or nonpositive gravity, and a coded inlet on a
27    /// barrel of another shape.
28    pub(crate) fn check(&self) -> Result<(), StructureError> {
29        let inlet = self.inlet.describe();
30        if !self.slope.is_finite() {
31            return Err(StructureError::definition(format!(
32                "{inlet},slope={:?}: supply a finite barrel slope in metres per metre",
33                self.slope
34            )));
35        }
36        let gravity = self.gravity_m_per_s2;
37        if !(gravity.is_finite() && gravity > 0.0) {
38            return Err(StructureError::definition(format!(
39                "{inlet},gravity_m_per_s2={gravity:?}: supply a finite positive gravity in metres per second squared"
40            )));
41        }
42        if let Some(shape) = self.inlet.barrel_shape()
43            && shape != self.barrel.shape()
44        {
45            return Err(StructureError::definition(format!(
46                "{inlet},barrel_shape={:?}: the code is for {shape:?} barrels. Supply a code for the barrel shape or explicit coefficients",
47                self.barrel.shape()
48            )));
49        }
50        Ok(())
51    }
52}