OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
CvodeKokkosSurfaceSolver.hpp
Go to the documentation of this file.
1
27
28#ifndef OPENSWMM_ENGINE_2D_GPU_CVODE_KOKKOS_SURFACE_SOLVER_HPP
29#define OPENSWMM_ENGINE_2D_GPU_CVODE_KOKKOS_SURFACE_SOLVER_HPP
30
33
34#include <nvector/nvector_kokkos.hpp>
35#include <sundials/sundials_context.h>
36#include <sundials/sundials_linearsolver.h>
37#include <sundials/sundials_types.h>
38
39#include <memory>
40
41namespace openswmm::twoD {
42
43struct MeshData;
44struct SurfaceStateData;
45struct SolverOptions2D;
46
47namespace gpu {
48
50using VecType = ::sundials::kokkos::Vector<ExecSpace>;
51
52#if defined(OPENSWMM_HAVE_HYPRE)
53class KokkosAmgPreconditioner; // complete type only in the .cpp (guarded)
54#endif
55
58 MeshViews* mesh = nullptr;
59 StateViews* state = nullptr;
60 double dry_depth = 1.0e-3;
61 double limiter_eps = 1.0e-6;
62 double flux_dh_eps = 4.0e-3;
63 bool prec_diag_built = false;
64#if defined(OPENSWMM_HAVE_HYPRE)
65 bool use_amg = false;
66 KokkosAmgPreconditioner* amg = nullptr;
67#endif
68};
69
71public:
72 // Out-of-line (see CvodeSurfaceSolver) so the unique_ptr AMG member's
73 // destructor is instantiated in the .cpp where the type is complete.
76
79
80 void initialize(MeshData& mesh, SurfaceStateData& state,
81 SolverOptions2D& opts) override;
82 double advance(double t_current, double t_target) override;
83 void reinitialize(double t0) override;
84 void finalize() override;
85
86 long last_num_steps() const noexcept override { return last_nsteps_; }
87 double last_step_size() const noexcept override { return last_h_; }
88 bool is_initialized() const noexcept override { return cvode_mem_ != nullptr; }
89
90private:
91 // SUNDIALS handles.
92 SUNContext sun_ctx_ = nullptr;
93 void* cvode_mem_ = nullptr;
94 SUNLinearSolver ls_ = nullptr;
95 std::unique_ptr<VecType> y_;
96 std::unique_ptr<VecType> abstol_;
97
98 // Device mirrors.
99 MeshViews mesh_v_;
100 StateViews state_v_;
101
102 // Host back-pointers (owned by SurfaceRouter2D; must outlive the solver).
103 MeshData* mesh_host_ = nullptr;
104 SurfaceStateData* state_host_ = nullptr;
105 SolverOptions2D* opts_host_ = nullptr;
106
108
109#if defined(OPENSWMM_HAVE_HYPRE)
110 std::unique_ptr<KokkosAmgPreconditioner> amg_precond_;
111#endif
112
113 int nt_ = 0;
114 int nv_ = 0;
115 long last_nsteps_ = 0;
116 double last_h_ = 0.0;
117
118 // Host<->device transfer helpers (no-ops in Phase 1 OpenMP host space).
119 void uploadMesh();
120 void uploadSources();
121 void uploadBoundaryStatic();
122 void uploadBoundaryDynamic();
123 void seedVolumeFromHead();
124 void downloadState();
125
126 // CVODE C-ABI callbacks.
127 static int rhs_cb(sunrealtype t, N_Vector y, N_Vector ydot, void* user_data);
128 static int psetup_cb(sunrealtype t, N_Vector y, N_Vector fy,
129 sunbooleantype jok, sunbooleantype* jcurPtr,
130 sunrealtype gamma, void* user_data);
131 static int psolve_cb(sunrealtype t, N_Vector y, N_Vector fy,
132 N_Vector r, N_Vector z,
133 sunrealtype gamma, sunrealtype delta, int lr,
134 void* user_data);
135};
136
137} // namespace gpu
138} // namespace openswmm::twoD
139
140#endif // OPENSWMM_ENGINE_2D_GPU_CVODE_KOKKOS_SURFACE_SOLVER_HPP
Backend-neutral interface for the 2D surface-routing time integrator.
Performance-portable RHS pipeline for the 2D surface router (Phase 1).
Abstract time integrator for the 2D surface-routing ODE system.
Definition ISurfaceSolver.hpp:49
void reinitialize(double t0) override
Reinitialize the integrator at t0 after external state edits.
Definition CvodeKokkosSurfaceSolver.cpp:389
~CvodeKokkosSurfaceSolver() override
Definition CvodeKokkosSurfaceSolver.cpp:238
CvodeKokkosSurfaceSolver(const CvodeKokkosSurfaceSolver &)=delete
long last_num_steps() const noexcept override
Number of internal integrator steps in the last advance() call.
Definition CvodeKokkosSurfaceSolver.hpp:86
bool is_initialized() const noexcept override
True once initialize() has completed and the solver is ready.
Definition CvodeKokkosSurfaceSolver.hpp:88
CvodeKokkosSurfaceSolver & operator=(const CvodeKokkosSurfaceSolver &)=delete
double last_step_size() const noexcept override
Last internal step size used by the integrator.
Definition CvodeKokkosSurfaceSolver.hpp:87
void finalize() override
Release all backend resources.
Definition CvodeKokkosSurfaceSolver.cpp:403
void initialize(MeshData &mesh, SurfaceStateData &state, SolverOptions2D &opts) override
One-time setup. mesh and state must outlive the solver.
Definition CvodeKokkosSurfaceSolver.cpp:242
double advance(double t_current, double t_target) override
Definition CvodeKokkosSurfaceSolver.cpp:369
BoomerAMG preconditioner over the Kokkos surface Newton matrix.
Definition KokkosAmgPreconditioner.hpp:40
Definition ArkodeKokkosSurfaceSolver.cpp:29
::sundials::kokkos::Vector< ExecSpace > VecType
SUNDIALS Kokkos vector specialised on the default execution space.
Definition ArkodeKokkosSurfaceSolver.hpp:47
Definition NodeCoupling.cpp:15
double * y
Definition odesolve.c:28
SoA storage for 2D triangular mesh geometry and topology.
Definition MeshData.hpp:34
Configuration for the 2D surface routing CVODE solver.
Definition SolverOptions2D.hpp:132
Definition SurfaceStateData.hpp:41
Context handed to the CVODE callbacks via CVodeSetUserData().
Definition CvodeKokkosSurfaceSolver.hpp:57
MeshViews * mesh
Definition CvodeKokkosSurfaceSolver.hpp:58
double limiter_eps
Definition CvodeKokkosSurfaceSolver.hpp:61
double flux_dh_eps
√|Δη| regularization (FLUX_DH_EPS)
Definition CvodeKokkosSurfaceSolver.hpp:62
StateViews * state
Definition CvodeKokkosSurfaceSolver.hpp:59
bool prec_diag_built
Jacobi diagonal cached (lag reuse)
Definition CvodeKokkosSurfaceSolver.hpp:63
double dry_depth
Definition CvodeKokkosSurfaceSolver.hpp:60
Immutable mesh geometry/topology mirrored to device once at initialize().
Definition KokkosSurfaceKernels.hpp:87
Mutable per-step state mirrored on device.
Definition KokkosSurfaceKernels.hpp:102