Cantera  3.2.0a4
Loading...
Searching...
No Matches
ReactorSurface.cpp
Go to the documentation of this file.
1//! @file ReactorSurface.cpp
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
12
13namespace Cantera
14{
15
16ReactorSurface::ReactorSurface(shared_ptr<Solution> soln,
17 const vector<shared_ptr<ReactorBase>>& reactors,
18 bool clone,
19 const string& name)
20 : ReactorBase(name)
21{
22 // TODO: After Cantera 3.2, raise an exception of 'reactors' is empty
23 vector<shared_ptr<Solution>> adjacent;
24 for (auto R : reactors) {
25 adjacent.push_back(R->contents4());
26 m_reactors.push_back(R.get());
27 R->addSurface(this);
28 }
29 if (clone) {
30 m_solution = soln->clone(adjacent, true, false);
31 } else {
32 m_solution = soln;
33 }
34 m_solution->thermo()->addSpeciesLock();
35 setThermo(*m_solution->thermo());
36 if (!std::dynamic_pointer_cast<SurfPhase>(soln->thermo())) {
37 throw CanteraError("ReactorSurface::ReactorSurface",
38 "Solution object must have a SurfPhase object as the thermo manager.");
39 }
40
41 if (!soln->kinetics() ) {
42 throw CanteraError("ReactorSurface::ReactorSurface",
43 "Solution object must have kinetics manager.");
44 } else if (!std::dynamic_pointer_cast<InterfaceKinetics>(soln->kinetics())) {
45 throw CanteraError("ReactorSurface::ReactorSurface",
46 "Kinetics manager must be an InterfaceKinetics object.");
47 }
48 // todo: move all member variables to use shared pointers after Cantera 3.2
49 m_kinetics = m_solution->kinetics().get();
50 m_thermo = m_solution->thermo().get();
51 m_surf = dynamic_cast<SurfPhase*>(m_thermo);
52 m_cov.resize(m_surf->nSpecies());
53 m_surf->getCoverages(m_cov.data());
54}
55
56ReactorSurface::ReactorSurface(shared_ptr<Solution> sol, const string& name)
57 : ReactorBase(sol, false, name)
58{
59 if (!std::dynamic_pointer_cast<SurfPhase>(sol->thermo())) {
60 throw CanteraError("ReactorSurface::ReactorSurface",
61 "Solution object must have a SurfPhase object as the thermo manager.");
62 }
63
64 if (!sol->kinetics() ) {
65 throw CanteraError("ReactorSurface::ReactorSurface",
66 "Solution object must have kinetics manager.");
67 } else if (!std::dynamic_pointer_cast<InterfaceKinetics>(sol->kinetics())) {
68 throw CanteraError("ReactorSurface::ReactorSurface",
69 "Kinetics manager must be an InterfaceKinetics object.");
70 }
71 // todo: move all member variables to use shared pointers after Cantera 3.2
72 m_kinetics = m_solution->kinetics().get();
73 m_thermo = m_solution->thermo().get();
74 m_surf = dynamic_cast<SurfPhase*>(m_thermo);
75 m_cov.resize(m_surf->nSpecies());
76 m_surf->getCoverages(m_cov.data());
77}
78
79ReactorSurface::ReactorSurface(shared_ptr<Solution> sol, bool clone, const string& name)
80 : ReactorSurface(sol, name)
81{
82 // TODO: Remove after Cantera 3.2 when removing ReactorSurface from ReactorFactory
83 if (clone) {
84 throw CanteraError("ReactorSurface::ReactorSurface", "Bad constructor arguments."
85 " When clone=true, list of adjacent reactors must be provided");
86 }
87}
88
90{
91 return m_area;
92}
93
95{
96 m_area = a;
97}
98
100{
101 warn_deprecated("ReactorSurface::setKinetics",
102 "To be removed after Cantera 3.2.");
103 m_kinetics = kin;
104 if (kin == nullptr) {
105 m_surf = nullptr;
106 return;
107 }
108
109 m_surf = dynamic_cast<SurfPhase*>(&kin->thermo(0));
110 if (m_surf == nullptr) {
111 throw CanteraError("ReactorSurface::setKinetics",
112 "Specified kinetics manager does not represent a surface "
113 "kinetics mechanism.");
114 }
115 m_cov.resize(m_surf->nSpecies());
116 m_surf->getCoverages(m_cov.data());
117}
118
120{
121 setKinetics(&kin);
122}
123
125{
126 if (std::find(m_reactors.begin(), m_reactors.end(), reactor) != m_reactors.end()) {
127 // Ignore case where reactor has already been added in the opposite direction
128 return;
129 }
130 warn_deprecated("ReactorSurface::setReactor", "To be removed after Cantera 3.2. "
131 "Superseded by constructor taking a list of adjacent reactors.");
132 m_reactors.resize(1);
133 m_reactors[0] = reactor;
134}
135
136void ReactorSurface::setCoverages(const double* cov)
137{
138 copy(cov, cov + m_cov.size(), m_cov.begin());
139}
140
142{
143 m_surf->setCoveragesByName(cov);
144 m_surf->getCoverages(m_cov.data());
145}
146
147void ReactorSurface::setCoverages(const string& cov)
148{
149 m_surf->setCoveragesByName(cov);
150 m_surf->getCoverages(m_cov.data());
151}
152
153void ReactorSurface::getCoverages(double* cov) const
154{
155 copy(m_cov.begin(), m_cov.end(), cov);
156}
157
159{
160 if (m_reactors.empty()) {
161 // TODO: Remove this check after Cantera 3.2, since it will no longer be
162 // possible to create the ReactorSurface without specifying the adjacent
163 // reactors in the constructor.
164 throw CanteraError("ReactorSurface::syncState",
165 "Surface is not installed on any Reactor");
166 }
167 m_surf->setTemperature(m_reactors[0]->temperature());
168 m_surf->setCoveragesNoNorm(m_cov.data());
169}
170
172{
173 warn_user("ReactorSurface::syncState", "Behavior changed in Cantera 3.2 for "
174 "consistency with ReactorBase. To set SurfPhase state from ReactorSurface "
175 "object, use restoreState().");
176 m_surf->getCoverages(m_cov.data());
177}
178
180{
181 if (rxn >= m_kinetics->nReactions()) {
182 throw CanteraError("ReactorSurface::addSensitivityReaction",
183 "Reaction number out of range ({})", rxn);
184 }
185 size_t p = m_reactors[0]->network().registerSensitivityParameter(
186 m_kinetics->reaction(rxn)->equation(), 1.0, 1.0);
187 m_sensParams.emplace_back(
188 SensitivityParameter{rxn, p, 1.0, SensParameterType::reaction});
189}
190
192{
193 for (auto& p : m_sensParams) {
194 p.value = m_kinetics->multiplier(p.local);
195 m_kinetics->setMultiplier(p.local, p.value*params[p.global]);
196 }
197}
198
200{
201 for (auto& p : m_sensParams) {
202 m_kinetics->setMultiplier(p.local, p.value);
203 }
204}
205
206}
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Header file for class ReactorSurface.
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase,...
Base class for exceptions thrown by Cantera classes.
Public interface for kinetics managers.
Definition Kinetics.h:126
double multiplier(size_t i) const
The current value of the multiplier for reaction i.
Definition Kinetics.h:1379
ThermoPhase & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
Definition Kinetics.h:248
shared_ptr< Reaction > reaction(size_t i)
Return the Reaction object for reaction i.
Definition Kinetics.cpp:806
size_t nReactions() const
Number of reactions in the reaction mechanism.
Definition Kinetics.h:161
virtual void setMultiplier(size_t i, double f)
Set the multiplier for reaction i to f.
Definition Kinetics.h:1388
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:232
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition Phase.h:648
Base class for reactor objects.
Definition ReactorBase.h:49
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
double temperature() const
Returns the current temperature (K) of the reactor's contents.
A surface where reactions can occur that is in contact with the bulk fluid of a Reactor.
void restoreState() override
Set the coverages and temperature in the surface phase object to the values for this surface.
double area() const
Returns the surface area [m^2].
void setReactor(ReactorBase *reactor)
Set the reactor that this Surface interacts with.
void setSensitivityParameters(const double *params)
Set reaction rate multipliers.
ReactorSurface(shared_ptr< Solution > soln, const vector< shared_ptr< ReactorBase > > &reactors, bool clone, const string &name="(none)")
Create a new ReactorSurface.
void getCoverages(double *cov) const
Get the surface coverages.
void setArea(double a)
Set the surface area [m^2].
void resetSensitivityParameters()
Set reaction rate multipliers back to their initial values.
void addSensitivityReaction(size_t rxn) override
Add a sensitivity parameter associated with the reaction number rxn
void setThermo(ThermoPhase &thermo) override
Specify the mixture contained in the reactor.
void syncState() override
Set the coverages for this ReactorSurface based on the attached SurfPhase.
void setCoverages(const double *cov)
Set the surface coverages.
void setKinetics(Kinetics *kin)
Set the InterfaceKinetics object for this surface.
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
Definition SurfPhase.h:98
void setCoveragesNoNorm(const double *theta)
Set the surface site fractions to a specified state.
void getCoverages(double *theta) const
Return a vector of surface coverages.
void setCoveragesByName(const string &cov)
Set the coverages from a string of colon-separated name:value pairs.
void warn_user(const string &method, const string &msg, const Args &... args)
Print a user warning raised from method as CanteraWarning.
Definition global.h:268
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1997
map< string, double > Composition
Map from string names to doubles.
Definition ct_defs.h:177