MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
Public Member Functions | Protected Types | Static Protected Member Functions | Protected Attributes | List of all members
mfem::CVODESolver Class Reference

Interface to the CVODE library – linear multi-step methods. More...

#include <sundials.hpp>

Inheritance diagram for mfem::CVODESolver:
[legend]
Collaboration diagram for mfem::CVODESolver:
[legend]

Public Member Functions

 CVODESolver (int lmm)
 Construct a serial wrapper to SUNDIALS' CVODE integrator.
 
 CVODESolver (MPI_Comm comm, int lmm)
 Construct a parallel wrapper to SUNDIALS' CVODE integrator.
 
void Init (TimeDependentOperator &f_)
 Initialize CVODE: calls CVodeCreate() to create the CVODE memory and set some defaults.
 
virtual void Step (Vector &x, double &t, double &dt)
 Integrate the ODE with CVODE using the specified step mode.
 
void UseMFEMLinearSolver ()
 Attach the linear system setup and solve methods from the TimeDependentOperator i.e., SUNImplicitSetup() and SUNImplicitSolve() to CVODE.
 
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 SetSStolerances (double reltol, double abstol)
 Set the scalar relative and scalar absolute tolerances.
 
void SetSVtolerances (double reltol, Vector abstol)
 Set the scalar relative and vector of absolute tolerances.
 
void SetRootFinder (int components, RootFunction func)
 Initialize Root Finder.
 
void SetMaxStep (double dt_max)
 Set the maximum time step.
 
void SetMaxNSteps (int steps)
 Set the maximum number of time steps.
 
long GetNumSteps ()
 Get the number of internal steps taken so far.
 
void SetMaxOrder (int max_order)
 Set the maximum method order.
 
void PrintInfo () const
 Print various CVODE statistics.
 
virtual ~CVODESolver ()
 Destroy the associated CVODE memory and SUNDIALS objects.
 
- Public Member Functions inherited from mfem::ODESolver
 ODESolver ()
 
virtual void Init (TimeDependentOperator &f_)
 Associate a TimeDependentOperator with the ODE solver.
 
virtual void Step (Vector &x, real_t &t, real_t &dt)=0
 Perform a time step from time t [in] to time t [out] based on the requested step size dt [in].
 
virtual void Run (Vector &x, real_t &t, real_t &dt, real_t tf)
 Perform time integration from time t [in] to time tf [in].
 
virtual int GetMaxStateSize ()
 Function for getting and setting the state vectors.
 
virtual int GetStateSize ()
 
virtual const VectorGetStateVector (int i)
 
virtual void GetStateVector (int i, Vector &state)
 
virtual void SetStateVector (int i, Vector &state)
 
virtual ~ODESolver ()
 
- Public Member Functions inherited from mfem::SundialsSolver
void * GetMem () const
 Access the SUNDIALS memory structure.
 
int GetFlag () const
 Returns the last flag returned by a call to a SUNDIALS function.
 

Protected Types

typedef std::function< int(realtype t, Vector y, Vector gout, CVODESolver *)> RootFunction
 Typedef for root finding functions.
 
typedef std::function< int(Vector y, Vector w, CVODESolver *)> EWTFunction
 Typedef declaration for error weight functions.
 

Static Protected Member Functions

static int RHS (realtype t, const N_Vector y, N_Vector ydot, void *user_data)
 Number of components in gout.
 
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 \( A x = b \).
 
static int LinSysSolve (SUNLinearSolver LS, SUNMatrix A, N_Vector x, N_Vector b, realtype tol)
 Solve the linear system \( A x = b \).
 
static int root (realtype t, N_Vector y, realtype *gout, void *user_data)
 Prototype to define root finding for CVODE.
 

Protected Attributes

int lmm_type
 Linear multistep method type.
 
int step_mode
 CVODE step mode (CV_NORMAL or CV_ONE_STEP).
 
int root_components
 
RootFunction root_func
 A class member to facilitate pointing to a user-specified root function.
 
EWTFunction ewt_func
 A class member to facilitate pointing to a user-specified error weight function.
 
- Protected Attributes inherited from mfem::ODESolver
TimeDependentOperatorf
 Pointer to the associated TimeDependentOperator.
 
MemoryType mem_type
 
- Protected Attributes inherited from mfem::SundialsSolver
void * sundials_mem
 SUNDIALS mem structure.
 
