Skip to main content

hydr_core/capability/
regime.rs

1//! Flow regimes and where a component supports them.
2
3use super::BoundaryKind;
4
5/// Flow regime.
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7#[non_exhaustive]
8pub enum Regime {
9    /// Wet flow with Froude number below one.
10    WetSubcritical,
11    /// Flow with Froude number above one.
12    Supercritical,
13    /// Flow at Froude number one.
14    Critical,
15    /// Dry cells or sections.
16    Dry,
17    /// Moving front between wet and dry.
18    WetDryFront,
19    /// Flow that reverses direction within one branch.
20    ReversalInBranch,
21    /// Weir flow with only the upstream side above the crest.
22    FreeWeirFlow,
23    /// Weir flow with both sides above the crest, including equal heads.
24    SubmergedWeirFlow,
25    /// Both sides of a weir at or below the crest, with no flow.
26    BelowCrest,
27    /// Orifice flow with both sides above the crown.
28    SubmergedOrificeFlow,
29    /// Gate flow with the downstream side at or below the sill.
30    FreeGateAperture,
31    /// Gate flow with the downstream side between the sill and the opening top.
32    MixedGateAperture,
33    /// Gate flow with both sides above the opening top.
34    SubmergedGateAperture,
35    /// Gate at zero opening, with no flow.
36    GateClosed,
37    /// Running pump on its curve, with positive flow.
38    PumpCurve,
39    /// Running pump at a lift where its curve gives zero flow.
40    PumpShutoff,
41    /// Stopped pump that isolates its two sides, with no flow.
42    PumpIsolated,
43    /// Culvert flow whose inlet-control headwater governs.
44    CulvertInletControl,
45    /// Culvert flow whose outlet-control headwater governs.
46    CulvertOutletControl,
47}
48
49impl Regime {
50    /// Returns the stable kebab-case id. Persisted decisions store it, so it never changes.
51    pub fn id(&self) -> &'static str {
52        match self {
53            Self::WetSubcritical => "wet-subcritical",
54            Self::Supercritical => "supercritical",
55            Self::Critical => "critical",
56            Self::Dry => "dry",
57            Self::WetDryFront => "wet-dry-front",
58            Self::ReversalInBranch => "reversal-in-branch",
59            Self::FreeWeirFlow => "free-weir-flow",
60            Self::SubmergedWeirFlow => "submerged-weir-flow",
61            Self::BelowCrest => "below-crest",
62            Self::SubmergedOrificeFlow => "submerged-orifice-flow",
63            Self::FreeGateAperture => "free-gate-aperture",
64            Self::MixedGateAperture => "mixed-gate-aperture",
65            Self::SubmergedGateAperture => "submerged-gate-aperture",
66            Self::GateClosed => "gate-closed",
67            Self::PumpCurve => "pump-curve",
68            Self::PumpShutoff => "pump-shutoff",
69            Self::PumpIsolated => "pump-isolated",
70            Self::CulvertInletControl => "culvert-inlet-control",
71            Self::CulvertOutletControl => "culvert-outlet-control",
72        }
73    }
74}
75
76/// Part of a component where a regime claim holds.
77#[derive(Clone, Copy, Debug, PartialEq, Eq)]
78#[non_exhaustive]
79pub enum RegimeScope {
80    /// At boundaries of this kind.
81    Boundary(BoundaryKind),
82    /// In the interior, away from boundaries.
83    Interior,
84}
85
86impl RegimeScope {
87    /// Returns the stable kebab-case id of the scope kind. Persisted decisions store it, so it
88    /// never changes. A `Boundary` id omits the boundary kind, which has its own id.
89    pub fn id(&self) -> &'static str {
90        match self {
91            Self::Boundary(_) => "boundary",
92            Self::Interior => "interior",
93        }
94    }
95}
96
97/// Regime that a component supports within one scope.
98#[derive(Clone, Copy, Debug, PartialEq, Eq)]
99pub struct RegimeSupport {
100    /// Where the claim holds.
101    pub scope: RegimeScope,
102    /// Supported regime.
103    pub regime: Regime,
104}
105
106#[cfg(test)]
107mod tests {
108    use super::*;
109    use crate::capability::id_check::assert_ids;
110
111    #[test]
112    fn regime_ids_are_unique_kebab_case() {
113        let all = [
114            Regime::WetSubcritical,
115            Regime::Supercritical,
116            Regime::Critical,
117            Regime::Dry,
118            Regime::WetDryFront,
119            Regime::ReversalInBranch,
120            Regime::FreeWeirFlow,
121            Regime::SubmergedWeirFlow,
122            Regime::BelowCrest,
123            Regime::SubmergedOrificeFlow,
124            Regime::FreeGateAperture,
125            Regime::MixedGateAperture,
126            Regime::SubmergedGateAperture,
127            Regime::GateClosed,
128            Regime::PumpCurve,
129            Regime::PumpShutoff,
130            Regime::PumpIsolated,
131            Regime::CulvertInletControl,
132            Regime::CulvertOutletControl,
133        ];
134        assert_ids(&all.map(|r| r.id()));
135    }
136
137    #[test]
138    fn structure_regime_ids_are_frozen() {
139        for (regime, id) in [
140            (Regime::SubmergedOrificeFlow, "submerged-orifice-flow"),
141            (Regime::FreeGateAperture, "free-gate-aperture"),
142            (Regime::MixedGateAperture, "mixed-gate-aperture"),
143            (Regime::SubmergedGateAperture, "submerged-gate-aperture"),
144            (Regime::GateClosed, "gate-closed"),
145            (Regime::PumpCurve, "pump-curve"),
146            (Regime::PumpShutoff, "pump-shutoff"),
147            (Regime::PumpIsolated, "pump-isolated"),
148            (Regime::CulvertInletControl, "culvert-inlet-control"),
149            (Regime::CulvertOutletControl, "culvert-outlet-control"),
150        ] {
151            assert_eq!(regime.id(), id);
152        }
153    }
154
155    #[test]
156    fn scope_ids_are_unique_kebab_case() {
157        let all = [
158            RegimeScope::Boundary(BoundaryKind::Wall),
159            RegimeScope::Interior,
160        ];
161        assert_ids(&all.map(|s| s.id()));
162    }
163}