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
47 int count() const { return static_cast<int>(node_idx.size()); }
48
49 std::vector<int> node_idx;
50 std::vector<std::string> node_name;
51 std::vector<std::string> constituent;
52 std::vector<std::string> ts_name;
53 std::vector<std::string> inflow_type;
54 std::vector<double> m_factor;
55 std::vector<double> s_factor;
56 std::vector<double> baseline;
57 std::vector<std::string> pattern_name;
58
59 void add(int ni, const std::string& cons, const std::string& ts,
60 const std::string& type, double mf, double sf, double base,
61 const std::string& pat, const std::string& name = {}) {
62 node_idx.push_back(ni); node_name.push_back(name);
63 constituent.push_back(cons);
64 ts_name.push_back(ts); inflow_type.push_back(type);
65 m_factor.push_back(mf); s_factor.push_back(sf);
66 baseline.push_back(base); pattern_name.push_back(pat);
67 }
68
71 void erase(int idx) {
72 if (idx < 0 || idx >= count()) return;
73 const auto u = static_cast<std::size_t>(idx);
74 node_idx.erase(node_idx.begin() + u);
75 node_name.erase(node_name.begin() + u);
76 constituent.erase(constituent.begin() + u);
77 ts_name.erase(ts_name.begin() + u);
78 inflow_type.erase(inflow_type.begin() + u);
79 m_factor.erase(m_factor.begin() + u);
80 s_factor.erase(s_factor.begin() + u);
81 baseline.erase(baseline.begin() + u);
82 pattern_name.erase(pattern_name.begin() + u);
83 }
84};
85
86// ============================================================================
87// Dry weather flow definitions (from [DWF] section)
88// ============================================================================
89
90struct DwfData {
91 int count() const { return static_cast<int>(node_idx.size()); }
92
93 std::vector<int> node_idx;
94 std::vector<std::string> node_name;
95 std::vector<std::string> constituent;
96 std::vector<double> avg_value;
97 std::vector<std::string> pat1;
98 std::vector<std::string> pat2;
99 std::vector<std::string> pat3;
100 std::vector<std::string> pat4;
101
102 void add(int ni, const std::string& cons, double avg,
103 const std::string& p1, const std::string& p2,
104 const std::string& p3, const std::string& p4,
105 const std::string& name = {}) {
106 node_idx.push_back(ni); node_name.push_back(name);
107 constituent.push_back(cons);
108 avg_value.push_back(avg);
109 pat1.push_back(p1); pat2.push_back(p2);
110 pat3.push_back(p3); pat4.push_back(p4);
111 }
112
113 void erase(int idx) {
114 if (idx < 0 || idx >= count()) return;
115 const auto u = static_cast<std::size_t>(idx);
116 node_idx.erase(node_idx.begin() + u);
117 node_name.erase(node_name.begin() + u);
118 constituent.erase(constituent.begin() + u);
119 avg_value.erase(avg_value.begin() + u);
120 pat1.erase(pat1.begin() + u);
121 pat2.erase(pat2.begin() + u);
122 pat3.erase(pat3.begin() + u);
123 pat4.erase(pat4.begin() + u);
124 }
125};
126
127// ============================================================================
128// RDII assignments (from [RDII] section)
129// ============================================================================
130
132 int count() const { return static_cast<int>(node_idx.size()); }
133
134 std::vector<int> node_idx;
135 std::vector<std::string> node_name;
136 std::vector<std::string> uh_name;
137 std::vector<double> sewer_area;
138
139 void add(int ni, const std::string& uh, double area,
140 const std::string& name = {}) {
141 node_idx.push_back(ni); node_name.push_back(name);
142 uh_name.push_back(uh);
143 sewer_area.push_back(area);
144 }
145
146 void erase(int idx) {
147 if (idx < 0 || idx >= count()) return;
148 const auto u = static_cast<std::size_t>(idx);
149 node_idx.erase(node_idx.begin() + u);
150 node_name.erase(node_name.begin() + u);
151 uh_name.erase(uh_name.begin() + u);
152 sewer_area.erase(sewer_area.begin() + u);
153 }
154};
155
156// ============================================================================
157// Unit Hydrograph data (from [HYDROGRAPHS] section)
158// ============================================================================
159
161 std::string name;
162 std::string gage_name;
163 int month;
165 double r;
166 double t;
167 double k;
168 double dmax;
169 double drecov;
170 double dinit;
171};
172
174 int count() const { return static_cast<int>(entries.size()); }
175
176 std::vector<UnitHydEntry> entries;
177
179 std::vector<std::string> gage_assignments;
180 std::vector<std::string> gage_names;
181
182 void add_gage(const std::string& uh_name, const std::string& gage) {
183 gage_assignments.push_back(uh_name);
184 gage_names.push_back(gage);
185 }
186
187 void add(const UnitHydEntry& e) { entries.push_back(e); }
188};
189
190// ============================================================================
191// RDII exponential-decay parameters (from [RDII_DECAY] section)
192// ============================================================================
193//
194// One row per (UH group, response). Granularity is per-response, NOT per-month
195// — the whole point of the exponential model is that seasonal variation in
196// IA recovery emerges from temperature dynamics, not from a monthly lookup.
197//
198// A UH group with no row here uses the legacy linear IA recovery for every
199// response. A group with one row falls back to linear for the two unspecified
200// responses, so adoption is incremental.
201//
202// @see docs/RDII_ExpDecay_Implementation.md
203
205 std::string uh_name;
206 int response = -1;
207 double k_dep = 0.0;
208 double k_0 = 0.0;
209 double k_T = 0.0;
210 double T_ref = 10.0;
211 double theta_rec = 0.0;
212 double T_freeze = 0.0;
213
214 // Optional degree-day snow model (SNOW keyword + 2 extra columns).
215 // When on, precipitation at T <= snow_T accumulates as SWE (no liquid
216 // input); at T > snow_T, melt = min(SWE, snow_ddf*(T - snow_T)*dt_days)
217 // is added to rainfall before the IA update (rain-on-snow adds).
218 bool snow_on = false;
219 double snow_T = 1.0;
220 double snow_ddf = 0.0;
221};
222
224 int count() const { return static_cast<int>(entries.size()); }
225
226 std::vector<RDIIDecayEntry> entries;
227
228 void add(const RDIIDecayEntry& e) { entries.push_back(e); }
229};
230
231// ============================================================================
232// Time patterns (from [PATTERNS] section)
233// ============================================================================
234
236 int count() const { return static_cast<int>(names.size()); }
237
238 std::vector<std::string> names;
239 std::vector<int> types;
240 std::vector<std::vector<double>> factors;
241
242 void add(const std::string& name, int type, const std::vector<double>& facs) {
243 names.push_back(name); types.push_back(type);
244 factors.push_back(facs);
245 }
246
249 int find(std::string_view name) const noexcept {
250 for (int i = 0; i < count(); ++i)
251 if (ieq(names[static_cast<std::size_t>(i)], name)) return i;
252 return -1;
253 }
254};
255
256} // namespace openswmm
257
258#endif // OPENSWMM_ENGINE_INFLOW_DATA_HPP
Case-insensitive string helpers matching legacy SWMM name semantics.
Definition Gage.cpp:36
Definition NodeCoupling.cpp:16
bool ieq(std::string_view a, std::string_view b) noexcept
Case-insensitive equality (ASCII fold), matching legacy samestr().
Definition StringCase.hpp:57
Definition InflowData.hpp:90
std::vector< std::string > constituent
"FLOW" or pollutant name
Definition InflowData.hpp:95
std::vector< int > node_idx
Target node.
Definition InflowData.hpp:93
std::vector< std::string > pat1
Monthly pattern name.
Definition InflowData.hpp:97
std::vector< std::string > pat2
Daily pattern name.
Definition InflowData.hpp:98
std::vector< double > avg_value
Average value.
Definition InflowData.hpp:96
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={})
Definition InflowData.hpp:102
void erase(int idx)
Definition InflowData.hpp:113
std::vector< std::string > pat4
Weekend pattern name.
Definition InflowData.hpp:100
int count() const
Definition InflowData.hpp:91
std::vector< std::string > node_name
Raw node name from input (for post-parse re-resolution)
Definition InflowData.hpp:94
std::vector< std::string > pat3
Hourly pattern name.
Definition InflowData.hpp:99
Definition InflowData.hpp:46
std::vector< std::string > pattern_name
Baseline pattern name.
Definition InflowData.hpp:57
std::vector< std::string > constituent
"FLOW" or pollutant name
Definition InflowData.hpp:51
std::vector< int > node_idx
Target node index.
Definition InflowData.hpp:49
std::vector< double > baseline
Baseline value.
Definition InflowData.hpp:56
int count() const
Definition InflowData.hpp:47
std::vector< std::string > inflow_type
"FLOW","CONCEN","MASS"
Definition InflowData.hpp:53
std::vector< double > s_factor
Scaling factor.
Definition InflowData.hpp:55
std::vector< double > m_factor
Multiplier factor.
Definition InflowData.hpp:54
std::vector< std::string > node_name
Raw node name from input (for post-parse re-resolution)
Definition InflowData.hpp:50
std::vector< std::string > ts_name
Timeseries name ("" if none)
Definition InflowData.hpp:52
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={})
Definition InflowData.hpp:59
void erase(int idx)
Definition InflowData.hpp:71
Definition InflowData.hpp:235
int find(std::string_view name) const noexcept
Definition InflowData.hpp:249
std::vector< std::vector< double > > factors
Up to 24 multiplier values.
Definition InflowData.hpp:240
void add(const std::string &name, int type, const std::vector< double > &facs)
Definition InflowData.hpp:242
std::vector< std::string > names
Pattern name.
Definition InflowData.hpp:238
int count() const
Definition InflowData.hpp:236
std::vector< int > types
0=MONTHLY,1=DAILY,2=HOURLY,3=WEEKEND
Definition InflowData.hpp:239
Definition InflowData.hpp:131
std::vector< std::string > uh_name
Unit hydrograph name.
Definition InflowData.hpp:136
std::vector< double > sewer_area
Tributary sewer area.
Definition InflowData.hpp:137
std::vector< std::string > node_name
Raw node name from input (for post-parse re-resolution)
Definition InflowData.hpp:135
std::vector< int > node_idx
Target node.
Definition InflowData.hpp:134
int count() const
Definition InflowData.hpp:132
void erase(int idx)
Definition InflowData.hpp:146
void add(int ni, const std::string &uh, double area, const std::string &name={})
Definition InflowData.hpp:139
Definition InflowData.hpp:223
int count() const
Definition InflowData.hpp:224
void add(const RDIIDecayEntry &e)
Definition InflowData.hpp:228
std::vector< RDIIDecayEntry > entries
Definition InflowData.hpp:226
Definition InflowData.hpp:204
double k_T
Thermal recovery rate at T_ref (1/hr)
Definition InflowData.hpp:209
double k_0
Base recovery rate (1/hr)
Definition InflowData.hpp:208
double k_dep
Depletion rate (1/project rain-depth unit: 1/in or 1/mm) — temperature-independent.
Definition InflowData.hpp:207
double theta_rec
Temperature sensitivity (1/deg C)
Definition InflowData.hpp:211
int response
0=SHORT, 1=MEDIUM, 2=LONG
Definition InflowData.hpp:206
std::string uh_name
Matches UnitHydEntry::name.
Definition InflowData.hpp:205
double snow_T
Rain/snow partition threshold & melt base (deg C)
Definition InflowData.hpp:219
bool snow_on
Degree-day snow model enabled for this row.
Definition InflowData.hpp:218
double T_freeze
Recovery suppressed when T < T_freeze (deg C)
Definition InflowData.hpp:212
double snow_ddf
Degree-day melt factor (project rain-depth unit/degC/day)
Definition InflowData.hpp:220
double T_ref
Reference temperature (deg C)
Definition InflowData.hpp:210
Definition InflowData.hpp:173
std::vector< std::string > gage_assignments
Rain gage names associated with each UH group (name → gage name)
Definition InflowData.hpp:179
std::vector< std::string > gage_names
Assigned rain gage names.
Definition InflowData.hpp:180
void add(const UnitHydEntry &e)
Definition InflowData.hpp:187
std::vector< UnitHydEntry > entries
Definition InflowData.hpp:176
void add_gage(const std::string &uh_name, const std::string &gage)
Definition InflowData.hpp:182
int count() const
Definition InflowData.hpp:174
Definition InflowData.hpp:160
double drecov
IA recovery rate.
Definition InflowData.hpp:169
std::string name
UH group name.
Definition InflowData.hpp:161
double t
Time to peak (hours)
Definition InflowData.hpp:166
int response
0=SHORT, 1=MEDIUM, 2=LONG
Definition InflowData.hpp:164
double dmax
Max initial abstraction depth.
Definition InflowData.hpp:168
double r
Fraction of rainfall volume.
Definition InflowData.hpp:165
int month
Month index (0-11, or -1 for ALL)
Definition InflowData.hpp:163
std::string gage_name
Associated rain gage name.
Definition InflowData.hpp:162
double dinit
Initial IA used.
Definition InflowData.hpp:170
double k
Recession-limb-to-peak-time ratio (tBase = t*(1+k); k >= 0)
Definition InflowData.hpp:167