Skip to main content

hydra_engine_wds/model/
state.rs

1use super::network::LinkStatus;
2
3// ── Per-step state ─────────────────────────────────────────────────────────────
4
5/// Per-step hydraulic and quality state for a single node (§2.4, per-step fields).
6///
7/// Not all fields are meaningful for every node type:
8/// - `head`, `quality`: all node types.
9/// - `demand_flow`, `emitter_flow`, `leakage_flow`: junctions only.
10/// - `net_flow`: reservoirs and tanks.
11/// - `level`, `volume`: tanks only.
12#[derive(Debug, Clone, Default)]
13pub struct NodeState {
14    /// Hydraulic head (m).
15    pub head: f64,
16    /// Actual delivered demand flow (m³/s).
17    pub demand_flow: f64,
18    /// Emitter outflow (m³/s).
19    pub emitter_flow: f64,
20    /// Leakage outflow from FAVAD model (m³/s).
21    pub leakage_flow: f64,
22    /// Net inflow to reservoir or tank (m³/s; positive = filling).
23    pub net_flow: f64,
24    /// Current water level above tank bottom (m); tanks only.
25    pub level: f64,
26    /// Current tank volume (m³); tanks only.
27    pub volume: f64,
28    /// Water quality concentration (mg/L, h, or % depending on mode).
29    pub quality: f64,
30}
31
32/// Per-step hydraulic and quality state for a single link (§2.6, per-step fields).
33#[derive(Debug, Clone)]
34pub struct LinkState {
35    /// Volumetric flow rate (m³/s; positive = from_node → to_node).
36    pub flow: f64,
37    /// Current operational status.
38    pub status: LinkStatus,
39    /// Current setting value (pump speed ratio or valve pressure setpoint).
40    pub setting: f64,
41    /// Water quality in this link.
42    pub quality: f64,
43    /// Volume-weighted average reaction rate (mass/L/day); only meaningful for pipes.
44    pub reaction_rate: f64,
45}
46
47impl Default for LinkState {
48    fn default() -> Self {
49        Self {
50            flow: 0.0,
51            status: LinkStatus::Open,
52            setting: 1.0,
53            quality: 0.0,
54            reaction_rate: 0.0,
55        }
56    }
57}