Cantera  2.4.0
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 http://www.cantera.org/license.txt for license and copyright information.
5 
10 
11 namespace Cantera
12 {
13 
14 ReactorSurface::ReactorSurface()
15  : m_area(1.0)
16  , m_thermo(nullptr)
17  , m_kinetics(nullptr)
18  , m_reactor(nullptr)
19 {
20 }
21 
22 double ReactorSurface::area() const
23 {
24  return m_area;
25 }
26 
27 void ReactorSurface::setArea(double a)
28 {
29  m_area = a;
30 }
31 
32 void ReactorSurface::setKinetics(Kinetics* kin) {
33  m_kinetics = kin;
34  if (kin == nullptr) {
35  m_thermo = nullptr;
36  return;
37  }
38 
39  size_t i = kin->surfacePhaseIndex();
40  if (i == npos) {
41  throw CanteraError("ReactorSurface::setKinetics",
42  "Specified surface kinetics manager does not represent a surface "
43  "kinetics mechanism.");
44  }
45  m_thermo = dynamic_cast<SurfPhase*>(&kin->thermo(i));
46  m_cov.resize(m_thermo->nSpecies());
47  m_thermo->getCoverages(m_cov.data());
48 }
49 
50 void ReactorSurface::setReactor(ReactorBase* reactor)
51 {
52  m_reactor = reactor;
53 }
54 
55 void ReactorSurface::setCoverages(const double* cov)
56 {
57  copy(cov, cov + m_cov.size(), m_cov.begin());
58 }
59 
60 void ReactorSurface::setCoverages(const Composition& cov)
61 {
62  m_thermo->setCoveragesByName(cov);
63  m_thermo->getCoverages(m_cov.data());
64 }
65 
66 void ReactorSurface::setCoverages(const std::string& cov)
67 {
68  m_thermo->setCoveragesByName(cov);
69  m_thermo->getCoverages(m_cov.data());
70 }
71 
72 void ReactorSurface::getCoverages(double* cov) const
73 {
74  copy(m_cov.begin(), m_cov.end(), cov);
75 }
76 
77 void ReactorSurface::syncCoverages()
78 {
79  m_thermo->setCoveragesNoNorm(m_cov.data());
80 }
81 
82 void ReactorSurface::addSensitivityReaction(size_t i)
83 {
84  if (i >= m_kinetics->nReactions()) {
85  throw CanteraError("ReactorSurface::addSensitivityReaction",
86  "Reaction number out of range ({})", i);
87  }
88  size_t p = m_reactor->network().registerSensitivityParameter(
89  m_kinetics->reactionString(i), 1.0, 1.0);
90  m_params.emplace_back(
91  SensitivityParameter{i, p, 1.0, SensParameterType::reaction});
92 }
93 
94 void ReactorSurface::setSensitivityParameters(const double* params)
95 {
96  for (auto& p : m_params) {
97  p.value = m_kinetics->multiplier(p.local);
98  m_kinetics->setMultiplier(p.local, p.value*params[p.global]);
99  }
100 }
101 
102 void ReactorSurface::resetSensitivityParameters()
103 {
104  for (auto& p : m_params) {
105  m_kinetics->setMultiplier(p.local, p.value);
106  }
107 }
108 
109 }
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase, assuming an ideal solution model (see Thermodynamic Properties and class SurfPhase).
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:165
std::map< std::string, doublereal > Composition
Map from string names to doubles.
Definition: ct_defs.h:153
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Header file for class ReactorSurface.
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8