Cantera  3.3.0a1
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 if (reactors.empty()) {
23 throw CanteraError("ReactorSurface::ReactorSurface",
24 "Surface requires at least one adjacent reactor.");
25 }
26 vector<shared_ptr<Solution>> adjacent;
27 for (auto R : reactors) {
28 adjacent.push_back(R->phase());
29 m_reactors.push_back(R.get());
30 R->addSurface(this);
31 }
32 if (clone) {
33 m_solution = soln->clone(adjacent, true, false);
34 } else {
35 m_solution = soln;
36 }
37 m_solution->thermo()->addSpeciesLock();
38 m_surf = std::dynamic_pointer_cast<SurfPhase>(m_solution->thermo());
39 if (!m_surf) {
40 throw CanteraError("ReactorSurface::ReactorSurface",
41 "Solution object must have a SurfPhase object as the thermo manager.");
42 }
43
44 if (!soln->kinetics() ) {
45 throw CanteraError("ReactorSurface::ReactorSurface",
46 "Solution object must have kinetics manager.");
47 } else if (!std::dynamic_pointer_cast<InterfaceKinetics>(soln->kinetics())) {
48 throw CanteraError("ReactorSurface::ReactorSurface",
49 "Kinetics manager must be an InterfaceKinetics object.");
50 }
51 m_kinetics = m_solution->kinetics();
52 m_thermo = m_surf.get();
53 m_cov.resize(m_surf->nSpecies());
54 m_surf->getCoverages(m_cov.data());
55}
56
58{
59 return m_area;
60}
61
63{
64 m_area = a;
65}
66
67void ReactorSurface::setCoverages(const double* cov)
68{
69 copy(cov, cov + m_cov.size(), m_cov.begin());
70}
71
73{
74 m_surf->setCoveragesByName(cov);
75 m_surf->getCoverages(m_cov.data());
76}
77
78void ReactorSurface::setCoverages(const string& cov)
79{
80 m_surf->setCoveragesByName(cov);
81 m_surf->getCoverages(m_cov.data());
82}
83
84void ReactorSurface::getCoverages(double* cov) const
85{
86 copy(m_cov.begin(), m_cov.end(), cov);
87}
88
90{
91 m_surf->setTemperature(m_reactors[0]->temperature());
92 m_surf->setCoveragesNoNorm(m_cov.data());
93}
94
96{
97 warn_user("ReactorSurface::syncState", "Behavior changed in Cantera 3.2 for "
98 "consistency with ReactorBase. To set SurfPhase state from ReactorSurface "
99 "object, use restoreState().");
100 m_surf->getCoverages(m_cov.data());
101}
102
104{
105 if (rxn >= m_kinetics->nReactions()) {
106 throw CanteraError("ReactorSurface::addSensitivityReaction",
107 "Reaction number out of range ({})", rxn);
108 }
109 size_t p = m_reactors[0]->network().registerSensitivityParameter(
110 m_kinetics->reaction(rxn)->equation(), 1.0, 1.0);
111 m_sensParams.emplace_back(
112 SensitivityParameter{rxn, p, 1.0, SensParameterType::reaction});
113}
114
116{
117 for (auto& p : m_sensParams) {
118 p.value = m_kinetics->multiplier(p.local);
119 m_kinetics->setMultiplier(p.local, p.value*params[p.global]);
120 }
121}
122
124{
125 for (auto& p : m_sensParams) {
126 m_kinetics->setMultiplier(p.local, p.value);
127 }
128}
129
130}
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.
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.
void restoreState() override
Set the coverages and temperature in the surface phase object to the values for this surface.
double area() const override
Returns the surface area [m²].
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 setArea(double a) override
Set the surface area [m²].
void getCoverages(double *cov) const
Get the surface coverages.
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 syncState() override
Set the coverages for this ReactorSurface based on the attached SurfPhase.
void setCoverages(const double *cov)
Set the surface coverages.
void warn_user(const string &method, const string &msg, const Args &... args)
Print a user warning raised from method as CanteraWarning.
Definition global.h:263
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
map< string, double > Composition
Map from string names to doubles.
Definition ct_defs.h:177