Cantera  2.5.1
CVodesIntegrator.h
Go to the documentation of this file.
1 /**
2  * @file CVodesIntegrator.h
3  */
4 
5 // This file is part of Cantera. See License.txt in the top-level directory or
6 // at https://cantera.org/license.txt for license and copyright information.
7 
8 #ifndef CT_CVODESWRAPPER_H
9 #define CT_CVODESWRAPPER_H
10 
13 
14 #include "sundials/sundials_nvector.h"
15 
16 namespace Cantera
17 {
18 
19 /**
20  * Wrapper class for 'cvodes' integrator from LLNL.
21  *
22  * @see FuncEval.h. Classes that use CVodesIntegrator:
23  * ImplicitChem, ImplicitSurfChem, Reactor
24  */
26 {
27 public:
28  /**
29  * Constructor. Default settings: dense Jacobian, no user-supplied
30  * Jacobian function, Newton iteration.
31  */
33  virtual ~CVodesIntegrator();
34  virtual void setTolerances(double reltol, size_t n, double* abstol);
35  virtual void setTolerances(double reltol, double abstol);
36  virtual void setSensitivityTolerances(double reltol, double abstol);
37  virtual void setProblemType(int probtype);
38  virtual void initialize(double t0, FuncEval& func);
39  virtual void reinitialize(double t0, FuncEval& func);
40  virtual void integrate(double tout);
41  virtual doublereal step(double tout);
42  virtual double& solution(size_t k);
43  virtual double* solution();
44  virtual double* derivative(double tout, int n);
45  virtual int lastOrder() const;
46  virtual int nEquations() const {
47  return static_cast<int>(m_neq);
48  }
49  virtual int nEvals() const;
50  virtual void setMaxOrder(int n) {
51  m_maxord = n;
52  }
53  virtual void setMethod(MethodType t);
54  virtual void setMaxStepSize(double hmax);
55  virtual void setMinStepSize(double hmin);
56  virtual void setMaxSteps(int nmax);
57  virtual int maxSteps();
58  virtual void setMaxErrTestFails(int n);
59  virtual void setBandwidth(int N_Upper, int N_Lower) {
60  m_mupper = N_Upper;
61  m_mlower = N_Lower;
62  }
63  virtual int nSensParams() {
64  return static_cast<int>(m_np);
65  }
66  virtual double sensitivity(size_t k, size_t p);
67 
68  //! Returns a string listing the weighted error estimates associated
69  //! with each solution component.
70  //! This information can be used to identify which variables are
71  //! responsible for integrator failures or unexpected small timesteps.
72  virtual std::string getErrorInfo(int N);
73 
74  //! Error message information provide by CVodes
75  std::string m_error_message;
76 
77 protected:
78  //! Applies user-specified options to the underlying CVODES solver. Called
79  //! during integrator initialization or reinitialization.
80  void applyOptions();
81 
82 private:
83  void sensInit(double t0, FuncEval& func);
84 
85  size_t m_neq;
86  void* m_cvode_mem;
87  void* m_linsol; //!< Sundials linear solver object
88  void* m_linsol_matrix; //!< matrix used by Sundials
89  FuncEval* m_func;
90  double m_t0;
91  double m_time; //!< The current integrator time
92  N_Vector m_y, m_abstol;
93  N_Vector m_dky;
94  int m_type;
95  int m_itol;
96  int m_method;
97  int m_maxord;
98  double m_reltol;
99  double m_abstols;
100  double m_reltolsens, m_abstolsens;
101  size_t m_nabs;
102  double m_hmax, m_hmin;
103  int m_maxsteps;
104  int m_maxErrTestFails;
105  N_Vector* m_yS;
106  size_t m_np;
107  int m_mupper, m_mlower;
108 
109  //! Indicates whether the sensitivities stored in m_yS have been updated
110  //! for at the current integrator time.
111  bool m_sens_ok;
112 };
113 
114 } // namespace
115 
116 #endif
Wrapper class for 'cvodes' integrator from LLNL.
virtual int nEvals() const
The number of function evaluations.
virtual int lastOrder() const
Order used during the last solution step.
virtual void setMinStepSize(double hmin)
Set the minimum step size.
void * m_linsol
Sundials linear solver object.
std::string m_error_message
Error message information provide by CVodes.
double m_time
The current integrator time.
bool m_sens_ok
Indicates whether the sensitivities stored in m_yS have been updated for at the current integrator ti...
virtual void initialize(double t0, FuncEval &func)
Initialize the integrator for a new problem.
virtual void integrate(double tout)
Integrate the system of equations.
virtual void setMaxSteps(int nmax)
Set the maximum number of time-steps the integrator can take before reaching the next output time.
virtual doublereal step(double tout)
Integrate the system of equations.
virtual void setSensitivityTolerances(double reltol, double abstol)
Set the sensitivity error tolerances.
virtual double * solution()
The current value of the solution of the system of equations.
virtual void setTolerances(double reltol, size_t n, double *abstol)
Set error tolerances.
virtual int maxSteps()
Returns the maximum number of time-steps the integrator can take before reaching the next output time...
virtual void setMaxStepSize(double hmax)
Set the maximum step size.
void applyOptions()
Applies user-specified options to the underlying CVODES solver.
virtual int nEquations() const
The number of equations.
virtual double * derivative(double tout, int n)
n-th derivative of the output function at time tout.
virtual void setProblemType(int probtype)
Set the problem type.
virtual void setMethod(MethodType t)
Set the solution method.
void * m_linsol_matrix
matrix used by Sundials
virtual void setMaxErrTestFails(int n)
Set the maximum permissible number of error test failures.
virtual std::string getErrorInfo(int N)
Returns a string listing the weighted error estimates associated with each solution component.
virtual void setMaxOrder(int n)
Set the maximum integration order that will be used.
Virtual base class for ODE right-hand-side function evaluators.
Definition: FuncEval.h:27
Abstract base class for ODE system integrators.
Definition: Integrator.h:53
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
MethodType
Specifies the method used to integrate the system of equations.
Definition: Integrator.h:32