Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RxnMolChange.cpp
Go to the documentation of this file.
1 /**
2  * @file example2.cpp
3  *
4  * $Id: RxnMolChange.cpp 571 2013-03-26 16:44:21Z hkmoffa $
5  *
6  */
7 
8 /*
9  * Copyright (2005) Sandia Corporation. Under the terms of
10  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
11  * U.S. Government retains certain rights in this software.
12  */
13 
14 #include "cantera/kinetics/RxnMolChange.h"
15 
16 
17 #include "cantera/thermo.h"
18 #include "cantera/kinetics.h"
20 
21 #include "cantera/kinetics/ExtraGlobalRxn.h"
22 
23 #include <iostream>
24 #include <new>
25 
26 using namespace Cantera;
27 using namespace std;
28 
29 namespace Cantera {
30 
32  m_nPhases(0),
33  m_kinBase(kinPtr),
34  m_iRxn(irxn),
35  m_ChargeTransferInRxn(0.0),
36  m_beta(0.0),
37  m_egr(0)
38 {
39  warn_deprecated("class RxnMolChange", "To be removed after Cantera 2.2.");
40  int iph;
41  AssertTrace(irxn >= 0);
42  AssertTrace(irxn < static_cast<int>(kinPtr->nReactions()));
43 
44  m_nPhases = static_cast<int>(kinPtr->nPhases());
45 
46  m_phaseMoleChange.resize(m_nPhases, 0.0);
47  m_phaseReactantMoles.resize(m_nPhases, 0.0);
48  m_phaseProductMoles.resize(m_nPhases, 0.0);
49  m_phaseMassChange.resize(m_nPhases, 0.0);
50  m_phaseChargeChange.resize(m_nPhases, 0.0);
51  m_phaseTypes.resize(m_nPhases, 0);
52  m_phaseDims.resize(m_nPhases, 0);
53 
54  int m_kk = static_cast<int>(kinPtr->nTotalSpecies());
55 
56  for (int kKin = 0; kKin < m_kk; kKin++) {
57  iph = static_cast<int>(m_kinBase->speciesPhaseIndex(kKin));
58  Cantera::ThermoPhase& tpRef = m_kinBase->thermo(iph);
59  int kLoc = kKin - static_cast<int>(m_kinBase->kineticsSpeciesIndex(0, iph));
60  double rsc = m_kinBase->reactantStoichCoeff(kKin, irxn);
61  double psc = m_kinBase->productStoichCoeff(kKin, irxn);
62  double nsc = psc - rsc;
63  m_phaseMoleChange[iph] += (nsc);
64  m_phaseReactantMoles[iph] += rsc;
65  m_phaseProductMoles[iph] += psc;
66  double mw = tpRef.molecularWeight(kLoc);
67  m_phaseMassChange[iph] += (nsc) * mw;
68  double chg = tpRef.charge(kLoc);
69  m_phaseChargeChange[iph] += nsc * chg;
70  }
71 
72  for (iph = 0; iph < m_nPhases; iph++) {
73  Cantera::ThermoPhase& tpRef = m_kinBase->thermo(iph);
74  m_phaseDims[iph] = static_cast<int>(tpRef.nDim());
75  m_phaseTypes[iph] = tpRef.eosType();
76  if (m_phaseChargeChange[iph] != 0.0) {
77  double tmp = fabs(m_phaseChargeChange[iph]);
78  if (tmp > m_ChargeTransferInRxn) {
80  }
81  }
82  }
83 
85  Cantera::InterfaceKinetics* iK = dynamic_cast<Cantera::InterfaceKinetics*>(kinPtr);
86  if (iK) {
87  m_beta = iK->electrochem_beta(irxn);
88  } else {
89  throw Cantera::CanteraError("RxnMolChange", "unknown condition on charge");
90  }
91  }
92 
93 }
94 
96  m_nPhases(0),
97  m_kinBase(kinPtr),
98  m_iRxn(-1),
99  m_ChargeTransferInRxn(0.0),
100  m_beta(0.0),
101  m_egr(egr)
102 {
103  int iph;
104  AssertTrace(egr != 0);
105 
106  m_nPhases = static_cast<int>(kinPtr->nPhases());
107 
108  m_phaseMoleChange.resize(m_nPhases, 0.0);
109  m_phaseReactantMoles.resize(m_nPhases, 0.0);
110  m_phaseProductMoles.resize(m_nPhases, 0.0);
111  m_phaseMassChange.resize(m_nPhases, 0.0);
112  m_phaseChargeChange.resize(m_nPhases, 0.0);
113  m_phaseTypes.resize(m_nPhases, 0);
114  m_phaseDims.resize(m_nPhases, 0);
115 
116  int m_kk = static_cast<int>(kinPtr->nTotalSpecies());
117 
118  for (int kKin = 0; kKin < m_kk; kKin++) {
119  iph = static_cast<int>(m_kinBase->speciesPhaseIndex(kKin));
120  ThermoPhase& tpRef = m_kinBase->thermo(iph);
121  int kLoc = kKin - static_cast<int>(m_kinBase->kineticsSpeciesIndex(0, iph));
122  double rsc = egr->reactantStoichCoeff(kKin);
123  double psc = egr->productStoichCoeff(kKin);
124  double nsc = psc - rsc;
125  m_phaseMoleChange[iph] += (nsc);
126  m_phaseReactantMoles[iph] += rsc;
127  m_phaseProductMoles[iph] += psc;
128  double mw = tpRef.molecularWeight(kLoc);
129  m_phaseMassChange[iph] += (nsc) * mw;
130  double chg = tpRef.charge(kLoc);
131  m_phaseChargeChange[iph] += nsc * chg;
132  }
133 
134  for (iph = 0; iph < m_nPhases; iph++) {
135  ThermoPhase& tpRef = m_kinBase->thermo(iph);
136  m_phaseDims[iph] = static_cast<int>(tpRef.nDim());
137  m_phaseTypes[iph] = tpRef.eosType();
138  if (m_phaseChargeChange[iph] != 0.0) {
139  double tmp = fabs(m_phaseChargeChange[iph]);
140  if (tmp > m_ChargeTransferInRxn) {
141  m_ChargeTransferInRxn = tmp;
142  }
143  }
144  }
145 
146  if (m_ChargeTransferInRxn) {
147  InterfaceKinetics* iK = dynamic_cast<InterfaceKinetics*>(kinPtr);
148  if (iK) {
149  m_beta = 0.0;
150  } else {
151  throw CanteraError("RxnMolChange", "unknown condition on charge");
152  }
153  }
154 
155 }
156 
157 }
158 
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:494
Support for thermo property calculation from C++ application programs.
doublereal electrochem_beta(size_t irxn) const
Return the charge transfer rxn Beta parameter for the ith reaction.
thermo_t & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism...
Definition: Kinetics.h:285
Cantera::Kinetics * m_kinBase
Shallow pointer pointing to the kinetics object.
Definition: RxnMolChange.h:95
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
Definition: Kinetics.h:297
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:78
double m_ChargeTransferInRxn
Maximum change in charge of any phase due to this reaction.
Definition: RxnMolChange.h:105
std::vector< double > m_phaseMassChange
Vector of mass changes for each phase in the Kinetics object due to the current reaction.
Definition: RxnMolChange.h:67
std::vector< double > m_phaseChargeChange
Vector of mass changes for each phase in the Kinetics object due to the current reaction.
Definition: RxnMolChange.h:75
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
size_t nPhases() const
The number of phases participating in the reaction mechanism.
Definition: Kinetics.h:225
A kinetics manager for heterogeneous reaction mechanisms.
Public interface for kinetics managers.
Definition: Kinetics.h:128
Class describing an extra global reaction, which is defined as a linear combination of actuals reacti...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
RxnMolChange(Cantera::Kinetics *kinPtr, int irxn)
Main constructor for the class.
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
Definition: Kinetics.h:323
std::vector< int > m_phaseDims
Vector of phase dimensions for the reaction.
Definition: RxnMolChange.h:89
#define AssertTrace(expr)
Assertion must be true or an error is thrown.
Definition: ctexceptions.h:270
size_t nDim() const
Returns the number of spatial dimensions (1, 2, or 3)
Definition: Phase.h:586
virtual int eosType() const
Equation of state type flag.
Definition: ThermoPhase.h:142
size_t speciesPhaseIndex(size_t k)
This function takes as an argument the kineticsSpecies index (i.e., the list index in the list of spe...
Definition: Kinetics.cpp:417
std::vector< double > m_phaseMoleChange
Vector of mole changes for each phase in the Kinetics object due to the current reaction.
Definition: RxnMolChange.h:55
std::vector< int > m_phaseTypes
Vector of phase types in the reaction.
Definition: RxnMolChange.h:82
size_t nReactions() const
Number of reactions in the reaction mechanism.
Definition: Kinetics.h:193
virtual double reactantStoichCoeff(size_t k, size_t i) const
Stoichiometric coefficient of species k as a reactant in reaction i.
Definition: Kinetics.cpp:428
virtual double productStoichCoeff(size_t k, size_t i) const
Stoichiometric coefficient of species k as a product in reaction i.
Definition: Kinetics.cpp:433
int m_nPhases
Number of phases in the kientics object.
Definition: RxnMolChange.h:92
double m_beta
Electrochemical beta parameter for the reaction.
Definition: RxnMolChange.h:108
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
Definition: Phase.h:578