int flag
 Last flag returned from a call to SUNDIALS.
 
bool reinit
 Flag to signal memory reinitialization is need.
 
long saved_global_size
 Global vector length on last initialization.
 
SundialsNVectorY
 State vector.
 
SUNMatrix A
 
SUNMatrix M
 Mass matrix M.
 
SUNLinearSolver LSA
 Linear solver for A.
 
SUNLinearSolver LSM
 Linear solver for M.
 
SUNNonlinearSolver NLS
 Nonlinear solver.
 

Additional Inherited Members

- Protected Member Functions inherited from mfem::SundialsSolver
bool Parallel () const
 
bool Parallel () const
 
 SundialsSolver ()
 Protected constructor: objects of this type should be constructed only as part of a derived class.
 
void AllocateEmptyNVector (N_Vector &y)
 
void AllocateEmptyNVector (N_Vector &y, MPI_Comm comm)
 
- Static Protected Attributes inherited from mfem::SundialsSolver
static constexpr double default_rel_tol = 1e-4
 Default scalar relative tolerance.
 
static constexpr double default_abs_tol = 1e-9
 Default scalar absolute tolerance.
 

Detailed Description

Interface to the CVODE library – linear multi-step methods.

Definition at line 385 of file sundials.hpp.

Member Typedef Documentation

◆ EWTFunction

typedef std::function<int(Vector y, Vector w, CVODESolver*)> mfem::CVODESolver::EWTFunction
protected

Typedef declaration for error weight functions.

Definition at line 416 of file sundials.hpp.

◆ RootFunction

typedef std::function<int(realtype t, Vector y, Vector gout, CVODESolver *)> mfem::CVODESolver::RootFunction
protected

Typedef for root finding functions.

Definition at line 410 of file sundials.hpp.

Constructor & Destructor Documentation

◆ CVODESolver() [1/2]

mfem::CVODESolver::CVODESolver ( int  lmm)

Construct a serial wrapper to SUNDIALS' CVODE integrator.

Parameters
[in]lmmSpecifies the linear multistep method, the options are:
  • CV_ADAMS - implicit methods for non-stiff systems,
  • CV_BDF - implicit methods for stiff systems.

Definition at line 695 of file sundials.cpp.

◆ CVODESolver() [2/2]

mfem::CVODESolver::CVODESolver ( MPI_Comm  comm,
int  lmm 
)

Construct a parallel wrapper to SUNDIALS' CVODE integrator.

Parameters
[in]commThe MPI communicator used to partition the ODE system
[in]lmmSpecifies the linear multistep method, the options are:
  • CV_ADAMS - implicit methods for non-stiff systems,
  • CV_BDF - implicit methods for stiff systems.

Definition at line 702 of file sundials.cpp.

◆ ~CVODESolver()

mfem::CVODESolver::~CVODESolver ( )
virtual

Destroy the associated CVODE memory and SUNDIALS objects.

Definition at line 964 of file sundials.cpp.

Member Function Documentation

◆ GetNumSteps()

long mfem::CVODESolver::GetNumSteps ( )

Get the number of internal steps taken so far.

Definition at line 905 of file sundials.cpp.

◆ Init()

void mfem::CVODESolver::Init ( TimeDependentOperator f_)
virtual

Initialize CVODE: calls CVodeCreate() to create the CVODE memory and set some defaults.

If the CVODE memory has already been created, it checks if the problem size has changed since the last call to Init(). If the problem is the same then CVodeReInit() will be called in the next call to Step(). If the problem size has changed, the CVODE memory is freed and realloced for the new problem size.

Parameters
[in]f_The TimeDependentOperator that defines the ODE system.
Note
All other methods must be called after Init().
If this method is called a second time with a different problem size, then any non-default user-set options will be lost and will need to be set again.

Reimplemented from mfem::ODESolver.

Definition at line 709 of file sundials.cpp.

◆ LinSysSetup()

int mfem::CVODESolver::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 
)
staticprotected

Setup the linear system \( A x = b \).

Definition at line 671 of file sundials.cpp.

◆ LinSysSolve()

int mfem::CVODESolver::LinSysSolve ( SUNLinearSolver  LS,
SUNMatrix  A,
N_Vector  x,
N_Vector  b,
realtype  tol 
)
staticprotected

Solve the linear system \( A x = b \).

Definition at line 685 of file sundials.cpp.

◆ PrintInfo()

