Skip to content

Commit

Permalink
Decorate two_fluid dispersion solver with @particle_input (#2022)
Browse files Browse the repository at this point in the history
* Decorate two_fluid with @particle_input

* Add initial changelog entry

* Add changelog entry

* Drop usage of Z in function

The charge number is now contained in `ion`.

* Make minor edits to two_fluid

* Update changelog entries

* Allow some parameters to be positional

The ones from that are positional are all distinguishable by
unit or particle-like-ness, so having allowing it to be
positional is not likely to cause any problems.

* Update docstrings

* Unicode!

* Update changelog entries

* Update docstrings and rename variables

* Remove test
  • Loading branch information
namurphy committed May 31, 2023
1 parent 3fe34d8 commit fca4155
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 138 deletions.
4 changes: 4 additions & 0 deletions changelog/2022.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
In `~plasmapy.dispersion.analytical.two_fluid_.two_fluid` in
`plasmapy.dispersion`, providing the |charge number| as a keyword
argument (formerly ``z_mean``) will no longer override the charge number
provided in ``ion``.
3 changes: 3 additions & 0 deletions changelog/2022.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The function `~plasmapy.dispersion.analytical.two_fluid_.two_fluid`
has been decorated with |particle_input| and now may accept an
argument for the mass number corresponding to the ion.
3 changes: 3 additions & 0 deletions changelog/2022.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
In `plasmapy.dispersion`, the ``z_mean`` parameter
to `~plasmapy.dispersion.analytical.two_fluid_.two_fluid` has been
deprecated. Provide the |charge number| to ``Z`` instead.
35 changes: 4 additions & 31 deletions plasmapy/dispersion/analytical/tests/test_two_fluid_.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from plasmapy.formulary.frequencies import wc_
from plasmapy.formulary.speeds import cs_, va_
from plasmapy.particles import Particle
from plasmapy.particles.exceptions import InvalidIonError
from plasmapy.utils.exceptions import PhysicsWarning


Expand Down Expand Up @@ -39,8 +40,8 @@ class TestTwoFluid:
({**_kwargs_single_valued, "B": -1 * u.T}, ValueError),
({**_kwargs_single_valued, "B": 5 * u.m}, u.UnitTypeError),
({**_kwargs_single_valued, "ion": {"not": "a particle"}}, TypeError),
({**_kwargs_single_valued, "ion": "e-"}, ValueError),
({**_kwargs_single_valued, "ion": "He", "z_mean": "wrong type"}, TypeError),
({**_kwargs_single_valued, "ion": "e-"}, InvalidIonError),
({**_kwargs_single_valued, "ion": "He", "Z": "wrong type"}, TypeError),
({**_kwargs_single_valued, "k": np.ones((3, 2)) * u.rad / u.m}, ValueError),
({**_kwargs_single_valued, "k": 0 * u.rad / u.m}, ValueError),
({**_kwargs_single_valued, "k": -1.0 * u.rad / u.m}, ValueError),
Expand Down Expand Up @@ -71,7 +72,7 @@ def test_raises(self, kwargs, _error):
@pytest.mark.parametrize(
("kwargs", "_warning"),
[
# violates the low-frequency assumption (w/kc << 1)
# violates the low-frequency assumption (ω/kc << 1)
(
{
"B": 8.3e-7 * u.T,
Expand Down Expand Up @@ -139,34 +140,6 @@ def test_on_bellan2012_vals(self, kwargs, expected):
norm = (np.absolute(val) / (kwargs["k"] * va)).value ** 2
assert np.isclose(norm, expected[mode])

@pytest.mark.parametrize(
("kwargs", "expected"),
[
(
{
**_kwargs_bellan2012,
"ion": Particle("He"),
"z_mean": 2.0,
"theta": 0 * u.deg,
},
{**_kwargs_bellan2012, "ion": Particle("He +2"), "theta": 0 * u.deg},
),
#
# z_mean defaults to 1
(
{**_kwargs_bellan2012, "ion": Particle("He"), "theta": 0 * u.deg},
{**_kwargs_bellan2012, "ion": Particle("He+"), "theta": 0 * u.deg},
),
],
)
def test_z_mean_override(self, kwargs, expected):
"""Test overriding behavior of kw 'z_mean'."""
ws = two_fluid(**kwargs)
ws_expected = two_fluid(**expected)

for mode in ws:
assert np.isclose(ws[mode], ws_expected[mode], atol=0, rtol=1.7e-4)

@pytest.mark.parametrize(
("kwargs", "expected"),
[
Expand Down

0 comments on commit fca4155

Please sign in to comment.