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
46 int count() const { return static_cast<int>(sweep_interval.size()); }
47
48 std::vector<double> sweep_interval;
49 std::vector<double> sweep_removal;
50 std::vector<double> last_swept;
51
57 std::vector<std::string> comments;
58
59 void resize(int n) {
60 auto un = static_cast<std::size_t>(n);
61 sweep_interval.assign(un, 0.0);
62 sweep_removal.assign(un, 0.0);
63 last_swept.assign(un, 0.0);
64 comments.assign(un, std::string{});
65 }
66
68 sweep_interval.shrink_to_fit();
69 sweep_removal.shrink_to_fit();
70 last_swept.shrink_to_fit();
71 comments.shrink_to_fit();
72 }
73};
74
75// ============================================================================
76// Buildup function per (landuse x pollutant)
77// ============================================================================
78
81 std::vector<int> func_type;
82 std::vector<double> coeff1;
83 std::vector<double> coeff2;
84 std::vector<double> coeff3;
85 std::vector<int> normalizer;
86
87 int n_landuses = 0;
88 int n_pollutants = 0;
89
90 void resize(int nlu, int npoll) {
91 n_landuses = nlu; n_pollutants = npoll;
92 auto total = static_cast<std::size_t>(nlu) *
93 static_cast<std::size_t>(npoll);
94 func_type.assign(total, 0);
95 coeff1.assign(total, 0.0);
96 coeff2.assign(total, 0.0);
97 coeff3.assign(total, 0.0);
98 normalizer.assign(total, 0);
99 }
100
102 func_type.shrink_to_fit();
103 coeff1.shrink_to_fit();
104 coeff2.shrink_to_fit();
105 coeff3.shrink_to_fit();
106 normalizer.shrink_to_fit();
107 }
108};
109
110// ============================================================================
111// Washoff function per (landuse x pollutant)
112// ============================================================================
113
116 std::vector<int> func_type;
117 std::vector<double> coeff;
118 std::vector<double> expon;
119 std::vector<double> sweep_effic;
120 std::vector<double> bmp_effic;
121
122 int n_landuses = 0;
124
125 void resize(int nlu, int npoll) {
126 n_landuses = nlu; n_pollutants = npoll;
127 auto total = static_cast<std::size_t>(nlu) *
128 static_cast<std::size_t>(npoll);
129 func_type.assign(total, 0);
130 coeff.assign(total, 0.0);
131 expon.assign(total, 0.0);
132 sweep_effic.assign(total, 0.0);
133 bmp_effic.assign(total, 0.0);
134 }
135
137 func_type.shrink_to_fit();
138 coeff.shrink_to_fit();
139 expon.shrink_to_fit();
140 sweep_effic.shrink_to_fit();
141 bmp_effic.shrink_to_fit();
142 }
143};
144
145// ============================================================================
146// Treatment expression per (node x pollutant)
147// ============================================================================
148
151 std::vector<std::string> expressions;
152
153 int n_nodes = 0;
155
157 std::vector<openswmm::treatment::TreatExpr> compiled;
158
160 std::vector<bool> has_treatment;
161
163 std::vector<double> cin;
164
167 std::vector<double> removal;
168
169 void resize(int nn, int npoll) {
170 n_nodes = nn; n_pollutants = npoll;
171 auto total = static_cast<std::size_t>(nn * npoll);
172 expressions.assign(total, "");
173 compiled.resize(total);
174 has_treatment.assign(static_cast<std::size_t>(nn), false);
175 cin.assign(static_cast<std::size_t>(npoll), 0.0);
176 removal.assign(static_cast<std::size_t>(npoll), -1.0);
177 }
178
180 expressions.shrink_to_fit();
181 compiled.shrink_to_fit();
182 }
183
184 bool hasAny() const {
185 for (const auto& e : expressions) if (!e.empty()) return true;
186 return false;
187 }
188};
189
190} // namespace openswmm
191
192#endif // OPENSWMM_ENGINE_QUALITY_DATA_HPP
Treatment expression evaluator for water quality.
Definition NodeCoupling.cpp:16
Definition QualityData.hpp:79
int n_pollutants
Definition QualityData.hpp:88
std::vector< int > func_type
Index: [landuse * n_pollutants + pollutant].
Definition QualityData.hpp:81
void shrink_to_fit()
Definition QualityData.hpp:101
int n_landuses
Definition QualityData.hpp:87
std::vector< double > coeff2
Definition QualityData.hpp:83
void resize(int nlu, int npoll)
Definition QualityData.hpp:90
std::vector< double > coeff1
Definition QualityData.hpp:82
std::vector< double > coeff3
Definition QualityData.hpp:84
std::vector< int > normalizer
0=PER_AREA, 1=PER_CURB
Definition QualityData.hpp:85
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:57
int count() const
Definition QualityData.hpp:46
void resize(int n)
Definition QualityData.hpp:59
std::vector< double > sweep_interval
Days between sweeps.
Definition QualityData.hpp:48
std::vector< double > last_swept
Days since last swept.
Definition QualityData.hpp:50
void shrink_to_fit()
Definition QualityData.hpp:67
std::vector< double > sweep_removal
Max removal fraction (0-100)
Definition QualityData.hpp:49
Definition QualityData.hpp:149
std::vector< std::string > expressions
Index: [node * n_pollutants + pollutant].
Definition QualityData.hpp:151
int n_nodes
Definition QualityData.hpp:153
std::vector< double > removal
Definition QualityData.hpp:167
void resize(int nn, int npoll)
Definition QualityData.hpp:169
std::vector< openswmm::treatment::TreatExpr > compiled
Compiled treatment expressions (same indexing as expressions[])
Definition QualityData.hpp:157
void shrink_to_fit()
Definition QualityData.hpp:179
std::vector< bool > has_treatment
Per-node flag: true if any pollutant has a treatment expression.
Definition QualityData.hpp:160
std::vector< double > cin
Per-node inflow concentrations (size = n_pollutants, reused each timestep)
Definition QualityData.hpp:163
bool hasAny() const
Definition QualityData.hpp:184
int n_pollutants
Definition QualityData.hpp:154
Definition QualityData.hpp:114
std::vector< double > sweep_effic
0-100
Definition QualityData.hpp:119
int n_pollutants
Definition QualityData.hpp:123
std::vector< double > expon
Definition QualityData.hpp:118
std::vector< int > func_type
Index: [landuse * n_pollutants + pollutant].
Definition QualityData.hpp:116
std::vector< double > bmp_effic
0-100
Definition QualityData.hpp:120
std::vector< double > coeff
Definition QualityData.hpp:117
void resize(int nlu, int npoll)
Definition QualityData.hpp:125
int n_landuses
Definition QualityData.hpp:122
void shrink_to_fit()
Definition QualityData.hpp:136