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

Add 1D Harris Sheet #2068

Merged
merged 65 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
d010902
Add equilibria 1d
mohawk811 Apr 10, 2023
0019934
add imports
mohawk811 Apr 10, 2023
d82ab27
Add API static file
mohawk811 Apr 10, 2023
826e2a0
Add example
mohawk811 Apr 10, 2023
60ac7ad
Test function
mohawk811 Apr 12, 2023
62624f9
Add equilibria test cases
mohawk811 Jun 1, 2023
35daffa
Add equilibria test cases
mohawk811 Jun 1, 2023
cef4e19
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jun 1, 2023
7fe2550
Apply suggestions from code review
mohawk811 Jun 1, 2023
e0199e4
Change log
mohawk811 Jun 9, 2023
aa7f7ee
Merge branch 'main' of github.com:PlasmaPy/PlasmaPy into Harris-Sheet
mohawk811 Jun 9, 2023
cb6b040
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jun 9, 2023
e67f9c0
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jun 15, 2023
d09a123
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jun 15, 2023
62a79fa
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jun 15, 2023
620cf4b
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jun 15, 2023
52067df
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jun 15, 2023
81c7e6e
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jun 15, 2023
20e91a7
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jun 15, 2023
f4eca98
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jun 15, 2023
a76a39a
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jun 23, 2023
bcef124
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jun 23, 2023
ca1830c
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jun 23, 2023
640fbea
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jun 23, 2023
adfe2b8
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jun 23, 2023
a731bf2
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jun 23, 2023
d38cb98
Apply suggestions from code review
mohawk811 Jun 30, 2023
39cb13e
Update equilibria1d.py
mohawk811 Jun 30, 2023
d2f9dec
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jul 3, 2023
828fd24
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jul 3, 2023
9768197
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 3, 2023
264c5a6
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jul 3, 2023
df72522
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jul 3, 2023
cbde8fe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 3, 2023
ca2d44e
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 26, 2023
7be54de
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 26, 2023
93b2ec5
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 26, 2023
7a84f47
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 26, 2023
5d20c9c
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 26, 2023
e805881
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jul 26, 2023
ffa1d2c
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 26, 2023
bb1f2db
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 26, 2023
290cb68
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 26, 2023
9f8218c
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 26, 2023
deba1f1
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 26, 2023
5ae8596
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 26, 2023
792e0e4
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jul 26, 2023
5d65b1f
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jul 26, 2023
981c7f3
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jul 26, 2023
298218a
Update plasmapy/plasma/tests/test_equilibria1d.py
mohawk811 Jul 26, 2023
edea208
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 26, 2023
db743ae
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 26, 2023
76ab400
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 26, 2023
4262c92
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 27, 2023
6e287ed
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 27, 2023
8e08d1e
Update plasmapy/plasma/equilibria1d.py
mohawk811 Jul 27, 2023
8a91579
Update plasmapy/plasma/equilibria1d.py
mohawk811 Aug 16, 2023
f0bebb4
Update plasmapy/plasma/equilibria1d.py
mohawk811 Aug 16, 2023
4e52a6e
Update plasmapy/plasma/equilibria1d.py
mohawk811 Aug 16, 2023
51a5ab0
Update plasmapy/plasma/equilibria1d.py
mohawk811 Aug 16, 2023
ec2b134
Update plasmapy/plasma/equilibria1d.py
mohawk811 Aug 16, 2023
882252d
Update plasmapy/plasma/equilibria1d.py
mohawk811 Aug 16, 2023
89d7804
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 17, 2023
f79a3f0
Merge branch 'main' of github.com:PlasmaPy/PlasmaPy into Harris-Sheet
namurphy Aug 17, 2023
94a919d
Minor formatting updates
namurphy Aug 17, 2023
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
1 change: 1 addition & 0 deletions changelog/2068.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added the `~plasmapy.plasma.equilibria1d.HarrisSheet` class to calculate magnetic field, current density, and plasma pressure for 1D Harris Sheets.
8 changes: 8 additions & 0 deletions docs/api_static/plasmapy.plasma.equilibria1d.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:orphan:

`plasmapy.plasma.equilibria1d`
==============================

.. currentmodule:: plasmapy.plasma.equilibria1d

.. automodapi:: plasmapy.plasma.equilibria1d
1 change: 1 addition & 0 deletions plasmapy/plasma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"""

from plasmapy.plasma import exceptions, grids, sources
from plasmapy.plasma.equilibria1d import HarrisSheet
from plasmapy.plasma.plasma_base import BasePlasma, GenericPlasma
from plasmapy.plasma.plasma_factory import Plasma
113 changes: 113 additions & 0 deletions plasmapy/plasma/equilibria1d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
"""Functionality for representing one-dimensional equilibria."""

__all__ = ["HarrisSheet"]
namurphy marked this conversation as resolved.
Show resolved Hide resolved
mohawk811 marked this conversation as resolved.
Show resolved Hide resolved

import astropy.constants as const
import astropy.units as u
import numpy as np

mohawk811 marked this conversation as resolved.
Show resolved Hide resolved
from plasmapy.utils.decorators.validators import validate_quantities


class HarrisSheet:
r"""
Define a Harris Sheet Equilibrium.
mohawk811 marked this conversation as resolved.
Show resolved Hide resolved

mohawk811 marked this conversation as resolved.
Show resolved Hide resolved
mohawk811 marked this conversation as resolved.
Show resolved Hide resolved
mohawk811 marked this conversation as resolved.
Show resolved Hide resolved
Magnetic field will be in the :math:`±x` direction and the current
density will be in the :math:`±z` direction in a :math:`\hat{x} ×
\hat{y} = \hat{z}` coordinate system.

