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 {
71}
72
73namespace openswmm::twoD {
74
75struct MeshData;
76struct SurfaceStateData;
77
78// ============================================================================
79// Value types
80// ============================================================================
81
86enum class Infil2DDest : int {
87 LOST = 0,
90};
91
94inline constexpr int kInfil2DMaxParams = 5;
95
117 bool has_method = false;
119 double p[kInfil2DMaxParams] = {0.0, 0.0, 0.0, 0.0, 0.0};
125 bool dest_explicit = false;
126};
127
131 std::string tag;
133};
134
137 int tri = -1;
139};
140
145 double infil_step = 0.0;
146};
147
150enum class Infil2DProvenance : std::uint8_t {
151 NONE = 0,
152 STAR = 1,
153 TAG = 2,
155};
156
157// ============================================================================
158// Infil2D — per-cell infiltration state and driver
159// ============================================================================
160
175class Infil2D {
176public:
177 // --- configuration (populated by the section handlers) -----------------
185 std::vector<Infil2DDefault>& defaults() noexcept { return defaults_; }
192 const std::vector<Infil2DDefault>& defaults() const noexcept { return defaults_; }
200 std::vector<Infil2DOverride>& overrides() noexcept { return overrides_; }
207 const std::vector<Infil2DOverride>& overrides() const noexcept { return overrides_; }
215 Infil2DOptions& options() noexcept { return options_; }
222 const Infil2DOptions& options() const noexcept { return options_; }
223
248 bool resolve(const MeshData& mesh, const SimulationOptions& opts, std::string& err);
259 void setAquiferOwners(std::vector<uint8_t> owners) { aquifer_owners_ = std::move(owners); }
266 const std::vector<std::string>& ownershipMessages() const noexcept {
267 return ownership_messages_;
268 }
269
282 void setAquifer2DAvailable(bool on) noexcept { aquifer_2d_available_ = on; }
288 bool aquifer2DAvailable() const noexcept { return aquifer_2d_available_; }
289
315 void updateRates(const MeshData& mesh, SurfaceStateData& state, double dt,
316 surface::InfilBank::Factors factors = {1.0, 1.0});
320 void updateRates(const MeshData& mesh, SurfaceStateData& state, double dt,
321 surface::InfilBank::Factors factors, int num_threads);
322
329 surface::InfilBank& bank() noexcept { return bank_; }
330
338 bool active() const noexcept { return active_; }
339
350 void deactivate() noexcept { active_ = false; }
351
361 const std::vector<Infil2DRow>& resolvedRows() const noexcept { return resolved_; }
362
371 const std::vector<Infil2DProvenance>& provenance() const noexcept { return prov_; }
372
387 const std::vector<double>& cumulative() const noexcept { return bank_.cumulative(); }
388
397 double stepSeconds() const noexcept { return step_seconds_; }
398
408 void reset();
409
410private:
411 bool resolveImpl(const MeshData&, const SimulationOptions&, std::string&);
412 std::vector<uint8_t> aquifer_owners_;
413 std::vector<std::string> ownership_messages_;
414 std::vector<Infil2DDefault> defaults_;
415 std::vector<Infil2DOverride> overrides_;
416 Infil2DOptions options_;
417
418 bool active_ = false;
419 double step_seconds_ = 0.0;
423 bool aquifer_2d_available_ = false;
424
425 // Per-triangle resolved state (empty when !active_).
426 std::vector<Infil2DRow> resolved_;
427 std::vector<Infil2DProvenance> prov_;
428 surface::InfilBank bank_;
429};
430
431// ============================================================================
432// Free helpers
433// ============================================================================
434
449bool parseInfil2DMethod(const std::string& token, InfilModel& method, bool& has_method);
450
458const char* infil2DMethodToken(const Infil2DRow& row);
459
469bool parseInfil2DDest(const std::string& token, Infil2DDest& dest);
470
478const char* infil2DDestToken(Infil2DDest dest);
479
489int infil2DParamCount(InfilModel method);
490
491} // namespace openswmm::twoD
492
493#endif // OPENSWMM_2D_INFIL2D_HPP
Infiltration state and operations for surface water owners.
Definition InfilBank.hpp:31
Owns per-cell infiltration parameters, kernel state and held rates.
Definition Infil2D.hpp:175
const Infil2DOptions & options() const noexcept
Borrow the authored infiltration cadence options.
Definition Infil2D.hpp:222
const std::vector< Infil2DDefault > & defaults() const noexcept
Borrow the authored ordered star/tag fallback rows.
Definition Infil2D.hpp:192
Infil2DOptions & options() noexcept
Borrow the authored infiltration cadence options.
Definition Infil2D.hpp:215
const std::vector< Infil2DOverride > & overrides() const noexcept
Borrow the authored ordered per-cell overrides.
Definition Infil2D.hpp:207
const std::vector< double > & cumulative() const noexcept
Cumulative infiltration CAPACITY per triangle (m): the integral of the published rate,...
Definition Infil2D.hpp:387
const std::vector< std::string > & ownershipMessages() const noexcept
Borrow the most recent successful resolution's default-ownership diagnostics.
Definition Infil2D.hpp:266
void reset()
Clear everything back to the unconfigured fast path.
Definition Infil2D.cpp:434
surface::InfilBank & bank() noexcept
Borrow the canonical mutable per-cell infiltration bank.
Definition Infil2D.hpp:329
std::vector< Infil2DDefault > & defaults() noexcept
Borrow the authored ordered star/tag fallback rows.
Definition Infil2D.hpp:185
void setAquiferOwners(std::vector< uint8_t > owners)
Effective coverage, not inferred from conductivity or authored rows.
Definition Infil2D.hpp:259
bool aquifer2DAvailable() const noexcept
Read the stored aquifer-availability fallback flag.
Definition Infil2D.hpp:288
const std::vector< Infil2DProvenance > & provenance() const noexcept
Provenance per triangle (D-I3, for the writer).
Definition Infil2D.hpp:371
void deactivate() noexcept
E2: [2D_OPTIONS] INFILTRATION NO — keep the rows (they still save) but run without infiltration....
Definition Infil2D.hpp:350
const std::vector< Infil2DRow > & resolvedRows() const noexcept
Resolved method per triangle; has_method == false entries are NONE.
Definition Infil2D.hpp:361
std::vector< Infil2DOverride > & overrides() noexcept
Borrow the authored ordered per-cell overrides.
Definition Infil2D.hpp:200
bool resolve(const MeshData &mesh, const SimulationOptions &opts, std::string &err)
Resolve tag/override precedence into flat per-cell state.
Definition Infil2D.cpp:255
bool active() const noexcept
True when at least one cell resolved to a model.
Definition Infil2D.hpp:338
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:282
double stepSeconds() const noexcept
Resolved cadence in seconds (options_.infil_step, or the project WET_STEP when that was <= 0)....
Definition Infil2D.hpp:397
void updateRates(const MeshData &mesh, SurfaceStateData &state, double dt, surface::InfilBank::Factors factors={1.0, 1.0})
Recompute and publish per-cell infiltration rates (D-I1).
Definition Infil2D.cpp:398
Definition ExchangeLaw.hpp:60
bool parseInfil2DMethod(const std::string &token, InfilModel &method, bool &has_method)
Parse a method token (HORTON, MODIFIED_HORTON, GREEN_AMPT, MODIFIED_GREEN_AMPT, CURVE_NUMBER,...
Definition Infil2D.cpp:150
@ NONE
Definition SolverOptions2D.hpp:116
@ TAG
every cell carrying tag
Definition GwTransportData.hpp:67
const char * infil2DDestToken(Infil2DDest dest)
Inverse of parseInfil2DDest.
Definition Infil2D.cpp:223
bool parseInfil2DDest(const std::string &token, Infil2DDest &dest)
Parse a destination token.
Definition Infil2D.cpp:207
Infil2DDest
Definition Infil2D.hpp:86
@ AQUIFER_2D
Obsolete; migrate using the ownership review.
Definition Infil2D.hpp:89
@ SUBCATCH_AQUIFER
Legacy subcatchment aquifer (U3 track I-b)
Definition Infil2D.hpp:88
@ LOST
Leaves the domain; booked to MassBalance2D::infil_out.
Definition Infil2D.hpp:87
Infil2DProvenance
Definition Infil2D.hpp:150
@ OVERRIDE
From a per-cell [2D_INFILTRATION] row.
Definition Infil2D.hpp:154
@ STAR
From the '*' default row.
Definition Infil2D.hpp:152
int infil2DParamCount(InfilModel method)
Number of meaningful positional parameters for method (used by the writer to trim trailing placeholde...
Definition Infil2D.cpp:235
const char * infil2DMethodToken(const Infil2DRow &row)
Inverse of parseInfil2DMethod — the canonical file token.
Definition Infil2D.cpp:187
constexpr int kInfil2DMaxParams
Definition Infil2D.hpp:94
Definition ExchangeLaw.hpp:60
InfilModel
Definition Infiltration.hpp:45
@ HORTON
Definition Infiltration.hpp:46
All SWMM simulation options parsed from [OPTIONS] section.
Definition SimulationOptions.hpp:168
Definition InfilBank.hpp:34
Definition Infil2D.hpp:130
std::string tag
Definition Infil2D.hpp:131
Infil2DRow row
Definition Infil2D.hpp:132
[2D_INFILTRATION_OPTIONS].
Definition Infil2D.hpp:142
double infil_step
Definition Infil2D.hpp:145
One [2D_INFILTRATION] per-cell override row.
Definition Infil2D.hpp:136
int tri
Triangle index (0-based internally; 1-based in file)
Definition Infil2D.hpp:137
Infil2DRow row
Definition Infil2D.hpp:138
One infiltration specification: method + positional parameters + destination.
Definition Infil2D.hpp:114
bool dest_explicit
Definition Infil2D.hpp:125
double p[kInfil2DMaxParams]
Definition Infil2D.hpp:119
bool has_method
Definition Infil2D.hpp:117
Infil2DDest dest
Definition Infil2D.hpp:120
InfilModel method
Definition Infil2D.hpp:118
SoA storage for 2D mixed triangle/quad mesh geometry and topology.
Definition MeshData.hpp:65
Definition SurfaceStateData.hpp:64