22 #include "cantera/kinetics/ExtraGlobalRxn.h"
29 #include "cantera/kinetics.h"
43 using namespace Cantera;
48 static void erase_vd(std::vector<doublereal>& m_vec,
int index)
50 std::vector<double>::iterator ipos;
56 static void erase_vi(std::vector<int>& m_vec,
int index)
58 std::vector<int>::iterator ipos;
72 static void addV(
int kkinspec,
double ps, std::vector<int>& m_Products,
73 std::vector<doublereal>& m_ProductStoich)
75 int nsize =
static_cast<int>(m_Products.size());
76 for (
int i = 0; i < nsize; i++) {
77 if (m_Products[i] == kkinspec) {
78 m_ProductStoich[i] += ps;
82 m_Products.push_back(kkinspec);
83 m_ProductStoich.push_back(ps);
86 ExtraGlobalRxn::ExtraGlobalRxn(
Kinetics* k_ptr) :
87 m_ThisIsASurfaceRxn(false),
89 m_InterfaceKinetics(0),
96 m_SpecialSpeciesProduct(true),
102 "Unfinished implementation to be removed after Cantera 2.2.");
105 m_ThisIsASurfaceRxn =
true;
108 m_ElemRxnVector.resize(m_nRxns,0.0);
112 void ExtraGlobalRxn::setupElemRxnVector(
double* RxnVector,
117 for (
size_t i = 0; i < (size_t) m_nRxns; i++) {
118 m_ElemRxnVector[i] = RxnVector[i];
120 for (
size_t i = 0; i < (size_t) m_nRxns; i++) {
121 if (RxnVector[i] > 0.0) {
122 for (kkinspec = 0; kkinspec < m_nKinSpecies; kkinspec++) {
125 addV(kkinspec, RxnVector[i]* ps, m_Products, m_ProductStoich);
126 addV(kkinspec, RxnVector[i]* ps, m_NetSpecies, m_netStoich);
131 addV(kkinspec, -RxnVector[i] * rs, m_NetSpecies, m_netStoich);
134 }
else if (RxnVector[i] < 0.0) {
135 for (kkinspec = 0; kkinspec < m_nKinSpecies; kkinspec++) {
139 addV(kkinspec, RxnVector[i]* ps, m_NetSpecies, m_netStoich);
143 addV(kkinspec, -RxnVector[i] * rs, m_Products, m_ProductStoich);
144 addV(kkinspec, -RxnVector[i] * rs, m_NetSpecies, m_netStoich);
150 for (i = 0; i < static_cast<int>(m_Products.size()); i++) {
151 if (m_ProductStoich[i] == 0.0) {
152 erase_vi(m_Products, i);
153 erase_vd(m_ProductStoich, i);
157 for (i = 0; i < static_cast<int>(
m_Reactants.size()); i++) {
164 for (i = 0; i < static_cast<int>(m_NetSpecies.size()); i++) {
165 if (m_netStoich[i] == 0.0) {
166 erase_vi(m_NetSpecies, i);
167 erase_vd(m_netStoich, i);
172 for (i = 0; i < static_cast<int>(m_Products.size()); i++) {
173 int ik = m_Products[i];
174 for (
int j = 0; j < static_cast<int>(
m_Reactants.size()); j++) {
178 erase_vi(m_Products, i);
179 erase_vd(m_ProductStoich, i);
188 erase_vi(m_Products, i);
189 erase_vd(m_ProductStoich, i);
197 m_nProducts =
static_cast<int>(m_Products.size());
199 m_nNetSpecies =
static_cast<int>(m_NetSpecies.size());
204 m_SpecialSpecies = specialSpecies;
205 if (specialSpecies == -1) {
206 m_SpecialSpecies = m_Products[0];
209 for (i = 0; i < (int) m_NetSpecies.size(); i++) {
210 int ik = m_NetSpecies[i];
211 if (ik == m_SpecialSpecies) {
212 if (m_netStoich[i] > 0.0) {
213 m_SpecialSpeciesProduct =
true;
215 m_SpecialSpeciesProduct =
false;
224 "Special species not a reactant or product: "
231 std::string ExtraGlobalRxn::reactionString()
239 istoich = (int) stoich;
240 if (fabs((
double)istoich - stoich) < 0.00001) {
243 rs +=
fp2str(stoich) +
" ";
248 if (k < (m_nReactants-1)) {
253 for (k = 0; k < m_nProducts; k++) {
254 int kkinspecies = m_Products[k];
255 double stoich = m_ProductStoich[k];
257 istoich = (int) stoich;
258 if (fabs((
double)istoich - stoich) < 0.00001) {
261 rs +=
fp2str(stoich) +
" ";
266 if (k < (m_nProducts-1)) {
274 std::vector<int>& ExtraGlobalRxn::reactants()
280 std::vector<int>& ExtraGlobalRxn::products()
286 bool ExtraGlobalRxn::isReversible()
292 double ExtraGlobalRxn::reactantStoichCoeff(
int kKin)
296 if (kkinspec == kKin) {
303 double ExtraGlobalRxn::productStoichCoeff(
int kKin)
305 for (
int k = 0; k < m_nProducts; k++) {
306 int kkinspec = m_Products[k];
307 if (kkinspec == kKin) {
308 return m_ProductStoich[k];
315 double ExtraGlobalRxn::deltaSpecValue(
double* speciesVectorProperty)
319 for (k = 0; k < m_nNetSpecies; k++) {
320 int kkinspec = m_NetSpecies[k];
321 val += speciesVectorProperty[kkinspec] * m_netStoich[k];
327 double ExtraGlobalRxn::deltaRxnVecValue(
double* rxnVectorProperty)
330 for (
int i = 0; i < m_nRxns; i++) {
331 val += m_ElemRxnVector[i] * rxnVectorProperty[i];
336 double ExtraGlobalRxn::ROPValue(
double* ROPElemKinVector)
339 for (
int i = 0; i < m_nRxns; i++) {
341 if (m_ElemRxnVector[i] > 0.0) {
342 val += ROPElemKinVector[i] * kstoich * m_ElemRxnVector[i];
344 val -= ROPElemKinVector[i] * kstoich * m_ElemRxnVector[i];
347 if (!m_SpecialSpeciesProduct) {
353 double ExtraGlobalRxn::FwdROPValue(
double* FwdROPElemKinVector,
354 double* RevROPElemKinVector)
357 for (
int i = 0; i < m_nRxns; i++) {
359 if (m_ElemRxnVector[i] > 0.0) {
360 val += FwdROPElemKinVector[i] * kstoich * m_ElemRxnVector[i];
362 if (m_ElemRxnVector[i] < 0.0) {
363 val += RevROPElemKinVector[i] * kstoich * m_ElemRxnVector[i];
366 if (!m_SpecialSpeciesProduct) {
372 double ExtraGlobalRxn::RevROPValue(
double* FwdROPElemKinVector,
373 double* RevROPElemKinVector)
376 for (
int i = 0; i < m_nRxns; i++) {
378 if (m_ElemRxnVector[i] > 0.0) {
379 val += RevROPElemKinVector[i] * kstoich * m_ElemRxnVector[i];
381 if (m_ElemRxnVector[i] < 0.0) {
382 val += FwdROPElemKinVector[i] * kstoich * m_ElemRxnVector[i];
385 if (!m_SpecialSpeciesProduct) {
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase, assuming an ideal solution model (see Thermodynamic Properties and class SurfPhase).
std::string kineticsSpeciesName(size_t k) const
Return the name of the kth species in the kinetics manager.
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
static void addV(int kkinspec, double ps, std::vector< int > &m_Products, std::vector< doublereal > &m_ProductStoich)
add the species into the list of products or reactants
A kinetics manager for heterogeneous reaction mechanisms.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Public interface for kinetics managers.
Base class for exceptions thrown by Cantera classes.
Headers for the DenseMatrix object, which deals with dense rectangular matrices and description of th...
size_t nReactions() const
Number of reactions in the reaction mechanism.
virtual double reactantStoichCoeff(size_t k, size_t i) const
Stoichiometric coefficient of species k as a reactant in reaction i.
virtual double productStoichCoeff(size_t k, size_t i) const
Stoichiometric coefficient of species k as a product in reaction i.