Cantera  3.0.0
Loading...
Searching...
No Matches
ResidEval.h
Go to the documentation of this file.
1//! @file ResidEval.h
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#ifndef CT_RESIDEVAL_H
7#define CT_RESIDEVAL_H
8
12#include "cantera/base/global.h"
13
14#ifndef CT_SKIP_DEPRECATION_WARNINGS
15#pragma message("warning: ResidEval.h and class ResidEval are deprecated and will " \
16 "be removed after Cantera 3.0.")
17#endif
18
19namespace Cantera
20{
21
22const int c_NONE = 0;
23const int c_GE_ZERO = 1;
24const int c_GT_ZERO = 2;
25const int c_LE_ZERO = -1;
26const int c_LT_ZERO = -2;
27
28/**
29 * Virtual base class for DAE residual function evaluators.
30 * Classes derived from ResidEval evaluate the residual function
31 * @f[
32 * \vec{F}(t,\vec{y}, \vec{y^\prime})
33 * @f]
34 * The DAE solver attempts to find a solution y(t) such that F = 0.
35 * @deprecated Unused. To be removed after %Cantera 3.0.
36 * @ingroup DAE_Group
37 */
39{
40public:
41 ResidEval() {
42 warn_deprecated("class ResidEval", "To be removed after Cantera 3.0");
43 }
44 virtual ~ResidEval() {}
45
46 /**
47 * Constrain solution component k. Possible values for
48 * 'flag' are:
49 * - c_NONE no constraint
50 * - c_GE_ZERO >= 0
51 * - c_GT_ZERO > 0
52 * - c_LE_ZERO <= 0
53 * - c_LT_ZERO < 0
54 */
55 virtual void constrain(const int k, const int flag) {
56 m_constrain[k] = flag;
57 }
58 int constraint(const int k) const {
59 return getValue(m_constrain, k, c_NONE);
60 }
61
62 //! Initialization function
63 virtual void initSizes() {
64 int neq = nEquations();
65 m_alg.resize(neq, 0);
66 }
67
68 /**
69 * Specify that solution component k is purely algebraic - that is, the
70 * derivative of this component does not appear in the residual function.
71 */
72 virtual void setAlgebraic(const int k) {
73 if ((int) m_alg.size() < (k+1)) {
74 initSizes();
75 }
76 m_alg[k] = 1;
77 }
78
79 virtual bool isAlgebraic(const int k) {
80 return (m_alg[k] == 1);
81 }
82
83 /**
84 * Evaluate the residual function. Called by the integrator.
85 * @param t time. (input)
86 * @param y solution vector. (input)
87 * @param ydot rate of change of solution vector. (input)
88 * @param r residual vector (output)
89 */
90 virtual int eval(const double t, const double* const y,
91 const double* const ydot,
92 double* const r) {
93 throw NotImplementedError("ResidEval::eval");
94 }
95
96 virtual int evalSS(const double t, const double* const y,
97 double* const r) {
98 return eval(t, y, 0, r);
99 }
100
101 virtual int evalSimpleTD(const double t, const double* const y,
102 const double* const yold, double deltaT,
103 double* const r) {
104 int nn = nEquations();
105 vector<double> ydot(nn);
106 for (int i = 0; i < nn; i++) {
107 ydot[i] = (y[i] - yold[i]) / deltaT;
108 }
109 return eval(t, y, ydot.data(), r);
110 }
111
112 //! Fill in the initial conditions
113 /*!
114 * Values for both the solution and the value of ydot may be provided.
115 *
116 * @param[in] t0 Time
117 * @param[out] y Solution vector
118 * @param[out] ydot Rate of change of solution vector.
119 *
120 * @returns a flag to indicate that operation is successful.
121 * 1 Means a successful operation
122 * -0 or neg value Means an unsuccessful operation
123 */
124 virtual int getInitialConditions(const double t0, double* const y,
125 double* const ydot) {
126 initSizes();
127 throw NotImplementedError("ResidEval::GetInitialConditions");
128 return 1;
129 }
130
131 //! Return the number of equations in the equation system
132 virtual int nEquations() const = 0;
133
134 //! Write out to a file or to standard output the current solution
135 /*!
136 * ievent is a description of the event that caused this function to be
137 * called.
138 */
139 virtual void writeSolution(int ievent, const double time,
140 const double deltaT,
141 const int time_step_num,
142 const double* y, const double* ydot) {
143 int k;
144 writelog("ResidEval::writeSolution\n");
145 writelogf(" Time = %g, ievent = %d, deltaT = %g\n", time, ievent, deltaT);
146 if (ydot) {
147 writelogf(" k y[] ydot[]\n");
148 for (k = 0; k < nEquations(); k++) {
149 writelogf("%d %g %g\n", k, y[k], ydot[k]);
150 }
151 } else {
152 writelogf(" k y[]\n");
153 for (k = 0; k < nEquations(); k++) {
154 writelogf("%d %g \n", k, y[k]);
155 }
156 }
157 }
158
159 //! Return the number of parameters in the calculation
160 /*!
161 * This is the number of parameters in the sensitivity calculation. We have
162 * set this to zero and have included it for later expansion
163 */
164 int nparams() const {
165 return 0;
166 }
167
168protected:
169 //! Mapping vector that stores whether a degree of freedom is a DAE or not
170 /*!
171 * The first index is the equation number. The second index is 1 if it is a
172 * DAE, and zero if it is not.
173 */
174 vector<int> m_alg;
175 map<int, int> m_constrain;
176};
177
178}
179
180#endif
An error indicating that an unimplemented function has been called.
Virtual base class for DAE residual function evaluators.
Definition ResidEval.h:39
virtual int getInitialConditions(const double t0, double *const y, double *const ydot)
Fill in the initial conditions.
Definition ResidEval.h:124
virtual int eval(const double t, const double *const y, const double *const ydot, double *const r)
Evaluate the residual function.
Definition ResidEval.h:90
virtual void writeSolution(int ievent, const double time, const double deltaT, const int time_step_num, const double *y, const double *ydot)
Write out to a file or to standard output the current solution.
Definition ResidEval.h:139
virtual void setAlgebraic(const int k)
Specify that solution component k is purely algebraic - that is, the derivative of this component doe...
Definition ResidEval.h:72
vector< int > m_alg
Mapping vector that stores whether a degree of freedom is a DAE or not.
Definition ResidEval.h:174
virtual int nEquations() const =0
Return the number of equations in the equation system.
int nparams() const
Return the number of parameters in the calculation.
Definition ResidEval.h:164
virtual void constrain(const int k, const int flag)
Constrain solution component k.
Definition ResidEval.h:55
virtual void initSizes()
Initialization function.
Definition ResidEval.h:63
This file contains definitions of constants, types and terms that are used in internal routines and a...
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
void writelogf(const char *fmt, const Args &... args)
Write a formatted message to the screen.
Definition global.h:195
void writelog(const string &fmt, const Args &... args)
Write a formatted message to the screen.
Definition global.h:175
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
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
const U & getValue(const map< T, U > &m, const T &key, const U &default_val)
Const accessor for a value in a map.
Definition utilities.h:190
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...