Kinetics.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "InterfaceKinetics.h"
00019 #include "SurfPhase.h"
00020 #include "StoichManager.h"
00021 #include "RateCoeffMgr.h"
00022
00023 #include "ImplicitSurfChem.h"
00024
00025 #include <iostream>
00026 using namespace std;
00027
00028
00029 namespace Cantera {
00030
00031
00032 Kinetics::Kinetics() : m_ii(0), m_thermo(0),
00033 m_index(-1), m_surfphase(-1), m_rxnphase(-1),
00034 m_mindim(4) {}
00035
00036 Kinetics::~Kinetics(){}
00037
00038
00039
00040
00041
00042
00043
00044 Kinetics::Kinetics(const Kinetics &right) :
00045 m_ii(0),
00046 m_thermo(0),
00047 m_index(-1),
00048 m_surfphase(-1),
00049 m_rxnphase(-1),
00050 m_mindim(4)
00051 {
00052
00053
00054
00055 *this = operator=(right);
00056 }
00057
00058
00059
00060
00061
00062
00063
00064
00065 Kinetics& Kinetics::
00066 operator=(const Kinetics &right) {
00067
00068
00069
00070 if (this == &right) return *this;
00071
00072 m_ii = right.m_ii;
00073 m_perturb = right.m_perturb;
00074 m_reactants = right.m_reactants;
00075 m_products = right.m_products;
00076
00077 m_thermo = right.m_thermo;
00078
00079 m_start = right.m_start;
00080 m_phaseindex = right.m_phaseindex;
00081 m_index = right.m_index;
00082 m_surfphase = right.m_surfphase;
00083 m_rxnphase = right.m_rxnphase;
00084 m_mindim = right.m_mindim;
00085 m_dummygroups = right.m_dummygroups;
00086
00087 return *this;
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 Kinetics *Kinetics::duplMyselfAsKinetics() const {
00102 Kinetics* tp = new Kinetics(*this);
00103 return tp;
00104 }
00105
00106
00107
00108 int Kinetics::ID() const {
00109 return 0;
00110 }
00111
00112 int Kinetics::type() const {
00113 return 0;
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 void Kinetics::selectPhase(const doublereal* data, const thermo_t* phase,
00128 doublereal* phase_data) {
00129 int n, nsp, np = nPhases();
00130 for (n = 0; n < np; n++) {
00131 if (phase == m_thermo[n]) {
00132 nsp = phase->nSpecies();
00133 copy(data + m_start[n],
00134 data + m_start[n] + nsp, phase_data);
00135 return;
00136 }
00137 }
00138 throw CanteraError("Kinetics::selectPhase", "Phase not found.");
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 string Kinetics::kineticsSpeciesName(int k) const {
00153 int np = m_start.size();
00154 for (int n = np-1; n >= 0; n--) {
00155 if (k >= m_start[n]) {
00156 return thermo(n).speciesName(k - m_start[n]);
00157 }
00158 }
00159 return "<unknown>";
00160 }
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 int Kinetics::kineticsSpeciesIndex(std::string nm, std::string ph) const {
00179 int np = static_cast<int>(m_thermo.size());
00180 int k;
00181 string id;
00182 for (int n = 0; n < np; n++) {
00183 id = thermo(n).id();
00184 if (ph == id) {
00185 k = thermo(n).speciesIndex(nm);
00186 if (k < 0) return -1;
00187 return k + m_start[n];
00188 }
00189 else if (ph == "<any>") {
00190
00191
00192
00193
00194 k = thermo(n).speciesIndex(nm);
00195 if (k >= 0) return k + m_start[n];
00196 }
00197 }
00198 return -2;
00199 }
00200
00201
00202
00203
00204
00205
00206
00207 thermo_t& Kinetics::speciesPhase(std::string nm) {
00208 int np = static_cast<int>(m_thermo.size());
00209 int k;
00210 string id;
00211 for (int n = 0; n < np; n++) {
00212 k = thermo(n).speciesIndex(nm);
00213 if (k >= 0) return thermo(n);
00214 }
00215 throw CanteraError("speciesPhase", "unknown species "+nm);
00216 return thermo(0);
00217 }
00218
00219
00220
00221
00222
00223
00224
00225 int Kinetics::speciesPhaseIndex(int k) {
00226 int np = m_start.size();
00227 for (int n = np-1; n >= 0; n--) {
00228 if (k >= m_start[n]) {
00229 return n;
00230 }
00231 }
00232 throw CanteraError("speciesPhaseIndex", "illegal species index: "+int2str(k));
00233 return -1;
00234 }
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 void Kinetics::addPhase(thermo_t& thermo) {
00254
00255
00256
00257 if (m_thermo.size() > 0) {
00258 m_start.push_back(m_start.back()
00259 + m_thermo.back()->nSpecies());
00260 }
00261
00262 else {
00263 m_start.push_back(0);
00264 }
00265
00266
00267
00268 if (thermo.nDim() <= m_mindim) {
00269 m_mindim = thermo.nDim();
00270 m_rxnphase = nPhases();
00271 }
00272
00273
00274 int ptype = -100;
00275 if (type() == cEdgeKinetics) ptype = cEdge;
00276 else if (type() == cInterfaceKinetics) ptype = cSurf;
00277 if (thermo.eosType() == ptype) {
00278
00279
00280
00281
00282 m_surfphase = nPhases();
00283 m_rxnphase = nPhases();
00284 }
00285 m_thermo.push_back(&thermo);
00286 m_phaseindex[m_thermo.back()->id()] = nPhases();
00287 }
00288
00289
00290
00291
00292
00293
00294
00295 void Kinetics::err(std::string m) const {
00296 throw CanteraError("Kinetics::" + m,
00297 "The default Base class method was called, when "
00298 "the inherited class's method should "
00299 "have been called");
00300 }
00301
00302 }