InterfaceKinetics rewite: added rmcVector and identifyMetalPhases routine.

added utility to clean tests. tests don't rerun when they should!
This commit is contained in:
Harry Moffat 2014-08-21 21:40:26 +00:00
parent 69c09709d1
commit e6863bfdae
5 changed files with 124 additions and 9 deletions

9
bin/clean_tests Executable file
View file

@ -0,0 +1,9 @@
#!/bin/sh
#
#
/bin/rm -rf build/test
#
#
scons test-clean
#
#

View file

@ -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<thermo_t*> & 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();

View file

@ -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<RxnMolChange*> rmcVector;
/*!
* Vector of strings of length m_ii, the number of
* reactions, containing the string expressions for each reaction

View file

@ -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<thermo_t*> &
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;
}
}
}
}
}
}
//==================================================================================================================
}

View file

@ -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<thermo_t*> &
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;
}