44#ifndef OPENSWMM_ENGINE_2D_EXPLICIT_INERTIAL_SOLVER_HPP
45#define OPENSWMM_ENGINE_2D_EXPLICIT_INERTIAL_SOLVER_HPP
72struct Rk2CheckpointBinding;
74class SubsurfaceSolver;
75class CommonSourceStage;
76class ChannelGroundState;
77class SourceResultHistory;
78class EngineSourceResultHistory;
133 double advance(
double t_current,
double t_target)
override;
140 return initialized_ ? t_last_sync_ : -1.0;
293 return row >= 0 && std::size_t(row) < rk_reacted_.size() ? rk_reacted_[row] : 0;
343 RunStats
run_stats() const noexcept override;
382 std::string checkpointBytes(std::string& bytes)
const;
391 std::string rk2CheckpointProfile()
const;
398 std::string rk2CheckpointModel()
const;
418 std::string rk2CheckpointBytes(std::string&)
const;
427 std::string loadRk2CheckpointBytes(std::string);
443 std::string loadRk2CheckpointBytes(
447 const std::function<
void()>*,
bool inspect);
470 std::string loadCheckpointBytes(
471 std::string bytes,
const std::array<double, 10>* router_boundary =
nullptr,
472 const std::vector<double>* pending_outfalls =
nullptr,
474 const std::function<
void()>* before_install =
nullptr,
475 const std::vector<int>* boundary_slots =
nullptr,
double* inspect_source_end =
nullptr);
485 void refreshSourceResultBoundary();
486 double advanceImpl(
double current,
double target);
499 std::string rk2ThermalProfileError()
const;
508 void advanceRk2Thermal(
double seconds,
double sample_time);
521 void advanceRk2BedContact(
double seconds);
536 void advanceRk2Snow(
double seconds,
double start);
550 void advanceRk2SurfaceReactions(
double seconds);
561 std::vector<int> rk_reaction_rows_;
562 std::vector<double> rk_decay_, rk_reacted_, rk_reacted_reported_;
563 std::string rk_reaction_identity_;
573 void reconstructAll();
590 void settleAccumulators();
612 void syncAndRebuild(
double t);
643 void fireFaces(
const std::vector<int>& faces,
double dt_f,
bool global_step =
false);
665 void fireCells(
const std::vector<int>& cells,
double dt_c,
bool tier0);
667 template <
bool kSwe,
bool kFuse>
696 void fireCellsImpl(
const std::vector<int>& cells,
double dt_c,
bool tier0);
714 void runMacroCycle(
double dt0,
int nsub,
double time);
720 void refreshConveyance();
726 std::vector<double> q_;
729 std::vector<double> qcx_, qcy_;
740 bool has_quads_ =
false;
744 std::vector<int> wall_ptr_, wall_slot_;
752 double swe_bc_dqx_ = 0.0, swe_bc_dqy_ = 0.0;
756 bool second_order_ =
false;
757 bool rk_transport_stage_ =
false;
758 std::vector<double> rk_stage_mass_, rk_stage_volume_;
761 std::vector<double> gex_, gey_, gux_, guy_, gvx_, gvy_;
762 std::vector<double> rk_v0_, rk_qx0_, rk_qy0_;
765 std::vector<double> rk_inf0_, rk_bc0_, rk_ex0_, rk_drawn0_, rk_cpl0_;
777 void computeLimitedGradientsSwe();
779 std::vector<int> wall_drag_slots_;
780 double wall_drag_energy_ = 0;
781 void applyMomentumPhysics(
double seconds);
782 double runMomentumStep(
double limit,
double time);
799 void runRk2Step(
double dt,
double time);
812 void runRk2Step(
double dt,
double time,
unsigned thermal_depth);
820 bool surfaceLatentCooling() const noexcept;
821 struct Rk2BoundarySignal {
822 int slot = -1, table = -1;
827 std::shared_ptr<const Table> curve{};
830 std::vector<Rk2BoundarySignal> rk_boundary_signals_;
831 double rk_boundary_anchor_ = 0;
838 bool front_rebuild_ =
false;
839 std::vector<uint8_t> frontier_;
840 bool front_breach_ =
false;
841 double h_on_front_ = 0.0;
844 std::vector<double> dw_slope_;
866 void fireFacesInertial(
const std::vector<int>& faces,
double dt_f,
bool global_step);
886 void fireFacesSwe(
const std::vector<int>& faces,
double dt_f,
bool global_step);
905 void fireFacesDiffusive(
const std::vector<int>& faces,
double dt_f,
bool global_step);
926 void bookFaceSpecies(
int e,
int a,
int b,
double dM,
double hf,
double dt_f,
927 bool global_step)
noexcept;
952 double boundaryFluxSwe(std::size_t k,
int i,
double dt_c,
953 const std::array<double, 4>* held =
nullptr);
965 void refreshDiffusiveSlopes();
966 std::vector<uint8_t> cell_active_;
967 std::vector<int> active_cells_;
972 std::vector<int> active_faces_;
973 std::vector<uint8_t> pin_t0_;
984 std::vector<uint8_t> rebuild_seed_;
985 std::vector<double> rebuild_dt_cell_;
988 std::vector<double> rebuild_dt_partial_;
990 std::vector<uint8_t> tier_;
991 std::vector<uint8_t> face_tier_;
996 std::vector<double> face_accum_;
997 std::size_t face_accum_stride_ = 2;
1009 std::vector<double> sacc_L_;
1010 std::vector<double> sacc_R_;
1015 bool species_on_ =
false;
1030 double donorConc(
int s,
int cell)
const noexcept;
1053 void sinkMassAtCellConc(
int i,
double dv_m3, std::vector<double>& ledger,
1054 double* per_point_ledger =
nullptr) noexcept;
1058 bool applyCellSources(
int cell,
double dt,
double* boundary_donor =
nullptr);
1059 bool applyPlainCellSources(
int cell,
double dt);
1061 bool plain_sources_ = false;
1062 bool applyRuntimeSources(
int cell,
double dt);
1063 struct CellSourceStep {
1064 double area_dt = 0, rain = 0, coupling = 0, available = 0,
infil = 0, evap = 0, out = 0,
1065 final_volume = 0, requested_infil = 0;
1066 double* ledger =
nullptr;
1068 bool prepareCellSources(
int cell,
double dt, CellSourceStep& source);
1069 void mixCellSourceRow(
int cell,
int row,
double& mass,
const CellSourceStep&);
1079 void prepareChannelGround(
double seconds);
1080 void applyCellSourceRow(
int cell,
int row,
double& mass,
const CellSourceStep& source);
1081 enum class SourceLedger {
1104 void bookSourceLedger(SourceLedger ledger,
int species,
double mass)
noexcept;
1113 void flushSourceLedgers();
1121 int sourceThread() const noexcept;
1124 std::vector<
double> source_ledgers_;
1125 std::
size_t source_ledger_stride_ = 0;
1126 ChannelGroundState* channel_ground_ =
nullptr;
1127 std::vector<CellSourceStep> channel_sources_;
1128 std::vector<uint8_t> channel_source_ready_, channel_temperature_mixed_;
1135 bool accumulators_pending_ = false;
1136 std::vector<std::vector<
int>> cells_by_tier_;
1137 std::vector<std::vector<
int>> edges_by_tier_;
1139 std::vector<
int> bc_cell_;
1140 std::vector<
int> bc_slot_;
1141 std::vector<
int> gw_row_map_;
1142 std::vector<
double> bc_accum_;
1144 std::vector<
double> bc_q_;
1159 std::vector<
double> exch_;
1160 std::vector<
double> node_drawn_;
1167 double spill_deficit_ = 0.0;
1185 std::vector<double> exch_head_slope_;
1186 double exch_tau_ = 0.0;
1188 double t_last_sync_ = 0.0;
1193 bool checkpoint_ready_ =
false;
1194 bool joint_checkpoint_ =
false;
1203 std::string checkpointBoundary()
const;
1224 void captureSourceResults();
1225 double source_phase_end_ = 0.0;
1226 int cycles_since_rebuild_ = 1000;
1238 void lazySourcesOnly(
double t);
1239 long substeps_run_ = 0;
1240 long face_passes_ = 0;
1241 long last_steps_ = 0;
1242 double last_dt_ = 0.0;
1243 bool initialized_ =
false;
1249 std::vector<std::pair<double, int>> telemetry_;
1250 std::string telemetry_path_;
1254 double active_frac_min_ = 1.0e30;
1255 double active_frac_max_ = -1.0e30;
1256 double active_frac_sum_ = 0.0;
1257 long active_samples_ = 0;
1259 std::array<long, 8> tier_occupancy_{};
1271 SubsurfaceSolver* gw_ =
nullptr;
Immutable groundwater source series in elapsed simulation time.
Backend-neutral interface for the 2D surface-routing time integrator.
Unique interior-edge structure for the local-inertial momentum DOFs.
Reaction kinetics integration over one reaction step (phase R3): EUL / RK5 (Cash–Karp) / ROS2 / BDF2 ...
Configuration options for the 2D surface routing solver.
Definition CompletedSourceArchive.hpp:25
Owned completed-source water/snow and conservative-pollutant trial driver. Context and kernel histori...
Definition SourceWaterDriver.hpp:83
Definition ReactionIntegrator.hpp:89
Definition ChannelGround.hpp:29
Definition CommonSourceStage.hpp:44
Definition EngineSourceResultHistory.hpp:23
Definition EngineSourceResultStream.hpp:27
Definition ExplicitInertialSolver.hpp:80
void finalize() override
Detach source/checkpoint recorders, settle CPU surface packets and release marching work lists.
Definition ExplicitInertialSolver.cpp:4786
void reinitialize(double t0) override
Reconstruct externally edited volume after discarding stale surface momentum/side packets.
Definition ExplicitInertialSolver.cpp:4620
void setCommonSourceStage(CommonSourceStage &stage)
Internal qualification adapter; owned externally and attached at time zero.
Definition ExplicitInertialSolver.cpp:4735
void publishMomentumVelocity()
Definition ExplicitInertialSolver.cpp:4151
friend class SurfaceRouter2D
Definition ExplicitInertialSolver.hpp:373
double completedSourceTime() const noexcept override
Read the finest accepted source synchronization horizon.
Definition ExplicitInertialSolver.hpp:139
bool is_initialized() const noexcept override
Read the marcher's stored lifecycle activation flag.
Definition ExplicitInertialSolver.hpp:350
void setChannelGround(ChannelGroundState &)
Attach a borrowed active channel/soil finite thermal owner before first advance.
Definition ExplicitInertialSolver.cpp:4722
std::string saveCheckpoint(const std::string &path) const
Internal accepted CPU source boundary or standalone water-only RK2 component checkpoint; not a whole-...
Definition ExplicitInertialCheckpoint.cpp:649
void resumeSourceResultHistory(SourceResultHistory &history)
Bind a saved exact source-history prefix after a marcher restore.
Definition ExplicitInertialSolver.cpp:4776
void pinExternalSourceCells(const std::vector< int > &cells)
External outfall transfers keep these cells and their halo on tier zero.
Definition ExplicitInertialSolver.cpp:4704
const std::vector< double > & last_coupling_exchange() const noexcept override
Borrow the last advance's integrated live junction exchange.
Definition ExplicitInertialSolver.hpp:358
void refreshBoundaries()
Refresh changed perimeter topology between completed advances.
Definition ExplicitInertialSolver.cpp:4638
void setSubsurface(SubsurfaceSolver *gw) noexcept
Attach (or detach, with nullptr) the groundwater kernel. Must be called before the first advance and ...
Definition ExplicitInertialSolver.hpp:1285
double advance(double t_current, double t_target) override
Advance one accepted CPU surface/groundwater window to its target horizon.
Definition ExplicitInertialSolver.cpp:4306
long last_num_steps() const noexcept override
Read base substeps executed by the most recent accepted advance.
Definition ExplicitInertialSolver.hpp:328
RunStats run_stats() const noexcept override
Snapshot cumulative CPU marcher work and rebuild-sampled active/tier statistics.
Definition ExplicitInertialSolver.cpp:4837
double spillDeficit() const noexcept
C3: cumulative spill volume (m³) the coupled nodes could not supply from their ponded storage....
Definition ExplicitInertialSolver.hpp:369
void resolveRk2BoundarySignals(double time)
Evaluate owned project boundary signals at the current coupled stage time/state.
Definition ExplicitInertialSolver.cpp:3168
void setSourceResultHistory(SourceResultHistory &history)
Capture initial state and every finest accepted source interval, after all due groundwater firings/no...
Definition ExplicitInertialSolver.cpp:4749
void resyncFromVolumes(double t0) override
Reconstruct head/depth after authoritative external volume transfers without losing momentum.
Definition ExplicitInertialSolver.cpp:4692
double surfaceReactionLoss(int row) const noexcept
Read one row's cumulative qualified RK2 native reaction loss.
Definition ExplicitInertialSolver.hpp:292
const InertialEdges & inertialEdges() const noexcept
The unique interior-edge topology this marcher built. Exposed so the groundwater kernel can put its l...
Definition ExplicitInertialSolver.hpp:1309
std::string configureRk2Reactions(const SimulationContext &)
Configure the standalone coupled RK2 surface reaction owner at time zero.
Definition ExplicitInertialSolver.cpp:3859
void initialize(MeshData &mesh, SurfaceStateData &state, SolverOptions2D &opts) override
Prepare the CPU finite-volume marcher from authoritative surface volume and resolved model.
Definition ExplicitInertialSolver.cpp:185
std::string loadCheckpoint(const std::string &path)
Restore a component checkpoint into fresh initialized matching exclusive owners.
Definition ExplicitInertialCheckpoint.cpp:712
void refreshSubsurfaceRows()
Rebuild exact-name native surface-to-groundwater row mapping after owners are prepared.
Definition ExplicitInertialSolver.cpp:507
friend class openswmm::SWMMEngine
Definition ExplicitInertialSolver.hpp:374
friend struct ExplicitInertialSolverTestAccess
Definition ExplicitInertialSolver.hpp:372
double last_step_size() const noexcept override
Read the most recent accepted base or tail duration.
Definition ExplicitInertialSolver.hpp:334
void setExchangeHeadSlopes(std::vector< double > slopes)
Experimental (OPENSWMM_2D_HEAD_RAMP): per-coupling-point 1D head trend slope (m/s,...
Definition ExplicitInertialSolver.hpp:1182
std::string configureRk2BoundarySignals(SimulationContext &, double stage_scale, double flow_scale)
Resolve owned cursor-free surface boundary forcing for the fresh coupled RK2 owner.
Definition ExplicitInertialSolver.cpp:3068
Abstract time integrator for the 2D surface-routing ODE system.
Definition ISurfaceSolver.hpp:61
Definition MomentumPhysics2D.hpp:25
Definition SourceResultHistory.hpp:41
The two-zone kernel. Owned by SurfaceRouter2D; driven by the marcher's tier hooks.
Definition SubsurfaceSolver.hpp:128
Definition OutfallExchange.hpp:17
Native infiltration kernels with caller-managed accepted-step state. These methods mutate the supplie...
Definition Infiltration.cpp:34
Definition ExplicitInertialSolver.hpp:68
Definition ExchangeLaw.hpp:60
Momentum2D
Momentum closure of the explicit 2D marcher (2D_FULL_SWE_SHOCK_CAPTURING_PLAN_2026-09-05 §2).
Definition SolverOptions2D.hpp:195
@ LOCAL_INERTIAL
Definition SolverOptions2D.hpp:195
Definition ExchangeLaw.hpp:60
Definition ReactionData.hpp:58
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
Definition TableData.hpp:154
Definition GwSourceForcing.hpp:27
Canonical unique interior-edge layout + per-cell incidence for the local-inertial scheme.
Definition InertialEdges.hpp:60
SoA storage for 2D mixed triangle/quad mesh geometry and topology.
Definition MeshData.hpp:65
Definition Rk2RuntimeSources.hpp:78
Definition SolverOptions2D.hpp:257
Definition SurfaceStateData.hpp:64