Skip to content

Commit

Permalink
[plasma] add test_set_electron_energy_distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
BangShiuh authored and speth committed Apr 25, 2022
1 parent fdc5f96 commit 61899f7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions interfaces/cython/cantera/_cantera.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ cdef extern from "cantera/thermo/PlasmaPhase.h":
CxxPlasmaPhase()
void setElectronEnergyGrid(vector[double]&) except +translate_exception
void getElectronEnergyGrid(vector[double]&)
void setElectronEnergyDistrb(vector[double]&, vector[double]&) except +translate_exception
void getElectronEnergyDistrb(vector[double]&)

cdef extern from "cantera/kinetics/ReactionRateFactory.h" namespace "Cantera":
cdef shared_ptr[CxxReactionRate] CxxNewReactionRate "newReactionRate" (string) except +translate_exception
Expand Down
23 changes: 23 additions & 0 deletions interfaces/cython/cantera/plasma.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ cdef class PlasmaPhase(ThermoPhase):
raise TypeError('Underlying ThermoPhase object is of the wrong type.')
self.plasma = <CxxPlasmaPhase*>(self.thermo)

def set_electron_energy_distribution(self, grid, distrb):
""" Set electron energy distribution. When this method is used, electron
temeprature is calculated from the distribution.
:param grid:
vector of electron energy grid [eV]
:param distrb:
vector of distribution
"""
cdef vector[double] cxxdata_grid
cdef vector[double] cxxdata_distrb
for value in grid:
cxxdata_grid.push_back(value)
for value in distrb:
cxxdata_distrb.push_back(value)
self.plasma.setElectronEnergyDistrb(cxxdata_grid, cxxdata_distrb)

property electron_energy_grid:
""" Electron energy grid [eV]"""
def __get__(self):
Expand All @@ -22,3 +38,10 @@ cdef class PlasmaPhase(ThermoPhase):
for value in grid:
cxxdata.push_back(value)
self.plasma.setElectronEnergyGrid(cxxdata)

property electron_energy_distribution:
""" Electron energy distribution """
def __get__(self):
cdef vector[double] cxxdata
self.plasma.getElectronEnergyDistrb(cxxdata)
return np.fromiter(cxxdata, np.double)
7 changes: 7 additions & 0 deletions interfaces/cython/cantera/test/test_plasma.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ def test_set_get_electron_energy_grid(self):
grid = np.linspace(0.01, 10, num=9)
self.phase.electron_energy_grid = grid
self.assertArrayNear(grid, self.phase.electron_energy_grid)

def test_set_electron_energy_distribution(self):
grid = np.linspace(0.01, 10, num=9)
distrb = np.linspace(10, 0.01, num=9)
self.phase.set_electron_energy_distribution(grid, distrb)
self.assertArrayNear(grid, self.phase.electron_energy_grid)
self.assertArrayNear(distrb, self.phase.electron_energy_distribution)

0 comments on commit 61899f7

Please sign in to comment.