Cantera  2.4.0
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 http://www.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 int nEquations() const {
45  return static_cast<int>(m_neq);
46  }
47  virtual int nEvals() const;
48  virtual void setMaxOrder(int n) {
49  m_maxord = n;
50  }
51  virtual void setMethod(MethodType t);
52  virtual void setIterator(IterType t);
53  virtual void setMaxStepSize(double hmax);
54  virtual void setMinStepSize(double hmin);
55  virtual void setMaxSteps(int nmax);
56  virtual void setMaxErrTestFails(int n);
57  virtual void setBandwidth(int N_Upper, int N_Lower) {
58  m_mupper = N_Upper;
59  m_mlower = N_Lower;
60  }
61  virtual int nSensParams() {
62  return static_cast<int>(m_np);
63  }
64  virtual double sensitivity(size_t k, size_t p);
65 
66  //! Returns a string listing the weighted error estimates associated
67  //! with each solution component.
68  //! This information can be used to identify which variables are
69  //! responsible for integrator failures or unexpected small timesteps.
70  virtual std::string getErrorInfo(int N);
71 
72  //! Error message information provide by CVodes
73  std::string m_error_message;
74 
75 protected:
76  //! Applies user-specified options to the underlying CVODES solver. Called
77  //! during integrator initialization or reinitialization.
78  void applyOptions();
79 
80 private:
81  void sensInit(double t0, FuncEval& func);
82 
83  size_t m_neq;
84  void* m_cvode_mem;
85  void* m_linsol; //!< Sundials linear solver object
86  void* m_linsol_matrix; //!< matrix used by Sundials
87  FuncEval* m_func;
88  double m_t0;
89  double m_time; //!< The current integrator time
90  N_Vector m_y, m_abstol;
91  int m_type;
92  int m_itol;
93  int m_method;
94  int m_iter;
95  int m_maxord;
96  double m_reltol;
97  double m_abstols;
98  double m_reltolsens, m_abstolsens;
99  size_t m_nabs;
100  double m_hmax, m_hmin;
101  int m_maxsteps;
102  int m_maxErrTestFails;
103  N_Vector* m_yS;
104  size_t m_np;
105  int m_mupper, m_mlower;
106 
107  //! Indicates whether the sensitivities stored in m_yS have been updated
108  //! for at the current integrator time.
109  bool m_sens_ok;
110 };
111 
112 } // namespace
113 
114 #endif
virtual void setProblemType(int probtype)
Set the problem type.
void applyOptions()
Applies user-specified options to the underlying CVODES solver.
Wrapper class for &#39;cvodes&#39; integrator from LLNL.
virtual int nEvals() const
The number of function evaluations.
void * m_linsol
Sundials linear solver object.
virtual void setMaxStepSize(double hmax)
Set the maximum step size.
virtual void setMethod(MethodType t)
Set the solution method.
virtual void setMinStepSize(double hmin)
Set the minimum step size.
virtual void setIterator(IterType t)
Set the linear iterator.
virtual double * solution()
The current value of the solution of the system of equations.
virtual void integrate(double tout)
Integrate the system of equations.
void * m_linsol_matrix
matrix used by Sundials
Abstract base class for ODE system integrators.
Definition: Integrator.h:52
virtual void setSensitivityTolerances(double reltol, double abstol)
Set the sensitivity error tolerances.
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 int nEquations() const
The number of equations.
virtual void setTolerances(double reltol, size_t n, double *abstol)
Set error tolerances.
virtual void setMaxErrTestFails(int n)
Set the maximum permissible number of error test failures.
bool m_sens_ok
Indicates whether the sensitivities stored in m_yS have been updated for at the current integrator ti...
IterType
Specifies the method used for iteration.
Definition: Integrator.h:41
virtual doublereal step(double tout)
Integrate the system of equations.
std::string m_error_message
Error message information provide by CVodes.
Virtual base class for ODE right-hand-side function evaluators.
Definition: FuncEval.h:26
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
MethodType
Specifies the method used to integrate the system of equations.
Definition: Integrator.h:32
double m_time
The current integrator time.
virtual void initialize(double t0, FuncEval &func)
Initialize the integrator for a new problem.