Cantera  2.3.0
Integrator.h
Go to the documentation of this file.
1 /**
2  * @file Integrator.h
3  */
4 
5 /**
6  * @defgroup odeGroup ODE Integrators
7  */
8 
9 // This file is part of Cantera. See License.txt in the top-level directory or
10 // at http://www.cantera.org/license.txt for license and copyright information.
11 
12 #ifndef CT_INTEGRATOR_H
13 #define CT_INTEGRATOR_H
14 #include "FuncEval.h"
15 
16 #include "cantera/base/global.h"
17 
18 namespace Cantera
19 {
20 
21 const int DIAG = 1;
22 const int DENSE = 2;
23 const int NOJAC = 4;
24 const int JAC = 8;
25 const int GMRES = 16;
26 const int BAND = 32;
27 
28 /**
29  * Specifies the method used to integrate the system of equations.
30  * Not all methods are supported by all integrators.
31  */
32 enum MethodType {
33  BDF_Method, //!< Backward Differentiation
34  Adams_Method //! Adams
35 };
36 
37 //! Specifies the method used for iteration.
38 /*!
39  * Not all methods are supported by all integrators.
40  */
41 enum IterType {
42  //! Newton Iteration
44  //! Functional Iteration
46 };
47 
48 //! Abstract base class for ODE system integrators.
49 /*!
50  * @ingroup odeGroup
51  */
53 {
54 public:
55  //! Default Constructor
57  }
58 
59  //! Destructor
60  virtual ~Integrator() {
61  }
62 
63  //! Set error tolerances.
64  /*!
65  * @param reltol scalar relative tolerance
66  * @param n Number of equations
67  * @param abstol array of N absolute tolerance values
68  */
69  virtual void setTolerances(doublereal reltol, size_t n,
70  doublereal* abstol) {
71  warn("setTolerances");
72  }
73 
74  //! Set error tolerances.
75  /*!
76  * @param reltol scalar relative tolerance
77  * @param abstol scalar absolute tolerance
78  */
79  virtual void setTolerances(doublereal reltol, doublereal abstol) {
80  warn("setTolerances");
81  }
82 
83  //! Set the sensitivity error tolerances
84  /*!
85  * @param reltol scalar relative tolerance
86  * @param abstol scalar absolute tolerance
87  */
88  virtual void setSensitivityTolerances(doublereal reltol, doublereal abstol)
89  { }
90 
91  //! Set the problem type.
92  /*!
93  * @param probtype Type of the problem
94  */
95  virtual void setProblemType(int probtype) {
96  warn("setProblemType");
97  }
98 
99  /**
100  * Initialize the integrator for a new problem. Call after all options have
101  * been set.
102  * @param t0 initial time
103  * @param func RHS evaluator object for system of equations.
104  */
105  virtual void initialize(doublereal t0, FuncEval& func) {
106  warn("initialize");
107  }
108 
109  virtual void reinitialize(doublereal t0, FuncEval& func) {
110  warn("reinitialize");
111  }
112 
113  //! Integrate the system of equations.
114  /*!
115  * @param tout Integrate to this time. Note that this is the
116  * absolute time value, not a time interval.
117  */
118  virtual void integrate(doublereal tout) {
119  warn("integrate");
120  }
121 
122  /**
123  * Integrate the system of equations.
124  * @param tout integrate to this time. Note that this is the
125  * absolute time value, not a time interval.
126  */
127  virtual doublereal step(doublereal tout) {
128  warn("step");
129  return 0.0;
130  }
131 
132  //! The current value of the solution of equation k.
133  virtual doublereal& solution(size_t k) {
134  warn("solution");
135  return m_dummy;
136  }
137 
138  //! The current value of the solution of the system of equations.
139  virtual doublereal* solution() {
140  warn("solution");
141  return 0;
142  }
143 
144  //! The number of equations.
145  virtual int nEquations() const {
146  warn("nEquations");
147  return 0;
148  }
149 
150  //! The number of function evaluations.
151  virtual int nEvals() const {
152  warn("nEvals");
153  return 0;
154  }
155 
156  //! Set the maximum integration order that will be used.
157  virtual void setMaxOrder(int n) {
158  warn("setMaxorder");
159  }
160 
161  //! Set the solution method
162  virtual void setMethod(MethodType t) {
163  warn("setMethodType");
164  }
165 
166  //! Set the linear iterator.
167  virtual void setIterator(IterType t) {
168  warn("setInterator");
169  }
170 
171  //! Set the maximum step size
172  virtual void setMaxStepSize(double hmax) {
173  warn("setMaxStepSize");
174  }
175 
176  //! Set the minimum step size
177  virtual void setMinStepSize(double hmin) {
178  warn("setMinStepSize");
179  }
180 
181  //! Set the maximum permissible number of error test failures
182  virtual void setMaxErrTestFails(int n) {
183  warn("setMaxErrTestFails");
184  }
185 
186  virtual void setMaxSteps(int nmax) {
187  warn("setMaxStep");
188  }
189 
190  virtual void setBandwidth(int N_Upper, int N_Lower) {
191  warn("setBandwidth");
192  }
193 
194  virtual int nSensParams() {
195  warn("nSensParams()");
196  return 0;
197  }
198 
199  virtual double sensitivity(size_t k, size_t p) {
200  warn("sensitivity");
201  return 0.0;
202  }
203 
204 private:
205  doublereal m_dummy;
206  void warn(const std::string& msg) const {
207  writelog(">>>> Warning: method "+msg+" of base class "
208  +"Integrator called. Nothing done.\n");
209  }
210 };
211 
212 // defined in ODE_integrators.cpp
213 Integrator* newIntegrator(const std::string& itype);
214 
215 } // namespace
216 
217 #endif
Backward Differentiation.
Definition: Integrator.h:33
virtual void setMaxStepSize(double hmax)
Set the maximum step size.
Definition: Integrator.h:172
virtual void integrate(doublereal tout)
Integrate the system of equations.
Definition: Integrator.h:118
virtual int nEquations() const
The number of equations.
Definition: Integrator.h:145
virtual void setTolerances(doublereal reltol, doublereal abstol)
Set error tolerances.
Definition: Integrator.h:79
void writelog(const std::string &fmt, const Args &... args)
Write a formatted message to the screen.
Definition: global.h:179
virtual void setTolerances(doublereal reltol, size_t n, doublereal *abstol)
Set error tolerances.
Definition: Integrator.h:69
virtual ~Integrator()
Destructor.
Definition: Integrator.h:60
virtual void setMaxOrder(int n)
Set the maximum integration order that will be used.
Definition: Integrator.h:157
virtual int nEvals() const
The number of function evaluations.
Definition: Integrator.h:151
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, (see Input File Handling, Diagnostic Output, and Writing messages to the screen).
virtual void initialize(doublereal t0, FuncEval &func)
Initialize the integrator for a new problem.
Definition: Integrator.h:105
Functional Iteration.
Definition: Integrator.h:45
virtual void setProblemType(int probtype)
Set the problem type.
Definition: Integrator.h:95
virtual doublereal * solution()
The current value of the solution of the system of equations.
Definition: Integrator.h:139
virtual void setMinStepSize(double hmin)
Set the minimum step size.
Definition: Integrator.h:177
Abstract base class for ODE system integrators.
Definition: Integrator.h:52
Integrator()
Default Constructor.
Definition: Integrator.h:56
virtual void setSensitivityTolerances(doublereal reltol, doublereal abstol)
Set the sensitivity error tolerances.
Definition: Integrator.h:88
IterType
Specifies the method used for iteration.
Definition: Integrator.h:41
virtual doublereal & solution(size_t k)
The current value of the solution of equation k.
Definition: Integrator.h:133
Newton Iteration.
Definition: Integrator.h:43
virtual doublereal step(doublereal tout)
Integrate the system of equations.
Definition: Integrator.h:127
virtual void setMaxErrTestFails(int n)
Set the maximum permissible number of error test failures.
Definition: Integrator.h:182
Virtual base class for ODE right-hand-side function evaluators.
Definition: FuncEval.h:26
virtual void setIterator(IterType t)
Set the linear iterator.
Definition: Integrator.h:167
Namespace for the Cantera kernel.
Definition: application.cpp:29
virtual void setMethod(MethodType t)
Set the solution method.
Definition: Integrator.h:162
MethodType
Specifies the method used to integrate the system of equations.
Definition: Integrator.h:32