Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DAE_Solver.h
Go to the documentation of this file.
1 /**
2  * @file DAE_Solver.h
3  * Header file for class DAE_Solver
4  */
5 
6 // Copyright 2006 California Institute of Technology
7 
8 #ifndef CT_DAE_Solver_H
9 #define CT_DAE_Solver_H
10 
11 #include "ResidJacEval.h"
12 #include "cantera/base/global.h"
13 
14 namespace Cantera
15 {
16 
17 #define DAE_DEVEL
18 #ifdef DAE_DEVEL
19 
20 class Jacobian
21 {
22 public:
23  Jacobian() {}
24  virtual ~Jacobian() {}
25  virtual bool supplied() {
26  return false;
27  }
28  virtual bool isBanded() {
29  return false;
30  }
31  virtual int lowerBandWidth() {
32  return 0;
33  }
34  virtual int upperBandWidth() {
35  return 0;
36  }
37 };
38 
39 class BandedJacobian : public Jacobian
40 {
41 public:
42  BandedJacobian(int ml, int mu) {
43  m_ml = ml;
44  m_mu = mu;
45  }
46  virtual bool supplied() {
47  return false;
48  }
49  virtual bool isBanded() {
50  return true;
51  }
52  virtual int lowerBandWidth() {
53  return m_ml;
54  }
55  virtual int upperBandWidth() {
56  return m_mu;
57  }
58 protected:
59  int m_ml, m_mu;
60 };
61 
62 const int cDirect = 0;
63 const int cKrylov = 1;
64 
65 
66 
67 /**
68  * Wrapper for DAE solvers
69  */
71 {
72 public:
73 
75  m_resid(f),
76  m_neq(f.nEquations()),
77  m_time(0.0) {
78  }
79 
80  virtual ~DAE_Solver() {}
81 
82  /**
83  * Set error tolerances. This version specifies a scalar
84  * relative tolerance, and a vector absolute tolerance.
85  */
86  virtual void setTolerances(doublereal reltol,
87  doublereal* abstol) {
88  warn("setTolerances");
89  }
90 
91  /**
92  * Set error tolerances. This version specifies a scalar
93  * relative tolerance, and a scalar absolute tolerance.
94  */
95  virtual void setTolerances(doublereal reltol, doublereal abstol) {
96  warn("setTolerances");
97  }
98 
99  /**
100  * Specify a Jacobian evaluator. If this method is not called,
101  * the Jacobian will be computed by finite difference.
102  */
103  void setJacobian(Jacobian& jac) {
104  warn("setJacobian");
105  }
106 
107  virtual void setLinearSolverType(int solverType) {
108  warn("setLinearSolverType");
109  }
110 
111  virtual void setDenseLinearSolver() {
112  warn("setDenseLinearSolver");
113  }
114 
115  virtual void setBandedLinearSolver(int m_upper, int m_lower) {
116  warn("setBandedLinearSolver");
117  }
118  virtual void setMaxStepSize(doublereal dtmax) {
119  warn("setMaxStepSize");
120  }
121  virtual void setMaxOrder(int n) {
122  warn("setMaxOrder");
123  }
124  virtual void setMaxNumSteps(int n) {
125  warn("setMaxNumSteps");
126  }
127  virtual void setInitialStepSize(doublereal h0) {
128  warn("setInitialStepSize");
129  }
130  virtual void setStopTime(doublereal tstop) {
131  warn("setStopTime");
132  }
133  virtual void setMaxErrTestFailures(int n) {
134  warn("setMaxErrTestFailures");
135  }
136  virtual void setMaxNonlinIterations(int n) {
137  warn("setMaxNonlinIterations");
138  }
139  virtual void setMaxNonlinConvFailures(int n) {
140  warn("setMaxNonlinConvFailures");
141  }
142  virtual void inclAlgebraicInErrorTest(bool yesno) {
143  warn("inclAlgebraicInErrorTest");
144  }
145 
146  //! Calculate consistent value of the starting solution given the starting
147  //! solution derivatives
148  /**
149  * This method may be called if the initial conditions do not
150  * satisfy the residual equation F = 0. Given the derivatives
151  * of all variables, this method computes the initial y
152  * values.
153  */
154  virtual void correctInitial_Y_given_Yp(doublereal* y, doublereal* yp,
155  doublereal tout) {
156  warn("correctInitial_Y_given_Yp");
157  }
158 
159  //! Calculate consistent value of the algebraic constraints and
160  //! derivatives at the start of the problem
161  /**
162  * This method may be called if the initial conditions do not
163  * satisfy the residual equation F = 0. Given the initial
164  * values of all differential variables, it computes the
165  * initial values of all algebraic variables and the initial
166  * derivatives of all differential variables.
167  * @param y Calculated value of the solution vector after the procedure ends
168  * @param yp Calculated value of the solution derivative after the procedure
169  * @param tout The first value of t at which a soluton will be
170  * requested (from IDASolve). (This is needed here to
171  * determine the direction of integration and rough scale
172  * in the independent variable t.
173  */
174  virtual void correctInitial_YaYp_given_Yd(doublereal* y, doublereal* yp,
175  doublereal tout) {
176  warn("correctInitial_YaYp_given_Yd");
177  }
178 
179  /**
180  * Solve the system of equations up to time tout.
181  */
182  virtual int solve(doublereal tout) {
183  warn("solve");
184  return 0;
185  }
186 
187  /**
188  * Take one internal step.
189  */
190  virtual doublereal step(doublereal tout) {
191  warn("step");
192  return 0;
193  }
194 
195  /// Number of equations.
196  int nEquations() const {
197  return m_resid.nEquations();
198  }
199 
200  /**
201  * initialize. Base class method does nothing.
202  */
203  virtual void init(doublereal t0) {}
204 
205  /**
206  * Set a solver-specific input parameter.
207  */
208  virtual void setInputParameter(int flag, doublereal value) {
209  warn("setInputParameter");
210  }
211 
212  /**
213  * Get the value of a solver-specific output parameter.
214  */
215  virtual doublereal getOutputParameter(int flag) const {
216  warn("getOutputParameter");
217  return 0.0;
218  }
219 
220  /// the current value of solution component k.
221  virtual doublereal solution(int k) const {
222  warn("solution");
223  return 0.0;
224  }
225 
226  virtual const doublereal* solutionVector() const {
227  warn("solutionVector");
228  return &m_dummy;
229  }
230 
231  /// the current value of the derivative of solution component k.
232  virtual doublereal derivative(int k) const {
233  warn("derivative");
234  return 0.0;
235  }
236 
237  virtual const doublereal* derivativeVector() const {
238  warn("derivativeVector");
239  return &m_dummy;
240  }
241 
242 protected:
243 
244  doublereal m_dummy;
245 
246  ResidJacEval& m_resid;
247 
248  //! Number of total equations in the system
249  integer m_neq;
250  doublereal m_time;
251 
252 
253 private:
254  void warn(const std::string& msg) const {
255  writelog(">>>> Warning: method "+msg+" of base class "
256  +"DAE_Solver called. Nothing done.\n");
257  }
258 };
259 
260 
261 //! Factor method for choosing a DAE solver
262 /*!
263  *
264  * @param itype String identifying the type
265  * (IDA is the only option)
266  * @param f Residual function to be solved by the DAE algorithm
267  *
268  * @return Returns a point to the instantiated DAE_Solver object
269  */
270 DAE_Solver* newDAE_Solver(const std::string& itype, ResidJacEval& f);
271 
272 #endif
273 
274 }
275 
276 #endif
integer m_neq
Number of total equations in the system.
Definition: DAE_Solver.h:249
virtual int nEquations() const
Return the number of equations in the equation system.
virtual void setTolerances(doublereal reltol, doublereal *abstol)
Set error tolerances.
Definition: DAE_Solver.h:86
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 correctInitial_Y_given_Yp(doublereal *y, doublereal *yp, doublereal tout)
Calculate consistent value of the starting solution given the starting solution derivatives.
Definition: DAE_Solver.h:154
virtual doublereal derivative(int k) const
the current value of the derivative of solution component k.
Definition: DAE_Solver.h:232
virtual void correctInitial_YaYp_given_Yd(doublereal *y, doublereal *yp, doublereal tout)
Calculate consistent value of the algebraic constraints and derivatives at the start of the problem...
Definition: DAE_Solver.h:174
Wrappers for the function evaluators for Nonlinear solvers and Time steppers.
Definition: ResidJacEval.h:51
virtual void init(doublereal t0)
initialize.
Definition: DAE_Solver.h:203
Dense, Square (not sparse) matrices.
virtual doublereal solution(int k) const
the current value of solution component k.
Definition: DAE_Solver.h:221
DAE_Solver * newDAE_Solver(const std::string &itype, ResidJacEval &f)
Factor method for choosing a DAE solver.
Definition: DAE_solvers.cpp:22
virtual doublereal step(doublereal tout)
Take one internal step.
Definition: DAE_Solver.h:190
virtual doublereal getOutputParameter(int flag) const
Get the value of a solver-specific output parameter.
Definition: DAE_Solver.h:215
virtual void setTolerances(doublereal reltol, doublereal abstol)
Set error tolerances.
Definition: DAE_Solver.h:95
void setJacobian(Jacobian &jac)
Specify a Jacobian evaluator.
Definition: DAE_Solver.h:103
int nEquations() const
Number of equations.
Definition: DAE_Solver.h:196
void writelog(const std::string &msg)
Write a message to the screen.
Definition: global.cpp:33
virtual int solve(doublereal tout)
Solve the system of equations up to time tout.
Definition: DAE_Solver.h:182
virtual void setInputParameter(int flag, doublereal value)
Set a solver-specific input parameter.
Definition: DAE_Solver.h:208
Wrapper for DAE solvers.
Definition: DAE_Solver.h:70