pub struct Network {Show 14 fields
pub title: Vec<String>,
pub options: SimulationOptions,
pub patterns: Vec<Pattern>,
pub curves: Vec<Curve>,
pub nodes: Vec<Node>,
pub links: Vec<Link>,
pub controls: Vec<SimpleControl>,
pub rules: Vec<Rule>,
pub pattern_index: HashMap<String, usize>,
pub report: ReportOptions,
pub coordinates: HashMap<String, (f64, f64)>,
pub vertices: HashMap<String, Vec<(f64, f64)>>,
pub node_tags: HashMap<String, String>,
pub link_tags: HashMap<String, String>,
}Expand description
The complete network data model (§2). Populated once at load time.
Nodes and links are stored in Vecs; their base.index fields are
1-based, so vec[i] has base.index == i + 1.
Fields§
§title: Vec<String>Up to 3 title lines from the [TITLE] section (for binary output prolog).
options: SimulationOptionsSimulation parameters from [OPTIONS] and [TIMES] sections.
patterns: Vec<Pattern>All patterns from the [PATTERNS] section.
curves: Vec<Curve>All curves from the [CURVES] section.
nodes: Vec<Node>All nodes (junctions, reservoirs, tanks).
links: Vec<Link>All links (pipes, pumps, valves).
controls: Vec<SimpleControl>Simple controls from the [CONTROLS] section.
rules: Vec<Rule>Rule-based controls from the [RULES] section.
pattern_index: HashMap<String, usize>Index mapping pattern ID → position in patterns. Built once at load
time via Network::build_pattern_index so hot-path lookups are O(1).
report: ReportOptionsReport formatting options from the [REPORT] INP section.
coordinates: HashMap<String, (f64, f64)>Node coordinates from the [COORDINATES] INP section: node ID → (x, y).
vertices: HashMap<String, Vec<(f64, f64)>>Link vertex points from the [VERTICES] INP section: link ID → [(x, y), …].
Node tags from the [TAGS] INP section: node ID → tag string.
Link tags from the [TAGS] INP section: link ID → tag string.
Implementations§
Source§impl Network
impl Network
Sourcepub fn build_pattern_index(&mut self)
pub fn build_pattern_index(&mut self)
Populates pattern_index from the current patterns vec. Must be
called once after construction (before any simulation work).
Sourcepub fn pattern_by_id(&self, id: &str) -> Option<&Pattern>
pub fn pattern_by_id(&self, id: &str) -> Option<&Pattern>
O(1) pattern lookup by ID. Returns None if the ID does not exist.
Source§impl Network
impl Network
Sourcepub fn compute_favad(&self) -> FavadCoeffs
pub fn compute_favad(&self) -> FavadCoeffs
Computes per-junction FAVAD resistance coefficients (§2.10).
For each pipe, the $K_1$ and $K_2$ FAVAD coefficients are split between its two end nodes according to whether the opposite end is a junction or a fixed-grade node (reservoir or tank). Only junctions accumulate FAVAD coefficients; reservoirs and tanks are skipped.
Returns a FavadCoeffs whose c_fa and c_va vectors are indexed by
the 0-based position of each node in self.nodes; non-junction entries
are always 0.
Source§impl Network
impl Network
Sourcepub fn validate(&self) -> Result<(), Vec<ValidationError>>
pub fn validate(&self) -> Result<(), Vec<ValidationError>>
Validates the network against all topology and referential-integrity constraints.
Returns Ok(()) if every constraint is satisfied. Returns
Err(errors) with every violation found — never stops at the first
error, so the caller can report all problems at once. An invalid
network must not be used for simulation.
The following constraints must all hold:
- Every node index referenced by a link exists in the node table.
- Every curve, pattern, or node ID referenced by any object exists in the corresponding table.
- No link connects a node to itself (
from_node≠to_node). - The network contains at least one fixed-grade node (reservoir or tank). Every junction is reachable from at least one fixed-grade node via the link graph.
- For each tank:
min_level≤init_level≤max_level. - All
PUMP_HEADcurves are strictly decreasing in y. - All curves have strictly increasing x-values.
- All patterns have at least one factor.
- Every rule action that references a link references a valid link index.
wall_orderis 0 or 1; no other value is valid.
Violations of any of the above are fatal — the simulation must not proceed.