Cantera 2.6.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 https://cantera.org/license.txt for license and copyright information.
5
6#include "cantera/numerics/ResidJacEval.h"
7#include "cantera/base/global.h"
8
9 using namespace std;
10
11 namespace Cantera
12{
13 ResidJacEval::ResidJacEval(doublereal atol) :
14 m_atol(atol)
15{
16}
17
18 int ResidJacEval::nEquations() const
19{
20 return neq_;
21}
22
23 void ResidJacEval::setAtol(doublereal atol)
24{
25 m_atol = atol;
26 if (m_atol <= 0.0) {
27 throw CanteraError("ResidJacEval::setAtol",
28 "atol must be greater than zero");
29 }
30}
31
32 int ResidJacEval::getInitialConditions(doublereal t0, doublereal* const y,
33 doublereal* const ydot)
34{
35 for (int i = 0; i < neq_; i++) {
36 y[i] = 0.0;
37 }
38 if (ydot) {
39 for (int i = 0; i < neq_; i++) {
40 ydot[i] = 0.0;
41 }
42 }
43 return 1;
44}
45
46 void ResidJacEval::user_out2(const int ifunc, const doublereal t,
47 const doublereal deltaT, const doublereal* y,
48 const doublereal* ydot)
49{
50}
51
52 void ResidJacEval::user_out(const int ifunc, const doublereal t,
53 const doublereal* y, const doublereal* ydot)
54{
55 user_out2(ifunc, t, 0.0, y, ydot);
56}
57
58 int ResidJacEval::evalTimeTrackingEqns(const doublereal t,
59 const doublereal delta_t,
60 const doublereal* y,
61 const doublereal* ydot)
62{
63 return 1;
64}
65
66 int ResidJacEval::calcDeltaSolnVariables(const doublereal t,
67 const doublereal* const ySoln,
68 const doublereal* const ySolnDot,
69 doublereal* const deltaYSoln,
70 const doublereal* const solnWeights)
71{
72 if (!solnWeights) {
73 for (int i = 0; i < neq_; i++) {
74 deltaYSoln[i] = m_atol + fabs(1.0E-6 * ySoln[i]);
75 }
76 } else {
77 for (int i = 0; i < neq_; i++) {
78 deltaYSoln[i] = std::max(1.0E-2 * solnWeights[i], 1.0E-6 * fabs(ySoln[i]));
79 }
80 }
81 return 1;
82}
83
84 void ResidJacEval::calcSolnScales(const doublereal t,
85 const doublereal* const ysoln,
86 const doublereal* const ysolnOld,
87 doublereal* const ysolnScales)
88{
89 if (ysolnScales && ysolnScales[0] == 0.0) {
90 for (int i = 0; i < neq_; i++) {
91 ysolnScales[i] = 1.0;
92 }
93 }
94}
95
96doublereal ResidJacEval::filterNewStep(doublereal t, const doublereal* const ybase, doublereal* const step)
97{
98 return 0.0;
99}
100
101doublereal ResidJacEval::filterSolnPrediction(doublereal t, doublereal* const y)
102{
103 return 0.0;
104}
105
106 bool ResidJacEval::evalStoppingCritera(const doublereal t,
107 const doublereal delta_t,
108 const doublereal* const y,
109 const doublereal* const ydot)
110{
111 return false;
112}
113
114 int ResidJacEval::matrixConditioning(doublereal* const matrix, const int nrows,
115 doublereal* const rhs)
116{
117 return 1;
118}
119
120 int ResidJacEval::evalResidNJ(const doublereal t, const doublereal deltaT,
121 const doublereal* y, const doublereal* ydot,
122 doublereal* const resid,
123 const ResidEval_Type_Enum evalType,
124 const int id_x, const doublereal delta_x)
125{
126 throw NotImplementedError("ResidJacEval::evalResidNJ");
127}
128
129 int ResidJacEval::eval(const doublereal t, const doublereal* const y, const doublereal* const ydot,
130 doublereal* const r)
131{
132 double deltaT = -1.0;
133 return evalResidNJ(t, deltaT, y, ydot, r);
134}
135
136 int ResidJacEval::evalJacobian(const doublereal t, const doublereal delta_t,
137 doublereal cj, const doublereal* const y,
138 const doublereal* const ydot, DenseMatrix& J,
139 doublereal* const resid)
140{
141 doublereal* const* jac_colPts = J.colPts();
142 return evalJacobianDP(t, delta_t, cj, y, ydot, jac_colPts, resid);
143}
144
145 int ResidJacEval::evalJacobianDP(const doublereal t, const doublereal delta_t,
146 const doublereal c_j,
147 const doublereal* const y,
148 const doublereal* const ydot,
149 doublereal* const* jac_colPts,
150 doublereal* const resid)
151{
152 throw NotImplementedError("ResidJacEval::evalJacobianDP");
153}
154
155}
ResidJacEval.h
Dense, Square (not sparse) matrices.
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Cantera::DenseMatrix
A class for full (non-sparse) matrices with Fortran-compatible data storage, which adds matrix operat...
Definition: DenseMatrix.h:51
Cantera::NotImplementedError
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:187
Cantera::ResidJacEval::calcSolnScales
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.
Definition: ResidJacEval.cpp:84
Cantera::ResidJacEval::filterSolnPrediction
virtual doublereal filterSolnPrediction(const doublereal t, doublereal *const y)
Filter the solution predictions.
Definition: ResidJacEval.cpp:101
Cantera::ResidJacEval::matrixConditioning
virtual int matrixConditioning(doublereal *const matrix, const int nrows, doublereal *const rhs)
Multiply the matrix by another matrix that leads to better conditioning.
Definition: ResidJacEval.cpp:114
Cantera::ResidJacEval::evalJacobianDP
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.
Definition: ResidJacEval.cpp:145
Cantera::ResidJacEval::user_out
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.
Definition: ResidJacEval.cpp:52
Cantera::ResidJacEval::nEquations
virtual int nEquations() const
Return the number of equations in the equation system.
Definition: ResidJacEval.cpp:18
Cantera::ResidJacEval::user_out2
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.
Definition: ResidJacEval.cpp:46
Cantera::ResidJacEval::evalJacobian
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.
Definition: ResidJacEval.cpp:136
Cantera::ResidJacEval::evalTimeTrackingEqns
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.
Definition: ResidJacEval.cpp:58
Cantera::ResidJacEval::evalStoppingCritera
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.
Definition: ResidJacEval.cpp:106
Cantera::ResidJacEval::eval
virtual int eval(const doublereal t, const doublereal *const y, const doublereal *const ydot, doublereal *const r)
Evaluate the residual function.
Definition: ResidJacEval.cpp:129
Cantera::ResidJacEval::setAtol
void setAtol(doublereal atol)
Set a global value of the absolute tolerance.
Definition: ResidJacEval.cpp:23
Cantera::ResidJacEval::evalResidNJ
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.
Definition: ResidJacEval.cpp:120
Cantera::ResidJacEval::calcDeltaSolnVariables
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's for calculation of the numerical Jacobian.
Definition: ResidJacEval.cpp:66
Cantera::ResidJacEval::ResidJacEval
ResidJacEval(doublereal atol=1.0e-13)
Default constructor.
Definition: ResidJacEval.cpp:13
Cantera::ResidJacEval::filterNewStep
virtual doublereal filterNewStep(const doublereal t, const doublereal *const ybase, doublereal *const step)
Filter the solution predictions.
Definition: ResidJacEval.cpp:96
Cantera::ResidJacEval::neq_
int neq_
Number of equations.
Definition: ResidJacEval.h:301
Cantera::ResidJacEval::getInitialConditions
virtual int getInitialConditions(const doublereal t0, doublereal *const y, doublereal *const ydot)
Fill in the initial conditions.
Definition: ResidJacEval.cpp:32
Cantera::ResidJacEval::m_atol
doublereal m_atol
constant value of atol
Definition: ResidJacEval.h:298
global.h
This file contains definitions for utility functions and text for modules, inputfiles,...
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::ResidEval_Type_Enum
ResidEval_Type_Enum
Differentiates the type of residual evaluations according to functionality.
Definition: ResidJacEval.h:20