MFEM  v4.1.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
sundials.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2020, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef MFEM_SUNDIALS
13 #define MFEM_SUNDIALS
14 
15 #include "../config/config.hpp"
16 
17 #ifdef MFEM_USE_SUNDIALS
18 
19 #ifdef MFEM_USE_MPI
20 #include <mpi.h>
21 #endif
22 
23 #include "ode.hpp"
24 #include "solvers.hpp"
25 
26 #include <sundials/sundials_config.h>
27 // Check for appropriate SUNDIALS version
28 #if !defined(SUNDIALS_VERSION_MAJOR) || (SUNDIALS_VERSION_MAJOR < 5)
29 #error MFEM requires SUNDIALS version 5.0.0 or newer!
30 #endif
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>
36 
37 namespace mfem
38 {
39 
40 // ---------------------------------------------------------------------------
41 // Base class for interfacing with SUNDIALS packages
42 // ---------------------------------------------------------------------------
43 
44 /// Base class for interfacing with SUNDIALS packages.
46 {
47 protected:
48  void *sundials_mem; ///< SUNDIALS mem structure.
49  mutable int flag; ///< Last flag returned from a call to SUNDIALS.
50  bool reinit; ///< Flag to signal memory reinitialization is need.
51  long saved_global_size; ///< Global vector length on last initialization.
52 
53  N_Vector y; ///< State vector.
54  SUNMatrix A; ///< Linear system A = I - gamma J, M - gamma J, or J.
55  SUNMatrix M; ///< Mass matrix M.
56  SUNLinearSolver LSA; ///< Linear solver for A.
57  SUNLinearSolver LSM; ///< Linear solver for M.
58  SUNNonlinearSolver NLS; ///< Nonlinear solver.
59 
60 #ifdef MFEM_USE_MPI
61  bool Parallel() const
62  { return (N_VGetVectorID(y) != SUNDIALS_NVEC_SERIAL); }
63 #else
64  bool Parallel() const { return false; }
65 #endif
66 
67  /// Default scalar relative tolerance.
68  static constexpr double default_rel_tol = 1e-4;
69  /// Default scalar absolute tolerance.
70  static constexpr double default_abs_tol = 1e-9;
71 
72  /** @brief Protected constructor: objects of this type should be constructed
73  only as part of a derived class. */
74  SundialsSolver() : sundials_mem(NULL), flag(0), reinit(false),
75  saved_global_size(0), y(NULL), A(NULL), M(NULL),
76  LSA(NULL), LSM(NULL), NLS(NULL) { }
77 
78 public:
79  /// Access the SUNDIALS memory structure.
80  void *GetMem() const { return sundials_mem; }
81 
82  /// Returns the last flag retured by a call to a SUNDIALS function.
83  int GetFlag() const { return flag; }
84 };
85 
86 
87 // ---------------------------------------------------------------------------
88 // Interface to the CVODE library -- linear multi-step methods
89 // ---------------------------------------------------------------------------
90 
91 /// Interface to the CVODE library -- linear multi-step methods.
92 class CVODESolver : public ODESolver, public SundialsSolver
93 {
94 protected:
95  int lmm_type; ///< Linear multistep method type.
96  int step_mode; ///< CVODE step mode (CV_NORMAL or CV_ONE_STEP).
97 
98  /// Wrapper to compute the ODE rhs function.
99  static int RHS(realtype t, const N_Vector y, N_Vector ydot, void *user_data);
100 
101  /// Setup the linear system \f$ A x = b \f$.
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);
106 
107  /// Solve the linear system \f$ A x = b \f$.
108  static int LinSysSolve(SUNLinearSolver LS, SUNMatrix A, N_Vector x,
109  N_Vector b, realtype tol);
110 
111 public:
112  /// Construct a serial wrapper to SUNDIALS' CVODE integrator.
113  /** @param[in] lmm Specifies the linear multistep method, the options are:
114  - CV_ADAMS - implicit methods for non-stiff systems,
115  - CV_BDF - implicit methods for stiff systems. */
116  CVODESolver(int lmm);
117 
118 #ifdef MFEM_USE_MPI
119  /// Construct a parallel wrapper to SUNDIALS' CVODE integrator.
120  /** @param[in] comm The MPI communicator used to partition the ODE system
121  @param[in] lmm Specifies the linear multistep method, the options are:
122  - CV_ADAMS - implicit methods for non-stiff systems,
123  - CV_BDF - implicit methods for stiff systems. */
124  CVODESolver(MPI_Comm comm, int lmm);
125 #endif
126 
127  /** @brief Initialize CVODE: calls CVodeCreate() to create the CVODE
128  memory and set some defaults.
129 
130  If the CVODE memory has already been created, it checks if the problem
131  size has changed since the last call to Init(). If the problem is the
132  same then CVodeReInit() will be called in the next call to Step(). If
133  the problem size has changed, the CVODE memory is freed and realloced
134  for the new problem size. */
135  /** @param[in] f_ The TimeDependentOperator that defines the ODE system.
136 
137  @note All other methods must be called after Init().
138 
139  @note If this method is called a second time with a different problem
140  size, then any non-default user-set options will be lost and will need
141  to be set again. */
142  void Init(TimeDependentOperator &f_);
143 
144  /// Integrate the ODE with CVODE using the specified step mode.
145  /** @param[in,out] x On output, the solution vector at the requested output
146  time tout = @a t + @a dt.
147  @param[in,out] t On output, the output time reached.
148  @param[in,out] dt On output, the last time step taken.
149 
150  @note On input, the values of @a t and @a dt are used to compute desired
151  output time for the integration, tout = @a t + @a dt.
152  */
153  virtual void Step(Vector &x, double &t, double &dt);
154 
155  /** @brief Attach the linear system setup and solve methods from the
156  TimeDependentOperator i.e., SUNImplicitSetup() and SUNImplicitSolve() to
157  CVODE.
158  */
159  void UseMFEMLinearSolver();
160 
161  /// Attach SUNDIALS GMRES linear solver to CVODE.
163 
164  /// Select the CVODE step mode: CV_NORMAL (default) or CV_ONE_STEP.
165  /** @param[in] itask The desired step mode. */
166  void SetStepMode(int itask);
167 
168  /// Set the scalar relative and scalar absolute tolerances.
169  void SetSStolerances(double reltol, double abstol);
170 
171  /// Set the maximum time step.
172  void SetMaxStep(double dt_max);
173 
174  /** @brief Set the maximum method order.
175 
176  CVODE uses adaptive-order integration, based on the local truncation
177  error. The default values for @a max_order are 12 for CV_ADAMS and
178  5 for CV_BDF. Use this if you know a priori that your system is such
179  that higher order integration formulas are unstable.
180 
181  @note @a max_order can't be higher than the current maximum order. */
182  void SetMaxOrder(int max_order);
183 
184  /// Print various CVODE statistics.
185  void PrintInfo() const;
186 
187  /// Destroy the associated CVODE memory and SUNDIALS objects.
188  virtual ~CVODESolver();
189 };
190 
191 
192 // ---------------------------------------------------------------------------
193 // Interface to ARKode's ARKStep module -- Additive Runge-Kutta methods
194 // ---------------------------------------------------------------------------
195 
196 /// Interface to ARKode's ARKStep module -- additive Runge-Kutta methods.
197 class ARKStepSolver : public ODESolver, public SundialsSolver
198 {
199 public:
200  /// Types of ARKODE solvers.
201  enum Type
202  {
203  EXPLICIT, ///< Explicit RK method
204  IMPLICIT, ///< Implicit RK method
205  IMEX ///< Implicit-explicit ARK method
206  };
207 
208 protected:
209  Type rk_type; ///< Runge-Kutta type.
210  int step_mode; ///< ARKStep step mode (ARK_NORMAL or ARK_ONE_STEP).
211  bool use_implicit; ///< True for implicit or imex integration.
212 
213  /** @name Wrappers to compute the ODE RHS functions.
214  RHS1 is explicit RHS and RHS2 the implicit RHS for IMEX integration. When
215  purely implicit or explicit only RHS1 is used. */
216  ///@{
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);
219  ///@}
220 
221  /// Setup the linear system \f$ A x = b \f$.
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);
226 
227  /// Solve the linear system \f$ A x = b \f$.
228  static int LinSysSolve(SUNLinearSolver LS, SUNMatrix A, N_Vector x,
229  N_Vector b, realtype tol);
230 
231  /// Setup the linear system \f$ M x = b \f$.
232  static int MassSysSetup(realtype t, SUNMatrix M, void *user_data,
233  N_Vector tmp1, N_Vector tmp2, N_Vector tmp3);
234 
235  /// Solve the linear system \f$ M x = b \f$.
236  static int MassSysSolve(SUNLinearSolver LS, SUNMatrix M, N_Vector x,
237  N_Vector b, realtype tol);
238 
239  /// Compute the matrix-vector product \f$ v = M x \f$.
240  static int MassMult1(SUNMatrix M, N_Vector x, N_Vector v);
241 
242  /// Compute the matrix-vector product \f$v = M_t x \f$ at time t.
243  static int MassMult2(N_Vector x, N_Vector v, realtype t,
244  void* mtimes_data);
245 
246 public:
247  /// Construct a serial wrapper to SUNDIALS' ARKode integrator.
248  /** @param[in] type Specifies the RK method type:
249  - EXPLICIT - explicit RK method (default)
250  - IMPLICIT - implicit RK method
251  - IMEX - implicit-explicit ARK method */
252  ARKStepSolver(Type type = EXPLICIT);
253 
254 #ifdef MFEM_USE_MPI
255  /// Construct a parallel wrapper to SUNDIALS' ARKode integrator.
256  /** @param[in] comm The MPI communicator used to partition the ODE system.
257  @param[in] type Specifies the RK method type:
258  - EXPLICIT - explicit RK method (default)
259  - IMPLICIT - implicit RK method
260  - IMEX - implicit-explicit ARK method */
261  ARKStepSolver(MPI_Comm comm, Type type = EXPLICIT);
262 #endif
263 
264  /** @brief Initialize ARKode: calls ARKStepCreate() to create the ARKStep
265  memory and set some defaults.
266 
267  If the ARKStep has already been created, it checks if the problem size
268  has changed since the last call to Init(). If the problem is the same
269  then ARKStepReInit() will be called in the next call to Step(). If the
270  problem size has changed, the ARKStep memory is freed and realloced
271  for the new problem size. */
272  /** @param[in] f_ The TimeDependentOperator that defines the ODE system
273 
274  @note All other methods must be called after Init().
275 
276  @note If this method is called a second time with a different problem
277  size, then any non-default user-set options will be lost and will need
278  to be set again. */
279  void Init(TimeDependentOperator &f_);
280 
281  /// Integrate the ODE with ARKode using the specified step mode.
282  /**
283  @param[in,out] x On output, the solution vector at the requested output
284  time, tout = @a t + @a dt
285  @param[in,out] t On output, the output time reached
286  @param[in,out] dt On output, the last time step taken
287 
288  @note On input, the values of @a t and @a dt are used to compute desired
289  output time for the integration, tout = @a t + @a dt.
290  */
291  virtual void Step(Vector &x, double &t, double &dt);
292 
293  /** @brief Attach the linear system setup and solve methods from the
294  TimeDependentOperator i.e., SUNImplicitSetup() and SUNImplicitSolve() to
295  ARKode.
296  */
297  void UseMFEMLinearSolver();
298 
299  /// Attach a SUNDIALS GMRES linear solver to ARKode.
301 
302  /** @brief Attach mass matrix linear system setup, solve, and matrix-vector
303  product methods from the TimeDependentOperator i.e., SUNMassSetup(),
304  SUNMassSolve(), and SUNMassMult() to ARKode.
305 
306  @param[in] tdep An integer flag indicating if the mass matrix is time
307  dependent (1) or time independent (0)
308  */
309  void UseMFEMMassLinearSolver(int tdep);
310 
311  /** @brief Attach the SUNDIALS GMRES linear solver and the mass matrix
312  matrix-vector product method from the TimeDependentOperator i.e.,
313  SUNMassMult() to ARKode to solve mass matrix systems.
314 
315  @param[in] tdep An integer flag indicating if the mass matrix is time
316  dependent (1) or time independent (0)
317  */
318  void UseSundialsMassLinearSolver(int tdep);
319 
320  /// Select the ARKode step mode: ARK_NORMAL (default) or ARK_ONE_STEP.
321  /** @param[in] itask The desired step mode */
322  void SetStepMode(int itask);
323 
324  /// Set the scalar relative and scalar absolute tolerances.
325  void SetSStolerances(double reltol, double abstol);
326 
327  /// Set the maximum time step.
328  void SetMaxStep(double dt_max);
329 
330  /// Chooses integration order for all explicit / implicit / IMEX methods.
331  /** The default is 4, and the allowed ranges are: [2, 8] for explicit;
332  [2, 5] for implicit; [3, 5] for IMEX. */
333  void SetOrder(int order);
334 
335  /// Choose a specific Butcher table for an explicit RK method.
336  /** See ARKODE documentation for all possible options, stability regions, etc.
337  For example, table_num = BOGACKI_SHAMPINE_4_2_3 is 4-stage 3rd order. */
338  void SetERKTableNum(int table_num);
339 
340  /// Choose a specific Butcher table for a diagonally implicit RK method.
341  /** See ARKODE documentation for all possible options, stability regions, etc.
342  For example, table_num = CASH_5_3_4 is 5-stage 4th order. */
343  void SetIRKTableNum(int table_num);
344 
345  /// Choose a specific Butcher table for an IMEX RK method.
346  /** See ARKODE documentation for all possible options, stability regions, etc.
347  For example, etable_num = ARK548L2SA_DIRK_8_4_5 and
348  itable_num = ARK548L2SA_ERK_8_4_5 is 8-stage 5th order. */
349  void SetIMEXTableNum(int etable_num, int itable_num);
350 
351  /// Use a fixed time step size (disable temporal adaptivity).
352  /** Use of this function is not recommended, since there is no assurance of
353  the validity of the computed solutions. It is primarily provided for
354  code-to-code verification testing purposes. */
355  void SetFixedStep(double dt);
356 
357  /// Print various ARKStep statistics.
358  void PrintInfo() const;
359 
360  /// Destroy the associated ARKode memory and SUNDIALS objects.
361  virtual ~ARKStepSolver();
362 };
363 
364 
365 // ---------------------------------------------------------------------------
366 // Interface to the KINSOL library -- nonlinear solver methods
367 // ---------------------------------------------------------------------------
368 
369 /// Interface to the KINSOL library -- nonlinear solver methods.
370 class KINSolver : public NewtonSolver, public SundialsSolver
371 {
372 protected:
373  int global_strategy; ///< KINSOL solution strategy
374  bool use_oper_grad; ///< use the Jv prod function
375  mutable N_Vector y_scale, f_scale; ///< scaling vectors
376  const Operator *jacobian; ///< stores oper->GetGradient()
377  int maa; ///< number of acceleration vectors
378 
379  /// Wrapper to compute the nonlinear residual \f$ F(u) = 0 \f$.
380  static int Mult(const N_Vector u, N_Vector fu, void *user_data);
381 
382  /// Wrapper to compute the Jacobian-vector product \f$ J(u) v = Jv \f$.
383  static int GradientMult(N_Vector v, N_Vector Jv, N_Vector u,
384  booleantype *new_u, void *user_data);
385 
386  /// Setup the linear system \f$ J u = b \f$.
387  static int LinSysSetup(N_Vector u, N_Vector fu, SUNMatrix J,
388  void *user_data, N_Vector tmp1, N_Vector tmp2);
389 
390  /// Solve the linear system \f$ J u = b \f$.
391  static int LinSysSolve(SUNLinearSolver LS, SUNMatrix J, N_Vector u,
392  N_Vector b, realtype tol);
393 
394 public:
395 
396  /// Construct a serial wrapper to SUNDIALS' KINSOL nonlinear solver.
397  /** @param[in] strategy Specifies the nonlinear solver strategy:
398  KIN_NONE / KIN_LINESEARCH / KIN_PICARD / KIN_FP.
399  @param[in] oper_grad Specifies whether the solver should use its
400  Operator's GetGradient() method to compute the
401  Jacobian of the system. */
402  KINSolver(int strategy, bool oper_grad = true);
403 
404 #ifdef MFEM_USE_MPI
405  /// Construct a parallel wrapper to SUNDIALS' KINSOL nonlinear solver.
406  /** @param[in] comm The MPI communicator used to partition the system.
407  @param[in] strategy Specifies the nonlinear solver strategy:
408  KIN_NONE / KIN_LINESEARCH / KIN_PICARD / KIN_FP.
409  @param[in] oper_grad Specifies whether the solver should use its
410  Operator's GetGradient() method to compute the
411  Jacobian of the system. */
412  KINSolver(MPI_Comm comm, int strategy, bool oper_grad = true);
413 #endif
414 
415  /// Destroy the associated KINSOL memory.
416  virtual ~KINSolver();
417 
418  /// Set the nonlinear Operator of the system and initialize KINSOL.
419  /** @note If this method is called a second time with a different problem
420  size, then non-default KINSOL-specific options will be lost and will need
421  to be set again. */
422  virtual void SetOperator(const Operator &op);
423 
424  /// Set the linear solver for inverting the Jacobian.
425  /** @note This function assumes that Operator::GetGradient(const Vector &)
426  is implemented by the Operator specified by
427  SetOperator(const Operator &).
428 
429  This method must be called after SetOperator(). */
430  virtual void SetSolver(Solver &solver);
431 
432  /// Equivalent to SetSolver(solver).
433  virtual void SetPreconditioner(Solver &solver) { SetSolver(solver); }
434 
435  /// Set KINSOL's scaled step tolerance.
436  /** The default tolerance is \f$ U^\frac{2}{3} \f$ , where
437  U = machine unit roundoff.
438  @note This method must be called after SetOperator(). */
439  void SetScaledStepTol(double sstol);
440 
441  /// Set maximum number of nonlinear iterations without a Jacobian update.
442  /** The default is 10.
443  @note This method must be called after SetOperator(). */
444  void SetMaxSetupCalls(int max_calls);
445 
446  /// Set the number of acceleration vectors to use with KIN_FP or KIN_PICARD.
447  /** The default is 0.
448  @ note This method must be called before SetOperator() to set the
449  maximum size of the acceleration space. The value of @a maa can be
450  altered after SetOperator() is called but it can't be higher than initial
451  maximum. */
452  void SetMAA(int maa);
453 
454  /// Solve the nonlinear system \f$ F(x) = 0 \f$.
455  /** This method computes the x_scale and fx_scale vectors and calls the
456  other Mult(Vector&, Vector&, Vector&) const method. The x_scale vector
457  is a vector of ones and values of fx_scale are determined by comparing
458  the chosen relative and functional norm (i.e. absolute) tolerances.
459  @param[in] b Not used, KINSOL always assumes zero RHS
460  @param[in,out] x On input, initial guess, if @a #iterative_mode = true,
461  otherwise the initial guess is zero; on output, the
462  solution */
463  virtual void Mult(const Vector &b, Vector &x) const;
464 
465  /// Solve the nonlinear system \f$ F(x) = 0 \f$.
466  /** Calls KINSol() to solve the nonlinear system. Before calling KINSol(),
467  this functions uses the data members inherited from class IterativeSolver
468  to set corresponding KINSOL options.
469  @param[in,out] x On input, initial guess, if @a #iterative_mode =
470  true, otherwise the initial guess is zero; on
471  output, the solution
472  @param[in] x_scale Elements of a diagonal scaling matrix D, s.t.
473  D*x has all elements roughly the same when
474  x is close to a solution
475  @param[in] fx_scale Elements of a diagonal scaling matrix E, s.t.
476  D*F(x) has all elements roughly the same when
477  x is not too close to a solution */
478  void Mult(Vector &x, const Vector &x_scale, const Vector &fx_scale) const;
479 };
480 
481 } // namespace mfem
482 
483 #endif // MFEM_USE_SUNDIALS
484 
485 #endif // MFEM_SUNDIALS
void Init(TimeDependentOperator &f_)
Initialize CVODE: calls CVodeCreate() to create the CVODE memory and set some defaults.
Definition: sundials.cpp:151
void SetSStolerances(double reltol, double abstol)
Set the scalar relative and scalar absolute tolerances.
Definition: sundials.cpp:342
void SetScaledStepTol(double sstol)
Set KINSOL&#39;s scaled step tolerance.
Definition: sundials.cpp:1219
void SetStepMode(int itask)
Select the ARKode step mode: ARK_NORMAL (default) or ARK_ONE_STEP.
Definition: sundials.cpp:824
Base abstract class for first order time dependent operators.
Definition: operator.hpp:259
virtual void Step(Vector &x, double &t, double &dt)
Integrate the ODE with CVODE using the specified step mode.
Definition: sundials.cpp:256
void * GetMem() const
Access the SUNDIALS memory structure.
Definition: sundials.hpp:80
virtual ~CVODESolver()
Destroy the associated CVODE memory and SUNDIALS objects.
Definition: sundials.cpp:405
bool use_oper_grad
use the Jv prod function
Definition: sundials.hpp:374
void SetIRKTableNum(int table_num)
Choose a specific Butcher table for a diagonally implicit RK method.
Definition: sundials.cpp:853
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
Definition: ode.hpp:22
void SetIMEXTableNum(int etable_num, int itable_num)
Choose a specific Butcher table for an IMEX RK method.
Definition: sundials.cpp:859
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 .
Definition: sundials.cpp:455
void SetMaxStep(double dt_max)
Set the maximum time step.
Definition: sundials.cpp:835
void SetOrder(int order)
Chooses integration order for all explicit / implicit / IMEX methods.
Definition: sundials.cpp:841
int GetFlag() const
Returns the last flag retured by a call to a SUNDIALS function.
Definition: sundials.hpp:83
void * sundials_mem
SUNDIALS mem structure.
Definition: sundials.hpp:48
long saved_global_size
Global vector length on last initialization.
Definition: sundials.hpp:51
static int MassSysSetup(realtype t, SUNMatrix M, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
Setup the linear system .
Definition: sundials.cpp:489
Explicit RK method.
Definition: sundials.hpp:203
void SetMaxSetupCalls(int max_calls)
Set maximum number of nonlinear iterations without a Jacobian update.
Definition: sundials.cpp:1225
ARKStepSolver(Type type=EXPLICIT)
Construct a serial wrapper to SUNDIALS&#39; ARKode integrator.
Definition: sundials.cpp:532
Implicit RK method.
Definition: sundials.hpp:204
Interface to ARKode&#39;s ARKStep module – additive Runge-Kutta methods.
Definition: sundials.hpp:197
int global_strategy
KINSOL solution strategy.
Definition: sundials.hpp:373
SUNLinearSolver LSA
Linear solver for A.
Definition: sundials.hpp:56
SUNMatrix A
Linear system A = I - gamma J, M - gamma J, or J.
Definition: sundials.hpp:54
static int MassMult1(SUNMatrix M, N_Vector x, N_Vector v)
Compute the matrix-vector product .
Definition: sundials.cpp:510
SundialsSolver()
Protected constructor: objects of this type should be constructed only as part of a derived class...
Definition: sundials.hpp:74
SUNMatrix M
Mass matrix M.
Definition: sundials.hpp:55
virtual void SetSolver(Solver &solver)
Set the linear solver for inverting the Jacobian.
Definition: sundials.cpp:1185
bool Parallel() const
Definition: sundials.hpp:61
int lmm_type
Linear multistep method type.
Definition: sundials.hpp:95
Interface to the CVODE library – linear multi-step methods.
Definition: sundials.hpp:92
double b
Definition: lissajous.cpp:42
Interface to the KINSOL library – nonlinear solver methods.
Definition: sundials.hpp:370
void SetMaxStep(double dt_max)
Set the maximum time step.
Definition: sundials.cpp:348
Type
Types of ARKODE solvers.
Definition: sundials.hpp:201
Type rk_type
Runge-Kutta type.
Definition: sundials.hpp:209
virtual ~ARKStepSolver()
Destroy the associated ARKode memory and SUNDIALS objects.
Definition: sundials.cpp:923
Newton&#39;s method for solving F(x)=b for a given operator F.
Definition: solvers.hpp:300
bool use_implicit
True for implicit or imex integration.
Definition: sundials.hpp:211
SUNNonlinearSolver NLS
Nonlinear solver.
Definition: sundials.hpp:58
CVODESolver(int lmm)
Construct a serial wrapper to SUNDIALS&#39; CVODE integrator.
Definition: sundials.cpp:120
static int Mult(const N_Vector u, N_Vector fu, void *user_data)
Wrapper to compute the nonlinear residual .
Definition: sundials.cpp:937
int step_mode
ARKStep step mode (ARK_NORMAL or ARK_ONE_STEP).
Definition: sundials.hpp:210
static int LinSysSetup(N_Vector u, N_Vector fu, SUNMatrix J, void *user_data, N_Vector tmp1, N_Vector tmp2)
Setup the linear system .
Definition: sundials.cpp:974
SUNLinearSolver LSM
Linear solver for M.
Definition: sundials.hpp:57
static int RHS1(realtype t, const N_Vector y, N_Vector ydot, void *user_data)
Definition: sundials.cpp:418
Base class for interfacing with SUNDIALS packages.
Definition: sundials.hpp:45
N_Vector f_scale
scaling vectors
Definition: sundials.hpp:375
void UseMFEMLinearSolver()
Attach the linear system setup and solve methods from the TimeDependentOperator i.e., SUNImplicitSetup() and SUNImplicitSolve() to CVODE.
Definition: sundials.cpp:291
virtual void SetOperator(const Operator &op)
Set the nonlinear Operator of the system and initialize KINSOL.
Definition: sundials.cpp:1052
virtual ~KINSolver()
Destroy the associated KINSOL memory.
Definition: sundials.cpp:1349
void SetFixedStep(double dt)
Use a fixed time step size (disable temporal adaptivity).
Definition: sundials.cpp:865
bool reinit
Flag to signal memory reinitialization is need.
Definition: sundials.hpp:50
int maa
number of acceleration vectors
Definition: sundials.hpp:377
void SetMAA(int maa)
Set the number of acceleration vectors to use with KIN_FP or KIN_PICARD.
Definition: sundials.cpp:1231
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 .
Definition: sundials.cpp:94
void PrintInfo() const
Print various ARKStep statistics.
Definition: sundials.cpp:871
static int RHS2(realtype t, const N_Vector y, N_Vector ydot, void *user_data)
Definition: sundials.cpp:438
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 .
Definition: sundials.cpp:951
const Operator * jacobian
stores oper-&gt;GetGradient()
Definition: sundials.hpp:376
static constexpr double default_rel_tol
Default scalar relative tolerance.
Definition: sundials.hpp:68
N_Vector y_scale
Definition: sundials.hpp:375
int step_mode
CVODE step mode (CV_NORMAL or CV_ONE_STEP).
Definition: sundials.hpp:96
static int MassMult2(N_Vector x, N_Vector v, realtype t, void *mtimes_data)
Compute the matrix-vector product at time t.
Definition: sundials.cpp:520
KINSolver(int strategy, bool oper_grad=true)
Construct a serial wrapper to SUNDIALS&#39; KINSOL nonlinear solver.
Definition: sundials.cpp:1004
Implicit-explicit ARK method.
Definition: sundials.hpp:205
static constexpr double default_abs_tol
Default scalar absolute tolerance.
Definition: sundials.hpp:70
int flag
Last flag returned from a call to SUNDIALS.
Definition: sundials.hpp:49
void UseMFEMLinearSolver()
Attach the linear system setup and solve methods from the TimeDependentOperator i.e., SUNImplicitSetup() and SUNImplicitSolve() to ARKode.
Definition: sundials.cpp:726
Vector data type.
Definition: vector.hpp:48
static int LinSysSolve(SUNLinearSolver LS, SUNMatrix A, N_Vector x, N_Vector b, realtype tol)
Solve the linear system .
Definition: sundials.cpp:474
static int LinSysSolve(SUNLinearSolver LS, SUNMatrix A, N_Vector x, N_Vector b, realtype tol)
Solve the linear system .
Definition: sundials.cpp:109
void PrintInfo() const
Print various CVODE statistics.
Definition: sundials.cpp:360
void SetMaxOrder(int max_order)
Set the maximum method order.
Definition: sundials.cpp:354
void UseMFEMMassLinearSolver(int tdep)
Attach mass matrix linear system setup, solve, and matrix-vector product methods from the TimeDepende...
Definition: sundials.cpp:772
Base class for solvers.
Definition: operator.hpp:500
N_Vector y
State vector.
Definition: sundials.hpp:53
void SetERKTableNum(int table_num)
Choose a specific Butcher table for an explicit RK method.
Definition: sundials.cpp:847
Abstract operator.
Definition: operator.hpp:24
void Init(TimeDependentOperator &f_)
Initialize ARKode: calls ARKStepCreate() to create the ARKStep memory and set some defaults...
Definition: sundials.cpp:565
virtual void SetPreconditioner(Solver &solver)
Equivalent to SetSolver(solver).
Definition: sundials.hpp:433
static int RHS(realtype t, const N_Vector y, N_Vector ydot, void *user_data)
Wrapper to compute the ODE rhs function.
Definition: sundials.cpp:78
void SetSStolerances(double reltol, double abstol)
Set the scalar relative and scalar absolute tolerances.
Definition: sundials.cpp:829
void UseSundialsLinearSolver()
Attach a SUNDIALS GMRES linear solver to ARKode.
Definition: sundials.cpp:757
static int LinSysSolve(SUNLinearSolver LS, SUNMatrix J, N_Vector u, N_Vector b, realtype tol)
Solve the linear system .
Definition: sundials.cpp:991
static int MassSysSolve(SUNLinearSolver LS, SUNMatrix M, N_Vector x, N_Vector b, realtype tol)
Solve the linear system .
Definition: sundials.cpp:499
virtual void Step(Vector &x, double &t, double &dt)
Integrate the ODE with ARKode using the specified step mode.
Definition: sundials.cpp:679
void UseSundialsLinearSolver()
Attach SUNDIALS GMRES linear solver to CVODE.
Definition: sundials.cpp:322
void SetStepMode(int itask)
Select the CVODE step mode: CV_NORMAL (default) or CV_ONE_STEP.
Definition: sundials.cpp:337
void UseSundialsMassLinearSolver(int tdep)
Attach the SUNDIALS GMRES linear solver and the mass matrix matrix-vector product method from the Tim...
Definition: sundials.cpp:804