OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
BoundaryData.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
38
39#ifndef OPENSWMM_ENGINE_2D_BOUNDARY_DATA_HPP
40#define OPENSWMM_ENGINE_2D_BOUNDARY_DATA_HPP
41
43#include <vector>
44#include <cstdint>
45#include <map>
46#include <string>
47
48namespace openswmm::twoD {
49
65
74
76 std::vector<int8_t> edge_bc_type;
77
79 std::vector<double> edge_wall_drag;
81 std::vector<uint8_t> edge_is_exterior;
82
87 std::vector<double> edge_bed_slope;
88
91 std::vector<double> edge_bc_head;
92
96 std::vector<int> edge_bc_tseries;
97
99 std::vector<std::string> edge_bc_tseries_name;
100
103 std::vector<double> edge_bc_cum_flux;
104
105 // -----------------------------------------------------------------------
106 // V-E4 — SPECIFIED_FLOW slots (per-metre-of-edge discharge).
107 // Sign convention: outward-positive (matches edge_bc_cum_flux).
108 // -----------------------------------------------------------------------
109
112 std::vector<double> edge_bc_flow;
113
117 std::vector<int> edge_bc_flow_tseries;
118
120 std::vector<std::string> edge_bc_flow_tseries_name;
121
122 // -----------------------------------------------------------------------
123 // V-E5 — RATING_CURVE slot (stage → flow lookup).
124 // -----------------------------------------------------------------------
125
128 std::vector<int> edge_bc_rating_curve;
129
131 std::vector<std::string> edge_bc_rating_curve_name;
132
139 std::map<int, RuntimeOriginal> runtime_original;
140 std::map<int, std::string> runtime_owner;
141 mutable std::map<int, RuntimeReceipt> receipts;
152 void ensureReceipt(int slot, int species) const {
153 auto& receipt = receipts[slot];
154
155 if (receipt.applied_mass.size() != static_cast<std::size_t>(species)) {
156 receipt.requested_mass.assign(species, 0.0);
157 receipt.applied_mass.assign(species, 0.0);
158 }
159 }
160
168 void saveRuntime(int slot) {
169 if (runtime_original.count(slot))
170 return;
171 runtime_original.emplace(
172 slot,
177 }
178
188 void clearRuntime(int slot) {
189 const auto it = runtime_original.find(slot);
190 if (it == runtime_original.end())
191 return;
192 const auto& b = it->second;
193 edge_bc_type[slot] = b.type;
194 edge_bc_head[slot] = b.head;
195 edge_bc_flow[slot] = b.flow;
196 edge_bed_slope[slot] = b.slope;
197 edge_bc_tseries[slot] = b.stage_ts;
198 edge_bc_flow_tseries[slot] = b.flow_ts;
199 edge_bc_rating_curve[slot] = b.rating;
200 edge_bc_tseries_name[slot] = b.stage_name;
201 edge_bc_flow_tseries_name[slot] = b.flow_name;
202 edge_bc_rating_curve_name[slot] = b.rating_name;
203 runtime_original.erase(it);
204 runtime_owner.erase(slot);
205 }
206
207 // -----------------------------------------------------------------------
208 // Lifecycle
209 // -----------------------------------------------------------------------
210
222 void resize(int n_edges) {
223 runtime_original.clear();
224 runtime_owner.clear();
225 receipts.clear();
226 auto n = static_cast<std::size_t>(n_edges);
227 edge_bc_type.assign(n, static_cast<int8_t>(BoundaryType::WALL));
228 edge_bed_slope.assign(n, 0.0);
229 edge_wall_drag.assign(n, 0.0);
230 edge_is_exterior.assign(n, 0);
231 edge_bc_head.assign(n, 0.0);
232 edge_bc_tseries.assign(n, -1);
233 edge_bc_tseries_name.resize(n);
234 edge_bc_cum_flux.assign(n, 0.0);
235 edge_bc_flow.assign(n, 0.0);
236 edge_bc_flow_tseries.assign(n, -1);
238 edge_bc_rating_curve.assign(n, -1);
240 }
241
247 int size() const noexcept { return static_cast<int>(edge_bc_type.size()); }
248};
249
250} // namespace openswmm::twoD
251
252#endif // OPENSWMM_ENGINE_2D_BOUNDARY_DATA_HPP
Runtime coupling state and canonical transport exchange quantities.
Definition ExchangeLaw.hpp:60
BoundaryType
Boundary condition types for 2D mesh edges.
Definition BoundaryData.hpp:58
@ RATING_CURVE
Stage → flow lookup (curve registry index)
Definition BoundaryData.hpp:63
@ SPECIFIED_FLOW
Prescribed discharge per metre of edge (constant or TS)
Definition BoundaryData.hpp:62
@ NORMAL_FLOW
Manning outflow using bed slope.
Definition BoundaryData.hpp:60
@ WALL
Zero-flux wall (default)
Definition BoundaryData.hpp:59
@ SPECIFIED_STAGE
Prescribed water surface elevation (constant or TS)
Definition BoundaryData.hpp:61
Definition BoundaryData.hpp:133
int stage_ts
Definition BoundaryData.hpp:136
double head
Definition BoundaryData.hpp:135
int flow_ts
Definition BoundaryData.hpp:136
std::string flow_name
Definition BoundaryData.hpp:137
std::string rating_name
Definition BoundaryData.hpp:137
std::string stage_name
Definition BoundaryData.hpp:137
double flow
Definition BoundaryData.hpp:135
int rating
Definition BoundaryData.hpp:136
double slope
Definition BoundaryData.hpp:135
int8_t type
Definition BoundaryData.hpp:134
SoA storage for per-edge boundary conditions.
Definition BoundaryData.hpp:73
std::vector< uint8_t > edge_is_exterior
Derived from authored connectivity before runtime topology exists.
Definition BoundaryData.hpp:81
std::map< int, RuntimeReceipt > receipts
Definition BoundaryData.hpp:141
std::vector< std::string > edge_bc_flow_tseries_name
Timeseries name for deferred resolution (cleared after resolve).
Definition BoundaryData.hpp:120
void resize(int n_edges)
Resize all arrays to n_edges and initialize to WALL defaults.
Definition BoundaryData.hpp:222
std::vector< int > edge_bc_tseries
Definition BoundaryData.hpp:96
std::vector< int8_t > edge_bc_type
Boundary condition type per edge (cast from BoundaryType)
Definition BoundaryData.hpp:76
std::vector< std::string > edge_bc_tseries_name
Timeseries name for deferred resolution (cleared after resolve).
Definition BoundaryData.hpp:99
std::vector< double > edge_bed_slope
Definition BoundaryData.hpp:87
std::vector< double > edge_bc_flow
Definition BoundaryData.hpp:112
std::vector< double > edge_bc_head
Definition BoundaryData.hpp:91
int size() const noexcept
Report the number of padded boundary edge slots.
Definition BoundaryData.hpp:247
std::vector< std::string > edge_bc_rating_curve_name
Curve name for deferred resolution (cleared after resolve).
Definition BoundaryData.hpp:131
std::vector< double > edge_wall_drag
Optional tangential wall drag: tau/rho = -Cw |ut| ut. Zero = free slip.
Definition BoundaryData.hpp:79
std::vector< double > edge_bc_cum_flux
Definition BoundaryData.hpp:103
std::map< int, std::string > runtime_owner
Definition BoundaryData.hpp:140
void saveRuntime(int slot)
Capture a boundary's authored prescription before its first runtime override.
Definition BoundaryData.hpp:168
std::vector< int > edge_bc_rating_curve
Definition BoundaryData.hpp:128
std::map< int, RuntimeOriginal > runtime_original
Definition BoundaryData.hpp:139
void clearRuntime(int slot)
Restore a saved authored boundary prescription for one runtime slot.
Definition BoundaryData.hpp:188
std::vector< int > edge_bc_flow_tseries
Definition BoundaryData.hpp:117
void ensureReceipt(int slot, int species) const
Ensure a boundary receipt has the selected transport tuple width.
Definition BoundaryData.hpp:152