Skip to content

Commit

Permalink
modified syntax for consistency with other code, added comment for in…
Browse files Browse the repository at this point in the history
…terface_current
  • Loading branch information
Corey Randall authored and ischoegl committed Oct 10, 2022
1 parent 9fa8d30 commit ba5d5f8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
11 changes: 10 additions & 1 deletion include/cantera/kinetics/InterfaceKinetics.h
Expand Up @@ -287,7 +287,16 @@ class InterfaceKinetics : public Kinetics
*/
int phaseStability(const size_t iphase) const;

double InterfaceCurrent(int iPhase);
//! Gets the interface current for the ith phaseExistence
/*!
* @param iphase Phase Id
* @return The double specifying the interface current. The interface Current
* is useful when charge transfer reactions occur at an interface. It
* is defined here as the net positive charge entering the phase
* specified by the Phase Id. (Units: A/m^2 for a surface reaction,
* A/m for an edge reaction).
*/
double InterfaceCurrent(const size_t iphase);

protected:
//! Temporary work vector of length m_kk
Expand Down
2 changes: 1 addition & 1 deletion interfaces/cython/cantera/kinetics.pxd
Expand Up @@ -69,7 +69,7 @@ cdef extern from "cantera/kinetics/InterfaceKinetics.h":
cdef cppclass CxxInterfaceKinetics "Cantera::InterfaceKinetics":
void advanceCoverages(double, double, double, double, size_t, size_t) except +translate_exception
void solvePseudoSteadyStateProblem() except +translate_exception
double InterfaceCurrent(int) except +translate_exception
double InterfaceCurrent(size_t) except +translate_exception


cdef extern from "cantera/cython/kinetics_utils.h":
Expand Down
4 changes: 2 additions & 2 deletions interfaces/cython/cantera/kinetics.pyx
Expand Up @@ -886,8 +886,8 @@ cdef class InterfaceKinetics(Kinetics):
an interface. It is defined here as the net positive charge entering the
phase ``phase`` (Units: A/m^2 for a surface, A/m for an edge reaction).
"""
iPhase = self.phase_index(phase)
return (<CxxInterfaceKinetics*>self.kinetics).InterfaceCurrent(iPhase)
i_phase = self.phase_index(phase)
return (<CxxInterfaceKinetics*>self.kinetics).InterfaceCurrent(i_phase)

def write_yaml(self, filename, phases=None, units=None, precision=None,
skip_user_defined=None):
Expand Down
26 changes: 13 additions & 13 deletions src/kinetics/InterfaceKinetics.cpp
Expand Up @@ -595,30 +595,30 @@ void InterfaceKinetics::setPhaseStability(const size_t iphase, const int isStabl
}
}

double InterfaceKinetics::InterfaceCurrent(int iPhase)
double InterfaceKinetics::InterfaceCurrent(const size_t iphase)
{
int sp = thermo(iPhase).nSpecies();
double charge_k[sp];
double net_k[sp];
doublereal netprods[m_kk];
int nSp = thermo(iphase).nSpecies();
double charge_k[nSp];
double sdot_k[nSp];
doublereal netProdRates[m_kk];

thermo(iPhase).getCharges(charge_k);
thermo(iphase).getCharges(charge_k);

getNetProductionRates(netprods);
getNetProductionRates(netProdRates);

for(int k=0; k<sp; k++)
for(int k=0; k<nSp; k++)
{
net_k[k] = netprods[m_start[iPhase]+k];
sdot_k[k] = netProdRates[m_start[iphase]+k];
}

double out = 0.0;
double dotProduct = 0.0;

for(int k=0; k<sp; k++)
for(int k=0; k<nSp; k++)
{
out += charge_k[k]*net_k[k];
dotProduct += charge_k[k]*sdot_k[k];
}

return out*Faraday;
return dotProduct*Faraday;
}

}
4 changes: 2 additions & 2 deletions test/python/test_kinetics.py
Expand Up @@ -1083,11 +1083,11 @@ def test_interface_current(self):
phases = [anode_int, anode, elect, elyte]

for p in phases:
productions = anode_int.get_net_production_rates(p)
net_prod_rates = anode_int.get_net_production_rates(p)
charges = p.charges

method = anode_int.interface_current(p)
manual = sum(productions*charges)*ct.faraday
manual = sum(net_prod_rates*charges)*ct.faraday

self.assertEqual(method,manual)

Expand Down

0 comments on commit ba5d5f8

Please sign in to comment.