Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namedtuples for dielectric #540

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions plasmapy/physics/dielectric.py
Expand Up @@ -5,8 +5,8 @@
from plasmapy import utils
from plasmapy.physics import parameters
from plasmapy.constants import (pi, m_e, c, mu0, e, eps0)
import scipy.special as spec
from plasmapy.mathematics import plasma_dispersion_func_deriv
from collections import namedtuple

r"""
Values should be returned as a `~astropy.units.Quantity` in SI units.
Expand All @@ -16,6 +16,8 @@
'cold_plasma_permittivity_LRP',
'permittivity_1D_Maxwellian']

StixTensorElements = namedtuple("StixTensorElements", ["sum", "difference", "plasma"], )
RotatingTensorElements = namedtuple("RotatingTensorElements", ["left", "right", "plasma"], )

@utils.check_quantity(
B={'units': u.T, 'can_be_negative': False},
Expand Down Expand Up @@ -111,7 +113,7 @@ def cold_plasma_permittivity_SDP(B, species, n, omega):
S += - omega_p ** 2 / (omega ** 2 - omega_c ** 2)
D += omega_c / omega * omega_p ** 2 / (omega ** 2 - omega_c ** 2)
P += - omega_p ** 2 / omega ** 2
return S, D, P
return StixTensorElements(S, D, P)


@utils.check_quantity(
Expand Down Expand Up @@ -204,7 +206,7 @@ def cold_plasma_permittivity_LRP(B: u.T, species, n, omega: u.rad / u.s):
L += - omega_p ** 2 / (omega * (omega - omega_c))
R += - omega_p ** 2 / (omega * (omega + omega_c))
P += - omega_p ** 2 / omega ** 2
return L, R, P
return RotatingTensorElements(L, R, P)


@u.quantity_input(omega=u.rad / u.s,
Expand Down
25 changes: 23 additions & 2 deletions plasmapy/physics/tests/test_dielectric.py
Expand Up @@ -6,7 +6,9 @@

from ..dielectric import (cold_plasma_permittivity_LRP,
cold_plasma_permittivity_SDP,
permittivity_1D_Maxwellian)
permittivity_1D_Maxwellian,
RotatingTensorElements,
StixTensorElements)

from ..parameters import (plasma_frequency,
gyrofrequency,
Expand Down Expand Up @@ -46,12 +48,23 @@ def test_proton_electron_plasma(self):
P_analytical = 1 - (omega_pe ** 2 + omega_pp ** 2) / omega ** 2

species = ['e', 'p']
S, D, P = cold_plasma_permittivity_SDP(B, species, n, omega)
S, D, P = tuple_result = cold_plasma_permittivity_SDP(B, species, n, omega)
namurphy marked this conversation as resolved.
Show resolved Hide resolved

assert tuple_result.sum is S
assert tuple_result.difference is D
assert tuple_result.plasma is P
assert isinstance(tuple_result, StixTensorElements)

assert np.isclose(S, S_analytical)
assert np.isclose(D, D_analytical)
assert np.isclose(P, P_analytical)

L, R, P = rotating_tuple_result = cold_plasma_permittivity_LRP(B, species, n, omega)
assert rotating_tuple_result.left is L
assert rotating_tuple_result.right is R
assert rotating_tuple_result.plasma is P
assert isinstance(rotating_tuple_result, RotatingTensorElements)

def test_three_species(self):
"""
Test with three species (2 ions): D plasma with 5%H minority fraction
Expand Down Expand Up @@ -79,6 +92,14 @@ def test_SD_to_LR_relationships(self):
assert np.isclose(S, (R + L) / 2)
assert np.isclose(D, (R - L) / 2)

def test_numpy_array_workflow(self):
"""as per @jhillairet at https://github.com/PlasmaPy/PlasmaPy/issues/539#issuecomment-425337810 """
ns = np.logspace(17, 19, 50)/u.m**3
B0 = 4*u.T
omega_RF = 2*np.pi*50e6*(u.rad/u.s)

S, D, P = cold_plasma_permittivity_SDP(B=B0, species=['e', 'D+'], n=[ns, ns], omega=omega_RF)
assert S.shape == D.shape == P.shape == (50,)

class Test_permittivity_1D_Maxwellian:
@classmethod
Expand Down