Cantera  4.0.0a1
Loading...
Searching...
No Matches
Reactor.h
Go to the documentation of this file.
1//! @file Reactor.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_REACTOR_H
7#define CT_REACTOR_H
8
9#include "ReactorBase.h"
10#include "cantera/numerics/eigen_sparse.h"
11
12
13namespace Cantera
14{
15
16class Solution;
17class AnyMap;
18
19/**
20 * Class Reactor is a general-purpose class for stirred reactors. The reactor
21 * may have an arbitrary number of inlets and outlets, each of which may be
22 * connected to a "flow device" such as a mass flow controller, a pressure
23 * regulator, etc. Additional reactors may be connected to the other end of
24 * the flow device, allowing construction of arbitrary reactor networks.
25 *
26 * The reactor class integrates the same governing equations no matter what
27 * type of reactor is simulated. The differences among reactor types are
28 * completely specified by the attached flow devices and the time-dependent
29 * user-specified boundary conditions.
30 *
31 * If an instance of class Reactor is used directly, it will simulate an
32 * adiabatic, constant volume reactor with gas-phase chemistry but no surface
33 * chemistry. Other reactor types may be simulated by deriving a class from
34 * Reactor. This method allows specifying the following in terms of the
35 * instantaneous reactor state:
36 *
37 * - rate of change of the total volume (m^3/s)
38 * - surface heat loss rate (W)
39 * - species surface production rates (kmol/s)
40 *
41 * See the [Science Reference](../reference/reactors/controlreactor.html) for
42 * the governing equations of class Reactor.
43 *
44 * @ingroup reactorGroup
45 */
46class Reactor : public ReactorBase
47{
48public:
49 Reactor(shared_ptr<Solution> sol, const string& name="(none)");
50 Reactor(shared_ptr<Solution> sol, bool clone, const string& name="(none)");
51
52 string type() const override {
53 return "Reactor";
54 }
55
56 //! Indicate whether the governing equations for this reactor type are a system of
57 //! ODEs or DAEs. In the first case, this class implements the eval() method. In the
58 //! second case, this class implements the evalDae() method.
59 virtual bool isOde() const {
60 return true;
61 }
62
63 void setInitialVolume(double vol) override {
64 m_vol = vol;
65 }
66
67 void setChemistryEnabled(bool cflag=true) override {
68 m_chem = cflag;
69 }
70
71 bool chemistryEnabled() const override {
72 return m_chem;
73 }
74
75 void setEnergyEnabled(bool eflag=true) override {
76 m_energy = eflag;
77 }
78
79 bool energyEnabled() const override {
80 return m_energy;
81 }
82
83 void getState(double* y) override;
84 void initialize(double t0=0.0) override;
85 void eval(double t, double* LHS, double* RHS) override;
86 void evalSteady(double t, double* LHS, double* RHS) override;
87 vector<size_t> initializeSteady() override;
88 void updateState(double* y) override;
89 void addSensitivityReaction(size_t rxn) override;
90 void addSensitivitySpeciesEnthalpy(size_t k) override;
91
92 //! Return the index in the solution vector for this reactor of the
93 //! component named *nm*. Possible values for *nm* are "mass", "volume",
94 //! "int_energy", the name of a homogeneous phase species, or the name of a
95 //! surface species.
96 size_t componentIndex(const string& nm) const override;
97 string componentName(size_t k) override;
98 double upperBound(size_t k) const override;
99 double lowerBound(size_t k) const override;
100 void resetBadValues(double* y) override;
101
102 //! Set absolute step size limits during advance
103 //! @param limits array of step size limits with length neq
104 void setAdvanceLimits(const double* limits);
105
106 //! Check whether Reactor object uses advance limits
107 //! @returns True if at least one limit is set, False otherwise
108 bool hasAdvanceLimits() const {
109 return !m_advancelimits.empty();
110 }
111
112 //! Retrieve absolute step size limits during advance
113 //! @param[out] limits array of step size limits with length neq
114 //! @returns True if at least one limit is set, False otherwise
115 bool getAdvanceLimits(double* limits) const;
116
117 //! Set individual step size limit for component name *nm*
118 //! @param nm component name
119 //! @param limit value for step size limit
120 void setAdvanceLimit(const string& nm, const double limit);
121
122 //! Calculate the reactor-specific Jacobian using a finite difference method.
123 //!
124 //! This method is used only for informational purposes. Jacobian calculations
125 //! for the full reactor system are handled internally by CVODES.
126 //!
127 //! @warning This method is an experimental part of the %Cantera
128 //! API and may be changed or removed without notice.
129 Eigen::SparseMatrix<double> finiteDifferenceJacobian();
130
131 void setDerivativeSettings(AnyMap& settings) override;
132
133 void applySensitivity(double* params) override;
134 void resetSensitivity(double* params) override;
135
136protected:
137 //! Update #m_sdot to reflect current production rates of bulk phase species due to
138 //! reactions on adjacent surfaces.
140
141 //! Evaluate terms related to Walls. Calculates #m_vdot and #m_Qdot based on
142 //! wall movement and heat transfer.
143 //! @param t the current time
144 void evalWalls(double t) override;
145
146 //! Pointer to the homogeneous Kinetics object that handles the reactions
147 Kinetics* m_kin = nullptr;
148
149 double m_vdot = 0.0; //!< net rate of volume change from moving walls [m^3/s]
150 double m_Qdot = 0.0; //!< net heat transfer into the reactor, through walls [W]
151 vector<double> m_wdot; //!< Species net molar production rates
152 vector<double> m_uk; //!< Species molar internal energies
153
154 //! Total production rate of bulk phase species on surfaces [kmol/s]
155 vector<double> m_sdot;
156
157 bool m_chem = false;
158 bool m_energy = true;
159
160 vector<double> m_advancelimits; //!< Advance step limit
161
162 //! Initial volume [m³]; used for steady-state calculations
164};
165}
166
167#endif
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:431
Public interface for kinetics managers.
Definition Kinetics.h:126
Base class for reactor objects.
Definition ReactorBase.h:51
double m_vol
Current volume of the reactor [m^3].
string name() const
Return the name of this reactor.
Definition ReactorBase.h:81
Class Reactor is a general-purpose class for stirred reactors.
Definition Reactor.h:47
void evalWalls(double t) override
Evaluate terms related to Walls.
Definition Reactor.cpp:193
double upperBound(size_t k) const override
Get the upper bound on the k-th component of the local state vector.
Definition Reactor.cpp:334
void setChemistryEnabled(bool cflag=true) override
Enable or disable changes in reactor composition due to chemical reactions.
Definition Reactor.h:67
void resetBadValues(double *y) override
Reset physically or mathematically problematic values, such as negative species concentrations.
Definition Reactor.cpp:362
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
Definition Reactor.h:147
vector< double > m_wdot
Species net molar production rates.
Definition Reactor.h:151
Eigen::SparseMatrix< double > finiteDifferenceJacobian()
Calculate the reactor-specific Jacobian using a finite difference method.
Definition Reactor.cpp:217
bool energyEnabled() const override
Returns true if solution of the energy equation is enabled.
Definition Reactor.h:79
void resetSensitivity(double *params) override
Reset the reaction rate multipliers.
Definition Reactor.cpp:387
void eval(double t, double *LHS, double *RHS) override
Evaluate the reactor governing equations.
Definition Reactor.cpp:123
string type() const override
String indicating the reactor model implemented.
Definition Reactor.h:52
double m_Qdot
net heat transfer into the reactor, through walls [W]
Definition Reactor.h:150
size_t componentIndex(const string &nm) const override
Return the index in the solution vector for this reactor of the component named nm.
Definition Reactor.cpp:302
vector< double > m_advancelimits
Advance step limit.
Definition Reactor.h:160
void setEnergyEnabled(bool eflag=true) override
Set the energy equation on or off.
Definition Reactor.h:75
void applySensitivity(double *params) override
Set reaction rate multipliers based on the sensitivity variables in params.
Definition Reactor.cpp:368
void evalSteady(double t, double *LHS, double *RHS) override
Evaluate the governing equations with modifications for the steady-state solver.
Definition Reactor.cpp:187
void setInitialVolume(double vol) override
Set the initial reactor volume.
Definition Reactor.h:63
vector< double > m_uk
Species molar internal energies.
Definition Reactor.h:152
void getState(double *y) override
Get the current state of the reactor.
Definition Reactor.cpp:46
void setAdvanceLimits(const double *limits)
Set absolute step size limits during advance.
Definition Reactor.cpp:405
void updateSurfaceProductionRates()
Update m_sdot to reflect current production rates of bulk phase species due to reactions on adjacent ...
Definition Reactor.cpp:290
void addSensitivitySpeciesEnthalpy(size_t k) override
Add a sensitivity parameter associated with the enthalpy formation of species k.
Definition Reactor.cpp:275
void setAdvanceLimit(const string &nm, const double limit)
Set individual step size limit for component name nm
Definition Reactor.cpp:427
vector< size_t > initializeSteady() override
Initialize the reactor before solving a steady-state problem.
Definition Reactor.cpp:205
void addSensitivityReaction(size_t rxn) override
Add a sensitivity parameter associated with the reaction number rxn
Definition Reactor.cpp:262
double lowerBound(size_t k) const override
Get the lower bound on the k-th component of the local state vector.
Definition Reactor.cpp:348
vector< double > m_sdot
Total production rate of bulk phase species on surfaces [kmol/s].
Definition Reactor.h:155
string componentName(size_t k) override
Return the name of the solution component with index i.
Definition Reactor.cpp:321
bool hasAdvanceLimits() const
Check whether Reactor object uses advance limits.
Definition Reactor.h:108
double m_vdot
net rate of volume change from moving walls [m^3/s]
Definition Reactor.h:149
void updateState(double *y) override
Set the state of the reactor to correspond to the state vector y.
Definition Reactor.cpp:76
void initialize(double t0=0.0) override
Initialize the reactor.
Definition Reactor.cpp:62
double m_initialVolume
Initial volume [m³]; used for steady-state calculations.
Definition Reactor.h:163
bool getAdvanceLimits(double *limits) const
Retrieve absolute step size limits during advance.
Definition Reactor.cpp:416
void setDerivativeSettings(AnyMap &settings) override
Use this to set the kinetics objects derivative settings.
Definition Reactor.cpp:41
virtual bool isOde() const
Indicate whether the governing equations for this reactor type are a system of ODEs or DAEs.
Definition Reactor.h:59
bool chemistryEnabled() const override
Returns true if changes in the reactor composition due to chemical reactions are enabled.
Definition Reactor.h:71
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595