Parameters
----------
B0 : `~astropy.units.Quantity`
Magnitude of magnetic field in the limit of :math:`y → ∞` in
units convertible to teslas.

delta : `~astropy.units.Quantity`
The thickness of the current sheet in units convertible to
meters.

P0 : `~astropy.units.Quantity`
The plasma pressure in the limit of :math:`y → ∞` in units
convertible to pascals.

Notes
-----
A current sheet is current limited to a surface.
mohawk811 marked this conversation as resolved.
Show resolved Hide resolved

A Harris sheet is a 1D ideal MHD equilibrium. In resistive MHD if
there is any resistivity, it won't be a true equilibrium since the
resistivity will gradually smooth the profile out over time.

A Harris sheet is often used as the initial condition for
simulations of magnetic reconnection.

Examples
--------
>>> import astropy.units as u
>>> harris_sheet = HarrisSheet(delta = 3 * u.m, B0 = 2 * u.T)
>>> harris_sheet.magnetic_field(y = 5 * u.m)
<Quantity 1.8622... T>
"""

def __init__(self, B0, delta, P0=0 * u.Pa):
self.B0 = B0
self.delta = delta
self.P0 = P0

@validate_quantities
def magnetic_field(self, y: u.m) -> u.T:
r"""
Compute the magnetic field.

In this equation, :math:`B_0` is the asymptotic magnitude of the
magnetic field for :math:`y → ±∞` and :math:`δ` is the thickness
of the sheet.

.. math::

B_x(y) = B_0 \tanh \left( \frac{y}{δ} \right)

Parameters
----------
y : `~astropy.units.Quantity`
Orthogonal distance from the current sheet center.
"""
return self.B0 * np.tanh(u.rad * y / self.delta)

@validate_quantities
def current_density(self, y: u.m) -> u.A / u.m**2:
r"""
Compute the current density.

.. math::

J_z(y) = - \frac{B_0}{δ μ_0) \mathrm{sech}^2 \left( \frac{y}{δ} \right)

Parameters
----------
y : `~astropy.units.Quantity`
Orthogonal distance from the current sheet center.
"""
return (
-self.B0 / (self.delta * const.mu0) * np.cosh(u.rad * y / self.delta) ** -2
)

@validate_quantities
def plasma_pressure(self, y: u.m) -> u.Pa:
r"""
Compute plasma pressure.

.. math::

p(y) = \frac{B_0^2}{2 μ_0} \mathrm{sech}^2 \left( \frac{y}{δ} \right) + p_0

Parameters
----------
y : `~astropy.units.Quantity`
Orthogonal distance from the current sheet center.
"""
return (
self.B0**2 / (2 * const.mu0) * (np.cosh(u.rad * y / self.delta) ** -2)
+ self.P0
)
65 changes: 65 additions & 0 deletions plasmapy/plasma/tests/test_equilibria1d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import astropy.units as u
import numpy as np

from plasmapy.formulary import magnetic_pressure
from plasmapy.plasma.equilibria1d import HarrisSheet


def test_HarrisSheet():
B0 = 1 * u.T
delta = 1 * u.m
P0 = 0 * u.Pa
hs = HarrisSheet(B0, delta, P0)
B = hs.magnetic_field(0 * u.m)
assert u.isclose(
B, 0 * u.T, atol=1e-9 * u.T
), "Magnetic field is supposed to be zero at y=0"


def test_HarrisSheet_pressure_balance():
B0 = 1 * u.T
delta = 1 * u.m
P0 = 0 * u.Pa
hs = HarrisSheet(B0, delta, P0)
y = [-7, -3, 0, 2, 47] * u.m
B = hs.magnetic_field(y)
P = hs.plasma_pressure(y)
p_b = magnetic_pressure(B)
total_pressure = P + p_b
assert u.allclose(total_pressure, total_pressure[0], atol=1e-9 * u.Pa)


def test_HarrisSheet_current_density():
B0 = 1 * u.T
delta = 1 * u.m
P0 = 0 * u.Pa
hs = HarrisSheet(B0, delta, P0)
y = [-2, 0, 2] * u.m
J = hs.current_density(y)
correct_J = [-56222.1400445, -795774.715459, -56222.1400445] * u.A / u.m**2
assert u.allclose(J, correct_J, atol=1e-8 * u.A / u.m**2)


def test_HarrisSheet_magnetic_field():
B0 = 1 * u.T
delta = 1 * u.m
P0 = 0 * u.Pa
hs = HarrisSheet(B0, delta, P0)
y = [-2, 0, 2] * u.m
B = hs.magnetic_field(y)
correct_B = [-0.96402758007, 0, 0.96402758007] * u.T
assert u.allclose(B, correct_B, atol=1e-9 * u.T)


def test_HarrisSheet_limits():
y = [-np.inf, np.inf] * u.m
B0 = 1 * u.T
delta = 1 * u.m
P0 = 0 * u.Pa
hs = HarrisSheet(B0, delta, P0)
B = hs.magnetic_field(y)
P = hs.plasma_pressure(y)
J = hs.current_density(y)
assert u.allclose(B, [-B0, B0], atol=1e-9 * u.T)
assert u.allclose(P, [P0, P0], atol=1e-9 * u.Pa)
assert u.allclose(J, [0, 0] * u.amp / u.m**2, atol=1e-9 * u.amp / u.m**2)