Cantera  2.3.0
ResidJacEval.cpp
Go to the documentation of this file.
1 //! @file ResidJacEval.cpp
2 
3 // This file is part of Cantera. See License.txt in the top-level directory or
4 // at http://www.cantera.org/license.txt for license and copyright information.
5 
6 #include "cantera/base/ct_defs.h"
8 
9 using namespace std;
10 
11 namespace Cantera
12 {
13 ResidJacEval::ResidJacEval(doublereal atol) :
14  m_atol(atol)
15 {
16 }
17 
19 {
20  warn_deprecated("ResidJacEval copy constructor",
21  "To be removed after Cantera 2.3.");
22  *this = right;
23 }
24 
26 {
27  warn_deprecated("ResidJacEval assignment operator",
28  "To be removed after Cantera 2.3.");
29  if (this == &right) {
30  return *this;
31  }
32 
33  ResidEval::operator=(right);
34 
35  m_atol = right.m_atol;
36  neq_ = right.neq_;
37 
38  return *this;
39 }
40 
42 {
43  return new ResidJacEval(*this);
44 }
45 
47 {
48  return neq_;
49 }
50 
51 void ResidJacEval::setAtol(doublereal atol)
52 {
53  m_atol = atol;
54  if (m_atol <= 0.0) {
55  throw CanteraError("ResidJacEval::setAtol",
56  "atol must be greater than zero");
57  }
58 }
59 
60 int ResidJacEval::getInitialConditions(doublereal t0, doublereal* const y,
61  doublereal* const ydot)
62 {
63  for (int i = 0; i < neq_; i++) {
64  y[i] = 0.0;
65  }
66  if (ydot) {
67  for (int i = 0; i < neq_; i++) {
68  ydot[i] = 0.0;
69  }
70  }
71  return 1;
72 }
73 
74 void ResidJacEval::user_out2(const int ifunc, const doublereal t,
75  const doublereal deltaT, const doublereal* y,
76  const doublereal* ydot)
77 {
78 }
79 
80 void ResidJacEval::user_out(const int ifunc, const doublereal t,
81  const doublereal* y, const doublereal* ydot)
82 {
83  user_out2(ifunc, t, 0.0, y, ydot);
84 }
85 
86 int ResidJacEval::evalTimeTrackingEqns(const doublereal t,
87  const doublereal delta_t,
88  const doublereal* y,
89  const doublereal* ydot)
90 {
91  return 1;
92 }
93 
94 int ResidJacEval::calcDeltaSolnVariables(const doublereal t,
95  const doublereal* const ySoln,
96  const doublereal* const ySolnDot,
97  doublereal* const deltaYSoln,
98  const doublereal* const solnWeights)
99 {
100  if (!solnWeights) {
101  for (int i = 0; i < neq_; i++) {
102  deltaYSoln[i] = m_atol + fabs(1.0E-6 * ySoln[i]);
103  }
104  } else {
105  for (int i = 0; i < neq_; i++) {
106  deltaYSoln[i] = std::max(1.0E-2 * solnWeights[i], 1.0E-6 * fabs(ySoln[i]));
107  }
108  }
109  return 1;
110 }
111 
112 void ResidJacEval::calcSolnScales(const doublereal t,
113  const doublereal* const ysoln,
114  const doublereal* const ysolnOld,
115  doublereal* const ysolnScales)
116 {
117  if (ysolnScales && ysolnScales[0] == 0.0) {
118  for (int i = 0; i < neq_; i++) {
119  ysolnScales[i] = 1.0;
120  }
121  }
122 }
123 
124 doublereal ResidJacEval::filterNewStep(doublereal t, const doublereal* const ybase, doublereal* const step)
125 {
126  return 0.0;
127 }
128 
129 doublereal ResidJacEval::filterSolnPrediction(doublereal t, doublereal* const y)
130 {
131  return 0.0;
132 }
133 
134 bool ResidJacEval::evalStoppingCritera(const doublereal t,
135  const doublereal delta_t,
136  const doublereal* const y,
137  const doublereal* const ydot)
138 {
139  return false;
140 }
141 
142 int ResidJacEval::matrixConditioning(doublereal* const matrix, const int nrows,
143  doublereal* const rhs)
144 {
145  return 1;
146 }
147 
148 int ResidJacEval::evalResidNJ(const doublereal t, const doublereal deltaT,
149  const doublereal* y, const doublereal* ydot,
150  doublereal* const resid,
151  const ResidEval_Type_Enum evalType,
152  const int id_x, const doublereal delta_x)
153 {
154  throw CanteraError("ResidJacEval::evalResidNJ()", "Not implemented\n");
155  return 1;
156 }
157 
158 int ResidJacEval::eval(const doublereal t, const doublereal* const y, const doublereal* const ydot,
159  doublereal* const r)
160 {
161  double deltaT = -1.0;
162  return evalResidNJ(t, deltaT, y, ydot, r);
163 }
164 
165 int ResidJacEval::evalJacobian(const doublereal t, const doublereal delta_t,
166  doublereal cj, const doublereal* const y,
167  const doublereal* const ydot, DenseMatrix& J,
168  doublereal* const resid)
169 {
170  doublereal* const* jac_colPts = J.colPts();
171  return evalJacobianDP(t, delta_t, cj, y, ydot, jac_colPts, resid);
172 }
173 
174 int ResidJacEval::evalJacobianDP(const doublereal t, const doublereal delta_t,
175  const doublereal c_j,
176  const doublereal* const y,
177  const doublereal* const ydot,
178  doublereal* const* jac_colPts,
179  doublereal* const resid)
180 {
181  throw CanteraError("ResidJacEval::evalJacobianDP()", "Not implemented\n");
182  return 1;
183 }
184 
185 }
virtual int evalJacobianDP(const doublereal t, const doublereal delta_t, doublereal cj, const doublereal *const y, const doublereal *const ydot, doublereal *const *jacobianColPts, doublereal *const resid)
Calculate an analytical Jacobian and the residual at the current time and values. ...
virtual void user_out2(const int ifunc, const doublereal t, const doublereal delta_t, const doublereal *const y, const doublereal *const ydot)
This function may be used to create output at various points in the execution of an application...
virtual int evalResidNJ(const doublereal t, const doublereal delta_t, const doublereal *const y, const doublereal *const ydot, doublereal *const resid, const ResidEval_Type_Enum evalType=Base_ResidEval, const int id_x=-1, const doublereal delta_x=0.0)
Evaluate the residual function.
virtual ResidJacEval * duplMyselfAsResidJacEval() const
Duplication routine for objects derived from residJacEval.
int neq_
Number of equations.
Definition: ResidJacEval.h:318
virtual int eval(const doublereal t, const doublereal *const y, const doublereal *const ydot, doublereal *const r)
Evaluate the residual function.
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
STL namespace.
virtual int getInitialConditions(const doublereal t0, doublereal *const y, doublereal *const ydot)
Fill in the initial conditions.
ResidJacEval(doublereal atol=1.0e-13)
Default constructor.
virtual void user_out(const int ifunc, const doublereal t, const doublereal *y, const doublereal *ydot)
This function may be used to create output at various points in the execution of an application...
ResidEval_Type_Enum
Differentiates the type of residual evaluations according to functionality.
Definition: ResidJacEval.h:20
Wrappers for the function evaluators for Nonlinear solvers and Time steppers.
Definition: ResidJacEval.h:55
virtual int nEquations() const
Return the number of equations in the equation system.
virtual int calcDeltaSolnVariables(const doublereal t, const doublereal *const y, const doublereal *const ydot, doublereal *const delta_y, const doublereal *const solnWeights=0)
Return a vector of delta y&#39;s for calculation of the numerical Jacobian.
virtual int matrixConditioning(doublereal *const matrix, const int nrows, doublereal *const rhs)
Multiply the matrix by another matrix that leads to better conditioning.
virtual int evalJacobian(const doublereal t, const doublereal delta_t, doublereal cj, const doublereal *const y, const doublereal *const ydot, DenseMatrix &J, doublereal *const resid)
Calculate an analytical Jacobian and the residual at the current time and values. ...
Dense, Square (not sparse) matrices.
doublereal m_atol
constant value of atol
Definition: ResidJacEval.h:315
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
virtual int evalTimeTrackingEqns(const doublereal t, const doublereal delta_t, const doublereal *const y, const doublereal *const ydot)
Evaluate the time tracking equations, if any.
virtual void calcSolnScales(const doublereal t, const doublereal *const y, const doublereal *const y_old, doublereal *const yScales)
Returns a vector of column scale factors that can be used to column scale Jacobians.
ResidJacEval & operator=(const ResidJacEval &right)
virtual doublereal filterSolnPrediction(const doublereal t, doublereal *const y)
Filter the solution predictions.
Namespace for the Cantera kernel.
Definition: application.cpp:29
virtual bool evalStoppingCritera(const doublereal t, const doublereal delta_t, const doublereal *const y, const doublereal *const ydot)
Evaluate any stopping criteria other than a final time limit.
void setAtol(doublereal atol)
Set a global value of the absolute tolerance.
virtual doublereal filterNewStep(const doublereal t, const doublereal *const ybase, doublereal *const step)
Filter the solution predictions.
A class for full (non-sparse) matrices with Fortran-compatible data storage, which adds matrix operat...
Definition: DenseMatrix.h:72