OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
InflowData.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
30
31#ifndef OPENSWMM_ENGINE_INFLOW_DATA_HPP
32#define OPENSWMM_ENGINE_INFLOW_DATA_HPP
33
34#include <vector>
35#include <string>
36#include <string_view>
37
39
40namespace openswmm {
41
42// ============================================================================
43// External inflow definitions (from [INFLOWS] section)
44// ============================================================================
45
57 int count() const { return static_cast<int>(node_idx.size()); }
58
59 std::vector<int> node_idx;
60 std::vector<std::string> node_name;
61 std::vector<std::string> constituent;
62 std::vector<std::string> ts_name;
63 std::vector<std::string> inflow_type;
64 std::vector<double> m_factor;
65 std::vector<double> s_factor;
66 std::vector<double> baseline;
67 std::vector<std::string> pattern_name;
68
87 void add(int ni, const std::string& cons, const std::string& ts, const std::string& type,
88 double mf, double sf, double base, const std::string& pat,
89 const std::string& name = {}) {
90 node_idx.push_back(ni);
91 node_name.push_back(name);
92 constituent.push_back(cons);
93 ts_name.push_back(ts);
94 inflow_type.push_back(type);
95 m_factor.push_back(mf);
96 s_factor.push_back(sf);
97 baseline.push_back(base);
98 pattern_name.push_back(pat);
99 }
100
110 void erase(int idx) {
111 if (idx < 0 || idx >= count())
112 return;
113 const auto u = static_cast<std::size_t>(idx);
114 node_idx.erase(node_idx.begin() + u);
115 node_name.erase(node_name.begin() + u);
116 constituent.erase(constituent.begin() + u);
117 ts_name.erase(ts_name.begin() + u);
118 inflow_type.erase(inflow_type.begin() + u);
119 m_factor.erase(m_factor.begin() + u);
120 s_factor.erase(s_factor.begin() + u);
121 baseline.erase(baseline.begin() + u);
122 pattern_name.erase(pattern_name.begin() + u);
123 }
124};
125
126// ============================================================================
127// Dry weather flow definitions (from [DWF] section)
128// ============================================================================
129
136struct DwfData {
141 int count() const { return static_cast<int>(node_idx.size()); }
142
143 std::vector<int> node_idx;
144 std::vector<std::string> node_name;
145 std::vector<std::string> constituent;
146 std::vector<double> avg_value;
147 std::vector<std::string> pat1;
148 std::vector<std::string> pat2;
149 std::vector<std::string> pat3;
150 std::vector<std::string> pat4;
151
169 void add(int ni, const std::string& cons, double avg, const std::string& p1,
170 const std::string& p2, const std::string& p3, const std::string& p4,
171 const std::string& name = {}) {
172 node_idx.push_back(ni);
173 node_name.push_back(name);
174 constituent.push_back(cons);
175 avg_value.push_back(avg);
176 pat1.push_back(p1);
177 pat2.push_back(p2);
178 pat3.push_back(p3);
179 pat4.push_back(p4);
180 }
181
191 void erase(int idx) {
192 if (idx < 0 || idx >= count())
193 return;
194 const auto u = static_cast<std::size_t>(idx);
195 node_idx.erase(node_idx.begin() + u);
196 node_name.erase(node_name.begin() + u);
197 constituent.erase(constituent.begin() + u);
198 avg_value.erase(avg_value.begin() + u);
199 pat1.erase(pat1.begin() + u);
200 pat2.erase(pat2.begin() + u);
201 pat3.erase(pat3.begin() + u);
202 pat4.erase(pat4.begin() + u);
203 }
204};
205
206// ============================================================================
207// RDII assignments (from [RDII] section)
208// ============================================================================
209
221 int count() const { return static_cast<int>(node_idx.size()); }
222
223 std::vector<int> node_idx;
224 std::vector<std::string> node_name;
225 std::vector<std::string> uh_name;
226 std::vector<double> sewer_area;
227
241 void add(int ni, const std::string& uh, double area, const std::string& name = {}) {
242 node_idx.push_back(ni);
243 node_name.push_back(name);
244 uh_name.push_back(uh);
245 sewer_area.push_back(area);
246 }
247
257 void erase(int idx) {
258 if (idx < 0 || idx >= count())
259 return;
260 const auto u = static_cast<std::size_t>(idx);
261 node_idx.erase(node_idx.begin() + u);
262 node_name.erase(node_name.begin() + u);
263 uh_name.erase(uh_name.begin() + u);
264 sewer_area.erase(sewer_area.begin() + u);
265 }
266};
267
268// ============================================================================
269// Unit Hydrograph data (from [HYDROGRAPHS] section)
270// ============================================================================
271
273 std::string name;
274 std::string gage_name;
275 int month;
277 double r;
278 double t;
279 double k;
280 double dmax;
281 double drecov;
282 double dinit;
283};
284
296 int count() const { return static_cast<int>(entries.size()); }
297
298 std::vector<UnitHydEntry> entries;
299
301 std::vector<std::string> gage_assignments;
302 std::vector<std::string> gage_names;
303
313 void add_gage(const std::string& uh_name, const std::string& gage) {
314 gage_assignments.push_back(uh_name);
315 gage_names.push_back(gage);
316 }
317
329 void add(const UnitHydEntry& e) { entries.push_back(e); }
330};
331
332// ============================================================================
333// RDII exponential-decay parameters (from [RDII_DECAY] section)
334// ============================================================================
335//
336// One row per (UH group, response). Granularity is per-response, NOT per-month
337// — the whole point of the exponential model is that seasonal variation in
338// IA recovery emerges from temperature dynamics, not from a monthly lookup.
339//
340// A UH group with no row here uses the legacy linear IA recovery for every
341// response. A group with one row falls back to linear for the two unspecified
342// responses, so adoption is incremental.
343//
344// @see docs/RDII_ExpDecay_Implementation.md
345
347 std::string uh_name;
348 int response = -1;
349 double k_dep =
350 0.0;
351 double k_0 = 0.0;
352 double k_T = 0.0;
353 double T_ref = 10.0;
354 double theta_rec = 0.0;
355 double T_freeze = 0.0;
356
357 // Optional degree-day snow model (SNOW keyword + 2 extra columns).
358 // When on, precipitation at T <= snow_T accumulates as SWE (no liquid
359 // input); at T > snow_T, melt = min(SWE, snow_ddf*(T - snow_T)*dt_days)
360 // is added to rainfall before the IA update (rain-on-snow adds).
361 bool snow_on = false;
362 double snow_T = 1.0;
363 double snow_ddf = 0.0;
364};
365
377 int count() const { return static_cast<int>(entries.size()); }
378
379 std::vector<RDIIDecayEntry> entries;
380
391 void add(const RDIIDecayEntry& e) { entries.push_back(e); }
392};
393
394// ============================================================================
395// Time patterns (from [PATTERNS] section)
396// ============================================================================
397
409 int count() const { return static_cast<int>(names.size()); }
410
411 std::vector<std::string> names;
412 std::vector<int> types;
413 std::vector<std::vector<double>> factors;
414
427 void add(const std::string& name, int type, const std::vector<double>& facs) {
428 names.push_back(name);
429 types.push_back(type);
430 factors.push_back(facs);
431 }
432
442 int find(std::string_view name) const noexcept {
443 for (int i = 0; i < count(); ++i)
444 if (ieq(names[static_cast<std::size_t>(i)], name))
445 return i;
446 return -1;
447 }
448};
449
450} // namespace openswmm
451
452#endif // OPENSWMM_ENGINE_INFLOW_DATA_HPP
Case-insensitive string helpers matching legacy SWMM name semantics.
Rain records, accepted runoff-clock state and read-only report lookups. Context routines require alig...
Definition Gage.cpp:38
Definition ExchangeLaw.hpp:60
bool ieq(std::string_view a, std::string_view b) noexcept
Compare two byte sequences using the legacy ASCII uppercase fold.
Definition StringCase.hpp:70
Dry-weather-flow authoring rows stored in aligned columns.
Definition InflowData.hpp:136
std::vector< std::string > constituent
"FLOW" or pollutant name
Definition InflowData.hpp:145
std::vector< int > node_idx
Target node.
Definition InflowData.hpp:143
std::vector< std::string > pat1
Monthly pattern name.
Definition InflowData.hpp:147
std::vector< std::string > pat2
Daily pattern name.
Definition InflowData.hpp:148
std::vector< double > avg_value
Average value.
Definition InflowData.hpp:146
void add(int ni, const std::string &cons, double avg, const std::string &p1, const std::string &p2, const std::string &p3, const std::string &p4, const std::string &name={})
Append a copied authoring row.
Definition InflowData.hpp:169
void erase(int idx)
Erase an aligned row and shift all later row indices down.
Definition InflowData.hpp:191
std::vector< std::string > pat4
Weekend pattern name.
Definition InflowData.hpp:150
int count() const
Count rows in the primary ordered column.
Definition InflowData.hpp:141
std::vector< std::string > node_name
Raw node name from input (for post-parse re-resolution)
Definition InflowData.hpp:144
std::vector< std::string > pat3
Hourly pattern name.
Definition InflowData.hpp:149
External inflow authoring rows stored in aligned columns.
Definition InflowData.hpp:52
std::vector< std::string > pattern_name
Baseline pattern name.
Definition InflowData.hpp:67
std::vector< std::string > constituent
"FLOW" or pollutant name
Definition InflowData.hpp:61
std::vector< int > node_idx
Target node index.
Definition InflowData.hpp:59
std::vector< double > baseline
Baseline value.
Definition InflowData.hpp:66
int count() const
Count rows in the primary ordered column.
Definition InflowData.hpp:57
std::vector< std::string > inflow_type
"FLOW","CONCEN","MASS"
Definition InflowData.hpp:63
std::vector< double > s_factor
Scaling factor.
Definition InflowData.hpp:65
std::vector< double > m_factor
Multiplier factor.
Definition InflowData.hpp:64
std::vector< std::string > node_name
Raw node name from input (for post-parse re-resolution)
Definition InflowData.hpp:60
std::vector< std::string > ts_name
Timeseries name ("" if none)
Definition InflowData.hpp:62
void add(int ni, const std::string &cons, const std::string &ts, const std::string &type, double mf, double sf, double base, const std::string &pat, const std::string &name={})
Append a copied authoring row.
Definition InflowData.hpp:87
void erase(int idx)
Erase an aligned row and shift all later row indices down.
Definition InflowData.hpp:110
Time-pattern authoring names, types and multiplier vectors.
Definition InflowData.hpp:404
int find(std::string_view name) const noexcept
Find the first ASCII-insensitive pattern name match.
Definition InflowData.hpp:442
std::vector< std::vector< double > > factors
Up to 24 multiplier values.
Definition InflowData.hpp:413
void add(const std::string &name, int type, const std::vector< double > &facs)
Append a copied pattern row.
Definition InflowData.hpp:427
std::vector< std::string > names
Pattern name.
Definition InflowData.hpp:411
int count() const
Count rows in the primary ordered column.
Definition InflowData.hpp:409
std::vector< int > types
0=MONTHLY,1=DAILY,2=HOURLY,3=WEEKEND
Definition InflowData.hpp:412
Node-to-hydrograph authoring assignments stored in aligned columns.
Definition InflowData.hpp:216
std::vector< std::string > uh_name
Unit hydrograph name.
Definition InflowData.hpp:225
std::vector< double > sewer_area
Tributary sewer area.
Definition InflowData.hpp:226
std::vector< std::string > node_name
Raw node name from input (for post-parse re-resolution)
Definition InflowData.hpp:224
std::vector< int > node_idx
Target node.
Definition InflowData.hpp:223
int count() const
Count rows in the primary ordered column.
Definition InflowData.hpp:221
void erase(int idx)
Erase an aligned row and shift all later row indices down.
Definition InflowData.hpp:257
void add(int ni, const std::string &uh, double area, const std::string &name={})
Append a copied authoring row.
Definition InflowData.hpp:241
Exponential IA-decay authoring rows keyed by group and response.
Definition InflowData.hpp:372
int count() const
Count rows in the primary ordered column.
Definition InflowData.hpp:377
void add(const RDIIDecayEntry &e)
Append a copied authoring row.
Definition InflowData.hpp:391
std::vector< RDIIDecayEntry > entries
Definition InflowData.hpp:379
Definition InflowData.hpp:346
double k_T
Thermal recovery rate at T_ref (1/hr)
Definition InflowData.hpp:352
double k_0
Base recovery rate (1/hr)
Definition InflowData.hpp:351
double k_dep
Depletion rate (1/project rain-depth unit: 1/in or 1/mm) — temperature-independent.
Definition InflowData.hpp:349
double theta_rec
Temperature sensitivity (1/deg C)
Definition InflowData.hpp:354
int response
0=SHORT, 1=MEDIUM, 2=LONG
Definition InflowData.hpp:348
std::string uh_name
Matches UnitHydEntry::name.
Definition InflowData.hpp:347
double snow_T
Rain/snow partition threshold & melt base (deg C)
Definition InflowData.hpp:362
bool snow_on
Degree-day snow model enabled for this row.
Definition InflowData.hpp:361
double T_freeze
Recovery suppressed when T < T_freeze (deg C)
Definition InflowData.hpp:355
double snow_ddf
Degree-day melt factor (project rain-depth unit/degC/day)
Definition InflowData.hpp:363
double T_ref
Reference temperature (deg C)
Definition InflowData.hpp:353
Hydrograph parameter rows and independent group-to-gage assignments.
Definition InflowData.hpp:291
std::vector< std::string > gage_assignments
Rain gage names associated with each UH group (name → gage name)
Definition InflowData.hpp:301
std::vector< std::string > gage_names
Assigned rain gage names.
Definition InflowData.hpp:302
void add(const UnitHydEntry &e)
Append a copied authoring row.
Definition InflowData.hpp:329
std::vector< UnitHydEntry > entries
Definition InflowData.hpp:298
void add_gage(const std::string &uh_name, const std::string &gage)
Append a copied group-to-gage assignment without deduplication.
Definition InflowData.hpp:313
int count() const
Count rows in the primary ordered column.
Definition InflowData.hpp:296
Definition InflowData.hpp:272
double drecov
IA recovery rate.
Definition InflowData.hpp:281
std::string name
UH group name.
Definition InflowData.hpp:273
double t
Time to peak (hours)
Definition InflowData.hpp:278
int response
0=SHORT, 1=MEDIUM, 2=LONG
Definition InflowData.hpp:276
double dmax
Max initial abstraction depth.
Definition InflowData.hpp:280
double r
Fraction of rainfall volume.
Definition InflowData.hpp:277
int month
Month index (0-11, or -1 for ALL)
Definition InflowData.hpp:275
std::string gage_name
Associated rain gage name.
Definition InflowData.hpp:274
double dinit
Initial IA used.
Definition InflowData.hpp:282
double k
Recession-limb-to-peak-time ratio (tBase = t*(1+k); k >= 0)
Definition InflowData.hpp:279