Cantera  4.0.0a1
Loading...
Searching...
No Matches
ReactorSurface.h
Go to the documentation of this file.
1//! @file ReactorSurface.h Header file for class ReactorSurface
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_REACTOR_SURFACE_H
7#define CT_REACTOR_SURFACE_H
8
11
12namespace Cantera
13{
14
15class SurfPhase;
16
17//! A surface where reactions can occur that is in contact with the bulk fluid of a
18//! Reactor.
19//! @ingroup reactorGroup
21{
22public:
23 //! Create a new ReactorSurface
24 //! @param soln Thermodynamic and kinetic model representing species and reactions
25 //! on the surface
26 //! @param clone Determines whether to clone `soln` so that the internal state of
27 //! this reactor surface is independent of the original Solution (Interface)
28 //! object and any Solution objects used by other reactors in the network.
29 //! @param reactors One or more reactors whose phases participate in reactions
30 //! occurring on the surface. For the purpose of rate evaluation, the
31 //! temperature of the surface is set equal to the temperature of the first
32 //! reactor specified.
33 //! @param name Name used to identify the surface
34 //! @since Constructor signature including `reactors` and `clone` arguments
35 //! introduced in %Cantera 3.2.
36 ReactorSurface(shared_ptr<Solution> soln,
37 const vector<shared_ptr<ReactorBase>>& reactors,
38 bool clone,
39 const string& name="(none)");
40
41 //! String indicating the wall model implemented.
42 string type() const override {
43 return "ReactorSurface";
44 }
45
46 //! Returns the surface area [m²]
47 double area() const override;
48
49 //! Set the surface area [m²]
50 void setArea(double a) override;
51
52 //! Accessor for the SurfPhase object
54 return m_surf.get();
55 }
56
57 //! Accessor for the InterfaceKinetics object
59 return m_kinetics.get();
60 }
61
62 void addInlet(FlowDevice& inlet) override {
63 throw NotImplementedError("ReactorSurface::addInlet",
64 "Inlets are undefined for reactors of type '{}'.", type());
65 }
66
67 void addOutlet(FlowDevice& outlet) override {
68 throw NotImplementedError("ReactorSurface::addOutlet",
69 "Outlets are undefined for reactors of type '{}'.", type());
70 }
71
72 void addWall(WallBase& w, int lr) override {
73 throw NotImplementedError("ReactorSurface::addWall");
74 }
75
76 void addSurface(ReactorSurface* surf) override {
77 throw NotImplementedError("ReactorSurface::addSurface");
78 }
79
80 //! Get the number of Reactor and Reservoir objects adjacent to this surface
81 //! @since New in %Cantera 4.0.
82 size_t nAdjacent() const {
83 return m_reactors.size();
84 }
85
86 //! Access an adjacent Reactor or Reservoir
87 //! @since New in %Cantera 4.0.
88 shared_ptr<ReactorBase> adjacent(size_t n) {
89 return m_reactors.at(n);
90 }
91
92 //! Set the surface coverages. Array `cov` has length equal to the number of
93 //! surface species.
94 void setCoverages(const double* cov);
95
96 //! Set the surface coverages by name
97 void setCoverages(const Composition& cov);
98
99 //! Set the surface coverages by name
100 void setCoverages(const string& cov);
101
102 //! Get the surface coverages. Array `cov` should have length equal to the
103 //! number of surface species.
104 void getCoverages(double* cov) const;
105
106 void getState(double* y) override;
107 void initialize(double t0=0.0) override;
108 vector<size_t> initializeSteady() override;
109 void updateState(double* y) override;
110 void eval(double t, double* LHS, double* RHS) override;
111 void evalSteady(double t, double* LHS, double* RHS) override;
112
113 void addSensitivityReaction(size_t rxn) override;
114 // void addSensitivitySpeciesEnthalpy(size_t k) override;
115 void applySensitivity(double* params) override;
116 void resetSensitivity(double* params) override;
117
118 size_t componentIndex(const string& nm) const override;
119 string componentName(size_t k) override;
120
121 double upperBound(size_t k) const override;
122 double lowerBound(size_t k) const override;
123 void resetBadValues(double* y) override;
124 // void setDerivativeSettings(AnyMap& settings) override;
125
126protected:
127 double m_area = 1.0;
128
129 shared_ptr<SurfPhase> m_surf;
130 shared_ptr<InterfaceKinetics> m_kinetics;
131 vector<shared_ptr<ReactorBase>> m_reactors;
132};
133
134//! A surface where the state variables are the total number of moles of each species.
135//!
136//! This class provides the approximate Jacobian elements for interactions between
137//! itself and the IdealGasMoleReactor and ConstPressureIdealGasMoleReactor classes
138//! needed to work with the AdaptivePreconditioner class.
139//!
140//! @ingroup reactorGroup
141//! @since New in %Cantera 4.0.
143{
144public:
146 string type() const override { return "MoleReactorSurface"; }
147 void initialize(double t0=0.0) override;
148 void getState(double* y) override;
149 void updateState(double* y) override;
150 void eval(double t, double* LHS, double* RHS) override;
151 void evalSteady(double t, double* LHS, double* RHS) override;
152 double upperBound(size_t k) const override;
153 double lowerBound(size_t k) const override;
154 void resetBadValues(double* y) override;
155 void getJacobianElements(vector<Eigen::Triplet<double>>& trips) override;
156
157protected:
158 //! Temporary storage for coverages
159 vector<double> m_cov_tmp;
160
161 //! Temporary storage for d(moles)/d(moles) scaling factor
162 vector<double> m_f_species;
163
164 //! Temporary storage for d(energy)/d(moles) scaling factors
165 vector<double> m_f_energy;
166
167 //! Mapping from InterfaceKinetics species index to ReactorNet state vector index.
168 //! Set to -1 for species not included in the reactor network state vector.
169 vector<Eigen::SparseMatrix<double>::StorageIndex> m_kin2net;
170
171 //! Mapping from InterfaceKinetics species index to the corresponding reactor.
172 //! Set to `nullptr` for surface species.
173 vector<ReactorBase*> m_kin2reactor;
174
175};
176
177//! A surface in contact with a FlowReactor.
178//!
179//! May represent the reactor wall or a catalytic surface within the reactor.
180//! @ingroup reactorGroup
182{
183public:
184 //! @copydoc ReactorSurface::ReactorSurface
185 FlowReactorSurface(shared_ptr<Solution> soln,
186 const vector<shared_ptr<ReactorBase>>& reactors,
187 bool clone,
188 const string& name="(none)");
189
190 string type() const override {
191 return "FlowReactorSurface";
192 }
193
194 bool timeIsIndependent() const override { return false; }
195
196 void evalDae(double t, double* y, double* ydot, double* residual) override;
197 void getStateDae(double* y, double* ydot) override;
198 void getConstraints(double* constraints) override;
199
200 //! Surface area per unit length [m]
201 //! @note If unspecified by the user, this will be calculated assuming the surface
202 //! is the wall of a cylindrical reactor.
203 double area() const override;
204
205 //! Set the reactor surface area per unit length [m].
206 //!
207 //! If the surface is the wall of the reactor, then this is the perimeter of the
208 //! reactor. If the surface represents something like a catalyst monolith, this is
209 //! the inverse of the surface area to volume ratio.
210 void setArea(double A) override { m_area = A; }
211
212 //! Get the steady state tolerances used to determine the initial state for
213 //! surface coverages
214 double initialAtol() const {
215 return m_ss_atol;
216 }
217
218 //! Set the steady state tolerances used to determine the initial state for
219 //! surface coverages
220 void setInitialAtol(double atol) {
221 m_ss_atol = atol;
222 }
223
224 //! Get the steady state tolerances used to determine the initial state for
225 //! surface coverages
226 double initialRtol() const {
227 return m_ss_rtol;
228 }
229
230 //! Set the steady state tolerances used to determine the initial state for
231 //! surface coverages
232 void setInitialRtol(double rtol) {
233 m_ss_rtol = rtol;
234 }
235
236 //! Get the steady state tolerances used to determine the initial state for
237 //! surface coverages
238 double initialMaxSteps() const {
239 return m_max_ss_steps;
240 }
241
242 //! Set the steady state tolerances used to determine the initial state for
243 //! surface coverages
244 void setInitialMaxSteps(int max_steps) {
245 m_max_ss_steps = max_steps;
246 }
247
248 //! Get the steady state tolerances used to determine the initial state for
249 //! surface coverages
250 double initialMaxErrorFailures() const {
252 }
253
254 //! Set the steady state tolerances used to determine the initial state for
255 //! surface coverages
256 void setInitialMaxErrorFailures(int max_fails) {
257 m_max_ss_error_fails = max_fails;
258 }
259
260protected:
261 //! steady-state relative tolerance, used to determine initial surface coverages
262 double m_ss_rtol = 1e-7;
263 //! steady-state absolute tolerance, used to determine initial surface coverages
264 double m_ss_atol = 1e-14;
265 //! maximum number of steady-state coverage integrator-steps
266 int m_max_ss_steps = 20000;
267 //! maximum number of steady-state integrator error test failures
269};
270
271}
272
273#endif
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition FlowDevice.h:25
A surface in contact with a FlowReactor.
double area() const override
Surface area per unit length [m].
double initialAtol() const
Get the steady state tolerances used to determine the initial state for surface coverages.
double initialRtol() const
Get the steady state tolerances used to determine the initial state for surface coverages.
void setInitialMaxErrorFailures(int max_fails)
Set the steady state tolerances used to determine the initial state for surface coverages.
void setInitialMaxSteps(int max_steps)
Set the steady state tolerances used to determine the initial state for surface coverages.
double m_ss_rtol
steady-state relative tolerance, used to determine initial surface coverages
int m_max_ss_error_fails
maximum number of steady-state integrator error test failures
void getConstraints(double *constraints) override
Given a vector of length neq(), mark which variables should be considered algebraic constraints.
bool timeIsIndependent() const override
Indicates whether the governing equations for this reactor are functions of time or a spatial variabl...
string type() const override
String indicating the reactor model implemented.
double initialMaxErrorFailures() const
Get the steady state tolerances used to determine the initial state for surface coverages.
void getStateDae(double *y, double *ydot) override
Get the current state and derivative vector of the reactor for a DAE solver.
void setInitialAtol(double atol)
Set the steady state tolerances used to determine the initial state for surface coverages.
double initialMaxSteps() const
Get the steady state tolerances used to determine the initial state for surface coverages.
int m_max_ss_steps
maximum number of steady-state coverage integrator-steps
void evalDae(double t, double *y, double *ydot, double *residual) override
Evaluate the reactor governing equations.
void setInitialRtol(double rtol)
Set the steady state tolerances used to determine the initial state for surface coverages.
double m_ss_atol
steady-state absolute tolerance, used to determine initial surface coverages
void setArea(double A) override
Set the reactor surface area per unit length [m].
A kinetics manager for heterogeneous reaction mechanisms.
A surface where the state variables are the total number of moles of each species.
double upperBound(size_t k) const override
Get the upper bound on the k-th component of the local state vector.
vector< double > m_f_energy
Temporary storage for d(energy)/d(moles) scaling factors.
vector< Eigen::SparseMatrix< double >::StorageIndex > m_kin2net
Mapping from InterfaceKinetics species index to ReactorNet state vector index.
void resetBadValues(double *y) override
Reset physically or mathematically problematic values, such as negative species concentrations.
vector< double > m_f_species
Temporary storage for d(moles)/d(moles) scaling factor.
void eval(double t, double *LHS, double *RHS) override
Evaluate the reactor governing equations.
string type() const override
String indicating the reactor model implemented.
vector< ReactorBase * > m_kin2reactor
Mapping from InterfaceKinetics species index to the corresponding reactor.
void evalSteady(double t, double *LHS, double *RHS) override
Evaluate the governing equations with modifications for the steady-state solver.
void getState(double *y) override
Get the current state of the reactor.
void getJacobianElements(vector< Eigen::Triplet< double > > &trips) override
Get Jacobian elements for this reactor within the full reactor network.
double lowerBound(size_t k) const override
Get the lower bound on the k-th component of the local state vector.
void updateState(double *y) override
Set the state of the reactor to correspond to the state vector y.
void initialize(double t0=0.0) override
Initialize the reactor.
vector< double > m_cov_tmp
Temporary storage for coverages.
An error indicating that an unimplemented function has been called.
Base class for reactor objects.
Definition ReactorBase.h:51
FlowDevice & outlet(size_t n=0)
Return a reference to the n-th outlet FlowDevice connected to this reactor.
FlowDevice & inlet(size_t n=0)
Return a reference to the n-th inlet FlowDevice connected to this reactor.
string name() const
Return the name of this reactor.
Definition ReactorBase.h:81
A surface where reactions can occur that is in contact with the bulk fluid of a Reactor.
double upperBound(size_t k) const override
Get the upper bound on the k-th component of the local state vector.
double area() const override
Returns the surface area [m²].
void resetBadValues(double *y) override
Reset physically or mathematically problematic values, such as negative species concentrations.
void addSurface(ReactorSurface *surf) override
Add a ReactorSurface object to a Reactor object.
void addOutlet(FlowDevice &outlet) override
Connect an outlet FlowDevice to this reactor.
ReactorSurface(shared_ptr< Solution > soln, const vector< shared_ptr< ReactorBase > > &reactors, bool clone, const string &name="(none)")
Create a new ReactorSurface.
void setArea(double a) override
Set the surface area [m²].
void resetSensitivity(double *params) override
Reset the reaction rate multipliers.
void eval(double t, double *LHS, double *RHS) override
Evaluate the reactor governing equations.
string type() const override
String indicating the wall model implemented.
size_t componentIndex(const string &nm) const override
Return the index in the solution vector for this reactor of the component named nm.
void applySensitivity(double *params) override
Set reaction rate multipliers based on the sensitivity variables in params.
void getCoverages(double *cov) const
Get the surface coverages.
void evalSteady(double t, double *LHS, double *RHS) override
Evaluate the governing equations with modifications for the steady-state solver.
void getState(double *y) override
Get the current state of the reactor.
vector< size_t > initializeSteady() override
Initialize the reactor before solving a steady-state problem.
size_t nAdjacent() const
Get the number of Reactor and Reservoir objects adjacent to this surface.
void addSensitivityReaction(size_t rxn) override
Add a sensitivity parameter associated with the reaction number rxn
double lowerBound(size_t k) const override
Get the lower bound on the k-th component of the local state vector.
string componentName(size_t k) override
Return the name of the solution component with index i.
shared_ptr< ReactorBase > adjacent(size_t n)
Access an adjacent Reactor or Reservoir.
void updateState(double *y) override
Set the state of the reactor to correspond to the state vector y.
InterfaceKinetics * kinetics()
Accessor for the InterfaceKinetics object.
void initialize(double t0=0.0) override
Initialize the reactor.
void setCoverages(const double *cov)
Set the surface coverages.
SurfPhase * thermo()
Accessor for the SurfPhase object.
void addInlet(FlowDevice &inlet) override
Connect an inlet FlowDevice to this reactor.
void addWall(WallBase &w, int lr) override
Insert a Wall between this reactor and another reactor.
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
Definition SurfPhase.h:114
Base class for 'walls' (walls, pistons, etc.) connecting reactors.
Definition Wall.h:23
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
map< string, double > Composition
Map from string names to doubles.
Definition ct_defs.h:179