OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
SubsurfaceSolver.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
70
71#ifndef OPENSWMM_ENGINE_2D_SUBSURFACE_SOLVER_HPP
72#define OPENSWMM_ENGINE_2D_SUBSURFACE_SOLVER_HPP
73
74#include "SigmaColumn.hpp"
75#include "SubsurfaceData.hpp"
76
77#include <string>
78#include <vector>
79
80namespace openswmm {
81struct NodeData;
82} // namespace openswmm
83
84namespace openswmm::twoD {
85
86struct MeshData;
87struct InertialEdges;
88struct SurfaceStateData;
89struct SolverOptions2D;
90
91using openswmm::NodeData;
92
98public:
119 std::string initialize(const MeshData& mesh, const InertialEdges& edges,
120 const SolverOptions2D& opts,
121 const GwUnitFactors& uf, int n_nodes,
122 SubsurfaceConfig& cfg,
123 std::vector<std::string>& warnings);
124
125 bool active() const noexcept { return state_.active; }
126 SubsurfaceState& state() noexcept { return state_; }
127 const SubsurfaceState& state() const noexcept { return state_; }
128 const GwOptions& options() const noexcept { return options_; }
129
130 // ---- LTS hooks -------------------------------------------------------
131
135 void refreshDtCell(const MeshData& mesh, const InertialEdges& edges);
136
140 void assignTiers(double dt0, int n_tiers);
141
145 int requiredTiers(double dt0) const noexcept;
146
148 void fireGwFaces(int tier, double dt);
150 void fireGwCells(int tier, double dt, SurfaceStateData& surf);
153 void settle(SurfaceStateData& surf);
154
156 bool tierHasCells(int tier) const noexcept {
157 return tier >= 0 && tier < static_cast<int>(cells_by_tier_.size()) &&
158 !cells_by_tier_[static_cast<std::size_t>(tier)].empty();
159 }
160 bool tierHasFaces(int tier) const noexcept {
161 return tier >= 0 && tier < static_cast<int>(faces_by_tier_.size()) &&
162 !faces_by_tier_[static_cast<std::size_t>(tier)].empty();
163 }
164 int tierCount() const noexcept {
165 return static_cast<int>(cells_by_tier_.size());
166 }
167
168 const std::vector<long>& tierFirings() const noexcept { return tier_firings_; }
169
170 // ---- surface ↔ subsurface --------------------------------------------
171
174 void bookInfiltrationFromSurface(int cell, double vol_m3) noexcept;
177 double takeToSurface(int cell) noexcept;
183 const std::vector<int>& pendingSurfaceCells() const noexcept {
184 return pending_surface_;
185 }
186
188 void compactPending() noexcept;
189
195 void sampleNodeExchange(const NodeData* nodes, double dt);
196
200 const std::vector<double>& nodeExchangeVolumes() const noexcept {
201 return node_exchange_vol_;
202 }
203
204 void resetNodeExchangeVolumes() noexcept;
205
207 double storage() const noexcept { return state_.storage(); }
208
209private:
210 void resolveRows(const MeshData& mesh, const GwUnitFactors& uf,
211 SubsurfaceConfig& cfg, std::vector<std::string>& warnings);
212 void resolveClosures(std::vector<std::string>& warnings);
213 soil::Params paramsOf(int i) const noexcept;
215 void fireCell(int i, double dt, SurfaceStateData& surf);
217 double gatherLateral(int i) noexcept;
219 double gatherNode(int i) noexcept;
220 void markPendingSurface(int i) noexcept;
221
222 SubsurfaceState state_;
223 GwOptions options_;
224 std::vector<GwNodeBed> node_beds_;
225
226 const MeshData* mesh_ = nullptr;
227 const InertialEdges* edges_ = nullptr;
228 const SolverOptions2D* opts_ = nullptr;
229
230 std::vector<std::vector<int>> cells_by_tier_;
231 std::vector<std::vector<int>> faces_by_tier_;
232 std::vector<uint8_t> face_tier_;
233 std::vector<long> tier_firings_;
234 std::vector<int> pending_surface_;
235 std::vector<uint8_t> pending_flag_;
236 std::vector<int> cell_nface_;
237 std::vector<double> node_exchange_vol_;
238 bool accumulators_pending_ = false;
239
242 std::vector<int> subcatch_outlet_node_;
245 std::vector<int> cell_subcatch_;
246};
247
248} // namespace openswmm::twoD
249
250#endif // OPENSWMM_ENGINE_2D_SUBSURFACE_SOLVER_HPP
G-steps 4 and 5 — closure B: the σ-coordinate explicit unsaturated column with a moving lower boundar...
G-step 1 — state, parameters and options for the two-zone groundwater kernel (TWO_ZONE_GROUNDWATER_EX...
The two-zone kernel. Owned by SurfaceRouter2D; driven by the marcher's tier hooks.
Definition SubsurfaceSolver.hpp:97
void refreshDtCell(const MeshData &mesh, const InertialEdges &edges)
Definition SubsurfaceSolver.cpp:306
void fireGwCells(int tier, double dt, SurfaceStateData &surf)
Gather + closure + node/deep/ET/Dunne for the cells of one tier.
Definition SubsurfaceSolver.cpp:883
bool tierHasCells(int tier) const noexcept
True when the tier's cell list is non-empty.
Definition SubsurfaceSolver.hpp:156
SubsurfaceState & state() noexcept
Definition SubsurfaceSolver.hpp:126
const std::vector< int > & pendingSurfaceCells() const noexcept
Definition SubsurfaceSolver.hpp:183
const std::vector< long > & tierFirings() const noexcept
Per-tier firing counts — the G-A telemetry (swmm_gw2d_get_tier_histogram).
Definition SubsurfaceSolver.hpp:168
double takeToSurface(int cell) noexcept
Definition SubsurfaceSolver.cpp:581
int tierCount() const noexcept
Definition SubsurfaceSolver.hpp:164
const std::vector< double > & nodeExchangeVolumes() const noexcept
Definition SubsurfaceSolver.hpp:200
const SubsurfaceState & state() const noexcept
Definition SubsurfaceSolver.hpp:127
double storage() const noexcept
Storage now, for the continuity ledger.
Definition SubsurfaceSolver.hpp:207
void assignTiers(double dt0, int n_tiers)
Definition SubsurfaceSolver.cpp:396
bool tierHasFaces(int tier) const noexcept
Definition SubsurfaceSolver.hpp:160
void fireGwFaces(int tier, double dt)
Lateral Darcy on the faces of one tier; books ±ΔV into eacc_L/R.
Definition SubsurfaceSolver.cpp:442
void compactPending() noexcept
Definition SubsurfaceSolver.cpp:595
void settle(SurfaceStateData &surf)
Definition SubsurfaceSolver.cpp:891
const GwOptions & options() const noexcept
Definition SubsurfaceSolver.hpp:128
bool active() const noexcept
Definition SubsurfaceSolver.hpp:125
int requiredTiers(double dt0) const noexcept
Definition SubsurfaceSolver.cpp:385
std::string initialize(const MeshData &mesh, const InertialEdges &edges, const SolverOptions2D &opts, const GwUnitFactors &uf, int n_nodes, SubsurfaceConfig &cfg, std::vector< std::string > &warnings)
Resolve the authored rows onto cells, seed state, size the accumulators.
Definition SubsurfaceSolver.cpp:207
void resetNodeExchangeVolumes() noexcept
Zero the per-node ledger at the start of a routing batch.
Definition SubsurfaceSolver.cpp:508
void bookInfiltrationFromSurface(int cell, double vol_m3) noexcept
Definition SubsurfaceSolver.cpp:567
void sampleNodeExchange(const NodeData *nodes, double dt)
Definition SubsurfaceSolver.cpp:512
Definition NodeCoupling.cpp:16
Definition NodeCoupling.cpp:16
Structure-of-Arrays storage for all nodes.
Definition NodeData.hpp:130
[2D_AQUIFER_OPTIONS]. Defaults are the plan's starred values.
Definition SubsurfaceData.hpp:87
Project-unit → SI multipliers for the four kinds of aquifer number.
Definition SubsurfaceData.hpp:226
Canonical unique interior-edge layout + per-cell incidence for the local-inertial scheme.
Definition InertialEdges.hpp:61
SoA storage for 2D mixed triangle/quad mesh geometry and topology.
Definition MeshData.hpp:67
Configuration for the 2D surface routing solver.
Definition SolverOptions2D.hpp:208
Everything the parser fills, before resolution onto cells.
Definition SubsurfaceData.hpp:234
Per-cell resolved parameters and state (SoA).
Definition SubsurfaceData.hpp:146
Definition SurfaceStateData.hpp:59
Definition SoilCharacteristic.hpp:90