void mfem::CVODESolver::PrintInfo ( ) const

Print various CVODE statistics.

Definition at line 919 of file sundials.cpp.

◆ RHS()

int mfem::CVODESolver::RHS ( realtype  t,
const N_Vector  y,
N_Vector  ydot,
void *  user_data 
)
staticprotected

Number of components in gout.

Wrapper to compute the ODE rhs function.

Definition at line 634 of file sundials.cpp.

◆ root()

int mfem::CVODESolver::root ( realtype  t,
N_Vector  y,
realtype *  gout,
void *  user_data 
)
staticprotected

Prototype to define root finding for CVODE.

Definition at line 651 of file sundials.cpp.

◆ SetMaxNSteps()

void mfem::CVODESolver::SetMaxNSteps ( int  steps)

Set the maximum number of time steps.

Definition at line 899 of file sundials.cpp.

◆ SetMaxOrder()

void mfem::CVODESolver::SetMaxOrder ( int  max_order)

Set the maximum method order.

CVODE uses adaptive-order integration, based on the local truncation error. The default values for max_order are 12 for CV_ADAMS and 5 for CV_BDF. Use this if you know a priori that your system is such that higher order integration formulas are unstable.

Note
max_order can't be higher than the current maximum order.

Definition at line 913 of file sundials.cpp.

◆ SetMaxStep()

void mfem::CVODESolver::SetMaxStep ( double  dt_max)

Set the maximum time step.

Definition at line 893 of file sundials.cpp.

◆ SetRootFinder()

void mfem::CVODESolver::SetRootFinder ( int  components,
RootFunction  func 
)

Initialize Root Finder.

Definition at line 663 of file sundials.cpp.

◆ SetSStolerances()

void mfem::CVODESolver::SetSStolerances ( double  reltol,
double  abstol 
)

Set the scalar relative and scalar absolute tolerances.

Definition at line 875 of file sundials.cpp.

◆ SetStepMode()

void mfem::CVODESolver::SetStepMode ( int  itask)

Select the CVODE step mode: CV_NORMAL (default) or CV_ONE_STEP.

Parameters
[in]itaskThe desired step mode.

Definition at line 870 of file sundials.cpp.

◆ SetSVtolerances()

void mfem::CVODESolver::SetSVtolerances ( double  reltol,
Vector  abstol 
)

Set the scalar relative and vector of absolute tolerances.

Definition at line 881 of file sundials.cpp.

◆ Step()

void mfem::CVODESolver::Step ( Vector x,
double &  t,
double &  dt 
)
virtual

Integrate the ODE with CVODE using the specified step mode.

Parameters
[in,out]xOn output, the solution vector at the requested output time tout = t + dt.
[in,out]tOn output, the output time reached.
[in,out]dtOn output, the last time step taken.
Note
On input, the values of t and dt are used to compute desired output time for the integration, tout = t + dt.

Reimplemented in mfem::CVODESSolver.

Definition at line 797 of file sundials.cpp.

◆ UseMFEMLinearSolver()

void mfem::CVODESolver::UseMFEMLinearSolver ( )

Attach the linear system setup and solve methods from the TimeDependentOperator i.e., SUNImplicitSetup() and SUNImplicitSolve() to CVODE.

Definition at line 824 of file sundials.cpp.

◆ UseSundialsLinearSolver()

void mfem::CVODESolver::UseSundialsLinearSolver ( )

Attach SUNDIALS GMRES linear solver to CVODE.

Definition at line 855 of file sundials.cpp.

Member Data Documentation

◆ ewt_func

EWTFunction mfem::CVODESolver::ewt_func
protected

A class member to facilitate pointing to a user-specified error weight function.

Definition at line 419 of file sundials.hpp.

◆ lmm_type

int mfem::CVODESolver::lmm_type
protected

Linear multistep method type.

Definition at line 388 of file sundials.hpp.

◆ root_components

int mfem::CVODESolver::root_components
protected

Definition at line 390 of file sundials.hpp.

◆ root_func

RootFunction mfem::CVODESolver::root_func
protected

A class member to facilitate pointing to a user-specified root function.

Definition at line 413 of file sundials.hpp.

◆ step_mode

int mfem::CVODESolver::step_mode
protected

CVODE step mode (CV_NORMAL or CV_ONE_STEP).

Definition at line 389 of file sundials.hpp.


The documentation for this class was generated from the following files: