From e6863bfdae647c77970a8a247d634f46d615fa14 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Thu, 21 Aug 2014 21:40:26 +0000 Subject: [PATCH] InterfaceKinetics rewite: added rmcVector and identifyMetalPhases routine. added utility to clean tests. tests don't rerun when they should! --- bin/clean_tests | 9 ++++ include/cantera/kinetics/ElectrodeKinetics.h | 13 +++++ include/cantera/kinetics/InterfaceKinetics.h | 24 +++++++-- src/kinetics/ElectrodeKinetics.cpp | 56 ++++++++++++++++++-- src/kinetics/InterfaceKinetics.cpp | 31 ++++++++++- 5 files changed, 124 insertions(+), 9 deletions(-) create mode 100755 bin/clean_tests diff --git a/bin/clean_tests b/bin/clean_tests new file mode 100755 index 000000000..b3b72194d --- /dev/null +++ b/bin/clean_tests @@ -0,0 +1,9 @@ +#!/bin/sh +# +# +/bin/rm -rf build/test +# +# +scons test-clean +# +# diff --git a/include/cantera/kinetics/ElectrodeKinetics.h b/include/cantera/kinetics/ElectrodeKinetics.h index f49530d0d..8052a036b 100644 --- a/include/cantera/kinetics/ElectrodeKinetics.h +++ b/include/cantera/kinetics/ElectrodeKinetics.h @@ -51,10 +51,23 @@ public: //! Assignment operator ElectrodeKinetics& operator=(const ElectrodeKinetics& right); + //! Duplication function + /*! + * @param tpVector Vector of %ThermoPhase pointers. These are shallow pointers to the + * %ThermoPhase objects that will comprise the phases for the new object. + * + * @return Returns the duplicated object as the base class %Kinetics object. + */ virtual Kinetics* duplMyselfAsKinetics(const std::vector & tpVector) const; virtual int type() const; + //! Identify the metal phase and the electrons species + /*! + * We fill in the internal variables, metalPhaseRS_ and kElectronRS_ here + */ + void identifyMetalPhase(); + diff --git a/include/cantera/kinetics/InterfaceKinetics.h b/include/cantera/kinetics/InterfaceKinetics.h index 3a7c66f5b..9a77b780d 100644 --- a/include/cantera/kinetics/InterfaceKinetics.h +++ b/include/cantera/kinetics/InterfaceKinetics.h @@ -10,6 +10,7 @@ #include "cantera/thermo/mix_defs.h" #include "Kinetics.h" +#include "cantera/kinetics/RxnMolChange.h" #include "cantera/base/utilities.h" #include "RateCoeffMgr.h" @@ -21,6 +22,7 @@ namespace Cantera // forward references class SurfPhase; class ImplicitSurfChem; +class RxnMolChange; //! A kinetics manager for heterogeneous reaction mechanisms. The //! reactions are assumed to occur at a 2D interface between two 3D phases. @@ -145,9 +147,17 @@ public: return m_prxn[k][i]; } - virtual int reactionType(size_t i) const { - return m_index[i].first; - } + //! return the reaction type of the reaction i + /*! + * @param[in] Reaction index + * + * @return Returns the reaction type of the reaction. + */ + virtual int reactionType(size_t i) const; + //virtual int reactionType(size_t i) const { + // return m_index[i].first; + //} + virtual void getActivityConcentrations(doublereal* const conc); @@ -484,7 +494,13 @@ protected: */ vector_int reactionType_; - //! String expression for each rxn + //! Vector of additional information about each reaction + /*! + * This vector contains information about the phase mole change for each reaction, + * for example. + */ + std::vector rmcVector; + /*! * Vector of strings of length m_ii, the number of * reactions, containing the string expressions for each reaction diff --git a/src/kinetics/ElectrodeKinetics.cpp b/src/kinetics/ElectrodeKinetics.cpp index 37242ba40..4cca1fa77 100644 --- a/src/kinetics/ElectrodeKinetics.cpp +++ b/src/kinetics/ElectrodeKinetics.cpp @@ -4,7 +4,6 @@ #include "cantera/kinetics/ElectrodeKinetics.h" - using namespace std; namespace Cantera @@ -32,7 +31,7 @@ ElectrodeKinetics::ElectrodeKinetics(const ElectrodeKinetics& right) : /* * Call the assignment operator */ - operator=(right); + ElectrodeKinetics::operator=(right); } //============================================================================================================================ ElectrodeKinetics& ElectrodeKinetics::operator=(const ElectrodeKinetics& right) @@ -66,9 +65,58 @@ Kinetics* ElectrodeKinetics::duplMyselfAsKinetics(const std::vector & return iK; } //============================================================================================================================ +//==================================================================================================================== +// Identify the metal phase and the electrons species +void ElectrodeKinetics::identifyMetalPhase() +{ + metalPhaseRS_ = npos; + kElectronRS_ = -1; + size_t np = nPhases(); + // + // Identify the metal phase as the phase with the electron species (element index of 1 for element E + // Should probably also stipulate a charge of -1. + // + for (size_t iph = 0; iph < np; iph++) { + ThermoPhase* tp = m_thermo[iph]; + size_t nSpecies = tp->nSpecies(); + size_t nElements = tp->nElements(); + size_t eElectron = tp->elementIndex("E"); + if (eElectron != npos) { + for (size_t k = 0; k < nSpecies; k++) { + if (tp->nAtoms(k,eElectron) == 1) { + int ifound = 1; + for (size_t e = 0; e < nElements; e++) { + if (tp->nAtoms(k,e) != 0.0) { + if (e != eElectron) { + ifound = 0; + } + } + } + if (ifound == 1) { + metalPhaseRS_ = iph; + kElectronRS_ = m_start[iph] + k; + } + } + } + } + // + // Identify the solution phase as a 3D phase, with nonzero phase charge change + // in at least one reaction + // + if (iph != metalPhaseRS_) { + for (size_t i = 0; i < m_ii; i++) { + RxnMolChange* rmc = rmcVector[i]; + if (rmc->m_phaseChargeChange[iph] != 0) { + if (rmc->m_phaseDims[iph] == 3) { + solnPhaseRS_ = iph; + break; + } + } + } + } - - + } +} //================================================================================================================== } diff --git a/src/kinetics/InterfaceKinetics.cpp b/src/kinetics/InterfaceKinetics.cpp index 44e86f2f7..e25bcf24e 100644 --- a/src/kinetics/InterfaceKinetics.cpp +++ b/src/kinetics/InterfaceKinetics.cpp @@ -57,6 +57,11 @@ InterfaceKinetics::InterfaceKinetics(thermo_t* thermo) : InterfaceKinetics::~InterfaceKinetics() { delete m_integrator; + + for (size_t i = 0; i < rmcVector.size(); i++) { + delete rmcVector[i]; + } + } //============================================================================================================================ InterfaceKinetics::InterfaceKinetics(const InterfaceKinetics& right) : @@ -160,6 +165,17 @@ InterfaceKinetics& InterfaceKinetics::operator=(const InterfaceKinetics& right) m_rxnPhaseIsProduct = right.m_rxnPhaseIsProduct; m_ioFlag = right.m_ioFlag; + for (size_t i = 0; i < rmcVector.size(); i++) { + delete rmcVector[i]; + } + rmcVector.resize(m_ii, 0); + for (size_t i = 0; i < m_ii; i++) { + if (right.rmcVector[i]) { + rmcVector[i] = new RxnMolChange(*(right.rmcVector[i])); + } + } + + return *this; } //============================================================================================================================ @@ -174,7 +190,7 @@ Kinetics* InterfaceKinetics::duplMyselfAsKinetics(const std::vector & iK->assignShallowPointers(tpVector); return iK; } - +//============================================================================================================================ void InterfaceKinetics::setElectricPotential(int n, doublereal V) { thermo(n).setElectricPotential(V); @@ -1287,6 +1303,11 @@ int InterfaceKinetics::phaseStability(const size_t iphase) const return m_phaseIsStable[iphase]; } //================================================================================================================== +int InterfaceKinetics::reactionType(size_t i) const +{ + return reactionType_[i]; +} +//================================================================================================================== void InterfaceKinetics::setPhaseStability(const size_t iphase, const int isStable) { if (iphase >= m_thermo.size()) { @@ -1335,6 +1356,14 @@ void EdgeKinetics::finalize() m_rkcn.resize(1, 0.0); } + // + // Malloc and calculate all of the quantities that go into the extra description of reactions + // + rmcVector.resize(m_ii, 0); + for (size_t i = 0; i < m_ii; i++) { + rmcVector[i] = new RxnMolChange(this, i); + } + m_finalized = true; }