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
92 double source_age(WaterAgeSource s, int node) const noexcept {
93 for (std::size_t i = 0; i < node_over_source.size(); ++i)
94 if (node_over_source[i] == static_cast<int>(s) && node_over_node[i] == node)
95 return node_over_age[i];
96 return global_age[static_cast<int>(s)];
97 }
98};
99
111enum class SubArea : int {
114 PERV = 2,
116};
117
119 std::vector<double> node_age_vol_in;
120 std::vector<double> node_age;
121 std::vector<double> link_age;
122
125 bool legacy_seeded = false;
126
127 // --- A3: watershed age -------------------------------------------
132 std::vector<double> subarea_age;
133
137 std::vector<double> subarea_vol_prev;
138
143 std::vector<double> subcatch_runoff_age;
144
149 std::vector<double> subcatch_runon_age_vol_in;
150
157 std::vector<double> node_lid_drain_age_vol_in;
158
171 std::vector<double> subcatch_lid_drain_age_cfs;
172 std::vector<double> subcatch_outfall_age_vol;
173
180 std::vector<double> node_ext_inflow_age;
181
185 bool hotstart_loaded = false;
186
200 void resize(int n_nodes, int n_links, int n_subcatch) {
201 node_age_vol_in.assign(static_cast<std::size_t>(n_nodes), 0.0);
202 node_age.assign(static_cast<std::size_t>(n_nodes), 0.0);
203 link_age.assign(static_cast<std::size_t>(n_links), 0.0);
204 node_lid_drain_age_vol_in.assign(static_cast<std::size_t>(n_nodes), 0.0);
205 // Z1: PRESERVE when already sized. InflowSolver::init sizes and
206 // fills this at open — BEFORE the first routing step's
207 // computeAll — and the loaders' first lazy resize() lands between
208 // that write and its first read. A blanket assign here re-NaN'd
209 // the array and cost the row exactly one routing step of table-
210 // default age (measured: a 4-ULP C5 residue that broke the
211 // Z1 equivalence gate). init() re-asserts NaN on every re-init,
212 // so a removed row cannot leave a stale age behind.
213 if (node_ext_inflow_age.size() != static_cast<std::size_t>(n_nodes))
214 node_ext_inflow_age.assign(static_cast<std::size_t>(n_nodes),
215 std::numeric_limits<double>::quiet_NaN());
216 const auto ns3 =
217 static_cast<std::size_t>(n_subcatch) * static_cast<std::size_t>(SubArea::COUNT_);
218 subarea_age.assign(ns3, 0.0);
219 subarea_vol_prev.assign(ns3, 0.0);
220 subcatch_runoff_age.assign(static_cast<std::size_t>(n_subcatch), 0.0);
221 subcatch_runon_age_vol_in.assign(static_cast<std::size_t>(n_subcatch), 0.0);
222 subcatch_lid_drain_age_cfs.assign(static_cast<std::size_t>(n_subcatch), 0.0);
223 subcatch_outfall_age_vol.assign(static_cast<std::size_t>(n_subcatch), 0.0);
224 legacy_seeded = false;
225 hotstart_loaded = false;
226 }
227
233 void clear() { *this = WaterAgeState{}; }
234};
235
236} // namespace openswmm
237
238#endif // OPENSWMM_ENGINE_DATA_WATER_AGE_DATA_HPP
Definition Node.cpp:38
Definition ExchangeLaw.hpp:60
SubArea
Runtime age state shared by the engines (phase A1a).
Definition WaterAgeData.hpp:111
@ COUNT_
Definition WaterAgeData.hpp:115
@ IMPERV0
Definition HeatData.hpp:88
@ IMPERV1
Definition HeatData.hpp:88
@ PERV
Definition HeatData.hpp:88
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
Read the first matching node/source age override or global fallback.
Definition WaterAgeData.hpp:92
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:118
void clear()
Release all water-age arrays and reset seeding/hotstart flags.
Definition WaterAgeData.hpp:233
std::vector< double > node_ext_inflow_age
Definition WaterAgeData.hpp:180
std::vector< double > subarea_vol_prev
Definition WaterAgeData.hpp:137
std::vector< double > subarea_age
Definition WaterAgeData.hpp:132
std::vector< double > node_age_vol_in
[node], age·ft³/s
Definition WaterAgeData.hpp:119
std::vector< double > subcatch_outfall_age_vol
Definition WaterAgeData.hpp:172
std::vector< double > node_age
[node], seconds
Definition WaterAgeData.hpp:120
std::vector< double > subcatch_runon_age_vol_in
Definition WaterAgeData.hpp:149
std::vector< double > subcatch_runoff_age
Definition WaterAgeData.hpp:143
bool hotstart_loaded
Definition WaterAgeData.hpp:185
void resize(int n_nodes, int n_links, int n_subcatch)
Replace network and watershed age state while preserving shaped inflow prescriptions.
Definition WaterAgeData.hpp:200
std::vector< double > node_lid_drain_age_vol_in
Definition WaterAgeData.hpp:157
std::vector< double > link_age
[link], seconds
Definition WaterAgeData.hpp:121
bool legacy_seeded
Definition WaterAgeData.hpp:125
std::vector< double > subcatch_lid_drain_age_cfs
Definition WaterAgeData.hpp:171