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 updateDefaultTolerances(span<double> atol, double baseAtol) override;
150 void updateState(span<const double> y) override;
151 void eval(double t, span<double> LHS, span<double> RHS) override;
152 void evalSteady(double t, span<double> LHS, span<double> RHS) override;
153 double upperBound(size_t k) const override;
154 double lowerBound(size_t k) const override;
155 void resetBadValues(span<double> y) override;
156 void getJacobianElements(vector<Eigen::Triplet<double>>& trips) override;
157
158protected:
159 //! Temporary storage for coverages
160 vector<double> m_cov_tmp;
161
162 //! Temporary storage for d(moles)/d(moles) scaling factor
163 vector<double> m_f_species;
164
165 //! Temporary storage for d(energy)/d(moles) scaling factors
166 vector<double> m_f_energy;
167
168 //! Mapping from InterfaceKinetics species index to ReactorNet state vector index.
169 //! Set to -1 for species not included in the reactor network state vector.
170 vector<Eigen::SparseMatrix<double>::StorageIndex> m_kin2net;
171
172 //! Mapping from InterfaceKinetics species index to the corresponding reactor.
173 //! Set to `nullptr` for surface species.
174 vector<ReactorBase*> m_kin2reactor;
175
176};
177
178//! A surface in contact with a FlowReactor.
179//!
180//! May represent the reactor wall or a catalytic surface within the reactor.
181//! @ingroup reactorGroup
183{
184public:
185 //! @copydoc ReactorSurface::ReactorSurface
186 FlowReactorSurface(shared_ptr<Solution> soln,
187 span<shared_ptr<ReactorBase>> reactors,
188 bool clone,
189 const string& name="(none)");
190
191 string type() const override {
192 return "FlowReactorSurface";
193 }
194
195 bool timeIsIndependent() const override { return false; }
196
197 void evalDae(double t, span<const double> y, span<const double> ydot,
198 span<double> residual) override;
199 void getStateDae(span<double> y, span<double> ydot) override;
200 void getConstraints(span<double> constraints) override;
201
202 //! Surface area per unit length [m]
203 //! @note If unspecified by the user, this will be calculated assuming the surface
204 //! is the wall of a cylindrical reactor.
205 double area() const override;
206
207 //! Set the reactor surface area per unit length [m].
208 //!
209 //! If the surface is the wall of the reactor, then this is the perimeter of the
210 //! reactor. If the surface represents something like a catalyst monolith, this is
211 //! the inverse of the surface area to volume ratio.
212 void setArea(double A) override { m_area = A; }
213
214 //! Get the steady state tolerances used to determine the initial state for
215 //! surface coverages
216 double initialAtol() const {
217 return m_ss_atol;
218 }
219
220 //! Set the steady state tolerances used to determine the initial state for
221 //! surface coverages
222 void setInitialAtol(double atol) {
223 m_ss_atol = atol;
224 }
225
226 //! Get the steady state tolerances used to determine the initial state for
227 //! surface coverages
228 double initialRtol() const {
229 return m_ss_rtol;
230 }
231
232 //! Set the steady state tolerances used to determine the initial state for
233 //! surface coverages
234 void setInitialRtol(double rtol) {
235 m_ss_rtol = rtol;
236 }
237
238 //! Get the steady state tolerances used to determine the initial state for
239 //! surface coverages
240 double initialMaxSteps() const {
241 return m_max_ss_steps;
242 }
243
244 //! Set the steady state tolerances used to determine the initial state for
245 //! surface coverages
246 void setInitialMaxSteps(int max_steps) {
247 m_max_ss_steps = max_steps;
248 }
249
250 //! Get the steady state tolerances used to determine the initial state for
251 //! surface coverages
252 double initialMaxErrorFailures() const {
254 }
255
256 //! Set the steady state tolerances used to determine the initial state for
257 //! surface coverages
258 void setInitialMaxErrorFailures(int max_fails) {
259 m_max_ss_error_fails = max_fails;
260 }
261
262protected:
263 //! steady-state relative tolerance, used to determine initial surface coverages
264 double m_ss_rtol = 1e-7;
265 //! steady-state absolute tolerance, used to determine initial surface coverages
266 double m_ss_atol = 1e-14;
267 //! maximum number of steady-state coverage integrator-steps
268 int m_max_ss_steps = 20000;
269 //! maximum number of steady-state integrator error test failures
271};
272
273}
274
275#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 updateDefaultTolerances(span< double > atol, double baseAtol) override
Update default absolute tolerances based on this reactor's state variables.
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