OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
TransportPolicy.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
26
61
62#ifndef OPENSWMM_ENGINE_TRANSPORT_POLICY_HPP
63#define OPENSWMM_ENGINE_TRANSPORT_POLICY_HPP
64
65#include <string>
66#include <vector>
67
68namespace openswmm {
70}
71
72namespace openswmm::transport {
73
75enum class Domain : int {
76 RUNOFF = 0,
81};
82
84enum class SpeciesClass : int {
86 MSX = 1,
87 AGE = 2,
90};
91
93enum class CellState : int {
94 ENABLED = 0,
97};
98
99struct Cell {
101 int count = 0;
102 std::string reason;
103};
104
111 int n_pollut = 0;
112 int n_msx = 0;
113 bool age = false;
114 bool temperature = false;
115 bool msx_has_wall = false;
116 bool msx_bulk_only = false;
122 int total() const noexcept { return n_pollut + n_msx + (age ? 1 : 0) + (temperature ? 1 : 0); }
123};
124
126ClassEnables network1DEnables(const SimulationContext& ctx) noexcept;
127
131ClassEnables surface2DEnables(const SimulationContext& ctx) noexcept;
132
138ClassEnables groundwaterEnables(const SimulationContext& ctx) noexcept;
139
142struct RowLayout {
143 int n_pollut = 0;
144 int n_msx = 0;
145 int age_row = -1;
146 int temp_row = -1;
147 int ns = 0;
148 std::vector<std::string> names;
149};
151
152struct Matrix {
153 Cell cells[static_cast<int>(Domain::COUNT)][static_cast<int>(SpeciesClass::COUNT)];
162 const Cell& at(Domain d, SpeciesClass c) const noexcept {
163 return cells[static_cast<int>(d)][static_cast<int>(c)];
164 }
165
173 Cell& at(Domain d, SpeciesClass c) noexcept {
174 return cells[static_cast<int>(d)][static_cast<int>(c)];
175 }
176};
177
179struct Draft {
180 bool ignore_quality = false, heat = false, age = false, ignore_2d = false;
181 bool surface_class[4] = {true, true, true, true};
182 bool groundwater = false;
183 bool mesh = false;
184};
185Matrix resolve(const SimulationContext& ctx, const Draft* draft = nullptr);
186
187const char* domainName(Domain d) noexcept;
188const char* speciesClassName(SpeciesClass c) noexcept;
189const char* cellStateName(CellState s) noexcept;
190
193std::string formatReportBlock(const Matrix& m);
194
195} // namespace openswmm::transport
196
197#endif // OPENSWMM_ENGINE_TRANSPORT_POLICY_HPP
Definition ExplicitFvSolver.hpp:53
ClassEnables network1DEnables(const SimulationContext &ctx) noexcept
Resolve allocation-free native network class counts from current project policy.
Definition TransportPolicy.cpp:133
Matrix resolve(const SimulationContext &ctx, const Draft *draft)
Build a domain-by-species transport capability matrix with explicit reasons and counts.
Definition TransportPolicy.cpp:264
const char * domainName(Domain d) noexcept
Format a transport matrix domain as a human-readable label.
Definition TransportPolicy.cpp:495
SpeciesClass
Columns of the matrix. Values are the C API's SWMM_TRANSPORT_CLASS_* codes.
Definition TransportPolicy.hpp:84
@ COUNT
Definition TransportPolicy.hpp:89
@ AGE
WATER_AGE
Definition TransportPolicy.hpp:87
@ POLLUTANTS
[POLLUTANTS]
Definition TransportPolicy.hpp:85
@ TEMPERATURE
TEMPERATURE
Definition TransportPolicy.hpp:88
@ MSX
reactions component species
Definition TransportPolicy.hpp:86
RowLayout canonicalRows(const SimulationContext &ctx, const ClassEnables &e)
Build an owned canonical pollutant/MSX/age/temperature row layout for supplied enables.
Definition TransportPolicy.cpp:220
Domain
Rows of the matrix. Values are the C API's SWMM_TRANSPORT_DOMAIN_* codes.
Definition TransportPolicy.hpp:75
@ SURFACE_2D
the 2D mesh
Definition TransportPolicy.hpp:79
@ NETWORK_1D
LEGACY / EULERIAN_ARD / LAGRANGIAN routing.
Definition TransportPolicy.hpp:78
@ COUNT
Definition TransportPolicy.hpp:80
@ GROUNDWATER
legacy per-subcatchment aquifers
Definition TransportPolicy.hpp:77
@ RUNOFF
subcatchment runoff + LID
Definition TransportPolicy.hpp:76
std::string formatReportBlock(const Matrix &m)
Format a capability matrix as a readable fixed-column report and unavailable explanations.
Definition TransportPolicy.cpp:560
ClassEnables groundwaterEnables(const SimulationContext &ctx) noexcept
Resolve allocation-free canonical aquifer class eligibility for an active integrated kernel.
Definition TransportPolicy.cpp:184
CellState
One cell's state. Values are the C API's SWMM_TRANSPORT_* state codes.
Definition TransportPolicy.hpp:93
@ UNAVAILABLE
nothing to carry, or the solver lacks it — reason says which
Definition TransportPolicy.hpp:96
@ DISABLED_BY_USER
a key turned it off — reason names the key
Definition TransportPolicy.hpp:95
@ ENABLED
rows are carried in this domain
Definition TransportPolicy.hpp:94
ClassEnables surface2DEnables(const SimulationContext &ctx) noexcept
Resolve allocation-free surface native class eligibility from project and 2D opt-outs.
Definition TransportPolicy.cpp:154
const char * cellStateName(CellState s) noexcept
Format a transport capability state as its canonical uppercase label.
Definition TransportPolicy.cpp:536
const char * speciesClassName(SpeciesClass c) noexcept
Format a transport species class as a human-readable label.
Definition TransportPolicy.cpp:515
Definition ExchangeLaw.hpp:60
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
Definition TransportPolicy.hpp:99
int count
rows of this class carried (0 unless ENABLED)
Definition TransportPolicy.hpp:101
CellState state
Definition TransportPolicy.hpp:100
std::string reason
key (DISABLED_BY_USER) or explanation (UNAVAILABLE); empty when ENABLED
Definition TransportPolicy.hpp:102
Allocation-free class enables for one domain — what the engines size from. n_msx is the reactions com...
Definition TransportPolicy.hpp:110
int total() const noexcept
Count all rows advertised by these enables.
Definition TransportPolicy.hpp:122
bool temperature
Definition TransportPolicy.hpp:114
bool age
Definition TransportPolicy.hpp:113
bool msx_bulk_only
Definition TransportPolicy.hpp:116
int n_pollut
Definition TransportPolicy.hpp:111
int n_msx
Definition TransportPolicy.hpp:112
bool msx_has_wall
Definition TransportPolicy.hpp:115
Build the full matrix (states + reasons). Pure: never writes warnings.
Definition TransportPolicy.hpp:179
bool surface_class[4]
Definition TransportPolicy.hpp:181
bool mesh
Definition TransportPolicy.hpp:183
bool groundwater
Definition TransportPolicy.hpp:182
bool ignore_2d
Definition TransportPolicy.hpp:180
bool ignore_quality
Definition TransportPolicy.hpp:180
bool heat
Definition TransportPolicy.hpp:180
bool age
Definition TransportPolicy.hpp:180
Definition TransportPolicy.hpp:152
const Cell & at(Domain d, SpeciesClass c) const noexcept
Borrow one transport matrix cell by enum index.
Definition TransportPolicy.hpp:162
Cell & at(Domain d, SpeciesClass c) noexcept
Borrow one transport matrix cell by enum index.
Definition TransportPolicy.hpp:173
Cell cells[static_cast< int >(Domain::COUNT)][static_cast< int >(SpeciesClass::COUNT)]
Definition TransportPolicy.hpp:153
Definition TransportPolicy.hpp:142
int n_pollut
Definition TransportPolicy.hpp:143
int n_msx
Definition TransportPolicy.hpp:144
int age_row
Definition TransportPolicy.hpp:145
int ns
Definition TransportPolicy.hpp:147
std::vector< std::string > names
one per row
Definition TransportPolicy.hpp:148
int temp_row
Definition TransportPolicy.hpp:146