Cantera  2.1.2
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 // Copyright 2001 California Institute of Technology
10 
11 #ifndef CT_INTEGRATOR_H
12 #define CT_INTEGRATOR_H
13 #include "FuncEval.h"
14 
15 #include "cantera/base/ct_defs.h"
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 
49 //! Abstract base class for ODE system integrators.
50 /*!
51  * @ingroup odeGroup
52  */
54 {
55 public:
56  //! Default Constructor
58  }
59 
60  //! Destructor
61  virtual ~Integrator() {
62  }
63 
64  /** Set or reset the number of equations. */
65  //virtual void resize(int n)=0;
66 
67  //! Set error tolerances.
68  /*!
69  * @param reltol scalar relative tolerance
70  * @param n Number of equations
71  * @param abstol array of N absolute tolerance values
72  */
73  virtual void setTolerances(doublereal reltol, size_t n,
74  doublereal* abstol) {
75  warn("setTolerances");
76  }
77 
78  //! Set error tolerances.
79  /*!
80  * @param reltol scalar relative tolerance
81  * @param abstol scalar absolute tolerance
82  */
83  virtual void setTolerances(doublereal reltol, doublereal abstol) {
84  warn("setTolerances");
85  }
86 
87  //! Set the sensitivity error tolerances
88  /*!
89  * @param reltol scalar relative tolerance
90  * @param abstol scalar absolute tolerance
91  */
92  virtual void setSensitivityTolerances(doublereal reltol, doublereal abstol)
93  { }
94 
95  //! Set the problem type.
96  /*!
97  * @param probtype Type of the problem
98  */
99  virtual void setProblemType(int probtype) {
100  warn("setProblemType");
101  }
102 
103  /**
104  * Initialize the integrator for a new problem. Call after
105  * all options have been set.
106  * @param t0 initial time
107  * @param func RHS evaluator object for system of equations.
108  */
109  virtual void initialize(doublereal t0, FuncEval& func) {
110  warn("initialize");
111  }
112 
113  virtual void reinitialize(doublereal t0, FuncEval& func) {
114  warn("reinitialize");
115  }
116 
117  //! Integrate the system of equations.
118  /*!
119  * @param tout Integrate to this time. Note that this is the
120  * absolute time value, not a time interval.
121  */
122  virtual void integrate(doublereal tout) {
123  warn("integrate");
124  }
125 
126  /**
127  * Integrate the system of equations.
128  * @param tout integrate to this time. Note that this is the
129  * absolute time value, not a time interval.
130  */
131  virtual doublereal step(doublereal tout) {
132  warn("step");
133  return 0.0;
134  }
135 
136  /** The current value of the solution of equation k. */
137  virtual doublereal& solution(size_t k) {
138  warn("solution");
139  return m_dummy;
140  }
141 
142  /** The current value of the solution of the system of equations. */
143  virtual doublereal* solution() {
144  warn("solution");
145  return 0;
146  }
147 
148  /** The number of equations. */
149  virtual int nEquations() const {
150  warn("nEquations");
151  return 0;
152  }
153 
154  /** The number of function evaluations. */
155  virtual int nEvals() const {
156  warn("nEvals");
157  return 0;
158  }
159 
160  /** Set the maximum integration order that will be used. **/
161  virtual void setMaxOrder(int n) {
162  warn("setMaxorder");
163  }
164 
165  /** Set the solution method */
166  virtual void setMethod(MethodType t) {
167  warn("setMethodType");
168  }
169 
170  /** Set the linear iterator. */
171  virtual void setIterator(IterType t) {
172  warn("setInterator");
173  }
174 
175  /** Set the maximum step size */
176  virtual void setMaxStepSize(double hmax) {
177  warn("setMaxStepSize");
178  }
179 
180  /** Set the minimum step size */
181  virtual void setMinStepSize(double hmin) {
182  warn("setMinStepSize");
183  }
184 
185  //! Set the maximum permissible number of error test failures
186  virtual void setMaxErrTestFails(int n) {
187  warn("setMaxErrTestFails");
188  }
189 
190  virtual void setMaxSteps(int nmax) {
191  warn("setMaxStep");
192  }
193 
194  virtual void setBandwidth(int N_Upper, int N_Lower) {
195  warn("setBandwidth");
196  }
197 
198  virtual int nSensParams() {
199  warn("nSensParams()");
200  return 0;
201  }
202 
203  virtual double sensitivity(size_t k, size_t p) {
204  warn("sensitivity");
205  return 0.0;
206  }
207 
208 private:
209 
210  doublereal m_dummy;
211  void warn(const std::string& msg) const {
212  writelog(">>>> Warning: method "+msg+" of base class "
213  +"Integrator called. Nothing done.\n");
214  }
215 
216 };
217 
218 // defined in ODE_integrators.cpp
219 Integrator* newIntegrator(const std::string& itype);
220 
221 } // namespace
222 
223 #endif
Backward Differentiation.
Definition: Integrator.h:33
virtual void setMaxStepSize(double hmax)
Set the maximum step size.
Definition: Integrator.h:176
virtual void integrate(doublereal tout)
Integrate the system of equations.
Definition: Integrator.h:122
virtual void setTolerances(doublereal reltol, doublereal abstol)
Set error tolerances.
Definition: Integrator.h:83
virtual void setTolerances(doublereal reltol, size_t n, doublereal *abstol)
Set or reset the number of equations.
Definition: Integrator.h:73
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
virtual ~Integrator()
Destructor.
Definition: Integrator.h:61
virtual void setMaxOrder(int n)
Set the maximum integration order that will be used.
Definition: Integrator.h:161
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, HTML_logs (see Input File Handling, Diagnostic Output, Writing messages to the screen and Writing HTML Logfiles).
virtual void initialize(doublereal t0, FuncEval &func)
Initialize the integrator for a new problem.
Definition: Integrator.h:109
Functional Iteration.
Definition: Integrator.h:45
virtual void setProblemType(int probtype)
Set the problem type.
Definition: Integrator.h:99
virtual doublereal * solution()
The current value of the solution of the system of equations.
Definition: Integrator.h:143
virtual void setMinStepSize(double hmin)
Set the minimum step size.
Definition: Integrator.h:181
Abstract base class for ODE system integrators.
Definition: Integrator.h:53
Integrator()
Default Constructor.
Definition: Integrator.h:57
virtual int nEvals() const
The number of function evaluations.
Definition: Integrator.h:155
virtual void setSensitivityTolerances(doublereal reltol, doublereal abstol)
Set the sensitivity error tolerances.
Definition: Integrator.h:92
IterType
Specifies the method used for iteration.
Definition: Integrator.h:41
virtual int nEquations() const
The number of equations.
Definition: Integrator.h:149
virtual doublereal & solution(size_t k)
The current value of the solution of equation k.
Definition: Integrator.h:137
Newton Iteration.
Definition: Integrator.h:43
virtual doublereal step(doublereal tout)
Integrate the system of equations.
Definition: Integrator.h:131
virtual void setMaxErrTestFails(int n)
Set the maximum permissible number of error test failures.
Definition: Integrator.h:186
Virtual base class for ODE right-hand-side function evaluators.
Definition: FuncEval.h:23
void writelog(const std::string &msg)
Write a message to the screen.
Definition: global.cpp:43
virtual void setIterator(IterType t)
Set the linear iterator.
Definition: Integrator.h:171
virtual void setMethod(MethodType t)
Set the solution method.
Definition: Integrator.h:166
MethodType
Specifies the method used to integrate the system of equations.
Definition: Integrator.h:32