OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
SurfaceRouter2D.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
37
38#ifndef OPENSWMM_ENGINE_2D_SURFACE_ROUTER_HPP
39#define OPENSWMM_ENGINE_2D_SURFACE_ROUTER_HPP
40
41#include "data/MeshData.hpp"
44#include "data/BoundaryData.hpp"
49#include "quality/SurfaceQuality2D.hpp" // S7
50#include "subsurface/SubsurfaceSolver.hpp" // G1: the two-zone GW kernel
52#include "infil/Infil2D.hpp"
54
55#include <memory>
56#include <functional>
57#include <array>
58#include <unordered_map>
59#include <unordered_set>
60#include <string>
61#include <vector>
62#ifdef OPENSWMM_HAS_2D
64#endif
65
66namespace openswmm::runoff {
68}
69namespace openswmm {
71struct HeatState;
72namespace climate {
73struct ClimateState;
74}
75class Router;
76class SWMMEngine;
77}
78
79namespace openswmm::twoD {
82
87public:
93 SurfaceRouter2D() = default;
100 ~SurfaceRouter2D() = default;
101
102 // Non-copyable, movable
122
152 void initialize(SimulationContext& ctx);
178 const ChannelGroundState& channelGround() const noexcept { return channel_ground_; }
190 ChannelGroundState& channelGround() noexcept { return channel_ground_; }
225 void setJointSourceStage(SimulationContext& ctx, CommonSourceStage& stage, Router& hydraulic);
262 std::string saveCheckpoint(const SimulationContext& ctx, const std::string& path) const;
275 std::string loadCheckpoint(SimulationContext& ctx, const std::string& path);
276
305 void step(SimulationContext& ctx, double dt, double t);
306
326 void updateOutfallsPreRouting(SimulationContext& ctx, double dt = 0.0);
327
354 void advancePostRouting(SimulationContext& ctx, double dt, double t);
355
370
387
400 double reportWeight(double report_ms) const noexcept;
401
417 void bookGageRates(const SimulationContext& ctx, double runoff_start_s);
418
432 void reportRainfall(const SimulationContext& ctx, double report_date,
433 std::vector<double>& out) const;
434
447 const std::vector<double>& reportRainCumulative(double report_ms) const noexcept {
448 return report_rain_ms_ == report_ms ? report_rain_cum_ : rain_cum_;
449 }
450
461 const std::vector<double>& reportOldDepth() const noexcept { return report_old_depth_; }
471 const std::vector<double>& reportOldHead() const noexcept { return report_old_head_; }
472
491 void finalize(SimulationContext& ctx);
492
500 bool isActive() const noexcept { return active_; }
510 void prepareLidStep(SimulationContext&, double dt, double evaporation);
511
523 const std::vector<std::string>& threadWarnings() const noexcept { return thread_warnings_; }
524
543 std::vector<std::pair<int, double>>& out) const;
544
555 void prepareForEdit();
556
570 const MeshData& mesh() const noexcept { return mesh_; }
571
585 MeshData& mesh() noexcept { return mesh_; }
586
600 const SurfaceStateData& state() const noexcept { return state_; }
601
615 SurfaceStateData& state() noexcept { return state_; }
616
627 double surfaceReactionLoss(int row) const noexcept;
628
641 const SolverOptions2D& options() const noexcept { return options_; }
642
655 SolverOptions2D& options() noexcept { return options_; }
656
670 const BoundaryData& boundary() const noexcept { return boundary_; }
671
685 BoundaryData& boundary() noexcept { return boundary_; }
686
698 bool runtimeCpuAvailable() const noexcept;
706 RuntimeSources& runtimeSources() noexcept { return state_.runtime_sources; }
713 bool commonSourceAttached() const noexcept { return common_stage_ != nullptr; }
720 const CommonSourceStage* commonSourceStage() const noexcept { return common_stage_; }
727 bool runtimeWaterCheckpointing() const noexcept;
733 bool runtimeBoundaryCheckpointing() const noexcept;
742 bool outfallTailwaterCheckpointing() const noexcept {
743 return joint_hydraulic_ && !outfall_exchange_.points_.empty();
744 }
745
755 const OutfallExchange& outfallExchange() const noexcept { return outfall_exchange_; }
769 std::string validateRuntimeWater(const RuntimeSources&, const RuntimeSources&,
770 const RuntimeForcings&, double time,
771 const BoundaryData* boundary = nullptr) const;
779 bool runtimeActive() const noexcept {
780 return state_.runtime_sources.active() || subsurface_.runtimeSources().active() ||
781 !boundary_.runtime_original.empty() || state_.runtime_forcings.active();
782 }
783
792 double nextRuntimeTime(double now) const noexcept {
793 return std::min({state_.runtime_sources.nextTime(now),
794 subsurface_.runtimeSources().nextTime(now),
795 state_.runtime_forcings.nextTime(now)});
796 }
797
805 void expireRuntime(double now) {
806 state_.runtime_sources.expire(now);
807 subsurface_.runtimeSources().expire(now);
808 state_.runtime_forcings.expire(now);
809 }
810
824 void invalidateBoundaryNames() noexcept { boundary_names_resolved_ = false; }
825
839 if (render_dirty_)
840 refreshRenderFields();
841 }
842
859 Infil2D& infil() noexcept { return infil_; }
870 const Infil2D& infil() const noexcept { return infil_; }
871
887 GwTransportData& gwTransport() noexcept { return gw_; }
899 const GwTransportData& gwTransport() const noexcept { return gw_; }
913 SurfaceQuality2D& surfaceQuality() noexcept { return surface_quality_; }
925 const SurfaceQuality2D& surfaceQuality() const noexcept { return surface_quality_; }
926
940 SubsurfaceConfig& aquiferConfig() noexcept { return aquifer_cfg_; }
951 const SubsurfaceConfig& aquiferConfig() const noexcept { return aquifer_cfg_; }
963 std::vector<std::string>& aquiferNodeNames() noexcept { return aquifer_node_names_; }
975 const std::vector<std::string>& aquiferNodeNames() const noexcept {
976 return aquifer_node_names_;
977 }
978
992 std::vector<std::string>& aquiferLinkNames() noexcept { return aquifer_link_names_; }
1004 const std::vector<std::string>& aquiferLinkNames() const noexcept {
1005 return aquifer_link_names_;
1006 }
1007
1020 SubsurfaceSolver& subsurface() noexcept { return subsurface_; }
1032 const SubsurfaceSolver& subsurface() const noexcept { return subsurface_; }
1033
1060 const std::vector<double>& subcatchRecharge() const noexcept { return subcatch_recharge_; }
1074 void drainSubcatchRecharge(std::vector<double>& out) {
1075 out = subcatch_recharge_;
1076 std::fill(subcatch_recharge_.begin(), subcatch_recharge_.end(), 0.0);
1077 }
1078
1088 const std::vector<int>& cellSubcatchment() const noexcept { return cell_subcatch_; }
1089
1096 double infiltrationElapsed() const noexcept { return infil_elapsed_; }
1108 void restoreInfiltration(const std::vector<double>& cumulative, double elapsed) {
1109 infil_cum_applied_ = cumulative;
1110 infil_elapsed_ = elapsed;
1111 }
1112
1119 const std::vector<double>& infilCumulative() const noexcept { return infil_cum_applied_; }
1120
1137 const std::vector<double>& couplingCumulative() const noexcept { return coupling_cum_applied_; }
1138
1152 const std::vector<double>& rainCumulative() const noexcept { return rain_cum_; }
1153
1164 const RainfallInterpolator& rainfallInterpolator() const noexcept { return interp_; }
1165
1190 std::vector<PendingInitialQualityRow>& pendingInitialQualityRows() noexcept {
1191 return pending_iq_rows_;
1192 }
1193
1202 std::vector<PendingInitialBedQualityRow>& pendingInitialBedQualityRows() noexcept {
1203 return pending_ibq_rows_;
1204 }
1205
1214 std::vector<PendingBoundaryQualityRow>& pendingBoundaryQualityRows() noexcept {
1215 return pending_bq_rows_;
1216 }
1217
1226 std::vector<PendingBoundaryRow>& pendingBCRows() noexcept { return pending_bc_rows_; }
1236 const std::vector<PendingBoundaryRow>& pendingBCRows() const noexcept {
1237 return pending_bc_rows_;
1238 }
1239
1259 std::vector<PendingEdgeConveyanceRow>& pendingEdgeConveyanceRows() noexcept {
1260 return pending_edge_conveyance_rows_;
1261 }
1262
1271 const std::vector<PendingEdgeConveyanceRow>& pendingEdgeConveyanceRows() const noexcept {
1272 return pending_edge_conveyance_rows_;
1273 }
1274
1284 double totalVolume() const;
1285
1295 double totalExchangeFlow() const;
1296#ifdef OPENSWMM_HAS_2D
1305 long lastSolverSteps() const { return solver_ ? solver_->last_num_steps() : 0; }
1312 double lastSolverStepSize() const { return solver_ ? solver_->last_step_size() : 0.0; }
1323 ISurfaceSolver::RunStats runStats() const {
1324 return solver_ ? solver_->run_stats() : ISurfaceSolver::RunStats{};
1325 }
1326#else
1333 long lastSolverSteps() const { return 0; }
1340 double lastSolverStepSize() const { return 0.0; }
1341#endif
1352 const std::string& backendName() const noexcept { return backend_name_; }
1353
1354private:
1356 struct RestartState;
1368 std::string checkpointBytes(const SimulationContext&, std::string&) const;
1397 std::string loadCheckpointBytes(
1398 SimulationContext&, std::string, const std::array<double, 6>* engine_boundary = nullptr,
1399 const std::vector<double>* engine_rainfall = nullptr,
1400 const double* engine_storage = nullptr, bool engine_routed = false,
1401 const std::function<void(const runoff::SourceWaterDriver&)>* validate_source = nullptr,
1402 const std::function<void()>* before_install = nullptr, double* inspect_source_end = nullptr,
1403 const climate::ClimateState* prepared_climate = nullptr,
1404 const HeatState* prepared_heat = nullptr);
1416 void attachCommonSourceStage(SimulationContext&, CommonSourceStage&, Router*);
1423 bool standaloneRk2Checkpointing() const noexcept;
1432 void attachStandaloneRk2Checkpoint(SimulationContext&);
1442 std::string standaloneRk2Boundary(const SimulationContext&) const;
1452 void configureSnowGroundContacts();
1463 void checkJointRoutingStep(const SimulationContext&, double dt, double start) const;
1464 Router* joint_hydraulic_ = nullptr; // externally owned, stable lifetime
1474 static double couplingSyncSpan(const SimulationContext&, const SolverOptions2D&);
1475 CommonSourceStage* common_stage_ = nullptr;
1476 bool checkpoint_owned_initialization_ = false; // scoped explicit native builder
1477 SimulationContext* source_context_ = nullptr;
1478 std::string source_router_model_;
1479 bool source_boundary_ready_ = false;
1494 std::string sourceBoundary(const SimulationContext& ctx) const;
1505 std::string sourceRouterModel(const SimulationContext& ctx) const;
1520 void drainPendingRows();
1521
1522 MeshData mesh_;
1523 SurfaceStateData state_;
1524 ChannelGroundState channel_ground_;
1525 SolverOptions2D options_;
1526 BoundaryData boundary_;
1527 std::vector<std::string> thread_warnings_;
1528 std::string backend_name_;
1529
1533 Infil2D infil_;
1534
1538 double infil_elapsed_ = 0.0;
1539
1545 std::vector<double> infil_cum_applied_;
1546
1551 std::vector<double> coupling_cum_applied_;
1552
1556 std::vector<int> cell_subcatch_;
1557 std::vector<double> subcatch_recharge_;
1558
1560 GwTransportData gw_;
1561 SurfaceQuality2D surface_quality_;
1562
1567 SubsurfaceConfig aquifer_cfg_;
1568 std::vector<std::string> aquifer_node_names_;
1569 std::vector<std::string> aquifer_link_names_;
1570 SubsurfaceSolver subsurface_;
1573 std::vector<GwLinkShare> aquifer_link_shares_;
1576 std::vector<int> aquifer_link_ids_;
1577
1580 std::vector<double> rain_cum_;
1581
1583 std::vector<PendingBoundaryRow> pending_bc_rows_;
1584 std::vector<PendingInitialQualityRow> pending_iq_rows_;
1585 std::vector<PendingInitialBedQualityRow> pending_ibq_rows_;
1586 std::vector<PendingBoundaryQualityRow> pending_bq_rows_;
1587
1591 std::vector<PendingEdgeConveyanceRow> pending_edge_conveyance_rows_;
1592
1593 std::vector<CouplingPoint> coupling_points_;
1594 OutfallExchange outfall_exchange_;
1595 bool outfall_state_changed_ = false;
1599 std::vector<CouplingPoint> node_coupling_points_;
1602 std::vector<int> coupling_head_cells_;
1606 std::vector<int> pond_track_ptr_;
1607 std::vector<int> pond_track_cell_;
1608 std::vector<double> pond_track_share_;
1609 std::vector<double> pond_chamber_ft2_;
1612 std::vector<double> node_pond_area_m2_;
1626 void updateTrackingPonds(SimulationContext& ctx, double dt);
1639 void publishEqualizeAreas(const SimulationContext& ctx, double window);
1643 std::vector<double> node_row_conc_;
1654 void publishNodeRows(const SimulationContext& ctx);
1673 void applyAgingAndReactions(SimulationContext& ctx, double dt);
1674 std::vector<double> react_phi_, react_a_, react_dx_;
1675
1677 double co_refresh_elapsed_ = 0.0;
1683 double co_render_elapsed_ = 0.0;
1684 bool render_dirty_ = false;
1687 std::vector<double> render_eta_;
1692 std::vector<int> bc_nonwall_slots_;
1695 bool bc_nonwall_dirty_ = true;
1698 std::unordered_set<int> mb_seen_nodes_;
1700 double co_forcing_elapsed_ = 0.0;
1701 bool co_forcing_first_ = true;
1731 void coAdvanceStep(SimulationContext& ctx, double dt, double t);
1749 void publishLinkCoupling(SimulationContext& ctx);
1768 double linkRowConc(const SimulationContext& ctx, int link, int s,
1769 const SubsurfaceTransportState& tr) const;
1788 void flushAquiferNodeSpecies(SimulationContext& ctx);
1802 bool refreshDue(const SimulationContext& ctx, double dt) const;
1814 void refreshRenderFields();
1815
1816 bool active_ = false;
1817 double sim_time_ = 0.0;
1819 double pending_dt_ = 0.0;
1820
1828 std::vector<double> report_old_depth_;
1829 std::vector<double> report_old_head_;
1830 double report_window_old_ms_ = 0.0;
1831 double report_window_new_ms_ = 0.0;
1832 bool report_old_valid_ = false;
1833
1837 std::vector<double> ramp_prev_head_;
1838 double ramp_prev_span_ = 0.0;
1839
1842 double prev_boundary_cum_ = 0.0;
1843 double prev_boundary_in_ = 0.0, prev_boundary_out_ = 0.0;
1844
1848 std::vector<double> window_outfall_accum_;
1856 void resetWindowAccumulators();
1857
1859 double last_t_ = 0.0;
1860
1864 bool boundary_names_resolved_ = false;
1865
1871 double bc_stage_scale_ = 1.0;
1872
1880 double bc_stage_ts_scale_ = 1.0;
1881
1886 double bc_flow_scale_ = 1.0;
1887#ifdef OPENSWMM_HAS_2D
1891 std::unique_ptr<ISurfaceSolver> solver_;
1892#endif
1893
1908 void updateRainfall(SimulationContext& ctx);
1909
1928 void gageRatesToCells(const SimulationContext& ctx, const std::vector<double>& rates,
1929 std::vector<double>& out) const;
1930
1934 RainfallInterpolator interp_;
1935
1939 std::vector<double> rain_gage_last_;
1940
1945 std::vector<double> gage_rate_, gage_cum_, gage_window_depth_, gage_window_rate_;
1946 double gage_since_ = 0.0;
1947 // Preserve the integral at the next report boundary before the runoff
1948 // clock moves beyond it. Only one gage row and one cell row are retained.
1949 std::vector<double> gage_report_depth_, report_rain_cum_;
1950 double report_rain_ms_ = -1.0;
1951
1972 void resolveBoundaryValues(SimulationContext& ctx, double t);
1973
1995 void accumulateMassBalance(SimulationContext& ctx, double dt);
1996};
1997
1998} // namespace openswmm::twoD
1999
2000#endif // OPENSWMM_ENGINE_2D_SURFACE_ROUTER_HPP
Structure-of-Arrays (SoA) storage for 2D mesh boundary conditions.
Coupled finite thermal solves for channels and shared ground columns.
U4 (2026-09-07) — authoring state for subsurface (groundwater) transport: [GW_TRANSPORT_OPTIONS],...
Backend-neutral interface for the 2D surface-routing time integrator.
Per-cell infiltration for the 2D overland-flow mesh (track I).
Structure-of-Arrays (SoA) storage for 2D triangular mesh geometry.
Orifice-equation exchange between 2D surface and SWMM nodes.
Routing-step reservation and application of outfall exchanges.
Parse-time scratch rows for [2D_BOUNDARY_CONDITIONS] and [2D_EDGE_CONVEYANCE] input sections.
Static per-cell weights mapping raingage rainfall onto the 2D mesh.
Configuration options for the 2D surface routing solver.
G-steps 3, 6-12, 16 — the two-zone groundwater kernel: saturated FV update, lateral Darcy,...
S7 (2026-09-19) — cell coverages, buildup, washoff and street sweeping on the 2D overland surface.
Structure-of-Arrays (SoA) storage for 2D surface routing state.
Top-level routing orchestrator.
Definition Routing.hpp:101
Owned completed-source water/snow and conservative-pollutant trial driver. Context and kernel histori...
Definition SourceWaterDriver.hpp:83
Definition ChannelGround.hpp:29
Definition CommonSourceStage.hpp:44
Owns per-cell infiltration parameters, kernel state and held rates.
Definition Infil2D.hpp:175
Definition OutfallExchange.hpp:24
Builds and applies static rainfall-interpolation weights for the mesh.
Definition RainfallInterpolator.hpp:60
Definition SourceResultHistory.hpp:41
The two-zone kernel. Owned by SurfaceRouter2D; driven by the marcher's tier hooks.
Definition SubsurfaceSolver.hpp:128
The S7 store: authored rows, resolved per-cell coverages and state, and the per-species ledgers.
Definition SurfaceQuality2D.hpp:125
~SurfaceRouter2D()=default
Destroy owned router members and release solver/plugin resources.
const SolverOptions2D & options() const noexcept
Access solver options (read-only).
Definition SurfaceRouter2D.hpp:641
bool commonSourceAttached() const noexcept
Test whether an external common-source stage pointer is attached.
Definition SurfaceRouter2D.hpp:713
void computeCouplingConductances(const SimulationContext &ctx, std::vector< std::pair< int, double > > &out) const
Windowless-coupling stabilizer: per coupled node, the exchange head sensitivity G = Σ_points −∂Q/∂h_1...
Definition SurfaceRouter2D.cpp:2818
void resumeSourceResultHistory(SourceResultHistory &history)
Resume a saved accepted-source recorder prefix at a completed router boundary.
Definition SurfaceRouterCheckpoint.cpp:943
void advancePostRouting(SimulationContext &ctx, double dt, double t)
Post-routing hook: compute coupling exchange and advance 2D solver.
Definition SurfaceRouter2D.cpp:3194
void initializeChannelGround(SimulationContext &ctx)
Bind selected finite channel contacts after 1D heat state is seeded.
Definition SurfaceRouter2D.cpp:2078
SurfaceRouter2D & operator=(const SurfaceRouter2D &)=delete
void expireRuntime(double now)
Retire all runtime source and forcing entries at an accepted completed horizon.
Definition SurfaceRouter2D.hpp:805
SurfaceRouter2D & operator=(SurfaceRouter2D &&)=default
Replace owned router members by default move assignment.
const ChannelGroundState & channelGround() const noexcept
Borrow the shared finite channel/physical-soil thermal contact owner and cumulative J/native receipts...
Definition SurfaceRouter2D.hpp:178
const std::vector< std::string > & threadWarnings() const noexcept
Thread-count advisories produced by initialize() (THREADS above the machine limits,...
Definition SurfaceRouter2D.hpp:523
twoD::PendingBoundaryRow PendingBoundaryRow
Per-row buffer for [2D_BOUNDARY_CONDITIONS] parse output.
Definition SurfaceRouter2D.hpp:1175
std::string saveCheckpoint(const SimulationContext &ctx, const std::string &path) const
Internal router/CPU/source boundary; not a full-project hotstart.
Definition SurfaceRouterCheckpoint.cpp:962
std::vector< PendingEdgeConveyanceRow > & pendingEdgeConveyanceRows() noexcept
Borrow retained interior/exterior edge conveyance authoring rows.
Definition SurfaceRouter2D.hpp:1259
bool runtimeCpuAvailable() const noexcept
Announce that a boundary slot's TYPE changed (the API BC-type setter), so the compact non-WALL slot l...
Definition SurfaceRouter2D.cpp:3821
const std::vector< double > & infilCumulative() const noexcept
Borrow actually applied cumulative infiltration depth.
Definition SurfaceRouter2D.hpp:1119
GwTransportData & gwTransport() noexcept
U4 (2026-09-07): the [GW_*] subsurface-transport authoring rows. Reached by the parser,...
Definition SurfaceRouter2D.hpp:887
bool runtimeActive() const noexcept
Test whether any runtime surface/aquifer source, boundary override or forcing is retained.
Definition SurfaceRouter2D.hpp:779
BoundaryData & boundary() noexcept
Access per-edge boundary-condition data (mutable, for forcing/parsing).
Definition SurfaceRouter2D.hpp:685
double reportWeight(double report_ms) const noexcept
Report-time interpolation weight for the 2D snapshot blend: f = (report_ms − window_old_ms)/(window_n...
Definition SurfaceRouter2D.cpp:3422
void setSourceResultHistory(SourceResultHistory &history)
Attach a fresh borrowed accepted-source history recorder through the CPU source marcher.
Definition SurfaceRouterCheckpoint.cpp:928
const CommonSourceStage * commonSourceStage() const noexcept
Borrow the externally attached common-source stage, if any.
Definition SurfaceRouter2D.hpp:720
const SubsurfaceConfig & aquiferConfig() const noexcept
Borrow the owned aquifer authoring rows, retained in project input units.
Definition SurfaceRouter2D.hpp:951
bool outfallTailwaterCheckpointing() const noexcept
Joint checkpoints of a model with coupled outfalls carry each one's tailwater record — a distinct che...
Definition SurfaceRouter2D.hpp:742
void bookGageRates(const SimulationContext &ctx, double runoff_start_s)
Book the gage rates a runoff step starting at runoff_start_s (seconds since the run start) takes,...
Definition SurfaceRouter2D.cpp:3770
const OutfallExchange & outfallExchange() const noexcept
Coupled-outfall delivery and tailwater records (report).
Definition SurfaceRouter2D.hpp:755
void invalidateBoundaryIndex()
Mark the compact non-wall boundary index stale and refresh attached CPU boundary work lists.
Definition SurfaceRouter2D.cpp:3835
SubsurfaceConfig & aquiferConfig() noexcept
G1: the authored [2D_AQUIFER*] rows, in the user's own units. Reached by the section handlers and the...
Definition SurfaceRouter2D.hpp:940
double infiltrationElapsed() const noexcept
Read elapsed duration since the last held infiltration model rate refresh.
Definition SurfaceRouter2D.hpp:1096
long lastSolverSteps() const
Read the last surface advance's base substep count.
Definition SurfaceRouter2D.hpp:1333
const std::vector< double > & reportOldDepth() const noexcept
Cell depth (m) at the start of the sync batch that crossed the current report instant (meaningful whe...
Definition SurfaceRouter2D.hpp:461
std::vector< PendingBoundaryRow > & pendingBCRows() noexcept
Borrow retained hydraulic boundary authoring rows.
Definition SurfaceRouter2D.hpp:1226
void step(SimulationContext &ctx, double dt, double t)
Advance the 2D surface routing by one SWMM routing step.
Definition SurfaceRouter2D.cpp:2115
void drainSubcatchRecharge(std::vector< double > &out)
Move the pending recharge into out (m³ per subcatchment) and zero the accumulator....
Definition SurfaceRouter2D.hpp:1074
SubsurfaceSolver & subsurface() noexcept
The running kernel. active() is false until [2D_AQUIFER] resolves.
Definition SurfaceRouter2D.hpp:1020
void refreshRenderFieldsIfStale()
Bring the render fields (face velocity, vertex heads, output gradients, vertex render depths) up to d...
Definition SurfaceRouter2D.hpp:838
MeshData & mesh() noexcept
Access mesh data (mutable, for input parsing).
Definition SurfaceRouter2D.hpp:585
const RainfallInterpolator & rainfallInterpolator() const noexcept
Static rainfall weights built at initialize() (diagnostic inspection).
Definition SurfaceRouter2D.hpp:1164
const std::vector< double > & rainCumulative() const noexcept
Ledger-consistent cumulative rainfall volume per cell (m³).
Definition SurfaceRouter2D.hpp:1152
const std::vector< std::string > & aquiferNodeNames() const noexcept
Borrow the owned node names parallel to aquiferConfig().node_beds authoring identity.
Definition SurfaceRouter2D.hpp:975
const std::vector< double > & couplingCumulative() const noexcept
Signed cumulative coupling exchange per cell (m³).
Definition SurfaceRouter2D.hpp:1137
const std::vector< double > & reportOldHead() const noexcept
Cell head (m) at the start of that batch.
Definition SurfaceRouter2D.hpp:471
const std::vector< double > & subcatchRecharge() const noexcept
Ledger-consistent cumulative infiltrated depth per cell (m).
Definition SurfaceRouter2D.hpp:1060
const SurfaceStateData & state() const noexcept
Access surface state (read-only).
Definition SurfaceRouter2D.hpp:600
const Infil2D & infil() const noexcept
Borrow the owned per-cell infiltration authoring, held capacity and model memory.
Definition SurfaceRouter2D.hpp:870
std::vector< PendingInitialQualityRow > & pendingInitialQualityRows() noexcept
S1/S2: raw [2D_INITIAL_QUALITY] rows, resolved at initialize().
Definition SurfaceRouter2D.hpp:1190
const SurfaceQuality2D & surfaceQuality() const noexcept
Borrow the owned land-use coverage/buildup/washoff/sweeping authoring and runtime ledgers.
Definition SurfaceRouter2D.hpp:925
double totalExchangeFlow() const
Get total exchange flow (sum of coupling flows, m³/s).
Definition SurfaceRouter2D.cpp:3683
std::string validateRuntimeWater(const RuntimeSources &, const RuntimeSources &, const RuntimeForcings &, double time, const BoundaryData *boundary=nullptr) const
Validate copied runtime water proposals through the attached common-source owner.
Definition SurfaceRouter2D.cpp:3407
const SubsurfaceSolver & subsurface() const noexcept
Borrow the owned groundwater solver with SI hydraulic state, native rows and paired physical/source/L...
Definition SurfaceRouter2D.hpp:1032
twoD::PendingInitialQualityRow PendingInitialQualityRow
Definition SurfaceRouter2D.hpp:1176
void setCommonSourceStage(SimulationContext &ctx, CommonSourceStage &stage)
Internal qualification hook: externally owned stage, all cells managed, wall boundaries,...
Definition SurfaceRouterCheckpoint.cpp:768
bool runtimeBoundaryCheckpointing() const noexcept
Test whether the attached common source owns runtime boundary checkpointing.
Definition SurfaceRouter2D.cpp:3388
SurfaceQuality2D & surfaceQuality() noexcept
S7: cell coverages / buildup / washoff / sweeping (authoring + state).
Definition SurfaceRouter2D.hpp:913
std::vector< std::string > & aquiferNodeNames() noexcept
Borrow the owned node names parallel to aquiferConfig().node_beds authoring identity.
Definition SurfaceRouter2D.hpp:963
std::vector< PendingBoundaryQualityRow > & pendingBoundaryQualityRows() noexcept
Borrow retained boundary native quality authoring rows.
Definition SurfaceRouter2D.hpp:1214
double totalVolume() const
Get total 2D surface volume (sum of depth * area).
Definition SurfaceRouter2D.cpp:3665
ChannelGroundState & channelGround() noexcept
Borrow the shared finite channel/physical-soil thermal contact owner and cumulative J/native receipts...
Definition SurfaceRouter2D.hpp:190
const std::string & backendName() const noexcept
Backend label chosen by SurfaceSolverFactory at initialize() ("cpu (explicitmarcher)",...
Definition SurfaceRouter2D.hpp:1352
void initialize(SimulationContext &ctx)
Initialize the 2D module after input parsing is complete.
Definition SurfaceRouter2D.cpp:289
double surfaceReactionLoss(int row) const noexcept
Signed native surface reaction loss for the qualified RK2 owner.
Definition SurfaceRouter2D.cpp:3650
double nextRuntimeTime(double now) const noexcept
Read the earliest scheduled source/forcing transition after a given time.
Definition SurfaceRouter2D.hpp:792
std::vector< std::string > & aquiferLinkNames() noexcept
G-X4: the [2D_AQUIFER_LINKS] row names, parallel to aquiferConfig().link_rows — the writer's round-tr...
Definition SurfaceRouter2D.hpp:992
void flushPendingBatch(SimulationContext &ctx)
Flush the pending (partial) sync batch, if any.
Definition SurfaceRouter2D.cpp:3363
SurfaceRouter2D()=default
Create an inactive authoring router with empty owned physical/source state.
void restoreInfiltration(const std::vector< double > &cumulative, double elapsed)
Replace router applied-infiltration reporting and held-model elapsed accounting.
Definition SurfaceRouter2D.hpp:1108
SurfaceStateData & state() noexcept
Access surface state (mutable, for forcing).
Definition SurfaceRouter2D.hpp:615
const std::vector< PendingBoundaryRow > & pendingBCRows() const noexcept
Borrow retained hydraulic boundary authoring rows.
Definition SurfaceRouter2D.hpp:1236
Infil2D & infil() noexcept
Access the per-cell infiltration model (plan §5.5, track I).
Definition SurfaceRouter2D.hpp:859
std::vector< PendingInitialBedQualityRow > & pendingInitialBedQualityRows() noexcept
Borrow retained local-bed initial native quality authoring rows.
Definition SurfaceRouter2D.hpp:1202
SurfaceRouter2D(const SurfaceRouter2D &)=delete
const std::vector< std::string > & aquiferLinkNames() const noexcept
Borrow the owned conduit names parallel to aquiferConfig().link_rows authoring identity.
Definition SurfaceRouter2D.hpp:1004
bool runtimeWaterCheckpointing() const noexcept
Test qualification ownership for managed runtime water checkpointing.
Definition SurfaceRouter2D.cpp:3380
void finalize(SimulationContext &ctx)
Finalize the 2D module at simulation end.
Definition SurfaceRouter2D.cpp:3592
SurfaceRouter2D(SurfaceRouter2D &&)=default
Move owned router members using their ordinary default move operations.
std::string loadCheckpoint(SimulationContext &ctx, const std::string &path)
Read and stage a router component checkpoint into fresh matching attached owners.
Definition SurfaceRouterCheckpoint.cpp:1065
twoD::PendingInitialBedQualityRow PendingInitialBedQualityRow
Definition SurfaceRouter2D.hpp:1177
friend class openswmm::SWMMEngine
Definition SurfaceRouter2D.hpp:1355
void setJointSourceStage(SimulationContext &ctx, CommonSourceStage &stage, Router &hydraulic)
Internal water-only joint DW/source checkpoint, including non-outfall surface exchange and pending no...
Definition SurfaceRouterCheckpoint.cpp:784
double lastSolverStepSize() const
Read the last accepted surface base/tail step duration.
Definition SurfaceRouter2D.hpp:1340
twoD::PendingBoundaryQualityRow PendingBoundaryQualityRow
Definition SurfaceRouter2D.hpp:1178
const MeshData & mesh() const noexcept
Access mesh data (read-only).
Definition SurfaceRouter2D.hpp:570
void prepareOneShotForcing(SimulationContext &ctx)
Prepare a RESET 2D forcing to apply on the next routing step.
Definition SurfaceRouter2D.cpp:3443
bool isActive() const noexcept
Check if the 2D module is active.
Definition SurfaceRouter2D.hpp:500
void reportRainfall(const SimulationContext &ctx, double report_date, std::vector< double > &out) const
Per-cell rainfall (m/s) as the .out reports subcatchment rainfall: the source gage rate at report_dat...
Definition SurfaceRouter2D.cpp:3799
const GwTransportData & gwTransport() const noexcept
Borrow the owned groundwater quality/thermal/source authoring and resolved SI transport metadata.
Definition SurfaceRouter2D.hpp:899
SolverOptions2D & options() noexcept
Access solver options (mutable).
Definition SurfaceRouter2D.hpp:655
const BoundaryData & boundary() const noexcept
Access per-edge boundary-condition data (read-only).
Definition SurfaceRouter2D.hpp:670
twoD::PendingEdgeConveyanceRow PendingEdgeConveyanceRow
Per-row buffer for [2D_EDGE_CONVEYANCE] parse output (§11A).
Definition SurfaceRouter2D.hpp:1249
void prepareLidStep(SimulationContext &, double dt, double evaporation)
Prepare the next finite Richards LID/mesh acceptance and conduit donor budgets.
Definition SurfaceRouter2D.cpp:3171
const std::vector< int > & cellSubcatchment() const noexcept
Cell → containing subcatchment index (-1 = none). Empty unless the SUBCATCH_AQUIFER destination resol...
Definition SurfaceRouter2D.hpp:1088
const std::vector< PendingEdgeConveyanceRow > & pendingEdgeConveyanceRows() const noexcept
Borrow retained interior/exterior edge conveyance authoring rows.
Definition SurfaceRouter2D.hpp:1271
const std::vector< double > & reportRainCumulative(double report_ms) const noexcept
Rainfall volume (m³) integrated to the report boundary, excluding the part of a routing/sync window a...
Definition SurfaceRouter2D.hpp:447
void invalidateBoundaryNames() noexcept
Mark symbolic boundary names unresolved after authoring/name changes.
Definition SurfaceRouter2D.hpp:824
void updateOutfallsPreRouting(SimulationContext &ctx, double dt=0.0)
Pre-routing hook: update outfall boundaries from 2D surface heads.
Definition SurfaceRouter2D.cpp:2140
RuntimeSources & runtimeSources() noexcept
Borrow mutable runtime prescriptions/receipts for the surface owner.
Definition SurfaceRouter2D.hpp:706
void prepareForEdit()
Make the parsed mesh editable without a full initialize().
Definition SurfaceRouter2D.cpp:259
Definition Rk2RuntimeSources.hpp:19
Definition ExplicitInertialSolver.hpp:68
Definition ExchangeLaw.hpp:60
Definition ExchangeLaw.hpp:60
Runtime heat state shared by the engines (phase H1).
Definition HeatData.hpp:427
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
Definition Climate.hpp:97
SoA storage for per-edge boundary conditions.
Definition BoundaryData.hpp:73
Descriptor for a single coupling point between 2D and 1D.
Definition NodeCoupling.hpp:59
Every [GW_*] authoring row of one model.
Definition GwTransportData.hpp:187
SoA storage for 2D mixed triangle/quad mesh geometry and topology.
Definition MeshData.hpp:65
Definition PendingRows2D.hpp:116
Per-row buffer for [2D_BOUNDARY_CONDITIONS] parse output.
Definition PendingRows2D.hpp:53
Per-row buffer for [2D_EDGE_CONVEYANCE] parse output (§11A).
Definition PendingRows2D.hpp:72
One [2D_INITIAL_BED_QUALITY] row for finite local-bed porewater.
Definition PendingRows2D.hpp:104
One [2D_INITIAL_QUALITY] row (overland transport S1/S2).
Definition PendingRows2D.hpp:89
Definition RuntimeCoupling.hpp:226
Definition RuntimeCoupling.hpp:44
Definition SolverOptions2D.hpp:257
Everything the parser fills, before resolution onto cells.
Definition SubsurfaceData.hpp:391
Species mass in both aquifer zones, and where mass crossed a boundary.
Definition SubsurfaceTransportState.hpp:69
Definition SurfaceRouterCheckpoint.cpp:195
Definition SurfaceStateData.hpp:64