27#ifndef OPENSWMM_ENGINE_2D_CVODE_SURFACE_SOLVER_HPP
28#define OPENSWMM_ENGINE_2D_CVODE_SURFACE_SOLVER_HPP
30#include "../data/MeshData.hpp"
31#include "../data/SurfaceStateData.hpp"
32#include "../data/SolverOptions2D.hpp"
40typedef struct SUNContext_* SUNContext;
41typedef struct _generic_N_Vector* N_Vector;
42typedef struct _generic_SUNLinearSolver* SUNLinearSolver;
46class CvodeSurfaceSolver;
59struct CvodeSolverContext {
60 MeshData* mesh =
nullptr;
61 SurfaceStateData* state =
nullptr;
62 SolverOptions2D* opts =
nullptr;
63 CvodeSurfaceSolver* solver =
nullptr;
69class CvodeSurfaceSolver {
71 CvodeSurfaceSolver() =
default;
72 ~CvodeSurfaceSolver();
75 CvodeSurfaceSolver(
const CvodeSurfaceSolver&) =
delete;
76 CvodeSurfaceSolver& operator=(
const CvodeSurfaceSolver&) =
delete;
79 CvodeSurfaceSolver(CvodeSurfaceSolver&& o)
noexcept;
80 CvodeSurfaceSolver& operator=(CvodeSurfaceSolver&& o)
noexcept;
92 void initialize(MeshData& mesh, SurfaceStateData& state,
93 SolverOptions2D& opts);
106 double advance(
double t_current,
double t_target);
115 void reinitialize(
double t0);
123 long last_num_steps() const noexcept {
return last_nsteps_; }
126 double last_step_size() const noexcept {
return last_h_; }
129 bool is_initialized() const noexcept {
return cvode_mem_ !=
nullptr; }
132 void* cvode_mem_ =
nullptr;
133 SUNLinearSolver ls_ =
nullptr;
134 N_Vector y_ =
nullptr;
135 SUNContext sun_ctx_ =
nullptr;
137 CvodeSolverContext ctx_;
139 long last_nsteps_ = 0;
140 double last_h_ = 0.0;
146 std::vector<double> precond_diag_;
160 static int rhs_fn(
double t, N_Vector
y, N_Vector ydot,
void* user_data);
173 static int psetup_fn(
double t, N_Vector
y, N_Vector fy,
174 int jok,
int* jcurPtr,
double gamma,
183 static int psolve_fn(
double t, N_Vector
y, N_Vector fy,
184 N_Vector r, N_Vector z,
185 double gamma,
double delta,
int lr,
Definition NodeCoupling.cpp:15
double * y
Definition odesolve.c:28