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"
63
64namespace openswmm::twoD::gpu {
65
67public:
70
71 void initialize(MeshData& mesh, SurfaceStateData& state,
72 SolverOptions2D& opts) override;
73 double advance(double t_current, double t_target) override;
74 void reinitialize(double t0) override;
75 void resyncFromVolumes(double t0) override;
76 void finalize() override;
77
78 long last_num_steps() const noexcept override { return last_steps_; }
79 double last_step_size() const noexcept override { return last_dt_; }
80 const std::vector<double>& last_coupling_exchange()
81 const noexcept override { return exch_host_; }
82 RunStats run_stats() const noexcept override;
83 bool is_initialized() const noexcept override { return initialized_; }
84
85private:
86 // Host-side handles (owned by SurfaceRouter2D; outlive the solver).
87 MeshData* mesh_ = nullptr;
88 SurfaceStateData* state_ = nullptr;
89 SolverOptions2D* opts_ = nullptr;
90 InertialEdges edges_;
91
92 // ---- device geometry (const after initialize) -------------------------
93 DView d_tri_area_, d_tri_cz_, d_tri_cx_, d_tri_cy_, d_vz_, d_vx_, d_vy_;
94 IView d_cell_v_;
95 DView d_vs_wt_;
96 IView d_vs_ptr_, d_vs_idx_;
97 DView d_edge_length_, d_mannings_n_;
98 // InertialEdges mirror
99 IView d_cL_, d_cR_, d_slotL_, d_slotR_, d_cell_ptr_, d_cell_edge_;
100 DView d_xi_, d_inv_dx_, d_zface_, d_ze_lo_, d_ze_hi_, d_nx_, d_ny_, d_mx_, d_my_;
101 DView d_n2_, d_sign_, d_lchar_;
102
103 // ---- device state -----------------------------------------------------
104 DView d_volume_, d_head_, d_depth_;
105 DView d_q_, d_faccL_, d_faccR_, d_qcx_, d_qcy_;
106 DView d_rain_, d_coup_, d_evap_, d_infil_;
107
113 DView d_infil_applied_;
119 DView d_coupling_applied_;
123 DView d_node_fullvol_;
124 std::vector<double> infil_applied_host_;
125 std::vector<double> coupling_applied_host_;
126 DView d_edge_flux_;
127 IView d_active_, d_pin_t0_, d_tier_, d_face_tier_;
128 IView d_cells_compact_, d_edges_compact_;
129 IView d_scratch_;
130 DView d_dtcell_;
131
132 // Boundary edges (non-WALL): built host-side at initialize.
133 IView d_bc_cell_, d_bc_slot_, d_bc_type_;
134 DView d_bc_accum_, d_bc_slope_, d_bc_head_, d_bc_flow_;
135 DView d_bc_q_;
137 std::vector<int> bc_cell_host_, bc_slot_host_;
138
139 // Live junction exchange (windowless coupling).
140 IView d_cp_cell_, d_cp_vertex_, d_cp_node_;
141 DView d_cp_cd_, d_cp_area_;
142 DView d_exch_, d_node_drawn_;
143 DView d_node_head_, d_node_depth_, d_node_volume_;
144 DView d_node_invert_, d_node_fulldepth_;
145 std::vector<double> exch_host_;
146
147 // ---- host mirrors / control -------------------------------------------
148 std::array<int, 9> tier_off_{};
149 std::array<int, 9> ftier_off_{};
150 int n_active_ = 0;
151 double dt0_ = 0.0;
152 int K_ = 1;
153 bool have_perot_ = false;
154 double t_last_sync_ = 0.0;
155 int cycles_since_rebuild_ = 1000;
156 double last_dt_ = 0.0;
157 long last_steps_ = 0, substeps_run_ = 0, face_passes_ = 0;
158 bool initialized_ = false;
159
160 std::array<long, 8> tier_occupancy_{};
161 std::vector<std::pair<double, int>> telemetry_;
162 std::string telemetry_path_;
163
164 // ---- internals (public for nvcc extended-lambda access) ----------------
165public:
166 void reconstructAllDev();
168 void lazySourcesDev(double t);
169 void syncAndRebuild(double t);
170 void refreshDt0();
171 void collapseToGlobalDt();
172 void fireFaces(int tier, double dt_f);
173 void fireCells(int tier, double dt_c);
174 void runMacroCycle(double dt0, int nsub);
175 void pushForcings();
176 void pushNodeState();
177 void publishAndCopyBack(double t_current, double t_target);
178};
179
180} // namespace openswmm::twoD::gpu
181
182#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.
Execution-space selection + view aliases for the Kokkos marcher plugin.
Abstract time integrator for the 2D surface-routing ODE system.
Definition ISurfaceSolver.hpp:63
void reconstructAllDev()
Definition ExplicitKokkosSurfaceSolver.cpp:389
void collapseToGlobalDt()
tail: everything to tier 0
Definition ExplicitKokkosSurfaceSolver.cpp:654
void settleAccumulatorsDev()
Definition ExplicitKokkosSurfaceSolver.cpp:407
void initialize(MeshData &mesh, SurfaceStateData &state, SolverOptions2D &opts) override
One-time setup. mesh and state must outlive the solver.
Definition ExplicitKokkosSurfaceSolver.cpp:145
void syncAndRebuild(double t)
Definition ExplicitKokkosSurfaceSolver.cpp:485
void finalize() override
Release all backend resources.
Definition ExplicitKokkosSurfaceSolver.cpp:1356
void pushForcings()
Definition ExplicitKokkosSurfaceSolver.cpp:1151
void pushNodeState()
Definition ExplicitKokkosSurfaceSolver.cpp:1182
void refreshDt0()
tighten-only dt0_ between rebuilds (== serial)
Definition ExplicitKokkosSurfaceSolver.cpp:623
long last_num_steps() const noexcept override
Number of internal integrator steps in the last advance() call.
Definition ExplicitKokkosSurfaceSolver.hpp:78
void publishAndCopyBack(double t_current, double t_target)
Definition ExplicitKokkosSurfaceSolver.cpp:1189
void resyncFromVolumes(double t0) override
Definition ExplicitKokkosSurfaceSolver.cpp:1350
double advance(double t_current, double t_target) override
Definition ExplicitKokkosSurfaceSolver.cpp:1250
~ExplicitKokkosSurfaceSolver() override
Definition ExplicitKokkosSurfaceSolver.hpp:69
void lazySourcesDev(double t)
Definition ExplicitKokkosSurfaceSolver.cpp:442
double last_step_size() const noexcept override
Last internal step size used by the integrator.
Definition ExplicitKokkosSurfaceSolver.hpp:79
void fireCells(int tier, double dt_c)
Definition ExplicitKokkosSurfaceSolver.cpp:789
bool is_initialized() const noexcept override
True once initialize() has completed and the solver is ready.
Definition ExplicitKokkosSurfaceSolver.hpp:83
void fireFaces(int tier, double dt_f)
Definition ExplicitKokkosSurfaceSolver.cpp:709
const std::vector< double > & last_coupling_exchange() const noexcept override
Definition ExplicitKokkosSurfaceSolver.hpp:80
RunStats run_stats() const noexcept override
Read cumulative statistics. Default: zeros (backend has no counters).
Definition ExplicitKokkosSurfaceSolver.cpp:1372
void reinitialize(double t0) override
Reinitialize the integrator at t0 after external state edits.
Definition ExplicitKokkosSurfaceSolver.cpp:1338
void runMacroCycle(double dt0, int nsub)
Definition ExplicitKokkosSurfaceSolver.cpp:1131
Definition ExplicitKokkosSurfaceSolver.cpp:36
Kokkos::View< int *, MemSpace > IView
mutable int array
Definition KokkosTypes.hpp:65
Kokkos::View< double *, MemSpace > DView
mutable double array
Definition KokkosTypes.hpp:63
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