Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
11 
12 #ifdef HAS_SUNDIALS
13 
14 #include "sundials/sundials_nvector.h"
15 
16 namespace Cantera
17 {
18 
19 class FuncData;
20 
21 /**
22  * Exception thrown when a CVODES error is encountered.
23  */
24 class CVodesErr : public CanteraError
25 {
26 public:
27  explicit CVodesErr(const std::string& msg) : CanteraError("CVodesIntegrator", msg) {}
28 };
29 
30 /**
31  * Wrapper class for 'cvodes' integrator from LLNL.
32  *
33  * @see FuncEval.h. Classes that use CVodeInt:
34  * ImplicitChem, ImplicitSurfChem, Reactor
35  */
37 {
38 public:
39  /**
40  * Constructor. Default settings: dense Jacobian, no user-supplied
41  * Jacobian function, Newton iteration.
42  */
44  virtual ~CVodesIntegrator();
45  virtual void setTolerances(double reltol, size_t n, double* abstol);
46  virtual void setTolerances(double reltol, double abstol);
47  virtual void setSensitivityTolerances(double reltol, double abstol);
48  virtual void setProblemType(int probtype);
49  virtual void initialize(double t0, FuncEval& func);
50  virtual void reinitialize(double t0, FuncEval& func);
51  virtual void integrate(double tout);
52  virtual doublereal step(double tout);
53  virtual double& solution(size_t k);
54  virtual double* solution();
55  virtual int nEquations() const {
56  return static_cast<int>(m_neq);
57  }
58  virtual int nEvals() const;
59  virtual void setMaxOrder(int n) {
60  m_maxord = n;
61  }
62  virtual void setMethod(MethodType t);
63  virtual void setIterator(IterType t);
64  virtual void setMaxStepSize(double hmax);
65  virtual void setMinStepSize(double hmin);
66  virtual void setMaxSteps(int nmax);
67  virtual void setMaxErrTestFails(int n);
68  virtual void setBandwidth(int N_Upper, int N_Lower) {
69  m_mupper = N_Upper;
70  m_mlower = N_Lower;
71  }
72  virtual int nSensParams() {
73  return static_cast<int>(m_np);
74  }
75  virtual double sensitivity(size_t k, size_t p);
76 
77  //! Returns a string listing the weighted error estimates associated
78  //! with each solution component.
79  //! This information can be used to identify which variables are
80  //! responsible for integrator failures or unexpected small timesteps.
81  virtual std::string getErrorInfo(int N);
82 
83  //! Error message information provide by CVodes
84  std::string m_error_message;
85 
86 protected:
87  //! Applies user-specified options to the underlying CVODES solver. Called
88  //! during integrator initialization or reinitialization.
89  void applyOptions();
90 
91 private:
92  void sensInit(double t0, FuncEval& func);
93 
94  size_t m_neq;
95  void* m_cvode_mem;
96  double m_t0;
97  double m_time; //!< The current integrator time
98  N_Vector m_y, m_abstol;
99  int m_type;
100  int m_itol;
101  int m_method;
102  int m_iter;
103  int m_maxord;
104  double m_reltol;
105  double m_abstols;
106  double m_reltolsens, m_abstolsens;
107  size_t m_nabs;
108  double m_hmax, m_hmin;
109  int m_maxsteps;
110  int m_maxErrTestFails;
111  FuncData* m_fdata;
112  N_Vector* m_yS;
113  size_t m_np;
114  int m_mupper, m_mlower;
115 
116  //! Indicates whether the sensitivities stored in m_yS have been updated
117  //! for at the current integrator time.
118  bool m_sens_ok;
119 
120 };
121 
122 } // namespace
123 
124 #else
125 
126 #error No sundials!
127 
128 #endif
129 
130 #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.
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: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...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
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:132
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:40
virtual doublereal step(double tout)
Integrate the system of equations.
std::string m_error_message
Error message information provide by CVodes.
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:31
double m_time
The current integrator time.
virtual void initialize(double t0, FuncEval &func)
Initialize the integrator for a new problem.