OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
ExplicitKokkosSurfaceSolver.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
51
52#ifndef OPENSWMM_ENGINE_2D_GPU_EXPLICIT_KOKKOS_SURFACE_SOLVER_HPP
53#define OPENSWMM_ENGINE_2D_GPU_EXPLICIT_KOKKOS_SURFACE_SOLVER_HPP
54
55#include <array>
56#include <string>
57#include <utility>
58#include <vector>
59
62#include "KokkosTypes.hpp"
64
65namespace openswmm::twoD::gpu {
66
68public:
85
104 void initialize(MeshData& mesh, SurfaceStateData& state, SolverOptions2D& opts) override;
120 double advance(double t_current, double t_target) override;
131 void reinitialize(double t0) override;
142 void resyncFromVolumes(double t0) override;
152 void finalize() override;
153
160 long last_num_steps() const noexcept override { return last_steps_; }
167 double last_step_size() const noexcept override { return last_dt_; }
175 const std::vector<double>& last_coupling_exchange() const noexcept override {
176 return exch_host_;
177 }
178
185 RunStats run_stats() const noexcept override;
192 bool is_initialized() const noexcept override { return initialized_; }
193
194private:
196 kperf::Counters perf_counters_;
197 // Host-side handles (owned by SurfaceRouter2D; outlive the solver).
198 MeshData* mesh_ = nullptr;
199 SurfaceStateData* state_ = nullptr;
200 SolverOptions2D* opts_ = nullptr;
201 void refreshConveyance();
202 InertialEdges edges_;
203 DView d_conveyance_;
204
205 // ---- device geometry (const after initialize) -------------------------
206 DView d_tri_area_, d_tri_cz_, d_tri_cx_, d_tri_cy_, d_vz_, d_vx_, d_vy_;
207 IView d_cell_v_;
208 DView d_vs_wt_;
209 IView d_vs_ptr_, d_vs_idx_;
210 DView d_edge_length_, d_mannings_n_;
211 // InertialEdges mirror
212 IView d_cL_, d_cR_, d_slotL_, d_slotR_, d_cell_ptr_, d_cell_edge_;
213 DView d_xi_, d_inv_dx_, d_zface_, d_ze_lo_, d_ze_hi_, d_nx_, d_ny_, d_mx_, d_my_;
214 DView d_n2_, d_sign_, d_lchar_;
215
216 // ---- device state -----------------------------------------------------
217 DView d_volume_, d_head_, d_depth_;
218 DView d_q_, d_faccL_, d_faccR_, d_qcx_, d_qcy_;
219 DView d_rain_, d_coup_, d_evap_, d_infil_;
220
226 DView d_infil_applied_;
227 DView d_evap_applied_;
228 std::vector<double> evap_applied_host_;
234 DView d_coupling_applied_;
238 DView d_node_fullvol_;
239 std::vector<double> infil_applied_host_;
240 std::vector<double> coupling_applied_host_;
241 DView d_edge_flux_;
242 IView d_active_, d_pin_t0_, d_tier_, d_face_tier_;
243 IView d_cells_compact_, d_edges_compact_;
244 IView d_scratch_;
245 DView d_dtcell_;
246
247 // Boundary edges (non-WALL): built host-side at initialize.
248 IView d_bc_cell_, d_bc_slot_, d_bc_type_;
249 DView d_bc_accum_, d_bc_slope_, d_bc_head_, d_bc_flow_;
250 DView d_bc_in_, d_bc_out_;
251 std::vector<double> bc_in_host_, bc_out_host_;
252 DView d_bc_requested_, d_bc_last_flow_, d_bc_last_dt_;
253 std::vector<double> bc_requested_host_, bc_last_flow_host_, bc_last_dt_host_;
254 DView d_bc_q_;
256 std::vector<int> bc_cell_host_, bc_slot_host_;
257
258 // Live junction exchange (windowless coupling).
259 IView d_cp_cell_, d_cp_vertex_, d_cp_node_;
260 DView d_cp_cd_, d_cp_area_;
261 // WEIR_ORIFICE per point: law, structure {z_crest, l_weir, a_orif} and
262 // coefficients {c_w, c_sw, c_oi, c_oo, h_eps}; COUPLING_HEAD cell runs.
263 IView d_cp_law_, d_cp_head_b_, d_cp_head_e_, d_head_cells_, d_cp_eq_;
264 DView d_cp_geo_, d_cp_coef_;
265 DView d_node_pond_area_;
266 DView d_exch_, d_node_drawn_;
267 DView d_node_head_, d_node_depth_, d_node_volume_;
268 DView d_node_invert_, d_node_fulldepth_;
269 std::vector<double> exch_host_;
270
271 // ---- host mirrors / control -------------------------------------------
272 std::array<int, 9> tier_off_{};
273 std::array<int, 9> ftier_off_{};
274 int n_active_ = 0;
275 double dt0_ = 0.0;
276 int K_ = 1;
277 bool have_perot_ = false;
278 double t_last_sync_ = 0.0;
279 int cycles_since_rebuild_ = 1000;
280 double last_dt_ = 0.0;
281 long last_steps_ = 0, substeps_run_ = 0, face_passes_ = 0;
282 bool initialized_ = false;
283
284 std::array<long, 8> tier_occupancy_{};
285 std::vector<std::pair<double, int>> telemetry_;
286 std::string telemetry_path_;
287
288 // ---- internals (public for nvcc extended-lambda access) ----------------
289public:
297 void reconstructAllDev();
316 void lazySourcesDev(double t);
328 void syncAndRebuild(double t);
337 void refreshDt0();
346 void collapseToGlobalDt();
360 void fireFaces(int tier, double dt_f, bool global_step = false);
374 void fireCells(int tier, double dt_c, bool global_step = false);
385 void runMacroCycle(double dt0, int nsub);
395 void pushForcings();
404 void pushNodeState();
418 void publishAndCopyBack(double t_current, double t_target);
419};
420
421} // namespace openswmm::twoD::gpu
422
423#endif // OPENSWMM_ENGINE_2D_GPU_EXPLICIT_KOKKOS_SURFACE_SOLVER_HPP
Backend-neutral interface for the 2D surface-routing time integrator.
Unique interior-edge structure for the local-inertial momentum DOFs.
OPENSWMM_PERF=1 launch/fence/deep_copy counters for the Kokkos surface solver, riding the in-process ...
Execution-space selection + view aliases for the Kokkos marcher plugin.
Abstract time integrator for the 2D surface-routing ODE system.
Definition ISurfaceSolver.hpp:61
void reconstructAllDev()
Launch reconstruction of every device cell head/depth from canonical device volume.
Definition ExplicitKokkosSurfaceSolver.cpp:486
void collapseToGlobalDt()
< tighten-only dt0_ between rebuilds (== serial)
Definition ExplicitKokkosSurfaceSolver.cpp:765
void settleAccumulatorsDev()
Gather and zero every cell's own pending lateral side packets on device.
Definition ExplicitKokkosSurfaceSolver.cpp:504
void initialize(MeshData &mesh, SurfaceStateData &state, SolverOptions2D &opts) override
Initialize device geometry, canonical water and publication receipt views.
Definition ExplicitKokkosSurfaceSolver.cpp:199
void syncAndRebuild(double t)
Settle device receipts/sources and rebuild active halos, CFL tiers and compact lists.
Definition ExplicitKokkosSurfaceSolver.cpp:582
void finalize() override
Write optional telemetry and retire the marcher activation flag.
Definition ExplicitKokkosSurfaceSolver.cpp:1629
void pushForcings()
Upload current held surface/boundary forcing to existing device views.
Definition ExplicitKokkosSurfaceSolver.cpp:1373
void pushNodeState()
Upload frozen live-junction node state for one surface window.
Definition ExplicitKokkosSurfaceSolver.cpp:1413
void refreshDt0()
Tighten the current base duration against active-cell CFL limits.
Definition ExplicitKokkosSurfaceSolver.cpp:728
long last_num_steps() const noexcept override
Read the most recent advance base-substep count.
Definition ExplicitKokkosSurfaceSolver.hpp:160
void publishAndCopyBack(double t_current, double t_target)
Publish device water/flux and drain applied receipts additively into host owners.
Definition ExplicitKokkosSurfaceSolver.cpp:1424
void resyncFromVolumes(double t0) override
Upload authoritative host volumes while retaining device momentum.
Definition ExplicitKokkosSurfaceSolver.cpp:1619
double advance(double t_current, double t_target) override
Advance the accepted surface window and publish additive host receipts.
Definition ExplicitKokkosSurfaceSolver.cpp:1509
~ExplicitKokkosSurfaceSolver() override
Retire optional telemetry through finalize() then release owned Kokkos view handles.
Definition ExplicitKokkosSurfaceSolver.hpp:84
friend struct ExplicitKokkosSurfaceSolverTestAccess
Definition ExplicitKokkosSurfaceSolver.hpp:195
void lazySourcesDev(double t)
Apply held cell sources to currently inactive cells through a synchronization horizon.
Definition ExplicitKokkosSurfaceSolver.cpp:540
double last_step_size() const noexcept override
Read the most recent accepted base or tail duration.
Definition ExplicitKokkosSurfaceSolver.hpp:167
void fireCells(int tier, double dt_c, bool global_step=false)
Fire one device cell tier or a global tail selection.
Definition ExplicitKokkosSurfaceSolver.cpp:960
bool is_initialized() const noexcept override
Read whether nonempty device initialization completed.
Definition ExplicitKokkosSurfaceSolver.hpp:192
const std::vector< double > & last_coupling_exchange() const noexcept override
Borrow the published integrated live junction exchange.
Definition ExplicitKokkosSurfaceSolver.hpp:175
RunStats run_stats() const noexcept override
Snapshot accumulated Kokkos marcher work and active-tier telemetry.
Definition ExplicitKokkosSurfaceSolver.cpp:1647
void reinitialize(double t0) override
Upload externally edited host volumes and reset stale device momentum.
Definition ExplicitKokkosSurfaceSolver.cpp:1605
ExplicitKokkosSurfaceSolver()=default
Construct an inactive marcher with empty device views and no borrowed host owners.
void runMacroCycle(double dt0, int nsub)
Execute accepted binary local-time substeps using the current compact tier lists.
Definition ExplicitKokkosSurfaceSolver.cpp:1351
void fireFaces(int tier, double dt_f, bool global_step=false)
< tail: everything to tier 0
Definition ExplicitKokkosSurfaceSolver.cpp:870
Definition ExplicitKokkosSurfaceSolver.cpp:48
Kokkos::View< int *, MemSpace > IView
mutable int array
Definition KokkosTypes.hpp:72
Kokkos::View< double *, MemSpace > DView
mutable double array
Definition KokkosTypes.hpp:70
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 SolverOptions2D.hpp:257
Definition SurfaceStateData.hpp:64
Definition KokkosPerfCounters.hpp:79