OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
MsxSurfaceData.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
48
49#ifndef OPENSWMM_ENGINE_DATA_MSX_SURFACE_DATA_HPP
50#define OPENSWMM_ENGINE_DATA_MSX_SURFACE_DATA_HPP
51
52#include <cstddef>
53#include <string>
54#include <vector>
55
56namespace openswmm {
57
60 struct Buildup {
61 std::string landuse, species;
62 int func_type = 0;
63 double c1 = 0.0, c2 = 0.0, c3 = 0.0;
64 std::string ts_name;
65 int normalizer = 0;
66 };
67 struct Washoff {
68 std::string landuse, species;
69 int func_type = 0;
70 double coeff = 0.0, expon = 0.0, sweep_effic = 0.0, bmp_effic = 0.0;
71 };
72 struct Loading {
73 std::string subcatch, species;
74 double value = 0.0;
75 };
76 std::vector<Buildup> buildup;
77 std::vector<Washoff> washoff;
78 std::vector<Loading> loadings;
83 bool empty() const noexcept { return buildup.empty() && washoff.empty() && loadings.empty(); }
84};
85
100
101 int n_landuses = 0;
102 int n_species = 0;
103 int n_subcatch = 0;
104
105 // ---- parameters [lu * n_species + m] --------------------------------
106 std::vector<int> bu_type;
107 std::vector<double> bu_c1, bu_c2, bu_c3;
108 std::vector<int> bu_normalizer;
109 std::vector<double> bu_max_days;
110 std::vector<int> wo_type;
112
113 // ---- initial loading [sc * n_species + m] (mass per unit area) ------
114 std::vector<double> init_loading;
115
116 // ---- per-species unit factor: concentration-mass → user mass --------
117 std::vector<double> mcf;
118
119 // ---- state ----------------------------------------------------------
120 std::vector<double> buildup;
121 std::vector<double> washoff_conc;
126 std::vector<double> washoff_conc_old;
131 std::vector<double> ponded_qual;
132 std::vector<double> runon_qual_rate;
136 std::vector<double> c_rain;
137 std::vector<bool> snow_only;
143 std::vector<double> lid_rmvl;
144 std::vector<double> lid_drain_load;
145 std::vector<double> lid_drain_load_old;
147 std::vector<double> lid_drain_runon_load;
148
149 // ---- ledgers per species [m], user mass ---------------------------
150 std::vector<double> led_init_buildup;
151 std::vector<double> led_buildup;
152 std::vector<double> led_runoff_load;
153 std::vector<double> led_sweeping;
154 std::vector<double> led_bmp_removal;
155 std::vector<double> led_wet_deposition;
156 std::vector<double> led_infil_loss;
157 std::vector<double> led_reacted;
158 std::vector<double> led_reaction_clamped;
159 std::vector<double> led_ponded_lost;
160 std::vector<double>
162
163 bool resolved = false;
168 bool active() const noexcept { return resolved && n_species > 0; }
169
177 std::size_t pidx(int lu, int m) const noexcept {
178 return static_cast<std::size_t>(lu) * static_cast<std::size_t>(n_species) +
179 static_cast<std::size_t>(m);
180 }
181
189 std::size_t bu_idx(int sc, int lu, int m) const noexcept {
190 return (static_cast<std::size_t>(sc) * static_cast<std::size_t>(n_landuses) +
191 static_cast<std::size_t>(lu)) *
192 static_cast<std::size_t>(n_species) +
193 static_cast<std::size_t>(m);
194 }
195
202 std::size_t sidx(int sc, int m) const noexcept {
203 return static_cast<std::size_t>(sc) * static_cast<std::size_t>(n_species) +
204 static_cast<std::size_t>(m);
205 }
206
218 void resize_params(int nlu, int nm) {
219 n_landuses = nlu;
220 n_species = nm;
221 const auto n = static_cast<std::size_t>(nlu) * static_cast<std::size_t>(nm);
222 bu_type.assign(n, 0);
223 bu_c1.assign(n, 0.0);
224 bu_c2.assign(n, 0.0);
225 bu_c3.assign(n, 0.0);
226 bu_normalizer.assign(n, 0);
227 bu_max_days.assign(n, 0.0);
228 wo_type.assign(n, 0);
229 wo_coeff.assign(n, 0.0);
230 wo_expon.assign(n, 0.0);
231 wo_sweep_effic.assign(n, 0.0);
232 wo_bmp_effic.assign(n, 0.0);
233 mcf.assign(static_cast<std::size_t>(nm), 1.0);
234 if (c_rain.size() != static_cast<std::size_t>(nm))
235 c_rain.assign(static_cast<std::size_t>(nm), 0.0);
236 snow_only.assign(static_cast<std::size_t>(nm), false);
237 }
238
249 void resize_state(int nsc) {
250 n_subcatch = nsc;
251 const auto nm = static_cast<std::size_t>(n_species);
252 buildup.assign(static_cast<std::size_t>(nsc) * static_cast<std::size_t>(n_landuses) * nm,
253 0.0);
254 washoff_conc.assign(static_cast<std::size_t>(nsc) * nm, 0.0);
255 washoff_conc_old.assign(static_cast<std::size_t>(nsc) * nm, 0.0);
256 ponded_qual.assign(static_cast<std::size_t>(nsc) * nm, 0.0);
257 runon_qual_rate.assign(static_cast<std::size_t>(nsc) * nm, 0.0);
258 lid_drain_runon_load.assign(static_cast<std::size_t>(nsc) * nm, 0.0);
259 if (init_loading.size() != static_cast<std::size_t>(nsc) * nm)
260 init_loading.assign(static_cast<std::size_t>(nsc) * nm, 0.0);
261 led_init_buildup.assign(nm, 0.0);
262 led_buildup.assign(nm, 0.0);
263 led_runoff_load.assign(nm, 0.0);
264 led_sweeping.assign(nm, 0.0);
265 led_bmp_removal.assign(nm, 0.0);
266 led_wet_deposition.assign(nm, 0.0);
267 led_infil_loss.assign(nm, 0.0);
268 led_ponded_lost.assign(nm, 0.0);
269 led_reacted.assign(nm, 0.0);
270 led_reaction_clamped.assign(nm, 0.0);
271 led_subcatch_load.assign(static_cast<std::size_t>(nsc) * nm, 0.0);
272 }
273};
274
275} // namespace openswmm
276
277#endif // OPENSWMM_ENGINE_DATA_MSX_SURFACE_DATA_HPP
Definition ExchangeLaw.hpp:60
Resolved MSX surface-quality parameters and state.
Definition MsxSurfaceData.hpp:98
std::vector< double > washoff_conc
Definition MsxSurfaceData.hpp:121
MsxSurfaceRows rows
parse-time, by name
Definition MsxSurfaceData.hpp:99
std::vector< double > bu_max_days
derived (99.9 % of max)
Definition MsxSurfaceData.hpp:109
std::vector< double > mcf
D-A27: MG → UCF(MASS), UG → /1000, else 1.
Definition MsxSurfaceData.hpp:117
std::vector< double > washoff_conc_old
Definition MsxSurfaceData.hpp:126
std::vector< double > led_ponded_lost
ponded mass written off when a surface dried
Definition MsxSurfaceData.hpp:159
bool active() const noexcept
Test whether resolved MSX surface state has at least one species.
Definition MsxSurfaceData.hpp:168
std::vector< double > led_buildup
net accrual over the run
Definition MsxSurfaceData.hpp:151
std::vector< double > led_init_buildup
Definition MsxSurfaceData.hpp:150
std::vector< int > wo_type
0=NONE,1=EXP,2=RC,3=EMC
Definition MsxSurfaceData.hpp:110
int n_species
MSX species count at resolve time.
Definition MsxSurfaceData.hpp:102
std::vector< double > bu_c3
EXT: c3 = time-series index.
Definition MsxSurfaceData.hpp:107
std::vector< double > led_bmp_removal
Definition MsxSurfaceData.hpp:154
std::vector< double > ponded_qual
Definition MsxSurfaceData.hpp:131
std::size_t sidx(int sc, int m) const noexcept
Calculate a subcatchment-major species matrix index.
Definition MsxSurfaceData.hpp:202
void resize_state(int nsc)
Replace MSX subcatchment state and continuity ledgers with zero arrays.
Definition MsxSurfaceData.hpp:249
std::vector< double > led_subcatch_load
[sc * n_species + m], per-subcatchment total (report)
Definition MsxSurfaceData.hpp:161
std::vector< double > led_infil_loss
infiltrated from ponded water and LID units
Definition MsxSurfaceData.hpp:156
int n_subcatch
Definition MsxSurfaceData.hpp:103
int n_landuses
Definition MsxSurfaceData.hpp:101
std::vector< double > led_reacted
signed wet-pool reaction loss, user mass
Definition MsxSurfaceData.hpp:157
std::vector< double > c_rain
Definition MsxSurfaceData.hpp:136
std::size_t bu_idx(int sc, int lu, int m) const noexcept
Calculate a subcatchment/land-use/species buildup index.
Definition MsxSurfaceData.hpp:189
std::vector< double > led_reaction_clamped
numerical addition after a negative RATE
Definition MsxSurfaceData.hpp:158
std::vector< double > runon_qual_rate
Definition MsxSurfaceData.hpp:132
void resize_params(int nlu, int nm)
Replace resolved MSX buildup/washoff parameter matrices.
Definition MsxSurfaceData.hpp:218
std::vector< double > lid_rmvl
Definition MsxSurfaceData.hpp:143
std::vector< bool > snow_only
Definition MsxSurfaceData.hpp:137
std::vector< double > wo_expon
Definition MsxSurfaceData.hpp:111
std::vector< double > bu_c2
Definition MsxSurfaceData.hpp:107
std::vector< double > lid_drain_runon_load
[sc * n_species + m] the species twin of SubcatchData::lid_drain_runon_qual.
Definition MsxSurfaceData.hpp:147
std::vector< double > led_runoff_load
delivered to the network
Definition MsxSurfaceData.hpp:152
std::vector< double > lid_drain_load_old
Definition MsxSurfaceData.hpp:145
std::size_t pidx(int lu, int m) const noexcept
Calculate a land-use-major parameter matrix index.
Definition MsxSurfaceData.hpp:177
std::vector< double > led_wet_deposition
rainfall concentration × rain volume
Definition MsxSurfaceData.hpp:155
std::vector< double > led_sweeping
Definition MsxSurfaceData.hpp:153
std::vector< double > bu_c1
Definition MsxSurfaceData.hpp:107
std::vector< double > init_loading
Definition MsxSurfaceData.hpp:114
std::vector< int > bu_type
0=NONE,1=POW,2=EXP,3=SAT,4=EXT
Definition MsxSurfaceData.hpp:106
bool resolved
Definition MsxSurfaceData.hpp:163
std::vector< int > bu_normalizer
0=PER_AREA, 1=PER_CURB
Definition MsxSurfaceData.hpp:108
std::vector< double > wo_sweep_effic
Definition MsxSurfaceData.hpp:111
std::vector< double > buildup
bu_idx(sc, lu, m), per normalizer unit
Definition MsxSurfaceData.hpp:120
std::vector< double > wo_bmp_effic
Definition MsxSurfaceData.hpp:111
std::vector< double > lid_drain_load
Definition MsxSurfaceData.hpp:144
std::vector< double > wo_coeff
Definition MsxSurfaceData.hpp:111
Definition MsxSurfaceData.hpp:60
std::string ts_name
EXT: time series name (resolved later)
Definition MsxSurfaceData.hpp:64
std::string species
Definition MsxSurfaceData.hpp:61
double c1
Definition MsxSurfaceData.hpp:63
double c2
Definition MsxSurfaceData.hpp:63
std::string landuse
Definition MsxSurfaceData.hpp:61
int normalizer
0=PER_AREA, 1=PER_CURB
Definition MsxSurfaceData.hpp:65
int func_type
0=NONE,1=POW,2=EXP,3=SAT,4=EXT
Definition MsxSurfaceData.hpp:62
double c3
Definition MsxSurfaceData.hpp:63
Definition MsxSurfaceData.hpp:72
std::string subcatch
Definition MsxSurfaceData.hpp:73
std::string species
Definition MsxSurfaceData.hpp:73
double value
initial buildup, mass per unit area
Definition MsxSurfaceData.hpp:74
Definition MsxSurfaceData.hpp:67
double sweep_effic
Definition MsxSurfaceData.hpp:70
std::string landuse
Definition MsxSurfaceData.hpp:68
double coeff
Definition MsxSurfaceData.hpp:70
std::string species
Definition MsxSurfaceData.hpp:68
double bmp_effic
Definition MsxSurfaceData.hpp:70
double expon
Definition MsxSurfaceData.hpp:70
int func_type
0=NONE,1=EXP,2=RC,3=EMC
Definition MsxSurfaceData.hpp:69
Rows parked by the section handlers for names that are not pollutants.
Definition MsxSurfaceData.hpp:59
std::vector< Buildup > buildup
Definition MsxSurfaceData.hpp:76
bool empty() const noexcept
Test whether all deferred MSX buildup/washoff/loading row lists are empty.
Definition MsxSurfaceData.hpp:83
std::vector< Loading > loadings
Definition MsxSurfaceData.hpp:78
std::vector< Washoff > washoff
Definition MsxSurfaceData.hpp:77