|
| 1 | +/** |
| 2 | + * |
| 3 | + * @file DAE_Solver.h |
| 4 | + * |
| 5 | + * Header file for class DAE_Solver |
| 6 | + */ |
| 7 | + |
| 8 | +/* $Author$ |
| 9 | + * $Date$ |
| 10 | + * $Revision$ |
| 11 | + * |
| 12 | + * Copyright 2006 California Institute of Technology |
| 13 | + * |
| 14 | + */ |
| 15 | + |
| 16 | +#undef DAE_DEVEL |
| 17 | + |
| 18 | +#ifndef CT_DAE_Solver_H |
| 19 | +#define CT_DAE_Solver_H |
| 20 | + |
| 21 | +#include <vector> |
| 22 | + |
| 23 | +#include "ct_defs.h" |
| 24 | +#include "ResidEval.h" |
| 25 | +#include "global.h" |
| 26 | + |
| 27 | +namespace Cantera { |
| 28 | + |
| 29 | + class Jacobian { |
| 30 | + public: |
| 31 | + Jacobian(){} |
| 32 | + virtual ~Jacobian(){} |
| 33 | + virtual bool supplied() { return false; } |
| 34 | + virtual bool isBanded() { return false; } |
| 35 | + virtual int lowerBandWidth() { return 0; } |
| 36 | + virtual int upperBandWidth() { return 0; } |
| 37 | + }; |
| 38 | + |
| 39 | + class BandedJacobian : public Jacobian { |
| 40 | + public: |
| 41 | + BandedJacobian(int ml, int mu) { |
| 42 | + m_ml = ml; m_mu = mu; |
| 43 | + } |
| 44 | + virtual bool supplied() { return false; } |
| 45 | + virtual bool isBanded() { return true; } |
| 46 | + virtual int lowerBandWidth() { return m_ml; } |
| 47 | + virtual int upperBandWidth() { return m_mu; } |
| 48 | + protected: |
| 49 | + int m_ml, m_mu; |
| 50 | + }; |
| 51 | + |
| 52 | + const int cDirect = 0; |
| 53 | + const int cKrylov = 1; |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + /** |
| 58 | + * Wrapper for DAE solvers |
| 59 | + */ |
| 60 | + class DAE_Solver { |
| 61 | + public: |
| 62 | + |
| 63 | + DAE_Solver(ResidEval& f) : m_resid(f), |
| 64 | + m_neq(f.nEquations()), |
| 65 | + m_time(0.0) {} |
| 66 | + |
| 67 | + virtual ~DAE_Solver(){} |
| 68 | + |
| 69 | + /** |
| 70 | + * Set error tolerances. This version specifies a scalar |
| 71 | + * relative tolerance, and a vector absolute tolerance. |
| 72 | + */ |
| 73 | + virtual void setTolerances(doublereal reltol, |
| 74 | + doublereal* abstol) { |
| 75 | + warn("setTolerances"); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Set error tolerances. This version specifies a scalar |
| 80 | + * relative tolerance, and a scalar absolute tolerance. |
| 81 | + */ |
| 82 | + virtual void setTolerances(doublereal reltol, doublereal abstol) { |
| 83 | + warn("setTolerances"); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Specify a Jacobian evaluator. If this method is not called, |
| 88 | + * the Jacobian will be computed by finite difference. |
| 89 | + */ |
| 90 | + void setJacobian(Jacobian& jac) { |
| 91 | + warn("setJacobian"); |
| 92 | + } |
| 93 | + |
| 94 | + virtual void setLinearSolverType(int solverType) { |
| 95 | + warn("setLinearSolverType"); |
| 96 | + } |
| 97 | + |
| 98 | + virtual void setDenseLinearSolver() { |
| 99 | + warn("setDenseLinearSolver"); |
| 100 | + } |
| 101 | + |
| 102 | + virtual void setBandedLinearSolver(int m_upper, int m_lower) { |
| 103 | + warn("setBandedLinearSolver"); |
| 104 | + } |
| 105 | + virtual void setMaxTime(doublereal tmax) { |
| 106 | + warn("setMaxTime"); |
| 107 | + } |
| 108 | + virtual void setMaxStepSize(doublereal dtmax) { |
| 109 | + warn("setMaxStepSize"); |
| 110 | + } |
| 111 | + virtual void setMaxOrder(int n) { |
| 112 | + warn("setMaxOrder"); |
| 113 | + } |
| 114 | + virtual void setMaxNumSteps(int n) { |
| 115 | + warn("setMaxNumSteps"); |
| 116 | + } |
| 117 | + virtual void setInitialStepSize(doublereal h0) { |
| 118 | + warn("setInitialStepSize"); |
| 119 | + } |
| 120 | + virtual void setStopTime(doublereal tstop) { |
| 121 | + warn("setStopTime"); |
| 122 | + } |
| 123 | + virtual void setMaxErrTestFailures(int n) { |
| 124 | + warn("setMaxErrTestFailures"); |
| 125 | + } |
| 126 | + virtual void setMaxNonlinIterations(int n) { |
| 127 | + warn("setMaxNonlinIterations"); |
| 128 | + } |
| 129 | + virtual void setMaxNonlinConvFailures(int n) { |
| 130 | + warn("setMaxNonlinConvFailures"); |
| 131 | + } |
| 132 | + virtual void inclAlgebraicInErrorTest(bool yesno) { |
| 133 | + warn("inclAlgebraicInErrorTest"); |
| 134 | + } |
| 135 | + |
| 136 | + virtual void correctInitial_Y_given_Yp() { |
| 137 | + warn("correctInitial_Y_given_Yp"); |
| 138 | + } |
| 139 | + |
| 140 | + virtual void correctInitial_YaYp_given_Yd() { |
| 141 | + warn("correctInitial_YaYp_given_Yd"); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * Solve the system of equations up to time tout. |
| 146 | + */ |
| 147 | + virtual int solve(doublereal tout) { |
| 148 | + warn("solve"); return 0; |
| 149 | + } |
| 150 | + |
| 151 | + /** |
| 152 | + * Take one internal step. |
| 153 | + */ |
| 154 | + virtual int step(doublereal tout) { |
| 155 | + warn("step"); return 0; |
| 156 | + } |
| 157 | + |
| 158 | + /// Number of equations. |
| 159 | + int nEquations() const { return m_resid.nEquations(); } |
| 160 | + |
| 161 | + /** |
| 162 | + * initialize. Base class method does nothing. |
| 163 | + */ |
| 164 | + virtual void init(doublereal t0) {} |
| 165 | + |
| 166 | + /** |
| 167 | + * Set a solver-specific input parameter. |
| 168 | + */ |
| 169 | + virtual void setInputParameter(int flag, doublereal value) { |
| 170 | + warn("setInputParameter"); |
| 171 | + } |
| 172 | + |
| 173 | + /** |
| 174 | + * Get the value of a solver-specific output parameter. |
| 175 | + */ |
| 176 | + virtual doublereal getOutputParameter(int flag) const { |
| 177 | + warn("getOutputParameter"); return 0.0; |
| 178 | + } |
| 179 | + |
| 180 | + /// the current value of solution component k. |
| 181 | + virtual doublereal solution(int k) const { |
| 182 | + warn("solution"); return 0.0; |
| 183 | + } |
| 184 | + |
| 185 | + virtual const doublereal* solutionVector() const { |
| 186 | + warn("solutionVector"); return &m_dummy; |
| 187 | + } |
| 188 | + |
| 189 | + /// the current value of the derivative of solution component k. |
| 190 | + virtual doublereal derivative(int k) const { |
| 191 | + warn("derivative"); return 0.0; |
| 192 | + } |
| 193 | + |
| 194 | + virtual const doublereal* derivativeVector() const { |
| 195 | + warn("derivativeVector"); return &m_dummy; |
| 196 | + } |
| 197 | + |
| 198 | + protected: |
| 199 | + |
| 200 | + doublereal m_dummy; |
| 201 | + |
| 202 | + ResidEval& m_resid; |
| 203 | + |
| 204 | + integer m_neq; |
| 205 | + doublereal m_time; |
| 206 | + |
| 207 | + |
| 208 | + private: |
| 209 | + void warn(string msg) const { |
| 210 | + writelog(">>>> Warning: method "+msg+" of base class " |
| 211 | + +"DAE_Solver called. Nothing done.\n"); |
| 212 | + } |
| 213 | + }; |
| 214 | + |
| 215 | +} |
| 216 | + |
| 217 | +#endif |
0 commit comments