Cantera  2.0
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 
9 #ifdef HAS_SUNDIALS
10 
14 #include "cantera/base/ct_defs.h"
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  CVodesErr(std::string msg) : CanteraError("CVodesIntegrator", msg) {}
34 };
35 
36 
37 /**
38  * Wrapper class for 'cvodes' integrator from LLNL.
39  *
40  * @see FuncEval.h. Classes that use CVodeInt:
41  * ImplicitChem, ImplicitSurfChem, Reactor
42  *
43  */
44 class CVodesIntegrator : public Integrator
45 {
46 
47 public:
48 
49  CVodesIntegrator();
50  virtual ~CVodesIntegrator();
51  virtual void setTolerances(double reltol, size_t n, double* abstol);
52  virtual void setTolerances(double reltol, double abstol);
53  virtual void setSensitivityTolerances(double reltol, double abstol);
54  virtual void setProblemType(int probtype);
55  virtual void initialize(double t0, FuncEval& func);
56  virtual void reinitialize(double t0, FuncEval& func);
57  virtual void integrate(double tout);
58  virtual doublereal step(double tout);
59  virtual double& solution(size_t k);
60  virtual double* solution();
61  virtual int nEquations() const {
62  return m_neq;
63  }
64  virtual int nEvals() const;
65  virtual void setMaxOrder(int n) {
66  m_maxord = n;
67  }
68  virtual void setMethod(MethodType t);
69  virtual void setIterator(IterType t);
70  virtual void setMaxStepSize(double hmax);
71  virtual void setMinStepSize(double hmin);
72  virtual void setMaxSteps(int nmax);
73  virtual void setBandwidth(int N_Upper, int N_Lower) {
74  m_mupper = N_Upper;
75  m_mlower = N_Lower;
76  }
77  virtual int nSensParams() {
78  return m_np;
79  }
80  virtual double sensitivity(size_t k, size_t p);
81 
82 private:
83 
84  void sensInit(double t0, FuncEval& func);
85 
86  size_t m_neq;
87  void* m_cvode_mem;
88  double m_t0;
89  void* m_y, *m_abstol;
90  int m_type;
91  int m_itol;
92  int m_method;
93  int m_iter;
94  int m_maxord;
95  double m_reltol;
96  double m_abstols;
97  double m_reltolsens, m_abstolsens;
98  size_t m_nabs;
99  double m_hmax, m_hmin;
100  int m_maxsteps;
101  FuncData* m_fdata;
102  N_Vector* m_yS;
103  size_t m_np;
104  int m_mupper, m_mlower;
105 };
106 
107 } // namespace
108 
109 #else
110 
111 #error No sundials!
112 
113 #endif
114 
115 #endif