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 span<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(span<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(span<double> cov) const;
105
106 void getState(span<double> y) override;
107 void initialize(double t0=0.0) override;
108 vector<size_t> initializeSteady() override;
109 void updateState(span<const double> y) override;
110 void eval(double t, span<double> LHS, span<double> RHS) override;
111 void evalSteady(double t, span<double> LHS, span<double> RHS) override;
112
113 void addSensitivityReaction(size_t rxn) override;
114 // void addSensitivitySpeciesEnthalpy(size_t k) override;
115 void applySensitivity(span<const double> params) override;
116 void resetSensitivity(span<const 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(span<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(span<double> y) override;
149 void updateState(span<const double> y) override;
150 void eval(double t, span<double> LHS, span<double> RHS) override;
151 void evalSteady(double t, span<double> LHS, span<double> RHS) override;
152 double upperBound(size_t k) const override;
153 double lowerBound(size_t k) const override;
154 void resetBadValues(span<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 span<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, span<const double> y, span<const double> ydot,
197 span<double> residual) override;
198 void getStateDae(span<double> y, span<double> ydot) override;
199 void getConstraints(span<double> constraints) override;
200
201 //! Surface area per unit length [m]
202 //! @note If unspecified by the user, this will be calculated assuming the surface
203 //! is the wall of a cylindrical reactor.
204 double area() const override;
205
206 //! Set the reactor surface area per unit length [m].
207 //!
208 //! If the surface is the wall of the reactor, then this is the perimeter of the
209 //! reactor. If the surface represents something like a catalyst monolith, this is
210 //! the inverse of the surface area to volume ratio.
211 void setArea(double A) override { m_area = A; }
212
213 //! Get the steady state tolerances used to determine the initial state for
214 //! surface coverages
215 double initialAtol() const {
216 return m_ss_atol;
217 }
218
219 //! Set the steady state tolerances used to determine the initial state for
220 //! surface coverages
221 void setInitialAtol(double atol) {
222 m_ss_atol = atol;
223 }
224
225 //! Get the steady state tolerances used to determine the initial state for
226 //! surface coverages
227 double initialRtol() const {
228 return m_ss_rtol;
229 }
230
231 //! Set the steady state tolerances used to determine the initial state for
232 //! surface coverages
233 void setInitialRtol(double rtol) {
234 m_ss_rtol = rtol;
235 }
236
237 //! Get the steady state tolerances used to determine the initial state for
238 //! surface coverages
239 double initialMaxSteps() const {
240 return m_max_ss_steps;
241 }
242
243 //! Set the steady state tolerances used to determine the initial state for
244 //! surface coverages
245 void setInitialMaxSteps(int max_steps) {
246 m_max_ss_steps = max_steps;
247 }
248
249 //! Get the steady state tolerances used to determine the initial state for
250 //! surface coverages
251 double initialMaxErrorFailures() const {
253 }
254
255 //! Set the steady state tolerances used to determine the initial state for
256 //! surface coverages
257 void setInitialMaxErrorFailures(int max_fails) {
258 m_max_ss_error_fails = max_fails;
259 }
260
261protected:
262 //! steady-state relative tolerance, used to determine initial surface coverages
263 double m_ss_rtol = 1e-7;
264 //! steady-state absolute tolerance, used to determine initial surface coverages
265 double m_ss_atol = 1e-14;
266 //! maximum number of steady-state coverage integrator-steps
267 int m_max_ss_steps = 20000;
268 //! maximum number of steady-state integrator error test failures
270};
271
272}
273
274#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
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 getConstraints(span< double > constraints) override
Given a vector of length neq(), mark which variables should be considered algebraic constraints.
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, span< const double > y, span< const double > ydot, span< 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 getStateDae(span< double > y, span< double > ydot) override
Get the current state and derivative vector of the reactor for a DAE solver.
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.
void resetBadValues(span< double > y) override
Reset physically or mathematically problematic values, such as negative species concentrations.
vector< double > m_f_energy
Temporary storage for d(energy)/d(moles) scaling factors.
void eval(double t, span< double > LHS, span< double > RHS) override
Evaluate the reactor governing equations.
vector< Eigen::SparseMatrix< double >::StorageIndex > m_kin2net
Mapping from InterfaceKinetics species index to ReactorNet state vector index.
void evalSteady(double t, span< double > LHS, span< double > RHS) override
Evaluate the governing equations with modifications for the steady-state solver.
vector< double > m_f_species
Temporary storage for d(moles)/d(moles) scaling factor.
string type() const override
String indicating the reactor model implemented.
vector< ReactorBase * > m_kin2reactor
Mapping from InterfaceKinetics species index to the corresponding 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 initialize(double t0=0.0) override
Initialize the reactor.
void updateState(span< const double > y) override
Set the state of the reactor to correspond to the state vector y.
vector< double > m_cov_tmp
Temporary storage for coverages.
void getState(span< double > y) override
Get the current state of the reactor.
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.
void resetBadValues(span< double > y) override
Reset physically or mathematically problematic values, such as negative species concentrations.
void eval(double t, span< double > LHS, span< double > RHS) override
Evaluate the reactor governing equations.
double area() const override
Returns the surface area [m²].
void addSurface(ReactorSurface *surf) override
Add a ReactorSurface object to a Reactor object.
void evalSteady(double t, span< double > LHS, span< double > RHS) override
Evaluate the governing equations with modifications for the steady-state solver.
void addOutlet(FlowDevice &outlet) override
Connect an outlet FlowDevice to this reactor.
ReactorSurface(shared_ptr< Solution > soln, span< shared_ptr< ReactorBase > > reactors, bool clone, const string &name="(none)")
Create a new ReactorSurface.
void setArea(double a) override
Set the surface area [m²].
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 setCoverages(span< const double > cov)
Set the surface coverages.
void resetSensitivity(span< const double > params) override
Reset the reaction rate multipliers.
void applySensitivity(span< const double > params) override
Set reaction rate multipliers based on the sensitivity variables in params.
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.
InterfaceKinetics * kinetics()
Accessor for the InterfaceKinetics object.
void getCoverages(span< double > cov) const
Get the surface coverages.
void initialize(double t0=0.0) override
Initialize the reactor.
void updateState(span< const double > y) override
Set the state of the reactor to correspond to the state vector y.
SurfPhase * thermo()
Accessor for the SurfPhase object.
void addInlet(FlowDevice &inlet) override
Connect an inlet FlowDevice to this reactor.
void getState(span< double > y) override
Get the current state of the 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:180