OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
QualityData.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
31
32#ifndef OPENSWMM_ENGINE_QUALITY_DATA_HPP
33#define OPENSWMM_ENGINE_QUALITY_DATA_HPP
34
35#include <vector>
36#include <string>
38
39namespace openswmm {
40
41// ============================================================================
42// Land use definitions
43// ============================================================================
44
50 int count() const { return static_cast<int>(sweep_interval.size()); }
51
52 std::vector<double> sweep_interval;
53 std::vector<double> sweep_removal;
54 std::vector<double> last_swept;
55
61 std::vector<std::string> comments;
62
71 void resize(int n) {
72 auto un = static_cast<std::size_t>(n);
73 sweep_interval.assign(un, 0.0);
74 sweep_removal.assign(un, 0.0);
75 last_swept.assign(un, 0.0);
76 comments.assign(un, std::string{});
77 }
78
86 sweep_interval.shrink_to_fit();
87 sweep_removal.shrink_to_fit();
88 last_swept.shrink_to_fit();
89 comments.shrink_to_fit();
90 }
91};
92
93// ============================================================================
94// Buildup function per (landuse x pollutant)
95// ============================================================================
96
99 std::vector<int> func_type;
100 std::vector<double> coeff1;
101 std::vector<double> coeff2;
102 std::vector<double> coeff3;
103 std::vector<int> normalizer;
104
105 int n_landuses = 0;
107
117 void resize(int nlu, int npoll) {
118 n_landuses = nlu;
119 n_pollutants = npoll;
120 auto total = static_cast<std::size_t>(nlu) * static_cast<std::size_t>(npoll);
121 func_type.assign(total, 0);
122 coeff1.assign(total, 0.0);
123 coeff2.assign(total, 0.0);
124 coeff3.assign(total, 0.0);
125 normalizer.assign(total, 0);
126 }
127
135 func_type.shrink_to_fit();
136 coeff1.shrink_to_fit();
137 coeff2.shrink_to_fit();
138 coeff3.shrink_to_fit();
139 normalizer.shrink_to_fit();
140 }
141};
142
143// ============================================================================
144// Washoff function per (landuse x pollutant)
145// ============================================================================
146
149 std::vector<int> func_type;
150 std::vector<double> coeff;
151 std::vector<double> expon;
152 std::vector<double> sweep_effic;
153 std::vector<double> bmp_effic;
154
155 int n_landuses = 0;
157
167 void resize(int nlu, int npoll) {
168 n_landuses = nlu;
169 n_pollutants = npoll;
170 auto total = static_cast<std::size_t>(nlu) * static_cast<std::size_t>(npoll);
171 func_type.assign(total, 0);
172 coeff.assign(total, 0.0);
173 expon.assign(total, 0.0);
174 sweep_effic.assign(total, 0.0);
175 bmp_effic.assign(total, 0.0);
176 }
177
185 func_type.shrink_to_fit();
186 coeff.shrink_to_fit();
187 expon.shrink_to_fit();
188 sweep_effic.shrink_to_fit();
189 bmp_effic.shrink_to_fit();
190 }
191};
192
193// ============================================================================
194// Treatment expression per (node x pollutant)
195// ============================================================================
196
199 std::vector<std::string> expressions;
200
201 int n_nodes = 0;
203
205 std::vector<openswmm::treatment::TreatExpr> compiled;
206
208 std::vector<bool> has_treatment;
209
211 std::vector<double> cin;
212
215 std::vector<double> removal;
216
229 void resize(int nn, int npoll) {
230 n_nodes = nn;
231 n_pollutants = npoll;
232 auto total = static_cast<std::size_t>(nn * npoll);
233 expressions.assign(total, "");
234 compiled.resize(total);
235 has_treatment.assign(static_cast<std::size_t>(nn), false);
236 cin.assign(static_cast<std::size_t>(npoll), 0.0);
237 removal.assign(static_cast<std::size_t>(npoll), -1.0);
238 }
239
247 expressions.shrink_to_fit();
248 compiled.shrink_to_fit();
249 }
250
257 bool hasAny() const {
258 for (const auto& e : expressions)
259 if (!e.empty())
260 return true;
261 return false;
262 }
263};
264
265} // namespace openswmm
266
267#endif // OPENSWMM_ENGINE_QUALITY_DATA_HPP
Treatment expression evaluator for water quality.
Definition ExchangeLaw.hpp:60
Definition QualityData.hpp:97
int n_pollutants
Definition QualityData.hpp:106
std::vector< int > func_type
Index: [landuse * n_pollutants + pollutant].
Definition QualityData.hpp:99
void shrink_to_fit()
Request capacity reduction for the owned parameter columns.
Definition QualityData.hpp:134
int n_landuses
Definition QualityData.hpp:105
std::vector< double > coeff2
Definition QualityData.hpp:101
void resize(int nlu, int npoll)
Replace the land-use-major pollutant parameter matrix.
Definition QualityData.hpp:117
std::vector< double > coeff1
Definition QualityData.hpp:100
std::vector< double > coeff3
Definition QualityData.hpp:102
std::vector< int > normalizer
0=PER_AREA, 1=PER_CURB
Definition QualityData.hpp:103
Definition QualityData.hpp:45
std::vector< std::string > comments
Object comment from the INP file (';'-prefixed lines immediately above this landuse's data row),...
Definition QualityData.hpp:61
int count() const
Count land-use rows from the sweep interval column.
Definition QualityData.hpp:50
void resize(int n)
Replace all land-use parameter/comment rows with defaults.
Definition QualityData.hpp:71
std::vector< double > sweep_interval
Days between sweeps.
Definition QualityData.hpp:52
std::vector< double > last_swept
Days since last swept.
Definition QualityData.hpp:54
void shrink_to_fit()
Request capacity reduction for the owned parameter columns.
Definition QualityData.hpp:85
std::vector< double > sweep_removal
Max removal fraction (0-100)
Definition QualityData.hpp:53
Definition QualityData.hpp:197
std::vector< std::string > expressions
Index: [node * n_pollutants + pollutant].
Definition QualityData.hpp:199
int n_nodes
Definition QualityData.hpp:201
std::vector< double > removal
Definition QualityData.hpp:215
void resize(int nn, int npoll)
Resize node-major treatment storage and reset authored expressions/workspaces.
Definition QualityData.hpp:229
std::vector< openswmm::treatment::TreatExpr > compiled
Compiled treatment expressions (same indexing as expressions[])
Definition QualityData.hpp:205
void shrink_to_fit()
Request capacity reduction for authored and compiled expression vectors.
Definition QualityData.hpp:246
std::vector< bool > has_treatment
Per-node flag: true if any pollutant has a treatment expression.
Definition QualityData.hpp:208
std::vector< double > cin
Per-node inflow concentrations (size = n_pollutants, reused each timestep)
Definition QualityData.hpp:211
bool hasAny() const
Test whether any authored treatment expression is nonempty.
Definition QualityData.hpp:257
int n_pollutants
Definition QualityData.hpp:202
Definition QualityData.hpp:147
std::vector< double > sweep_effic
0-100
Definition QualityData.hpp:152
int n_pollutants
Definition QualityData.hpp:156
std::vector< double > expon
Definition QualityData.hpp:151
std::vector< int > func_type
Index: [landuse * n_pollutants + pollutant].
Definition QualityData.hpp:149
std::vector< double > bmp_effic
0-100
Definition QualityData.hpp:153
std::vector< double > coeff
Definition QualityData.hpp:150
void resize(int nlu, int npoll)
Replace the land-use-major pollutant parameter matrix.
Definition QualityData.hpp:167
int n_landuses
Definition QualityData.hpp:155
void shrink_to_fit()
Request capacity reduction for the owned parameter columns.
Definition QualityData.hpp:184