OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
Infil2D.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
59
60#ifndef OPENSWMM_2D_INFIL2D_HPP
61#define OPENSWMM_2D_INFIL2D_HPP
62
63#include <cstdint>
64#include <string>
65#include <vector>
66
68
69namespace openswmm { struct SimulationOptions; }
70
71namespace openswmm::twoD {
72
73struct MeshData;
74struct SurfaceStateData;
75
76// ============================================================================
77// Value types
78// ============================================================================
79
91enum class Infil2DDest : int {
92 LOST = 0,
95};
96
99inline constexpr int kInfil2DMaxParams = 5;
100
123 bool has_method = false;
125 double p[kInfil2DMaxParams] = {0.0, 0.0, 0.0, 0.0, 0.0};
131 bool dest_explicit = false;
132};
133
137 std::string tag;
139};
140
143 int tri = -1;
145};
146
151 double infil_step = 0.0;
152};
153
156enum class Infil2DProvenance : std::uint8_t {
157 NONE = 0,
158 STAR = 1,
159 TAG = 2,
161};
162
163// ============================================================================
164// Infil2D — per-cell infiltration state and driver
165// ============================================================================
166
181class Infil2D {
182public:
183 // --- configuration (populated by the section handlers) -----------------
184 std::vector<Infil2DDefault>& defaults() noexcept { return defaults_; }
185 const std::vector<Infil2DDefault>& defaults() const noexcept { return defaults_; }
186 std::vector<Infil2DOverride>& overrides() noexcept { return overrides_; }
187 const std::vector<Infil2DOverride>& overrides() const noexcept { return overrides_; }
188 Infil2DOptions& options() noexcept { return options_; }
189 const Infil2DOptions& options() const noexcept { return options_; }
190
204 bool resolve(const MeshData& mesh, const SimulationOptions& opts,
205 std::string& err);
206
216 void setAquifer2DAvailable(bool on) noexcept { aquifer_2d_available_ = on; }
217 bool aquifer2DAvailable() const noexcept { return aquifer_2d_available_; }
218
234 void updateRates(const MeshData& mesh, SurfaceStateData& state, double dt);
235
237 bool active() const noexcept { return active_; }
238
241 void deactivate() noexcept { active_ = false; }
242
244 const std::vector<Infil2DRow>& resolvedRows() const noexcept { return resolved_; }
245
247 const std::vector<Infil2DProvenance>& provenance() const noexcept { return prov_; }
248
256 const std::vector<double>& cumulative() const noexcept { return cum_depth_; }
257
260 double stepSeconds() const noexcept { return step_seconds_; }
261
263 void reset();
264
265private:
266 std::vector<Infil2DDefault> defaults_;
267 std::vector<Infil2DOverride> overrides_;
268 Infil2DOptions options_;
269
270 bool active_ = false;
271 double step_seconds_ = 0.0;
275 bool aquifer_2d_available_ = false;
276
277 // Per-triangle resolved state (empty when !active_).
278 std::vector<Infil2DRow> resolved_;
279 std::vector<Infil2DProvenance> prov_;
280 std::vector<double> cum_depth_;
281
282 // Kernel state, one entry per triangle (allocated only for the methods in
283 // use; indexed by triangle so lookups stay branch-free).
284 std::vector<infil::HortonState> horton_;
285 std::vector<infil::GreenAmptState> grnampt_;
286 std::vector<infil::CurveNumState> curvenum_;
287};
288
289// ============================================================================
290// Free helpers
291// ============================================================================
292
297bool parseInfil2DMethod(const std::string& token, InfilModel& method,
298 bool& has_method);
299
301const char* infil2DMethodToken(const Infil2DRow& row);
302
304bool parseInfil2DDest(const std::string& token, Infil2DDest& dest);
305
307const char* infil2DDestToken(Infil2DDest dest);
308
311int infil2DParamCount(InfilModel method);
312
313} // namespace openswmm::twoD
314
315#endif // OPENSWMM_2D_INFIL2D_HPP
Infiltration models — Horton, Green-Ampt, SCS Curve Number.
Owns per-cell infiltration parameters, kernel state and held rates.
Definition Infil2D.hpp:181
const Infil2DOptions & options() const noexcept
Definition Infil2D.hpp:189
const std::vector< Infil2DDefault > & defaults() const noexcept
Definition Infil2D.hpp:185
Infil2DOptions & options() noexcept
Definition Infil2D.hpp:188
const std::vector< Infil2DOverride > & overrides() const noexcept
Definition Infil2D.hpp:187
const std::vector< double > & cumulative() const noexcept
Definition Infil2D.hpp:256
void reset()
Clear everything back to the unconfigured fast path.
Definition Infil2D.cpp:379
std::vector< Infil2DDefault > & defaults() noexcept
Definition Infil2D.hpp:184
bool aquifer2DAvailable() const noexcept
Definition Infil2D.hpp:217
const std::vector< Infil2DProvenance > & provenance() const noexcept
Provenance per triangle (D-I3, for the writer).
Definition Infil2D.hpp:247
void deactivate() noexcept
Definition Infil2D.hpp:241
const std::vector< Infil2DRow > & resolvedRows() const noexcept
Resolved method per triangle; has_method == false entries are NONE.
Definition Infil2D.hpp:244
std::vector< Infil2DOverride > & overrides() noexcept
Definition Infil2D.hpp:186
bool resolve(const MeshData &mesh, const SimulationOptions &opts, std::string &err)
Resolve tag/override precedence into flat per-cell state.
Definition Infil2D.cpp:206
void updateRates(const MeshData &mesh, SurfaceStateData &state, double dt)
Recompute and publish per-cell infiltration rates (D-I1).
Definition Infil2D.cpp:331
bool active() const noexcept
True when at least one cell resolved to a model.
Definition Infil2D.hpp:237
void setAquifer2DAvailable(bool on) noexcept
G1 — tell validation that a [2D_AQUIFER] resolved, so the AQUIFER_2D destination has somewhere to sen...
Definition Infil2D.hpp:216
double stepSeconds() const noexcept
Definition Infil2D.hpp:260
Definition NodeCoupling.cpp:16
bool parseInfil2DMethod(const std::string &token, InfilModel &method, bool &has_method)
Definition Infil2D.cpp:141
@ NONE
Definition SolverOptions2D.hpp:115
@ TAG
every cell carrying tag
Definition GwTransportData.hpp:69
const char * infil2DDestToken(Infil2DDest dest)
Inverse of parseInfil2DDest.
Definition Infil2D.cpp:181
bool parseInfil2DDest(const std::string &token, Infil2DDest &dest)
Parse a destination token.
Definition Infil2D.cpp:174
Infil2DDest
Definition Infil2D.hpp:91
@ AQUIFER_2D
The two-zone 2D kernel (G1 step 11b)
Definition Infil2D.hpp:94
@ SUBCATCH_AQUIFER
Legacy subcatchment aquifer (U3 track I-b)
Definition Infil2D.hpp:93
@ LOST
Leaves the domain; booked to MassBalance2D::infil_out.
Definition Infil2D.hpp:92
Infil2DProvenance
Definition Infil2D.hpp:156
@ OVERRIDE
From a per-cell [2D_INFILTRATION] row.
Definition Infil2D.hpp:160
@ STAR
From the '*' default row.
Definition Infil2D.hpp:158
int infil2DParamCount(InfilModel method)
Definition Infil2D.cpp:190
const char * infil2DMethodToken(const Infil2DRow &row)
Inverse of parseInfil2DMethod — the canonical file token.
Definition Infil2D.cpp:161
constexpr int kInfil2DMaxParams
Definition Infil2D.hpp:99
Definition NodeCoupling.cpp:16
InfilModel
Definition Infiltration.hpp:45
@ HORTON
Definition Infiltration.hpp:46
All SWMM simulation options parsed from [OPTIONS] section.
Definition SimulationOptions.hpp:166
Definition Infil2D.hpp:136
std::string tag
Definition Infil2D.hpp:137
Infil2DRow row
Definition Infil2D.hpp:138
[2D_INFILTRATION_OPTIONS].
Definition Infil2D.hpp:148
double infil_step
Definition Infil2D.hpp:151
One [2D_INFILTRATION] per-cell override row.
Definition Infil2D.hpp:142
int tri
Triangle index (0-based internally; 1-based in file)
Definition Infil2D.hpp:143
Infil2DRow row
Definition Infil2D.hpp:144
One infiltration specification: method + positional parameters + destination.
Definition Infil2D.hpp:120
bool dest_explicit
Definition Infil2D.hpp:131
double p[kInfil2DMaxParams]
Definition Infil2D.hpp:125
bool has_method
Definition Infil2D.hpp:123
Infil2DDest dest
Definition Infil2D.hpp:126
InfilModel method
Definition Infil2D.hpp:124
SoA storage for 2D mixed triangle/quad mesh geometry and topology.
Definition MeshData.hpp:67
Definition SurfaceStateData.hpp:59