27#ifndef OPENSWMM_ENGINE_2D_CVODE_SURFACE_SOLVER_HPP
28#define OPENSWMM_ENGINE_2D_CVODE_SURFACE_SOLVER_HPP
42typedef struct SUNContext_* SUNContext;
43typedef struct _generic_N_Vector* N_Vector;
44typedef struct _generic_SUNLinearSolver* SUNLinearSolver;
48class CvodeSurfaceSolver;
49#if defined(OPENSWMM_HAVE_HYPRE)
64struct CvodeSolverContext {
65 MeshData* mesh =
nullptr;
66 SurfaceStateData* state =
nullptr;
67 SolverOptions2D* opts =
nullptr;
68 CvodeSurfaceSolver* solver =
nullptr;
69 bool amg_active =
false;
81 ~CvodeSurfaceSolver()
override;
84 CvodeSurfaceSolver(
const CvodeSurfaceSolver&) =
delete;
85 CvodeSurfaceSolver& operator=(
const CvodeSurfaceSolver&) =
delete;
88 CvodeSurfaceSolver(CvodeSurfaceSolver&& o)
noexcept;
89 CvodeSurfaceSolver& operator=(CvodeSurfaceSolver&& o)
noexcept;
101 void initialize(MeshData& mesh, SurfaceStateData& state,
102 SolverOptions2D& opts)
override;
115 double advance(
double t_current,
double t_target)
override;
124 void reinitialize(
double t0)
override;
129 void finalize()
override;
132 long last_num_steps() const noexcept
override {
return last_nsteps_; }
135 double last_step_size() const noexcept
override {
return last_h_; }
141 const std::vector<double>& last_coupling_exchange() const noexcept
override {
142 return last_coupling_exchange_;
146 bool is_initialized() const noexcept
override {
return cvode_mem_ !=
nullptr; }
149 void* cvode_mem_ =
nullptr;
150 SUNLinearSolver ls_ =
nullptr;
151 N_Vector y_ =
nullptr;
152 N_Vector abstol_ =
nullptr;
153 SUNContext sun_ctx_ =
nullptr;
155 CvodeSolverContext ctx_;
157 long last_nsteps_ = 0;
158 double last_h_ = 0.0;
167 std::vector<double> coupling_accum_start_;
168 std::vector<double> last_coupling_exchange_;
174 std::vector<double> precond_diag_;
176#if defined(OPENSWMM_HAVE_HYPRE)
180 std::unique_ptr<HypreAmgPreconditioner> amg_precond_;
185 bool amg_used_last_setup_ =
false;
200 static int rhs_fn(
double t, N_Vector
y, N_Vector ydot,
void* user_data);
213 static int psetup_fn(
double t, N_Vector
y, N_Vector fy,
214 int jok,
int* jcurPtr,
double gamma,
223 static int psolve_fn(
double t, N_Vector
y, N_Vector fy,
224 N_Vector r, N_Vector z,
225 double gamma,
double delta,
int lr,
Backend-neutral interface for the 2D surface-routing time integrator.
Structure-of-Arrays (SoA) storage for 2D triangular mesh geometry.
Configuration options for the 2D surface routing solver.
Structure-of-Arrays (SoA) storage for 2D surface routing state.
BoomerAMG preconditioner over the 2D diffusion Newton matrix.
Definition HypreAmgPreconditioner.hpp:42
Abstract time integrator for the 2D surface-routing ODE system.
Definition ISurfaceSolver.hpp:49
Definition NodeCoupling.cpp:15
double * y
Definition odesolve.c:28