OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
ArkodeKokkosSurfaceSolver.hpp
Go to the documentation of this file.
1
24
25#ifndef OPENSWMM_ENGINE_2D_GPU_ARKODE_KOKKOS_SURFACE_SOLVER_HPP
26#define OPENSWMM_ENGINE_2D_GPU_ARKODE_KOKKOS_SURFACE_SOLVER_HPP
27
31
32#include <nvector/nvector_kokkos.hpp>
33#include <sundials/sundials_context.h>
34#include <sundials/sundials_linearsolver.h>
35#include <sundials/sundials_types.h>
36
37#include <memory>
38
39namespace openswmm::twoD {
40
41struct MeshData;
42struct SurfaceStateData;
43struct SolverOptions2D;
44
45namespace gpu {
46
47using VecType = ::sundials::kokkos::Vector<ExecSpace>;
48
51 MeshViews* mesh = nullptr;
52 StateViews* state = nullptr;
55 double dry_depth = 1.0e-3;
56 int nt = 0;
57 int ne = 0;
58};
59
61public:
64
67
68 void initialize(MeshData& mesh, SurfaceStateData& state,
69 SolverOptions2D& opts) override;
70 double advance(double t_current, double t_target) override;
71 void reinitialize(double t0) override;
72 void finalize() override;
73
74 long last_num_steps() const noexcept override { return last_nsteps_; }
75 double last_step_size() const noexcept override { return last_h_; }
76 bool is_initialized() const noexcept override { return arkode_mem_ != nullptr; }
77
78private:
79 SUNContext sun_ctx_ = nullptr;
80 void* arkode_mem_ = nullptr;
81 SUNLinearSolver ls_ = nullptr;
82 std::unique_ptr<VecType> y_;
83 std::unique_ptr<VecType> abstol_;
84
85 MeshViews mesh_v_;
86 StateViews state_v_;
87 InertialEdgeViews edges_v_;
88 DView prec_wq_;
89
90 MeshData* mesh_host_ = nullptr;
91 SurfaceStateData* state_host_ = nullptr;
92 SolverOptions2D* opts_host_ = nullptr;
93
95
96 int nt_ = 0;
97 int ne_ = 0;
98 int nv_ = 0;
99 long last_nsteps_ = 0;
100 double last_h_ = 0.0;
101
102 void uploadMesh();
103 void uploadEdges();
104 void uploadSources();
105 void seedState();
106 void downloadState();
107
108 static int fe_cb(sunrealtype t, N_Vector y, N_Vector ydot, void* user_data);
109 static int fi_cb(sunrealtype t, N_Vector y, N_Vector ydot, void* user_data);
110 static int psetup_cb(sunrealtype t, N_Vector y, N_Vector fy,
111 sunbooleantype jok, sunbooleantype* jcurPtr,
112 sunrealtype gamma, void* user_data);
113 static int psolve_cb(sunrealtype t, N_Vector y, N_Vector fy,
114 N_Vector r, N_Vector z,
115 sunrealtype gamma, sunrealtype delta, int lr,
116 void* user_data);
117};
118
119} // namespace gpu
120} // namespace openswmm::twoD
121
122#endif // OPENSWMM_ENGINE_2D_GPU_ARKODE_KOKKOS_SURFACE_SOLVER_HPP
Backend-neutral interface for the 2D surface-routing time integrator.
Performance-portable RHS + preconditioner for the local-inertial solver.
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
bool is_initialized() const noexcept override
True once initialize() has completed and the solver is ready.
Definition ArkodeKokkosSurfaceSolver.hpp:76
void finalize() override
Release all backend resources.
Definition ArkodeKokkosSurfaceSolver.cpp:286
ArkodeKokkosSurfaceSolver(const ArkodeKokkosSurfaceSolver &)=delete
void reinitialize(double t0) override
Reinitialize the integrator at t0 after external state edits.
Definition ArkodeKokkosSurfaceSolver.cpp:280
double advance(double t_current, double t_target) override
Definition ArkodeKokkosSurfaceSolver.cpp:263
long last_num_steps() const noexcept override
Number of internal integrator steps in the last advance() call.
Definition ArkodeKokkosSurfaceSolver.hpp:74
double last_step_size() const noexcept override
Last internal step size used by the integrator.
Definition ArkodeKokkosSurfaceSolver.hpp:75
~ArkodeKokkosSurfaceSolver() override
Definition ArkodeKokkosSurfaceSolver.cpp:186
void initialize(MeshData &mesh, SurfaceStateData &state, SolverOptions2D &opts) override
One-time setup. mesh and state must outlive the solver.
Definition ArkodeKokkosSurfaceSolver.cpp:188
ArkodeKokkosSurfaceSolver & operator=(const ArkodeKokkosSurfaceSolver &)=delete
Definition ArkodeKokkosSurfaceSolver.cpp:29
::sundials::kokkos::Vector< ExecSpace > VecType
SUNDIALS Kokkos vector specialised on the default execution space.
Definition ArkodeKokkosSurfaceSolver.hpp:47
Kokkos::View< double *, MemSpace > DView
mutable double array
Definition KokkosSurfaceKernels.hpp:81
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 ARKStep callbacks via ARKodeSetUserData().
Definition ArkodeKokkosSurfaceSolver.hpp:50
DView prec_wq
[ne] friction-damped q-diagonal
Definition ArkodeKokkosSurfaceSolver.hpp:54
int nt
Definition ArkodeKokkosSurfaceSolver.hpp:56
InertialEdgeViews * edges
Definition ArkodeKokkosSurfaceSolver.hpp:53
double dry_depth
Definition ArkodeKokkosSurfaceSolver.hpp:55
MeshViews * mesh
Definition ArkodeKokkosSurfaceSolver.hpp:51
int ne
Definition ArkodeKokkosSurfaceSolver.hpp:57
StateViews * state
Definition ArkodeKokkosSurfaceSolver.hpp:52
Definition KokkosInertialKernels.hpp:34
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