| Cantera 3.0.0

Loading...
Searching...
No Matches
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#define CT_SKIP_DEPRECATION_WARNINGS
7#include "cantera/numerics/ResidJacEval.h"
8#include "cantera/base/global.h"
9
10 namespace Cantera
11{
12 ResidJacEval::ResidJacEval(double atol) :
13 m_atol(atol)
14{
15 warn_deprecated("class ResidJacEval", "To be removed after Cantera 3.0");
16}
17
18 int ResidJacEval::nEquations() const
19{
20 return neq_;
21}
22
23 void ResidJacEval::setAtol(double 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(double t0, double* const y,
33 double* 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 double t,
47 const double deltaT, const double* y,
48 const double* ydot)
49{
50}
51
52 void ResidJacEval::user_out(const int ifunc, const double t,
53 const double* y, const double* ydot)
54{
55 user_out2(ifunc, t, 0.0, y, ydot);
56}
57
58 int ResidJacEval::evalTimeTrackingEqns(const double t,
59 const double delta_t,
60 const double* y,
61 const double* ydot)
62{
63 return 1;
64}
65
66 int ResidJacEval::calcDeltaSolnVariables(const double t,
67 const double* const ySoln,
68 const double* const ySolnDot,
69 double* const deltaYSoln,
70 const double* 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 double t,
85 const double* const ysoln,
86 const double* const ysolnOld,
87 double* 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
96 double ResidJacEval::filterNewStep(double t, const double* const ybase, double* const step)
97{
98 return 0.0;
99}
100
101 double ResidJacEval::filterSolnPrediction(double t, double* const y)
102{
103 return 0.0;
104}
105
106 bool ResidJacEval::evalStoppingCritera(const double t,
107 const double delta_t,
108 const double* const y,
109 const double* const ydot)
110{
111 return false;
112}
113
114 int ResidJacEval::matrixConditioning(double* const matrix, const int nrows,
115 double* const rhs)
116{
117 return 1;
118}
119
120 int ResidJacEval::evalResidNJ(const double t, const double deltaT,
121 const double* y, const double* ydot,
122 double* const resid,
123 const ResidEval_Type_Enum evalType,
124 const int id_x, const double delta_x)
125{
126 throw NotImplementedError("ResidJacEval::evalResidNJ");
127}
128
129 int ResidJacEval::eval(const double t, const double* const y, const double* const ydot,
130 double* const r)
131{
132 double deltaT = -1.0;
133 return evalResidNJ(t, deltaT, y, ydot, r);
134}
135
136 int ResidJacEval::evalJacobian(const double t, const double delta_t,
137 double cj, const double* const y,
138 const double* const ydot, DenseMatrix& J,
139 double* const resid)
140{
141 double* const* jac_colPts = J.colPts();
142 return evalJacobianDP(t, delta_t, cj, y, ydot, jac_colPts, resid);
143}
144
145 int ResidJacEval::evalJacobianDP(const double t, const double delta_t,
146 const double c_j,
147 const double* const y,
148 const double* const ydot,
149 double* const* jac_colPts,
150 double* 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:66
Cantera::DenseMatrix
A class for full (non-sparse) matrices with Fortran-compatible data storage, which adds matrix operat...
Definition DenseMatrix.h:55
Cantera::NotImplementedError
An error indicating that an unimplemented function has been called.
Definition ctexceptions.h:195
Cantera::ResidJacEval::filterNewStep
virtual double filterNewStep(const double t, const double *const ybase, double *const step)
Filter the solution predictions.
Definition ResidJacEval.cpp:96
Cantera::ResidJacEval::evalTimeTrackingEqns
virtual int evalTimeTrackingEqns(const double t, const double delta_t, const double *const y, const double *const ydot)
Evaluate the time tracking equations, if any.
Definition ResidJacEval.cpp:58
Cantera::ResidJacEval::evalResidNJ
virtual int evalResidNJ(const double t, const double delta_t, const double *const y, const double *const ydot, double *const resid, const ResidEval_Type_Enum evalType=Base_ResidEval, const int id_x=-1, const double delta_x=0.0)
Evaluate the residual function.
Definition ResidJacEval.cpp:120
Cantera::ResidJacEval::setAtol
void setAtol(double atol)
Set a global value of the absolute tolerance.
Definition ResidJacEval.cpp:23
Cantera::ResidJacEval::nEquations
int nEquations() const override
Return the number of equations in the equation system.
Definition ResidJacEval.cpp:18
Cantera::ResidJacEval::user_out
virtual void user_out(const int ifunc, const double t, const double *y, const double *ydot)
This function may be used to create output at various points in the execution of an application.
Definition ResidJacEval.cpp:52
Cantera::ResidJacEval::matrixConditioning
virtual int matrixConditioning(double *const matrix, const int nrows, double *const rhs)
Multiply the matrix by another matrix that leads to better conditioning.
Definition ResidJacEval.cpp:114
Cantera::ResidJacEval::calcDeltaSolnVariables
virtual int calcDeltaSolnVariables(const double t, const double *const y, const double *const ydot, double *const delta_y, const double *const solnWeights=0)
Return a vector of delta y's for calculation of the numerical Jacobian.
Definition ResidJacEval.cpp:66
Cantera::ResidJacEval::evalStoppingCritera
virtual bool evalStoppingCritera(const double t, const double delta_t, const double *const y, const double *const ydot)
Evaluate any stopping criteria other than a final time limit.
Definition ResidJacEval.cpp:106
Cantera::ResidJacEval::user_out2
virtual void user_out2(const int ifunc, const double t, const double delta_t, const double *const y, const double *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::ResidJacEval
ResidJacEval(double atol=1.0e-13)
Default constructor.
Definition ResidJacEval.cpp:12
Cantera::ResidJacEval::filterSolnPrediction
virtual double filterSolnPrediction(const double t, double *const y)
Filter the solution predictions.
Definition ResidJacEval.cpp:101
Cantera::ResidJacEval::eval
int eval(const double t, const double *const y, const double *const ydot, double *const r) override
Evaluate the residual function.
Definition ResidJacEval.cpp:129
Cantera::ResidJacEval::evalJacobian
virtual int evalJacobian(const double t, const double delta_t, double cj, const double *const y, const double *const ydot, DenseMatrix &J, double *const resid)
Calculate an analytical Jacobian and the residual at the current time and values.
Definition ResidJacEval.cpp:136
Cantera::ResidJacEval::getInitialConditions
int getInitialConditions(const double t0, double *const y, double *const ydot) override
Fill in the initial conditions.
Definition ResidJacEval.cpp:32
Cantera::ResidJacEval::neq_
int neq_
Number of equations.
Definition ResidJacEval.h:307
Cantera::ResidJacEval::m_atol
double m_atol
constant value of atol
Definition ResidJacEval.h:304
Cantera::ResidJacEval::calcSolnScales
virtual void calcSolnScales(const double t, const double *const y, const double *const y_old, double *const yScales)
Returns a vector of column scale factors that can be used to column scale Jacobians.
Definition ResidJacEval.cpp:84
Cantera::ResidJacEval::evalJacobianDP
virtual int evalJacobianDP(const double t, const double delta_t, double cj, const double *const y, const double *const ydot, double *const *jacobianColPts, double *const resid)
Calculate an analytical Jacobian and the residual at the current time and values.
Definition ResidJacEval.cpp:145
global.h
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::ResidEval_Type_Enum
ResidEval_Type_Enum
Differentiates the type of residual evaluations according to functionality.
Definition ResidJacEval.h:25
Cantera::warn_deprecated
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1926