Skip to main content

hydr_structures/structures/gate/
parameters.rs

1//! Immutable rectangular-aperture geometry and common-regime coefficient.
2
3use super::GateApplicability;
4use crate::structures::{StructureError, StructureInputErrorKind};
5
6/// Thin vertical rectangular aperture between explicitly quiescent hydrostatic pools.
7#[derive(Clone, Debug, PartialEq)]
8pub struct GateParameters {
9    width_m: f64,
10    sill_m: f64,
11    maximum_opening_m: f64,
12    discharge_coefficient: f64,
13    gravity_m_per_s2: f64,
14    applicability: GateApplicability,
15}
16impl GateParameters {
17    /// Check finite sill, positive geometry and coefficients, and complete applicability evidence.
18    pub fn new(
19        width_m: f64,
20        sill_m: f64,
21        maximum_opening_m: f64,
22        discharge_coefficient: f64,
23        gravity_m_per_s2: f64,
24        applicability: GateApplicability,
25    ) -> Result<Self, StructureError> {
26        applicability.check()?;
27        if !sill_m.is_finite()
28            || [
29                width_m,
30                maximum_opening_m,
31                discharge_coefficient,
32                gravity_m_per_s2,
33            ]
34            .iter()
35            .any(|value| !value.is_finite() || *value <= 0.0)
36        {
37            return Err(StructureError::input(
38                StructureInputErrorKind::Definition,
39                format!(
40                    "width_m={width_m},sill_m={sill_m},maximum_opening_m={maximum_opening_m},discharge_coefficient={discharge_coefficient},gravity_m_per_s2={gravity_m_per_s2}: supply finite sill and positive finite width, maximum opening, coefficient, and gravity"
41                ),
42            ));
43        }
44        Ok(Self {
45            width_m,
46            sill_m,
47            maximum_opening_m,
48            discharge_coefficient,
49            gravity_m_per_s2,
50            applicability,
51        })
52    }
53    /// Actual aperture width before contraction, in metres.
54    pub fn width_m(&self) -> f64 {
55        self.width_m
56    }
57    /// Aperture sill elevation on the declared common datum, in metres.
58    pub fn sill_m(&self) -> f64 {
59        self.sill_m
60    }
61    /// Largest admitted original relative opening, in metres.
62    pub fn maximum_opening_m(&self) -> f64 {
63        self.maximum_opening_m
64    }
65    /// Positive dimensionless coefficient shared across all admitted aperture regimes.
66    pub fn discharge_coefficient(&self) -> f64 {
67        self.discharge_coefficient
68    }
69    /// Explicit positive gravitational acceleration, in m/s².
70    pub fn gravity_m_per_s2(&self) -> f64 {
71        self.gravity_m_per_s2
72    }
73    /// Complete immutable coefficient and physical-envelope evidence.
74    pub fn applicability(&self) -> &GateApplicability {
75        &self.applicability
76    }
77}