hydr_structures/structures/definition.rs
1//! Concrete law definitions, exact endpoint identities, and declared ideal flaps.
2
3use super::{
4 StructureError, StructureInputErrorKind, SubmergedOrificeParameters,
5 SuppressedRectangularWeirParameters,
6};
7
8/// Explicitly admitted physical closures with separate applicability declarations.
9#[derive(Clone, Debug, PartialEq)]
10pub enum StructureLaw {
11 /// HDS-5 culvert: discharge inverts the larger of the inlet and outlet control headwaters.
12 ///
13 /// Build a batch that holds it with [`StructureBatch::with_culverts`](super::StructureBatch::with_culverts).
14 Culvert(super::CulvertParameters),
15 /// Thin hydrostatic rectangular aperture with an explicit instantaneous opening.
16 HydrostaticRectangularGate(super::GateParameters),
17 /// Explicit oriented reference pump curve with declared speed/applicability policy.
18 Pump(super::PumpParameters),
19 /// Both supported wet stages must lie strictly above the declared opening crown.
20 SubmergedOrifice(SubmergedOrificeParameters),
21 /// Suppressed sharp-crested rectangular free/submerged overflow with adopted Villemonte correction.
22 SuppressedRectangularWeir(SuppressedRectangularWeirParameters),
23}
24/// Explicit ideal direction policy. Blockage lives in the element's condition.
25#[derive(Clone, Copy, Debug, PartialEq, Eq)]
26pub enum DirectionPolicy {
27 /// Reversed flow requires explicit symmetric coefficient applicability.
28 Bidirectional,
29 /// Ideal flap allows positive A-to-B flow only.
30 AtoBOnly,
31 /// Ideal flap allows negative B-to-A flow only.
32 BtoAOnly,
33}
34/// Nominal proposed physical direction before ideal flap blocking.
35#[derive(Clone, Copy, Debug, PartialEq, Eq)]
36pub enum FlowDirection {
37 /// Positive signed discharge.
38 AtoB,
39 /// Negative signed discharge.
40 BtoA,
41}
42/// Immutable physical destination and coefficient identity.
43#[derive(Clone, Debug, PartialEq)]
44pub struct StructureElement {
45 /// Unique nonempty structure identity.
46 pub id: String,
47 /// Ordered positive-direction source endpoint identity.
48 pub endpoint_a: String,
49 /// Ordered positive-direction destination endpoint identity, distinct from A.
50 pub endpoint_b: String,
51 /// Exact common vertical reference. No transformation occurs.
52 pub datum: String,
53 /// Explicit ideal flap or symmetric direction policy.
54 pub direction: DirectionPolicy,
55 /// Complete concrete physical law with its unblocked geometry.
56 pub law: StructureLaw,
57 /// Physical condition of the declared geometry: as built, blocked, or closed.
58 pub condition: super::StructureCondition,
59}
60pub(crate) fn text(value: &str, field: &str) -> Result<(), StructureError> {
61 if value.trim().is_empty() || value.chars().any(char::is_control) {
62 return Err(StructureError::input(
63 StructureInputErrorKind::Definition,
64 format!(
65 "{field}={value:?}: supply nonempty explicit identity/evidence without control characters"
66 ),
67 ));
68 }
69 Ok(())
70}