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