diff --git a/include/cantera/kinetics/Kinetics.h b/include/cantera/kinetics/Kinetics.h index f6251d5a2..52323cd0e 100644 --- a/include/cantera/kinetics/Kinetics.h +++ b/include/cantera/kinetics/Kinetics.h @@ -202,10 +202,10 @@ public: * This returns the integer index of the phase which has ThermoPhase type * cSurf. For heterogeneous mechanisms, this identifies the one surface * phase. For homogeneous mechanisms, this returns -1. + * + * @deprecated To be removed after Cantera 3.0. Use reactionPhaseIndex instead. */ - size_t surfacePhaseIndex() const { - return m_surfphase; - } + size_t surfacePhaseIndex() const; /** * Phase where the reactions occur. For heterogeneous mechanisms, one of @@ -1088,7 +1088,9 @@ public: * * - #m_start -> vector of integers, containing the starting position of * the species for each phase in the kinetics mechanism. - * - #m_surfphase -> index of the surface phase. + * - #m_rxnphase -> index of the phase where reactions occur, which is the lowest- + * dimensional phase in the system, for example the surface in a surface + * mechanism. * - #m_thermo -> vector of pointers to ThermoPhase phases that * participate in the kinetics mechanism. * - #m_phaseindex -> map containing the std::string id of each @@ -1333,6 +1335,7 @@ protected: std::map m_phaseindex; //! Index in the list of phases of the one surface phase. + //! @deprecated To be removed after Cantera 3.0. size_t m_surfphase; //! Phase Index where reactions are assumed to be taking place diff --git a/src/kinetics/ImplicitSurfChem.cpp b/src/kinetics/ImplicitSurfChem.cpp index ecde4b6ad..5af3c0920 100644 --- a/src/kinetics/ImplicitSurfChem.cpp +++ b/src/kinetics/ImplicitSurfChem.cpp @@ -41,13 +41,14 @@ ImplicitSurfChem::ImplicitSurfChem( for (size_t n = 0; n < k.size(); n++) { InterfaceKinetics* kinPtr = k[n]; m_vecKinPtrs.push_back(kinPtr); - size_t ns = k[n]->surfacePhaseIndex(); - if (ns == npos) { + size_t ns = k[n]->reactionPhaseIndex(); + SurfPhase* surf = dynamic_cast(&k[n]->thermo(ns)); + if (surf == nullptr) { throw CanteraError("ImplicitSurfChem::ImplicitSurfChem", "kinetics manager contains no surface phase"); } m_surfindex.push_back(ns); - m_surf.push_back((SurfPhase*)&k[n]->thermo(ns)); + m_surf.push_back(surf); size_t nsp = m_surf.back()->nSpecies(); m_nsp.push_back(nsp); m_nv += m_nsp.back(); diff --git a/src/kinetics/InterfaceKinetics.cpp b/src/kinetics/InterfaceKinetics.cpp index 6a288ed9e..793a3041f 100644 --- a/src/kinetics/InterfaceKinetics.cpp +++ b/src/kinetics/InterfaceKinetics.cpp @@ -60,7 +60,7 @@ void InterfaceKinetics::_update_rates_T() _update_rates_phi(); // Go find the temperature from the surface - doublereal T = thermo(surfacePhaseIndex()).temperature(); + doublereal T = thermo(reactionPhaseIndex()).temperature(); m_redo_rates = true; if (T != m_temp || m_redo_rates) { // Calculate the forward rate constant by calling m_rates and store it in m_rfn[] @@ -78,7 +78,7 @@ void InterfaceKinetics::_update_rates_T() // loop over interface MultiRate evaluators for each reaction type for (auto& rates : m_interfaceRates) { - bool changed = rates->update(thermo(surfacePhaseIndex()), *this); + bool changed = rates->update(thermo(reactionPhaseIndex()), *this); if (changed) { rates->getRateConstants(m_rfn.data()); m_ROP_ok = false; diff --git a/src/kinetics/InterfaceRate.cpp b/src/kinetics/InterfaceRate.cpp index cd830685d..504f5ff0f 100644 --- a/src/kinetics/InterfaceRate.cpp +++ b/src/kinetics/InterfaceRate.cpp @@ -55,7 +55,7 @@ bool InterfaceData::update(const ThermoPhase& phase, const Kinetics& kin) double T = phase.temperature(); bool changed = false; const auto& surf = dynamic_cast( - kin.thermo(kin.surfacePhaseIndex())); + kin.thermo(kin.reactionPhaseIndex())); double site_density = surf.siteDensity(); if (density != site_density) { density = surf.siteDensity(); @@ -319,7 +319,7 @@ void StickingCoverage::getStickingParameters(AnyMap& node) const void StickingCoverage::setContext(const Reaction& rxn, const Kinetics& kin) { // Ensure that site density is initialized - const ThermoPhase& phase = kin.thermo(kin.surfacePhaseIndex()); + const ThermoPhase& phase = kin.thermo(kin.reactionPhaseIndex()); const auto& surf = dynamic_cast(phase); m_siteDensity = surf.siteDensity(); if (!m_explicitMotzWise) { diff --git a/src/kinetics/Kinetics.cpp b/src/kinetics/Kinetics.cpp index 90b1cd7dc..75f7e7802 100644 --- a/src/kinetics/Kinetics.cpp +++ b/src/kinetics/Kinetics.cpp @@ -86,6 +86,13 @@ void Kinetics::checkPhaseArraySize(size_t mm) const } } +size_t Kinetics::surfacePhaseIndex() const +{ + warn_deprecated("Kinetics::surfacePhaseIndex", + "To be removed after Cantera 3.0. Use reactionPhaseIndex instead."); + return m_surfphase; +} + void Kinetics::checkSpeciesIndex(size_t k) const { if (k >= m_kk) { @@ -566,7 +573,6 @@ void Kinetics::addPhase(ThermoPhase& thermo) // there should only be one surface phase if (thermo.type() == kineticsType()) { m_surfphase = nPhases(); - m_rxnphase = nPhases(); } m_thermo.push_back(&thermo); m_phaseindex[m_thermo.back()->name()] = nPhases(); diff --git a/src/kinetics/Reaction.cpp b/src/kinetics/Reaction.cpp index ac5bee926..8465cf6d3 100644 --- a/src/kinetics/Reaction.cpp +++ b/src/kinetics/Reaction.cpp @@ -606,7 +606,7 @@ void Reaction::checkBalance(const Kinetics& kin) const // Check that the number of surface sites is balanced double reac_sites = 0.0; double prod_sites = 0.0; - auto& surf = dynamic_cast(kin.thermo(kin.surfacePhaseIndex())); + auto& surf = dynamic_cast(kin.thermo(kin.reactionPhaseIndex())); for (const auto& reactant : reactants) { size_t k = surf.speciesIndex(reactant.first); if (k != npos) { diff --git a/src/kinetics/solveSP.cpp b/src/kinetics/solveSP.cpp index e469cc6cc..1c0cd1ffd 100644 --- a/src/kinetics/solveSP.cpp +++ b/src/kinetics/solveSP.cpp @@ -38,21 +38,16 @@ solveSP::solveSP(ImplicitSurfChem* surfChemPtr, int bulkFunc) : m_numSurfPhases = 0; for (size_t n = 0; n < m_objects.size(); n++) { InterfaceKinetics* kin = m_objects[n]; - size_t surfPhaseIndex = kin->surfacePhaseIndex(); - if (surfPhaseIndex != npos) { - m_numSurfPhases++; - m_indexKinObjSurfPhase.push_back(n); - m_kinObjPhaseIDSurfPhase.push_back(surfPhaseIndex); - } else { + size_t surfPhaseIndex = kin->reactionPhaseIndex(); + SurfPhase* sp = dynamic_cast(&kin->thermo(surfPhaseIndex)); + if (sp == nullptr) { throw CanteraError("solveSP::solveSP", "InterfaceKinetics object has no surface phase"); } - SurfPhase* sp = dynamic_cast(&kin->thermo(surfPhaseIndex)); - if (!sp) { - throw CanteraError("solveSP::solveSP", - "Inconsistent ThermoPhase object within " - "InterfaceKinetics object"); - } + + m_numSurfPhases++; + m_indexKinObjSurfPhase.push_back(n); + m_kinObjPhaseIDSurfPhase.push_back(surfPhaseIndex); m_ptrsSurfPhase.push_back(sp); size_t nsp = sp->nSpecies(); @@ -361,7 +356,7 @@ void solveSP::fun_eval(doublereal* resid, const doublereal* CSoln, for (size_t isp = 0; isp < m_numSurfPhases; isp++) { size_t nsp = m_nSpeciesSurfPhase[isp]; InterfaceKinetics* kinPtr = m_objects[isp]; - size_t surfIndex = kinPtr->surfacePhaseIndex(); + size_t surfIndex = kinPtr->reactionPhaseIndex(); size_t kstart = kinPtr->kineticsSpeciesIndex(0, surfIndex); size_t kins = kindexSP; kinPtr->getNetProductionRates(m_netProductionRatesSave.data()); @@ -383,7 +378,7 @@ void solveSP::fun_eval(doublereal* resid, const doublereal* CSoln, for (size_t isp = 0; isp < m_numSurfPhases; isp++) { size_t nsp = m_nSpeciesSurfPhase[isp]; InterfaceKinetics* kinPtr = m_objects[isp]; - size_t surfIndex = kinPtr->surfacePhaseIndex(); + size_t surfIndex = kinPtr->reactionPhaseIndex(); size_t kstart = kinPtr->kineticsSpeciesIndex(0, surfIndex); size_t kins = kindexSP; kinPtr->getNetProductionRates(m_netProductionRatesSave.data()); @@ -608,7 +603,7 @@ doublereal solveSP::calc_t(doublereal netProdRateSolnSP[], // Calculate the start of the species index for surfaces within // the InterfaceKinetics object - size_t surfIndex = kin->surfacePhaseIndex(); + size_t surfIndex = kin->reactionPhaseIndex(); size_t kstart = kin->kineticsSpeciesIndex(0, surfIndex); kin->getNetProductionRates(m_numEqn1.data()); double sden = kin->thermo(surfIndex).molarDensity(); diff --git a/src/oneD/Boundary1D.cpp b/src/oneD/Boundary1D.cpp index 8baa51855..9093604d2 100644 --- a/src/oneD/Boundary1D.cpp +++ b/src/oneD/Boundary1D.cpp @@ -616,7 +616,7 @@ ReactingSurf1D::ReactingSurf1D(shared_ptr solution, const std::string& m_kin = kin.get(); m_sphase = phase.get(); - m_surfindex = m_kin->surfacePhaseIndex(); + m_surfindex = m_kin->reactionPhaseIndex(); m_nsp = m_sphase->nSpecies(); m_enabled = true; } @@ -624,7 +624,7 @@ ReactingSurf1D::ReactingSurf1D(shared_ptr solution, const std::string& void ReactingSurf1D::setKineticsMgr(InterfaceKinetics* kin) { m_kin = kin; - m_surfindex = kin->surfacePhaseIndex(); + m_surfindex = kin->reactionPhaseIndex(); m_sphase = (SurfPhase*)&kin->thermo(m_surfindex); m_nsp = m_sphase->nSpecies(); m_enabled = true; diff --git a/src/zeroD/MoleReactor.cpp b/src/zeroD/MoleReactor.cpp index 1bfe6ac3b..69157732a 100644 --- a/src/zeroD/MoleReactor.cpp +++ b/src/zeroD/MoleReactor.cpp @@ -69,7 +69,7 @@ void MoleReactor::evalSurfaces(double* LHS, double* RHS, double* sdot) size_t nk = surf->nSpecies(); S->syncState(); kin->getNetProductionRates(&m_work[0]); - size_t ns = kin->surfacePhaseIndex(); + size_t ns = kin->reactionPhaseIndex(); size_t surfloc = kin->kineticsSpeciesIndex(0,ns); for (size_t k = 0; k < nk; k++) { RHS[loc + k] = m_work[surfloc + k] * wallarea / surf->size(k); diff --git a/src/zeroD/Reactor.cpp b/src/zeroD/Reactor.cpp index 5c45a00bc..92a9591fe 100644 --- a/src/zeroD/Reactor.cpp +++ b/src/zeroD/Reactor.cpp @@ -293,7 +293,7 @@ void Reactor::evalSurfaces(double* LHS, double* RHS, double* sdot) double sum = 0.0; S->syncState(); kin->getNetProductionRates(&m_work[0]); - size_t ns = kin->surfacePhaseIndex(); + size_t ns = kin->reactionPhaseIndex(); size_t surfloc = kin->kineticsSpeciesIndex(0,ns); for (size_t k = 1; k < nk; k++) { LHS[loc] = 1.0; diff --git a/src/zeroD/ReactorSurface.cpp b/src/zeroD/ReactorSurface.cpp index 9311f8650..e8f2b56f0 100644 --- a/src/zeroD/ReactorSurface.cpp +++ b/src/zeroD/ReactorSurface.cpp @@ -36,13 +36,12 @@ void ReactorSurface::setKinetics(Kinetics* kin) { return; } - size_t i = kin->surfacePhaseIndex(); - if (i == npos) { + m_thermo = dynamic_cast(&kin->thermo(kin->reactionPhaseIndex())); + if (m_thermo == nullptr) { throw CanteraError("ReactorSurface::setKinetics", - "Specified surface kinetics manager does not represent a surface " + "Specified kinetics manager does not represent a surface " "kinetics mechanism."); } - m_thermo = dynamic_cast(&kin->thermo(i)); m_cov.resize(m_thermo->nSpecies()); m_thermo->getCoverages(m_cov.data()); }