Cantera  3.2.0a2
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> sol, const string& name)
17 : ReactorBase(sol, name)
18{
19 if (!std::dynamic_pointer_cast<SurfPhase>(sol->thermo())) {
20 throw CanteraError("ReactorSurface::ReactorSurface",
21 "Solution object must have a SurfPhase object as the thermo manager.");
22 }
23
24 if (!sol->kinetics() ) {
25 throw CanteraError("ReactorSurface::ReactorSurface",
26 "Solution object must have kinetics manager.");
27 } else if (!std::dynamic_pointer_cast<InterfaceKinetics>(sol->kinetics())) {
28 throw CanteraError("ReactorSurface::ReactorSurface",
29 "Kinetics manager must be an InterfaceKinetics object.");
30 }
31 // todo: move all member variables to use shared pointers after Cantera 3.2
32 m_kinetics = m_solution->kinetics().get();
33 m_thermo = m_solution->thermo().get();
34 m_surf = dynamic_cast<SurfPhase*>(m_thermo);
35 m_cov.resize(m_surf->nSpecies());
36 m_surf->getCoverages(m_cov.data());
37}
38
39double ReactorSurface::area() const
40{
41 return m_area;
42}
43
44void ReactorSurface::setArea(double a)
45{
46 m_area = a;
47}
48
49void ReactorSurface::setKinetics(Kinetics* kin)
50{
51 warn_deprecated("ReactorSurface::setKinetics",
52 "To be removed after Cantera 3.2.");
53 m_kinetics = kin;
54 if (kin == nullptr) {
55 m_surf = nullptr;
56 return;
57 }
58
59 m_surf = dynamic_cast<SurfPhase*>(&kin->thermo(0));
60 if (m_surf == nullptr) {
61 throw CanteraError("ReactorSurface::setKinetics",
62 "Specified kinetics manager does not represent a surface "
63 "kinetics mechanism.");
64 }
65 m_cov.resize(m_surf->nSpecies());
66 m_surf->getCoverages(m_cov.data());
67}
68
69void ReactorSurface::setKinetics(Kinetics& kin)
70{
71 setKinetics(&kin);
72}
73
74void ReactorSurface::setReactor(ReactorBase* reactor)
75{
76 m_reactor = reactor;
77}
78
79void ReactorSurface::setCoverages(const double* cov)
80{
81 copy(cov, cov + m_cov.size(), m_cov.begin());
82}
83
84void ReactorSurface::setCoverages(const Composition& cov)
85{
86 m_surf->setCoveragesByName(cov);
87 m_surf->getCoverages(m_cov.data());
88}
89
90void ReactorSurface::setCoverages(const string& cov)
91{
92 m_surf->setCoveragesByName(cov);
93 m_surf->getCoverages(m_cov.data());
94}
95
96void ReactorSurface::getCoverages(double* cov) const
97{
98 copy(m_cov.begin(), m_cov.end(), cov);
99}
100
101void ReactorSurface::syncState()
102{
103 m_surf->setTemperature(m_reactor->temperature());
104 m_surf->setCoveragesNoNorm(m_cov.data());
105}
106
107void ReactorSurface::addSensitivityReaction(size_t rxn)
108{
109 if (rxn >= m_kinetics->nReactions()) {
110 throw CanteraError("ReactorSurface::addSensitivityReaction",
111 "Reaction number out of range ({})", rxn);
112 }
113 size_t p = m_reactor->network().registerSensitivityParameter(
114 m_kinetics->reaction(rxn)->equation(), 1.0, 1.0);
115 m_sensParams.emplace_back(
116 SensitivityParameter{rxn, p, 1.0, SensParameterType::reaction});
117}
118
119void ReactorSurface::setSensitivityParameters(const double* params)
120{
121 for (auto& p : m_sensParams) {
122 p.value = m_kinetics->multiplier(p.local);
123 m_kinetics->setMultiplier(p.local, p.value*params[p.global]);
124 }
125}
126
127void ReactorSurface::resetSensitivityParameters()
128{
129 for (auto& p : m_sensParams) {
130 m_kinetics->setMultiplier(p.local, p.value);
131 }
132}
133
134}
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
ThermoPhase & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
Definition Kinetics.h:240
Base class for reactor objects.
Definition ReactorBase.h:49
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
Definition SurfPhase.h:98
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