14 #ifdef MFEM_USE_SUNDIALS
22 #include <nvector/nvector_serial.h>
24 #include <nvector/nvector_parallel.h>
28 #include <sunlinsol/sunlinsol_spgmr.h>
31 #define GET_CONTENT(X) ( X->content )
43 static SUNMatrix_ID MatGetID(SUNMatrix A)
45 return (SUNMATRIX_CUSTOM);
48 static void MatDestroy(SUNMatrix A)
50 if (A->content) { A->content = NULL; }
51 if (A->ops) { free(A->ops); A->ops = NULL; }
61 static SUNLinearSolver_Type LSGetType(SUNLinearSolver LS)
63 return (SUNLINEARSOLVER_MATRIX_ITERATIVE);
66 static int LSFree(SUNLinearSolver LS)
68 if (LS->content) { LS->content = NULL; }
69 if (LS->ops) { free(LS->ops); LS->ops = NULL; }
78 int CVODESolver::RHS(realtype t,
const N_Vector y, N_Vector ydot,
88 self->f->Mult(mfem_y, mfem_ydot);
94 int CVODESolver::LinSysSetup(realtype t, N_Vector y, N_Vector fy, SUNMatrix A,
95 booleantype jok, booleantype *jcur,
96 realtype gamma,
void *user_data, N_Vector tmp1,
97 N_Vector tmp2, N_Vector tmp3)
106 return (self->f->SUNImplicitSetup(mfem_y, mfem_fy, jok, jcur, gamma));
109 int CVODESolver::LinSysSolve(SUNLinearSolver LS, SUNMatrix A, N_Vector x,
110 N_Vector
b, realtype tol)
117 return (self->f->SUNImplicitSolve(mfem_b, mfem_x, tol));
120 CVODESolver::CVODESolver(
int lmm)
121 : lmm_type(lmm), step_mode(CV_NORMAL)
124 y = N_VNewEmpty_Serial(0);
125 MFEM_VERIFY(
y,
"error in N_VNewEmpty_Serial()");
130 : lmm_type(lmm), step_mode(CV_NORMAL)
132 if (comm == MPI_COMM_NULL)
136 y = N_VNewEmpty_Serial(0);
137 MFEM_VERIFY(
y,
"error in N_VNewEmpty_Serial()");
144 y = N_VNewEmpty_Parallel(comm, 0, 0);
145 MFEM_VERIFY(
y,
"error in N_VNewEmpty_Parallel()");
157 long local_size = f_.
Height();
165 MPI_Allreduce(&local_size, &global_size, 1, MPI_LONG, MPI_SUM,
179 resize = (NV_LENGTH_S(
y) != local_size);
184 int l_resize = (NV_LOCLENGTH_P(
y) != local_size) ||
186 MPI_Allreduce(&l_resize, &resize, 1, MPI_INT, MPI_LOR, NV_COMM_P(
y));
205 NV_LENGTH_S(
y) = local_size;
206 NV_DATA_S(
y) =
new double[local_size]();
211 NV_LOCLENGTH_P(
y) = local_size;
212 NV_GLOBLENGTH_P(
y) = global_size;
214 NV_DATA_P(
y) =
new double[local_size]();
224 MFEM_VERIFY(
flag == CV_SUCCESS,
"error in CVodeInit()");
228 MFEM_VERIFY(
flag == CV_SUCCESS,
"error in CVodeSetUserData()");
232 MFEM_VERIFY(
flag == CV_SUCCESS,
"error in CVodeSetSStolerances()");
240 delete [] NV_DATA_S(
y);
246 delete [] NV_DATA_P(
y);
261 MFEM_VERIFY(NV_LENGTH_S(
y) == x.
Size(),
"");
267 MFEM_VERIFY(NV_LOCLENGTH_P(
y) == x.
Size(),
"");
275 MFEM_VERIFY(
flag == CV_SUCCESS,
"error in CVodeReInit()");
282 double tout = t + dt;
284 MFEM_VERIFY(
flag >= 0,
"error in CVode()");
288 MFEM_VERIFY(
flag == CV_SUCCESS,
"error in CVodeGetLastStep()");
294 if (A != NULL) { SUNMatDestroy(A); A = NULL; }
295 if (
LSA != NULL) { SUNLinSolFree(
LSA);
LSA = NULL; }
298 LSA = SUNLinSolNewEmpty();
299 MFEM_VERIFY(
LSA,
"error in SUNLinSolNewEmpty()");
302 LSA->ops->gettype = LSGetType;
304 LSA->ops->free = LSFree;
306 A = SUNMatNewEmpty();
307 MFEM_VERIFY(A,
"error in SUNMatNewEmpty()");
310 A->ops->getid = MatGetID;
311 A->ops->destroy = MatDestroy;
315 MFEM_VERIFY(
flag == CV_SUCCESS,
"error in CVodeSetLinearSolver()");
319 MFEM_VERIFY(
flag == CV_SUCCESS,
"error in CVodeSetLinSysFn()");
325 if (A != NULL) { SUNMatDestroy(A); A = NULL; }
326 if (
LSA != NULL) { SUNLinSolFree(
LSA);
LSA = NULL; }
329 LSA = SUNLinSol_SPGMR(
y, PREC_NONE, 0);
330 MFEM_VERIFY(
LSA,
"error in SUNLinSol_SPGMR()");
334 MFEM_VERIFY(
flag == CV_SUCCESS,
"error in CVodeSetLinearSolver()");
345 MFEM_VERIFY(
flag == CV_SUCCESS,
"error in CVodeSStolerances()");
351 MFEM_VERIFY(
flag == CV_SUCCESS,
"error in CVodeSetMaxStep()");
357 MFEM_VERIFY(
flag == CV_SUCCESS,
"error in CVodeSetMaxOrd()");
362 long int nsteps, nfevals, nlinsetups, netfails;
364 double hinused, hlast, hcur, tcur;
365 long int nniters, nncfails;
379 MFEM_VERIFY(
flag == CV_SUCCESS,
"error in CVodeGetIntegratorStats()");
385 MFEM_VERIFY(
flag == CV_SUCCESS,
"error in CVodeGetNonlinSolvStats()");
389 "num steps: " << nsteps <<
"\n"
390 "num rhs evals: " << nfevals <<
"\n"
391 "num lin setups: " << nlinsetups <<
"\n"
392 "num nonlin sol iters: " << nniters <<
"\n"
393 "num nonlin conv fail: " << nncfails <<
"\n"
394 "num error test fails: " << netfails <<
"\n"
395 "last order: " << qlast <<
"\n"
396 "current order: " << qcur <<
"\n"
397 "initial dt: " << hinused <<
"\n"
398 "last dt: " << hlast <<
"\n"
399 "current dt: " << hcur <<
"\n"
400 "current t: " << tcur <<
"\n" << endl;
410 SUNNonlinSolFree(
NLS);
428 if (self->rk_type ==
IMEX)
432 self->f->Mult(mfem_y, mfem_ydot);
449 self->f->Mult(mfem_y, mfem_ydot);
456 SUNMatrix M, booleantype jok, booleantype *jcur,
457 realtype gamma,
void *user_data, N_Vector tmp1,
458 N_Vector tmp2, N_Vector tmp3)
467 if (self->rk_type ==
IMEX)
471 return (self->f->SUNImplicitSetup(mfem_y, mfem_fy, jok, jcur, gamma));
475 N_Vector
b, realtype tol)
482 if (self->rk_type ==
IMEX)
486 return (self->f->SUNImplicitSolve(mfem_b, mfem_x, tol));
490 N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
496 return (self->f->SUNMassSetup());
500 N_Vector
b, realtype tol)
507 return (self->f->SUNMassSolve(mfem_b, mfem_x, tol));
517 return (self->f->SUNMassMult(mfem_x, mfem_v));
529 return (self->f->SUNMassMult(mfem_x, mfem_v));
533 : rk_type(type), step_mode(ARK_NORMAL),
534 use_implicit(type == IMPLICIT || type == IMEX)
537 y = N_VNewEmpty_Serial(0);
538 MFEM_VERIFY(
y,
"error in N_VNewEmpty_Serial()");
543 : rk_type(type), step_mode(ARK_NORMAL),
544 use_implicit(type == IMPLICIT || type == IMEX)
546 if (comm == MPI_COMM_NULL)
550 y = N_VNewEmpty_Serial(0);
551 MFEM_VERIFY(
y,
"error in N_VNewEmpty_Serial()");
558 y = N_VNewEmpty_Parallel(comm, 0, 0);
559 MFEM_VERIFY(
y,
"error in N_VNewEmpty_Parallel()");
571 long local_size = f_.
Height();
579 MPI_Allreduce(&local_size, &global_size, 1, MPI_LONG, MPI_SUM,
593 resize = (NV_LENGTH_S(
y) != local_size);
598 int l_resize = (NV_LOCLENGTH_P(
y) != local_size) ||
600 MPI_Allreduce(&l_resize, &resize, 1, MPI_INT, MPI_LOR, NV_COMM_P(
y));
620 NV_LENGTH_S(
y) = local_size;
621 NV_DATA_S(
y) =
new double[local_size]();
626 NV_LOCLENGTH_P(
y) = local_size;
627 NV_GLOBLENGTH_P(
y) = global_size;
629 NV_DATA_P(
y) =
new double[local_size]();
651 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetUserData()");
655 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetSStolerances()");
663 delete [] NV_DATA_S(
y);
669 delete [] NV_DATA_P(
y);
684 MFEM_VERIFY(NV_LENGTH_S(
y) == x.
Size(),
"");
690 MFEM_VERIFY(NV_LOCLENGTH_P(
y) == x.
Size(),
"");
710 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepReInit()");
717 double tout = t + dt;
719 MFEM_VERIFY(
flag >= 0,
"error in ARKStepEvolve()");
723 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepGetLastStep()");
729 if (A != NULL) { SUNMatDestroy(A); A = NULL; }
730 if (
LSA != NULL) { SUNLinSolFree(
LSA);
LSA = NULL; }
733 LSA = SUNLinSolNewEmpty();
734 MFEM_VERIFY(
LSA,
"error in SUNLinSolNewEmpty()");
737 LSA->ops->gettype = LSGetType;
739 LSA->ops->free = LSFree;
741 A = SUNMatNewEmpty();
742 MFEM_VERIFY(A,
"error in SUNMatNewEmpty()");
745 A->ops->getid = MatGetID;
746 A->ops->destroy = MatDestroy;
750 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetLinearSolver()");
754 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetLinSysFn()");
760 if (A != NULL) { SUNMatDestroy(A); A = NULL; }
761 if (
LSA != NULL) { SUNLinSolFree(
LSA);
LSA = NULL; }
764 LSA = SUNLinSol_SPGMR(
y, PREC_NONE, 0);
765 MFEM_VERIFY(
LSA,
"error in SUNLinSol_SPGMR()");
769 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetLinearSolver()");
775 if (
M != NULL) { SUNMatDestroy(
M);
M = NULL; }
776 if (
LSM != NULL) { SUNLinSolFree(
LSM);
LSM = NULL; }
779 LSM = SUNLinSolNewEmpty();
780 MFEM_VERIFY(
LSM,
"error in SUNLinSolNewEmpty()");
783 LSM->ops->gettype = LSGetType;
785 LSA->ops->free = LSFree;
787 M = SUNMatNewEmpty();
788 MFEM_VERIFY(
M,
"error in SUNMatNewEmpty()");
791 M->ops->getid = SUNMatGetID;
793 M->ops->destroy = MatDestroy;
797 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetLinearSolver()");
801 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetMassFn()");
807 if (
M != NULL) { SUNMatDestroy(A);
M = NULL; }
808 if (
LSM != NULL) { SUNLinSolFree(
LSM);
LSM = NULL; }
811 LSM = SUNLinSol_SPGMR(
y, PREC_NONE, 0);
812 MFEM_VERIFY(
LSM,
"error in SUNLinSol_SPGMR()");
816 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetMassLinearSolver()");
821 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetMassTimes()");
832 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSStolerances()");
838 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetMaxStep()");
844 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetOrder()");
850 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetTableNum()");
856 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetTableNum()");
862 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetTableNum()");
868 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepSetFixedStep()");
873 long int nsteps, expsteps, accsteps, step_attempts;
874 long int nfe_evals, nfi_evals;
875 long int nlinsetups, netfails;
876 double hinused, hlast, hcur, tcur;
877 long int nniters, nncfails;
888 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepGetTimestepperStats()");
901 MFEM_VERIFY(
flag == ARK_SUCCESS,
"error in ARKStepGetNonlinSolvStats()");
905 "num steps: " << nsteps <<
"\n"
906 "num exp rhs evals: " << nfe_evals <<
"\n"
907 "num imp rhs evals: " << nfi_evals <<
"\n"
908 "num lin setups: " << nlinsetups <<
"\n"
909 "num nonlin sol iters: " << nniters <<
"\n"
910 "num nonlin conv fail: " << nncfails <<
"\n"
911 "num steps attempted: " << step_attempts <<
"\n"
912 "num acc limited steps: " << accsteps <<
"\n"
913 "num exp limited stepfails: " << expsteps <<
"\n"
914 "num error test fails: " << netfails <<
"\n"
915 "initial dt: " << hinused <<
"\n"
916 "last dt: " << hlast <<
"\n"
917 "current dt: " << hcur <<
"\n"
918 "current t: " << tcur <<
"\n" << endl;
928 SUNNonlinSolFree(
NLS);
952 booleantype *new_u,
void *user_data)
962 self->jacobian = &
self->oper->GetGradient(mfem_u);
967 self->jacobian->Mult(mfem_v, mfem_Jv);
975 void *user_data, N_Vector tmp1, N_Vector tmp2)
984 self->prec->SetOperator(*self->jacobian);
992 N_Vector
b, realtype tol)
994 Vector mfem_u(u), mfem_b(b);
1005 : global_strategy(strategy), use_oper_grad(oper_grad), y_scale(NULL),
1006 f_scale(NULL), jacobian(NULL), maa(0)
1009 y = N_VNewEmpty_Serial(0);
1010 y_scale = N_VNewEmpty_Serial(0);
1011 f_scale = N_VNewEmpty_Serial(0);
1012 MFEM_VERIFY(
y &&
y_scale &&
f_scale,
"Error in N_VNewEmpty_Serial().");
1015 abs_tol = pow(UNIT_ROUNDOFF, 1.0/3.0);
1021 : global_strategy(strategy), use_oper_grad(oper_grad), y_scale(NULL),
1022 f_scale(NULL), jacobian(NULL), maa(0)
1024 if (comm == MPI_COMM_NULL)
1028 y = N_VNewEmpty_Serial(0);
1029 y_scale = N_VNewEmpty_Serial(0);
1030 f_scale = N_VNewEmpty_Serial(0);
1031 MFEM_VERIFY(
y &&
y_scale &&
f_scale,
"error in N_VNewEmpty_Serial()");
1038 y = N_VNewEmpty_Parallel(comm, 0, 0);
1039 y_scale = N_VNewEmpty_Parallel(comm, 0, 0);
1040 f_scale = N_VNewEmpty_Parallel(comm, 0, 0);
1041 MFEM_VERIFY(
y &&
y_scale &&
f_scale,
"error in N_VNewEmpty_Parallel()");
1046 abs_tol = pow(UNIT_ROUNDOFF, 1.0/3.0);
1059 long local_size =
height;
1067 MPI_Allreduce(&local_size, &global_size, 1, MPI_LONG, MPI_SUM,
1078 resize = (NV_LENGTH_S(
y) != local_size);
1083 int l_resize = (NV_LOCLENGTH_P(
y) != local_size) ||
1085 MPI_Allreduce(&l_resize, &resize, 1, MPI_INT, MPI_LOR, NV_COMM_P(
y));
1102 NV_LENGTH_S(
y) = local_size;
1103 NV_DATA_S(
y) =
new double[local_size]();
1104 NV_LENGTH_S(
y_scale) = local_size;
1106 NV_LENGTH_S(
f_scale) = local_size;
1112 NV_LOCLENGTH_P(
y) = local_size;
1113 NV_GLOBLENGTH_P(
y) = global_size;
1114 NV_DATA_P(
y) =
new double[local_size]();
1115 NV_LOCLENGTH_P(
y_scale) = local_size;
1116 NV_GLOBLENGTH_P(
y_scale) = global_size;
1118 NV_LOCLENGTH_P(
f_scale) = local_size;
1119 NV_GLOBLENGTH_P(
f_scale) = global_size;
1133 MFEM_ASSERT(
flag == KIN_SUCCESS,
"error in KINSetMAA()");
1138 MFEM_VERIFY(
flag == KIN_SUCCESS,
"error in KINInit()");
1142 MFEM_ASSERT(
flag == KIN_SUCCESS,
"error in KINSetUserData()");
1152 if (A != NULL) { SUNMatDestroy(A); A = NULL; }
1153 if (
LSA != NULL) { SUNLinSolFree(
LSA);
LSA = NULL; }
1155 LSA = SUNLinSol_SPGMR(
y, PREC_NONE, 0);
1156 MFEM_VERIFY(
LSA,
"error in SUNLinSol_SPGMR()");
1159 MFEM_ASSERT(
flag == KIN_SUCCESS,
"error in KINSetLinearSolver()");
1165 MFEM_ASSERT(
flag == KIN_SUCCESS,
"error in KINSetJacTimesVecFn()");
1172 delete [] NV_DATA_S(
y);
1173 NV_DATA_S(
y) = NULL;
1178 delete [] NV_DATA_P(
y);
1179 NV_DATA_P(
y) = NULL;
1191 if (A != NULL) { SUNMatDestroy(A); A = NULL; }
1192 if (
LSA != NULL) { SUNLinSolFree(
LSA);
LSA = NULL; }
1195 LSA = SUNLinSolNewEmpty();
1196 MFEM_VERIFY(
LSA,
"error in SUNLinSolNewEmpty()");
1198 LSA->content =
this;
1199 LSA->ops->gettype = LSGetType;
1201 LSA->ops->free = LSFree;
1203 A = SUNMatNewEmpty();
1204 MFEM_VERIFY(A,
"error in SUNMatNewEmpty()");
1207 A->ops->getid = MatGetID;
1208 A->ops->destroy = MatDestroy;
1212 MFEM_VERIFY(
flag == KIN_SUCCESS,
"error in KINSetLinearSolver()");
1216 MFEM_VERIFY(
flag == KIN_SUCCESS,
"error in KINSetJacFn()");
1222 MFEM_ASSERT(
flag == KIN_SUCCESS,
"error in KINSetScaledStepTol()");
1228 MFEM_ASSERT(
flag == KIN_SUCCESS,
"error in KINSetMaxSetupCalls()");
1239 MFEM_ASSERT(
flag == KIN_SUCCESS,
"error in KINSetMAA()");
1265 double lnorm = norm;
1266 MPI_Allreduce(&lnorm, &norm, 1, MPI_DOUBLE, MPI_MAX, NV_COMM_P(
y));
1288 MFEM_ASSERT(
flag == KIN_SUCCESS,
"error in KINSetFuncNormTol()");
1299 MFEM_ASSERT(
flag == KIN_SUCCESS,
"KINSetNumMaxIters() failed!");
1305 MFEM_VERIFY(NV_LENGTH_S(
y) == x.
Size(),
"");
1310 MFEM_VERIFY(
flag == KIN_SUCCESS,
"KINSetPrintLevel() failed!");
1317 MFEM_VERIFY(NV_LOCLENGTH_P(
y) == x.
Size(),
"");
1322 MPI_Comm_rank(NV_COMM_P(
y), &rank);
1326 MFEM_VERIFY(
flag == KIN_SUCCESS,
"KINSetPrintLevel() failed!");
1341 MFEM_ASSERT(
flag == KIN_SUCCESS,
"error in KINGetNumNonlinSolvIters()");
1346 MFEM_ASSERT(
flag == KIN_SUCCESS,
"error in KINGetFuncNorm()");
virtual double GetTime() const
Read the currently set time.
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 Operator & GetGradient(const Vector &x) const
Evaluate the gradient operator at the point x. The default behavior in class Operator is to generate ...
virtual void Step(Vector &x, double &t, double &dt)
Integrate the ODE with CVODE using the specified step mode.
virtual void Init(TimeDependentOperator &f)
Associate a TimeDependentOperator with the ODE solver.
virtual void SetTime(const double _t)
Set the current time.
virtual ~CVODESolver()
Destroy the associated CVODE memory and SUNDIALS objects.
bool use_oper_grad
use the Jv prod function
int Size() const
Returns the size of the vector.
void SetIRKTableNum(int table_num)
Choose a specific Butcher table for a diagonally implicit RK method.
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.
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
void * sundials_mem
SUNDIALS mem structure.
double Normlinf() const
Returns the l_infinity norm of the vector.
long saved_global_size
Global vector length on last initialization.
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
static int MassSysSetup(realtype t, SUNMatrix M, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
Setup the linear system .
double * GetData() const
Return a pointer to the beginning of the Vector data.
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.
static int MassMult1(SUNMatrix M, N_Vector x, N_Vector v)
Compute the matrix-vector product .
virtual void SetEvalMode(const EvalMode new_eval_mode)
Set the evaluation mode of the time-dependent operator.
SUNMatrix M
Mass matrix M.
virtual void SetSolver(Solver &solver)
Set the linear solver for inverting the Jacobian.
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
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.
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)
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
int height
Dimension of the output / number of rows in the matrix.
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.
TimeDependentOperator * f
Pointer to the associated TimeDependentOperator.
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.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
void Init(TimeDependentOperator &f_)
Initialize ARKode: calls ARKStepCreate() to create the ARKStep memory and set some defaults...
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.
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
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...