OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
WaterAgeData.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
41
42#ifndef OPENSWMM_ENGINE_DATA_WATER_AGE_DATA_HPP
43#define OPENSWMM_ENGINE_DATA_WATER_AGE_DATA_HPP
44
45#include <limits>
46#include <vector>
47
48namespace openswmm {
49
52enum class WaterAgeSource : int {
54 DWF = 1,
55 GW = 2,
56 RDII = 3,
58 IFACE = 5,
61};
62
73 bool configured = false;
74
76 double global_age[static_cast<int>(WaterAgeSource::COUNT_)] = {};
77
78 // NODE-scope overrides (DWF / EXTERNAL_INFLOW), parallel arrays.
79 std::vector<int> node_over_source;
80 std::vector<int> node_over_node;
81 std::vector<double> node_over_age;
82
84 double source_age(WaterAgeSource s, int node) const noexcept {
85 for (std::size_t i = 0; i < node_over_source.size(); ++i)
86 if (node_over_source[i] == static_cast<int>(s) &&
87 node_over_node[i] == node)
88 return node_over_age[i];
89 return global_age[static_cast<int>(s)];
90 }
91};
92
104enum class SubArea : int {
107 PERV = 2,
109};
110
112 std::vector<double> node_age_vol_in;
113 std::vector<double> node_age;
114 std::vector<double> link_age;
115
118 bool legacy_seeded = false;
119
120 // --- A3: watershed age -------------------------------------------
125 std::vector<double> subarea_age;
126
130 std::vector<double> subarea_vol_prev;
131
136 std::vector<double> subcatch_runoff_age;
137
142 std::vector<double> subcatch_runon_age_vol_in;
143
150 std::vector<double> node_lid_drain_age_vol_in;
151
164 std::vector<double> subcatch_lid_drain_age_cfs;
165 std::vector<double> subcatch_outfall_age_vol;
166
173 std::vector<double> node_ext_inflow_age;
174
178 bool hotstart_loaded = false;
179
188 void resize(int n_nodes, int n_links, int n_subcatch) {
189 node_age_vol_in.assign(static_cast<std::size_t>(n_nodes), 0.0);
190 node_age.assign(static_cast<std::size_t>(n_nodes), 0.0);
191 link_age.assign(static_cast<std::size_t>(n_links), 0.0);
192 node_lid_drain_age_vol_in.assign(static_cast<std::size_t>(n_nodes), 0.0);
193 // Z1: PRESERVE when already sized. InflowSolver::init sizes and
194 // fills this at open — BEFORE the first routing step's
195 // computeAll — and the loaders' first lazy resize() lands between
196 // that write and its first read. A blanket assign here re-NaN'd
197 // the array and cost the row exactly one routing step of table-
198 // default age (measured: a 4-ULP C5 residue that broke the
199 // Z1 equivalence gate). init() re-asserts NaN on every re-init,
200 // so a removed row cannot leave a stale age behind.
201 if (node_ext_inflow_age.size() != static_cast<std::size_t>(n_nodes))
202 node_ext_inflow_age.assign(
203 static_cast<std::size_t>(n_nodes),
204 std::numeric_limits<double>::quiet_NaN());
205 const auto ns3 = static_cast<std::size_t>(n_subcatch) *
206 static_cast<std::size_t>(SubArea::COUNT_);
207 subarea_age.assign(ns3, 0.0);
208 subarea_vol_prev.assign(ns3, 0.0);
209 subcatch_runoff_age.assign(static_cast<std::size_t>(n_subcatch), 0.0);
211 static_cast<std::size_t>(n_subcatch), 0.0);
213 static_cast<std::size_t>(n_subcatch), 0.0);
215 static_cast<std::size_t>(n_subcatch), 0.0);
216 legacy_seeded = false;
217 hotstart_loaded = false;
218 }
219 void clear() { *this = WaterAgeState{}; }
220};
221
222} // namespace openswmm
223
224#endif // OPENSWMM_ENGINE_DATA_WATER_AGE_DATA_HPP
Definition Node.cpp:38
Definition NodeCoupling.cpp:16
SubArea
Runtime age state shared by the engines (phase A1a).
Definition WaterAgeData.hpp:104
@ COUNT_
Definition WaterAgeData.hpp:108
@ IMPERV0
Definition HeatData.hpp:89
@ IMPERV1
Definition HeatData.hpp:90
@ PERV
Definition HeatData.hpp:91
WaterAgeSource
Definition WaterAgeData.hpp:52
@ COUNT_
Definition WaterAgeData.hpp:60
@ RAINFALL
Definition HeatData.hpp:71
@ RDII
Definition HeatData.hpp:76
@ COUNT_
Definition HeatData.hpp:80
@ DWF
Definition HeatData.hpp:74
@ EXTERNAL_INFLOW
Definition HeatData.hpp:77
@ INITIAL_STATE
water in the network at t = 0
Definition HeatData.hpp:79
@ GW
Definition HeatData.hpp:75
@ IFACE
Definition HeatData.hpp:78
Parsed model.age state (waterage component, phase A1a).
Definition WaterAgeData.hpp:72
std::vector< double > node_over_age
seconds
Definition WaterAgeData.hpp:81
std::vector< int > node_over_node
node index
Definition WaterAgeData.hpp:80
double source_age(WaterAgeSource s, int node) const noexcept
Age of source water entering node (seconds).
Definition WaterAgeData.hpp:84
bool configured
Definition WaterAgeData.hpp:73
double global_age[static_cast< int >(WaterAgeSource::COUNT_)]
GLOBAL initial age per source, SECONDS (default 0 = fresh water).
Definition WaterAgeData.hpp:76
std::vector< int > node_over_source
WaterAgeSource as int.
Definition WaterAgeData.hpp:79
Definition WaterAgeData.hpp:111
void clear()
Definition WaterAgeData.hpp:219
std::vector< double > node_ext_inflow_age
Definition WaterAgeData.hpp:173
std::vector< double > subarea_vol_prev
Definition WaterAgeData.hpp:130
std::vector< double > subarea_age
Definition WaterAgeData.hpp:125
std::vector< double > node_age_vol_in
[node], age·ft³/s
Definition WaterAgeData.hpp:112
std::vector< double > subcatch_outfall_age_vol
Definition WaterAgeData.hpp:165
std::vector< double > node_age
[node], seconds
Definition WaterAgeData.hpp:113
std::vector< double > subcatch_runon_age_vol_in
Definition WaterAgeData.hpp:142
std::vector< double > subcatch_runoff_age
Definition WaterAgeData.hpp:136
bool hotstart_loaded
Definition WaterAgeData.hpp:178
void resize(int n_nodes, int n_links, int n_subcatch)
Definition WaterAgeData.hpp:188
std::vector< double > node_lid_drain_age_vol_in
Definition WaterAgeData.hpp:150
std::vector< double > link_age
[link], seconds
Definition WaterAgeData.hpp:114
bool legacy_seeded
Definition WaterAgeData.hpp:118
std::vector< double > subcatch_lid_drain_age_cfs
Definition WaterAgeData.hpp:164