Cantera  2.1.2
CVodesIntegrator.h
Go to the documentation of this file.
1 /**
2  * @file CVodesIntegrator.h
3  */
4 // Copyright 2005 California Institute of Technology
5 
6 #ifndef CT_CVODESWRAPPER_H
7 #define CT_CVODESWRAPPER_H
8 
12 #include "cantera/base/ct_defs.h"
13 
14 #ifdef HAS_SUNDIALS
15 
16 #if SUNDIALS_VERSION == 22
17 #include "nvector_serial.h"
18 #else
19 #include "sundials/sundials_nvector.h"
20 #endif
21 
22 namespace Cantera
23 {
24 
25 class FuncData;
26 
27 /**
28  * Exception thrown when a CVODES error is encountered.
29  */
30 class CVodesErr : public CanteraError
31 {
32 public:
33  explicit CVodesErr(const std::string& msg) : CanteraError("CVodesIntegrator", msg) {}
34 };
35 
36 /**
37  * Wrapper class for 'cvodes' integrator from LLNL.
38  *
39  * @see FuncEval.h. Classes that use CVodeInt:
40  * ImplicitChem, ImplicitSurfChem, Reactor
41  *
42  * @deprecated Support for Sundials 2.2 and 2.3 is deprecated. Starting with
43  * %Cantera 2.2, only Sundials versions 2.4 and newer will be supported.
44  * (The CVodesIntegrator class itself is not deprecated).
45  */
47 {
48 public:
49  /**
50  * Constructor. Default settings: dense jacobian, no user-supplied
51  * Jacobian function, Newton iteration.
52  */
54  virtual ~CVodesIntegrator();
55  virtual void setTolerances(double reltol, size_t n, double* abstol);
56  virtual void setTolerances(double reltol, double abstol);
57  virtual void setSensitivityTolerances(double reltol, double abstol);
58  virtual void setProblemType(int probtype);
59  virtual void initialize(double t0, FuncEval& func);
60  virtual void reinitialize(double t0, FuncEval& func);
61  virtual void integrate(double tout);
62  virtual doublereal step(double tout);
63  virtual double& solution(size_t k);
64  virtual double* solution();
65  virtual int nEquations() const {
66  return m_neq;
67  }
68  virtual int nEvals() const;
69  virtual void setMaxOrder(int n) {
70  m_maxord = n;
71  }
72  virtual void setMethod(MethodType t);
73  virtual void setIterator(IterType t);
74  virtual void setMaxStepSize(double hmax);
75  virtual void setMinStepSize(double hmin);
76  virtual void setMaxSteps(int nmax);
77  virtual void setMaxErrTestFails(int n);
78  virtual void setBandwidth(int N_Upper, int N_Lower) {
79  m_mupper = N_Upper;
80  m_mlower = N_Lower;
81  }
82  virtual int nSensParams() {
83  return m_np;
84  }
85  virtual double sensitivity(size_t k, size_t p);
86 
87  //! Returns a string listing the weighted error estimates associated
88  //! with each solution component.
89  //! This information can be used to identify which variables are
90  //! responsible for integrator failures or unexpected small timesteps.
91  virtual std::string getErrorInfo(int N);
92 
93 protected:
94  //! Applies user-specified options to the underlying CVODES solver. Called
95  //! during integrator initialization or reinitialization.
96  void applyOptions();
97 
98 private:
99  void sensInit(double t0, FuncEval& func);
100 
101  size_t m_neq;
102  void* m_cvode_mem;
103  double m_t0;
104  double m_time; //!< The current integrator time
105  N_Vector m_y, m_abstol;
106  int m_type;
107  int m_itol;
108  int m_method;
109  int m_iter;
110  int m_maxord;
111  double m_reltol;
112  double m_abstols;
113  double m_reltolsens, m_abstolsens;
114  size_t m_nabs;
115  double m_hmax, m_hmin;
116  int m_maxsteps;
117  int m_maxErrTestFails;
118  FuncData* m_fdata;
119  N_Vector* m_yS;
120  size_t m_np;
121  int m_mupper, m_mlower;
122 
123  //! Indicates whether the sensitivities stored in m_yS have been updated
124  //! for at the current integrator time.
125  bool m_sens_ok;
126 };
127 
128 } // namespace
129 
130 #else
131 
132 #error No sundials!
133 
134 #endif
135 
136 #endif
virtual void setProblemType(int probtype)
Set the problem type.
void applyOptions()
Applies user-specified options to the underlying CVODES solver.
Wrapper class for 'cvodes' integrator from LLNL.
Exception thrown when a CVODES error is encountered.
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
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 int nEvals() const
The number of function evaluations.
virtual double * solution()
The current value of the solution of the system of equations.
virtual void integrate(double tout)
Integrate the system of equations.
Abstract base class for ODE system integrators.
Definition: Integrator.h:53
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...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
virtual void setMaxOrder(int n)
Set the maximum integration order that will be used.
CanteraError()
Protected default constructor discourages throwing errors containing no information.
Definition: ctexceptions.h:101
virtual void setTolerances(double reltol, size_t n, double *abstol)
Set or reset the number of equations.
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.
virtual int nEquations() const
The number of equations.
Virtual base class for ODE right-hand-side function evaluators.
Definition: FuncEval.h:23
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.