Skip to content

Commit

Permalink
interface_current method and accompanying test added
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey Randall authored and ischoegl committed Oct 10, 2022
1 parent 332bb9b commit 84a643c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions interfaces/cython/cantera/kinetics.pyx
Expand Up @@ -6,6 +6,7 @@ import warnings
cimport numpy as np
import numpy as np

from .constants import *
from .reaction cimport *
from ._utils cimport *
from . import _utils
Expand Down Expand Up @@ -880,6 +881,14 @@ cdef class InterfaceKinetics(Kinetics):
"""
return self.net_production_rates[self._phase_slice(phase)]

def interface_current(self, phase):
"""
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 ``phase`` (Units: A/m^2).
"""
return sum(self.get_net_production_rates(phase)*phase.charges)*faraday

def write_yaml(self, filename, phases=None, units=None, precision=None,
skip_user_defined=None):
"""
Expand Down
23 changes: 23 additions & 0 deletions test/python/test_kinetics.py
Expand Up @@ -1065,6 +1065,29 @@ def cathode_current(phi_s, phi_l, X_Li_cathode):
ref = np.genfromtxt(self.test_data_path / "lithium-ion-battery-test.csv")
assert np.allclose(data, ref, rtol=1e-7)

def test_interface_current(self):
file = "lithium_ion_battery.yaml"

# The 'elde' electrode phase is needed as a source/sink for electrons:
anode = ct.Solution(file,"anode")
elect = ct.Solution(file,"electron")
elyte = ct.Solution(file,"electrolyte")
anode_int = ct.Interface(file,"edge_anode_electrolyte",[anode,elect,elyte])

anode.X = [0.9, 0.1]
elyte.X = [0.4, 0.3, 0.15, 0.15]

anode.electric_potential = 0.
elyte.electric_potential = 3.

species_productions = anode_int.get_net_production_rates(elyte)
species_charges = elyte.charges

method = anode_int.interface_current(elyte)
manual = sum(species_productions*species_charges)*ct.faraday

self.assertEqual(method,manual)


class TestDuplicateReactions(utilities.CanteraTest):
infile = 'duplicate-reactions.yaml'
Expand Down

0 comments on commit 84a643c

Please sign in to comment.