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
52
53#ifndef OPENSWMM_ENGINE_TRANSPORT_POLICY_HPP
54#define OPENSWMM_ENGINE_TRANSPORT_POLICY_HPP
55
56#include <string>
57#include <vector>
58
59namespace openswmm {
61}
62
63namespace openswmm::transport {
64
66enum class Domain : int {
67 RUNOFF = 0,
72};
73
75enum class SpeciesClass : int {
77 MSX = 1,
78 AGE = 2,
81};
82
84enum class CellState : int {
85 ENABLED = 0,
88};
89
90struct Cell {
92 int count = 0;
93 std::string reason;
94};
95
103 int n_pollut = 0;
104 int n_msx = 0;
105 bool age = false;
106 bool temperature = false;
107 bool msx_has_wall = false;
108 int total() const noexcept { return n_pollut + n_msx + (age ? 1 : 0) + (temperature ? 1 : 0); }
109};
110
112ClassEnables network1DEnables(const SimulationContext& ctx) noexcept;
113
117ClassEnables surface2DEnables(const SimulationContext& ctx) noexcept;
118
121struct RowLayout {
122 int n_pollut = 0;
123 int n_msx = 0;
124 int age_row = -1;
125 int temp_row = -1;
126 int ns = 0;
127 std::vector<std::string> names;
128};
130
131struct Matrix {
132 Cell cells[static_cast<int>(Domain::COUNT)][static_cast<int>(SpeciesClass::COUNT)];
133 const Cell& at(Domain d, SpeciesClass c) const noexcept {
134 return cells[static_cast<int>(d)][static_cast<int>(c)];
135 }
136 Cell& at(Domain d, SpeciesClass c) noexcept {
137 return cells[static_cast<int>(d)][static_cast<int>(c)];
138 }
139};
140
142Matrix resolve(const SimulationContext& ctx);
143
144const char* domainName(Domain d) noexcept;
145const char* speciesClassName(SpeciesClass c) noexcept;
146const char* cellStateName(CellState s) noexcept;
147
150std::string formatReportBlock(const Matrix& m);
151
152} // namespace openswmm::transport
153
154#endif // OPENSWMM_ENGINE_TRANSPORT_POLICY_HPP
Definition ExplicitFvSolver.hpp:52
ClassEnables network1DEnables(const SimulationContext &ctx) noexcept
1D network enables: LEGACY / ARD / LARD all size from this.
Definition TransportPolicy.cpp:78
Matrix resolve(const SimulationContext &ctx)
Build the full matrix (states + reasons). Pure: never writes warnings.
Definition TransportPolicy.cpp:128
const char * domainName(Domain d) noexcept
Definition TransportPolicy.cpp:244
SpeciesClass
Columns of the matrix. Values are the C API's SWMM_TRANSPORT_CLASS_* codes.
Definition TransportPolicy.hpp:75
@ COUNT
Definition TransportPolicy.hpp:80
@ AGE
WATER_AGE
Definition TransportPolicy.hpp:78
@ POLLUTANTS
[POLLUTANTS]
Definition TransportPolicy.hpp:76
@ TEMPERATURE
TEMPERATURE
Definition TransportPolicy.hpp:79
@ MSX
reactions component species
Definition TransportPolicy.hpp:77
RowLayout canonicalRows(const SimulationContext &ctx, const ClassEnables &e)
Definition TransportPolicy.cpp:108
Domain
Rows of the matrix. Values are the C API's SWMM_TRANSPORT_DOMAIN_* codes.
Definition TransportPolicy.hpp:66
@ SURFACE_2D
the 2D mesh
Definition TransportPolicy.hpp:70
@ NETWORK_1D
LEGACY / EULERIAN_ARD / LAGRANGIAN routing.
Definition TransportPolicy.hpp:69
@ COUNT
Definition TransportPolicy.hpp:71
@ GROUNDWATER
legacy per-subcatchment aquifers
Definition TransportPolicy.hpp:68
@ RUNOFF
subcatchment runoff + LID
Definition TransportPolicy.hpp:67
std::string formatReportBlock(const Matrix &m)
Definition TransportPolicy.cpp:273
CellState
One cell's state. Values are the C API's SWMM_TRANSPORT_* state codes.
Definition TransportPolicy.hpp:84
@ UNAVAILABLE
nothing to carry, or the solver lacks it — reason says which
Definition TransportPolicy.hpp:87
@ DISABLED_BY_USER
a key turned it off — reason names the key
Definition TransportPolicy.hpp:86
@ ENABLED
rows are carried in this domain
Definition TransportPolicy.hpp:85
ClassEnables surface2DEnables(const SimulationContext &ctx) noexcept
Definition TransportPolicy.cpp:89
const char * cellStateName(CellState s) noexcept
Definition TransportPolicy.cpp:264
const char * speciesClassName(SpeciesClass c) noexcept
Definition TransportPolicy.cpp:254
Definition NodeCoupling.cpp:16
Central, reentrant simulation context.
Definition SimulationContext.hpp:353
Definition TransportPolicy.hpp:90
int count
rows of this class carried (0 unless ENABLED)
Definition TransportPolicy.hpp:92
CellState state
Definition TransportPolicy.hpp:91
std::string reason
key (DISABLED_BY_USER) or explanation (UNAVAILABLE); empty when ENABLED
Definition TransportPolicy.hpp:93
Allocation-free class enables for one domain — what the engines size from. n_msx is the reactions com...
Definition TransportPolicy.hpp:102
int total() const noexcept
Definition TransportPolicy.hpp:108
bool temperature
Definition TransportPolicy.hpp:106
bool age
Definition TransportPolicy.hpp:105
int n_pollut
Definition TransportPolicy.hpp:103
int n_msx
Definition TransportPolicy.hpp:104
bool msx_has_wall
Definition TransportPolicy.hpp:107
Definition TransportPolicy.hpp:131
const Cell & at(Domain d, SpeciesClass c) const noexcept
Definition TransportPolicy.hpp:133
Cell & at(Domain d, SpeciesClass c) noexcept
Definition TransportPolicy.hpp:136
Cell cells[static_cast< int >(Domain::COUNT)][static_cast< int >(SpeciesClass::COUNT)]
Definition TransportPolicy.hpp:132
Definition TransportPolicy.hpp:121
int n_pollut
Definition TransportPolicy.hpp:122
int n_msx
Definition TransportPolicy.hpp:123
int age_row
Definition TransportPolicy.hpp:124
int ns
Definition TransportPolicy.hpp:126
std::vector< std::string > names
one per row
Definition TransportPolicy.hpp:127
int temp_row
Definition TransportPolicy.hpp:125