44#ifndef OPENSWMM_ENGINE_2D_EXPLICIT_INERTIAL_SOLVER_HPP
45#define OPENSWMM_ENGINE_2D_EXPLICIT_INERTIAL_SOLVER_HPP
64 double advance(
double t_current,
double t_target)
override;
71 RunStats
run_stats() const noexcept override;
74 const noexcept
override {
86 void reconstructAll();
92 void settleAccumulators();
96 void syncAndRebuild(
double t);
105 void fireFaces(
const std::vector<int>& faces,
double dt_f,
106 bool global_step =
false);
112 void fireCells(
const std::vector<int>& cells,
double dt_c,
bool tier0);
115 void fireCellsImpl(
const std::vector<int>& cells,
double dt_c,
bool tier0);
118 void runMacroCycle(
double dt0,
int nsub);
128 std::vector<double> q_;
131 std::vector<double> qcx_, qcy_;
142 bool has_quads_ =
false;
146 std::vector<int> wall_ptr_, wall_slot_;
150 std::vector<double> macc_x_L_, macc_x_R_, macc_y_L_, macc_y_R_;
154 double swe_bc_dqx_ = 0.0, swe_bc_dqy_ = 0.0;
158 bool second_order_ =
false;
159 std::vector<double> gex_, gey_, gux_, guy_, gvx_, gvy_;
160 std::vector<double> rk_v0_, rk_qx0_, rk_qy0_;
163 std::vector<double> rk_inf0_, rk_bc0_, rk_ex0_, rk_drawn0_, rk_cpl0_;
164 void computeLimitedGradientsSwe();
168 void runRk2Step(
double dt);
174 bool front_rebuild_ =
false;
175 std::vector<uint8_t> frontier_;
176 bool front_breach_ =
false;
177 double h_on_front_ = 0.0;
180 std::vector<double> dw_slope_;
182 void fireFacesInertial(
const std::vector<int>& faces,
double dt_f,
bool global_step);
183 void fireFacesSwe(
const std::vector<int>& faces,
double dt_f,
bool global_step);
184 void fireFacesDiffusive(
const std::vector<int>& faces,
double dt_f,
bool global_step);
187 void bookFaceSpecies(
int e,
int a,
int b,
double dM,
double hf,
double dt_f,
188 bool global_step)
noexcept;
192 double boundaryFluxSwe(std::size_t k,
int i,
double dt_c);
194 void refreshDiffusiveSlopes();
195 std::vector<uint8_t> cell_active_;
196 std::vector<int> active_cells_;
201 std::vector<int> active_faces_;
202 std::vector<uint8_t> pin_t0_;
213 std::vector<uint8_t> rebuild_seed_;
214 std::vector<double> rebuild_dt_cell_;
217 std::vector<double> rebuild_dt_partial_;
219 std::vector<uint8_t> tier_;
220 std::vector<uint8_t> face_tier_;
221 std::vector<double> facc_L_;
222 std::vector<double> facc_R_;
233 std::vector<double> sacc_L_;
234 std::vector<double> sacc_R_;
239 double donorConc(
int s,
int cell)
const noexcept;
244 void sinkMassAtCellConc(
int i,
double dv_m3, std::vector<double>& ledger,
245 double* per_point_ledger =
nullptr) noexcept;
248 void addRainMass(
int i,
double rain_m3) noexcept;
251 void addCouplingSourceMass(
int i,
double area_dt) noexcept;
254 void sinkTemperatureWithEvap(
int i,
double evap_m3) noexcept;
261 bool accumulators_pending_ = false;
262 std::vector<std::vector<
int>> cells_by_tier_;
263 std::vector<std::vector<
int>> edges_by_tier_;
265 std::vector<
int> bc_cell_;
266 std::vector<
int> bc_slot_;
267 std::vector<
double> bc_accum_;
269 std::vector<
double> bc_q_;
284 std::vector<
double> exch_;
285 std::vector<
double> node_drawn_;
292 double spill_deficit_ = 0.0;
300 exch_head_slope_ = std::move(slopes);
303 std::vector<double> exch_head_slope_;
304 double exch_tau_ = 0.0;
306 double t_last_sync_ = 0.0;
307 int cycles_since_rebuild_ = 1000;
310 void lazySourcesOnly(
double t);
311 long substeps_run_ = 0;
312 long face_passes_ = 0;
313 long last_steps_ = 0;
314 double last_dt_ = 0.0;
315 bool initialized_ =
false;
321 std::vector<std::pair<double, int>> telemetry_;
322 std::string telemetry_path_;
324 std::array<long, 8> tier_occupancy_{};
336 SubsurfaceSolver* gw_ =
nullptr;
Backend-neutral interface for the 2D surface-routing time integrator.
Unique interior-edge structure for the local-inertial momentum DOFs.
Configuration options for the 2D surface routing solver.
Definition ExplicitInertialSolver.hpp:60
void finalize() override
Release all backend resources.
Definition ExplicitInertialSolver.cpp:2252
void reinitialize(double t0) override
Reinitialize the integrator at t0 after external state edits.
Definition ExplicitInertialSolver.cpp:2224
bool is_initialized() const noexcept override
True once initialize() has completed and the solver is ready.
Definition ExplicitInertialSolver.hpp:72
const std::vector< double > & last_coupling_exchange() const noexcept override
Definition ExplicitInertialSolver.hpp:73
void setSubsurface(SubsurfaceSolver *gw) noexcept
Definition ExplicitInertialSolver.hpp:341
double advance(double t_current, double t_target) override
Definition ExplicitInertialSolver.cpp:2070
long last_num_steps() const noexcept override
Number of internal integrator steps in the last advance() call.
Definition ExplicitInertialSolver.hpp:69
RunStats run_stats() const noexcept override
Read cumulative statistics. Default: zeros (backend has no counters).
Definition ExplicitInertialSolver.cpp:2274
double spillDeficit() const noexcept
Definition ExplicitInertialSolver.hpp:82
void resyncFromVolumes(double t0) override
Definition ExplicitInertialSolver.cpp:2244
const InertialEdges & inertialEdges() const noexcept
Definition ExplicitInertialSolver.hpp:347
void initialize(MeshData &mesh, SurfaceStateData &state, SolverOptions2D &opts) override
One-time setup. mesh and state must outlive the solver.
Definition ExplicitInertialSolver.cpp:65
double last_step_size() const noexcept override
Last internal step size used by the integrator.
Definition ExplicitInertialSolver.hpp:70
void setExchangeHeadSlopes(std::vector< double > slopes)
Definition ExplicitInertialSolver.hpp:299
Abstract time integrator for the 2D surface-routing ODE system.
Definition ISurfaceSolver.hpp:63
The two-zone kernel. Owned by SurfaceRouter2D; driven by the marcher's tier hooks.
Definition SubsurfaceSolver.hpp:97
Definition NodeCoupling.cpp:16
Momentum2D
Momentum closure of the explicit 2D marcher (2D_FULL_SWE_SHOCK_CAPTURING_PLAN_2026-09-05 §2).
Definition SolverOptions2D.hpp:157
@ LOCAL_INERTIAL
Definition SolverOptions2D.hpp:158
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
Definition SurfaceStateData.hpp:59