15 #include "../config/config.hpp"
17 #ifdef MFEM_USE_SUNDIALS
26 #include <sundials/sundials_config.h>
28 #if !defined(SUNDIALS_VERSION_MAJOR) || (SUNDIALS_VERSION_MAJOR < 5)
29 #error MFEM requires SUNDIALS version 5.0.0 or newer!
31 #include <sundials/sundials_matrix.h>
32 #include <sundials/sundials_linearsolver.h>
33 #include <cvode/cvode.h>
34 #include <arkode/arkode_arkstep.h>
35 #include <kinsol/kinsol.h>
58 SUNNonlinearSolver
NLS;
62 {
return (N_VGetVectorID(
y) != SUNDIALS_NVEC_SERIAL); }
99 static int RHS(realtype t,
const N_Vector
y, N_Vector ydot,
void *user_data);
102 static int LinSysSetup(realtype t, N_Vector
y, N_Vector fy, SUNMatrix
A,
103 booleantype jok, booleantype *jcur,
104 realtype gamma,
void *user_data, N_Vector tmp1,
105 N_Vector tmp2, N_Vector tmp3);
108 static int LinSysSolve(SUNLinearSolver LS, SUNMatrix
A, N_Vector x,
109 N_Vector
b, realtype tol);
153 virtual void Step(
Vector &x,
double &t,
double &dt);
217 static int RHS1(realtype t,
const N_Vector
y, N_Vector ydot,
void *user_data);
218 static int RHS2(realtype t,
const N_Vector
y, N_Vector ydot,
void *user_data);
222 static int LinSysSetup(realtype t, N_Vector
y, N_Vector fy, SUNMatrix
A,
223 SUNMatrix
M, booleantype jok, booleantype *jcur,
224 realtype gamma,
void *user_data, N_Vector tmp1,
225 N_Vector tmp2, N_Vector tmp3);
228 static int LinSysSolve(SUNLinearSolver LS, SUNMatrix
A, N_Vector x,
229 N_Vector
b, realtype tol);
232 static int MassSysSetup(realtype t, SUNMatrix
M,
void *user_data,
233 N_Vector tmp1, N_Vector tmp2, N_Vector tmp3);
236 static int MassSysSolve(SUNLinearSolver LS, SUNMatrix
M, N_Vector x,
237 N_Vector
b, realtype tol);
240 static int MassMult1(SUNMatrix
M, N_Vector x, N_Vector v);
243 static int MassMult2(N_Vector x, N_Vector v, realtype t,
291 virtual void Step(
Vector &x,
double &t,
double &dt);
380 static int Mult(
const N_Vector u, N_Vector fu,
void *user_data);
383 static int GradientMult(N_Vector v, N_Vector Jv, N_Vector u,
384 booleantype *new_u,
void *user_data);
387 static int LinSysSetup(N_Vector u, N_Vector fu, SUNMatrix J,
388 void *user_data, N_Vector tmp1, N_Vector tmp2);
391 static int LinSysSolve(SUNLinearSolver LS, SUNMatrix J, N_Vector u,
392 N_Vector
b, realtype tol);
402 KINSolver(
int strategy,
bool oper_grad =
true);
412 KINSolver(MPI_Comm comm,
int strategy,
bool oper_grad =
true);
483 #endif // MFEM_USE_SUNDIALS
485 #endif // MFEM_SUNDIALS
void Init(TimeDependentOperator &f_)
Initialize CVODE: calls CVodeCreate() to create the CVODE memory and set some defaults.
void SetSStolerances(double reltol, double abstol)
Set the scalar relative and scalar absolute tolerances.
void SetScaledStepTol(double sstol)
Set KINSOL's scaled step tolerance.
void SetStepMode(int itask)
Select the ARKode step mode: ARK_NORMAL (default) or ARK_ONE_STEP.
Base abstract class for first order time dependent operators.
virtual void Step(Vector &x, double &t, double &dt)
Integrate the ODE with CVODE using the specified step mode.
void * GetMem() const
Access the SUNDIALS memory structure.
virtual ~CVODESolver()
Destroy the associated CVODE memory and SUNDIALS objects.
bool use_oper_grad
use the Jv prod function
void SetIRKTableNum(int table_num)
Choose a specific Butcher table for a diagonally implicit RK method.
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
void SetIMEXTableNum(int etable_num, int itable_num)
Choose a specific Butcher table for an IMEX RK method.
static int LinSysSetup(realtype t, N_Vector y, N_Vector fy, SUNMatrix A, SUNMatrix M, booleantype jok, booleantype *jcur, realtype gamma, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
Setup the linear system .
void SetMaxStep(double dt_max)
Set the maximum time step.
void SetOrder(int order)
Chooses integration order for all explicit / implicit / IMEX methods.
int GetFlag() const
Returns the last flag retured by a call to a SUNDIALS function.
void * sundials_mem
SUNDIALS mem structure.
long saved_global_size
Global vector length on last initialization.
static int MassSysSetup(realtype t, SUNMatrix M, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
Setup the linear system .
void SetMaxSetupCalls(int max_calls)
Set maximum number of nonlinear iterations without a Jacobian update.
ARKStepSolver(Type type=EXPLICIT)
Construct a serial wrapper to SUNDIALS' ARKode integrator.
Interface to ARKode's ARKStep module – additive Runge-Kutta methods.
int global_strategy
KINSOL solution strategy.
SUNLinearSolver LSA
Linear solver for A.
SUNMatrix A
Linear system A = I - gamma J, M - gamma J, or J.
static int MassMult1(SUNMatrix M, N_Vector x, N_Vector v)
Compute the matrix-vector product .
SundialsSolver()
Protected constructor: objects of this type should be constructed only as part of a derived class...
SUNMatrix M
Mass matrix M.
virtual void SetSolver(Solver &solver)
Set the linear solver for inverting the Jacobian.
int lmm_type
Linear multistep method type.
Interface to the CVODE library – linear multi-step methods.
Interface to the KINSOL library – nonlinear solver methods.
void SetMaxStep(double dt_max)
Set the maximum time step.
Type
Types of ARKODE solvers.
Type rk_type
Runge-Kutta type.
virtual ~ARKStepSolver()
Destroy the associated ARKode memory and SUNDIALS objects.
Newton's method for solving F(x)=b for a given operator F.
bool use_implicit
True for implicit or imex integration.
SUNNonlinearSolver NLS
Nonlinear solver.
CVODESolver(int lmm)
Construct a serial wrapper to SUNDIALS' CVODE integrator.
static int Mult(const N_Vector u, N_Vector fu, void *user_data)
Wrapper to compute the nonlinear residual .
int step_mode
ARKStep step mode (ARK_NORMAL or ARK_ONE_STEP).
static int LinSysSetup(N_Vector u, N_Vector fu, SUNMatrix J, void *user_data, N_Vector tmp1, N_Vector tmp2)
Setup the linear system .
SUNLinearSolver LSM
Linear solver for M.
static int RHS1(realtype t, const N_Vector y, N_Vector ydot, void *user_data)
Base class for interfacing with SUNDIALS packages.
N_Vector f_scale
scaling vectors
void UseMFEMLinearSolver()
Attach the linear system setup and solve methods from the TimeDependentOperator i.e., SUNImplicitSetup() and SUNImplicitSolve() to CVODE.
virtual void SetOperator(const Operator &op)
Set the nonlinear Operator of the system and initialize KINSOL.
virtual ~KINSolver()
Destroy the associated KINSOL memory.
void SetFixedStep(double dt)
Use a fixed time step size (disable temporal adaptivity).
bool reinit
Flag to signal memory reinitialization is need.
int maa
number of acceleration vectors
void SetMAA(int maa)
Set the number of acceleration vectors to use with KIN_FP or KIN_PICARD.
static int LinSysSetup(realtype t, N_Vector y, N_Vector fy, SUNMatrix A, booleantype jok, booleantype *jcur, realtype gamma, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
Setup the linear system .
void PrintInfo() const
Print various ARKStep statistics.
static int RHS2(realtype t, const N_Vector y, N_Vector ydot, void *user_data)
static int GradientMult(N_Vector v, N_Vector Jv, N_Vector u, booleantype *new_u, void *user_data)
Wrapper to compute the Jacobian-vector product .
const Operator * jacobian
stores oper->GetGradient()
static constexpr double default_rel_tol
Default scalar relative tolerance.
int step_mode
CVODE step mode (CV_NORMAL or CV_ONE_STEP).
static int MassMult2(N_Vector x, N_Vector v, realtype t, void *mtimes_data)
Compute the matrix-vector product at time t.
KINSolver(int strategy, bool oper_grad=true)
Construct a serial wrapper to SUNDIALS' KINSOL nonlinear solver.
Implicit-explicit ARK method.
static constexpr double default_abs_tol
Default scalar absolute tolerance.
int flag
Last flag returned from a call to SUNDIALS.
void UseMFEMLinearSolver()
Attach the linear system setup and solve methods from the TimeDependentOperator i.e., SUNImplicitSetup() and SUNImplicitSolve() to ARKode.
static int LinSysSolve(SUNLinearSolver LS, SUNMatrix A, N_Vector x, N_Vector b, realtype tol)
Solve the linear system .
static int LinSysSolve(SUNLinearSolver LS, SUNMatrix A, N_Vector x, N_Vector b, realtype tol)
Solve the linear system .
void PrintInfo() const
Print various CVODE statistics.
void SetMaxOrder(int max_order)
Set the maximum method order.
void UseMFEMMassLinearSolver(int tdep)
Attach mass matrix linear system setup, solve, and matrix-vector product methods from the TimeDepende...
void SetERKTableNum(int table_num)
Choose a specific Butcher table for an explicit RK method.
void Init(TimeDependentOperator &f_)
Initialize ARKode: calls ARKStepCreate() to create the ARKStep memory and set some defaults...
virtual void SetPreconditioner(Solver &solver)
Equivalent to SetSolver(solver).
static int RHS(realtype t, const N_Vector y, N_Vector ydot, void *user_data)
Wrapper to compute the ODE rhs function.
void SetSStolerances(double reltol, double abstol)
Set the scalar relative and scalar absolute tolerances.
void UseSundialsLinearSolver()
Attach a SUNDIALS GMRES linear solver to ARKode.
static int LinSysSolve(SUNLinearSolver LS, SUNMatrix J, N_Vector u, N_Vector b, realtype tol)
Solve the linear system .
static int MassSysSolve(SUNLinearSolver LS, SUNMatrix M, N_Vector x, N_Vector b, realtype tol)
Solve the linear system .
virtual void Step(Vector &x, double &t, double &dt)
Integrate the ODE with ARKode using the specified step mode.
void UseSundialsLinearSolver()
Attach SUNDIALS GMRES linear solver to CVODE.
void SetStepMode(int itask)
Select the CVODE step mode: CV_NORMAL (default) or CV_ONE_STEP.
void UseSundialsMassLinearSolver(int tdep)
Attach the SUNDIALS GMRES linear solver and the mass matrix matrix-vector product method from the Tim...