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

Audit for dimensionless.jl #13

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/Manifest.toml
/docs/Manifest.toml
/docs/build/
.CondaPkg/
3 changes: 3 additions & 0 deletions CondaPkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
astropy = ""
plasmapy = ""
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ authors = ["Zijin Zhang", "Luke Adams <[email protected]>"]
version = "0.1.0"

[deps]
PermuteArgs = "9536dbe3-0ca9-4073-961c-7241c6d3471f"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
UnitfulEquivalences = "da9c4bc3-91c8-4f02-8a40-6b990d2a7e0c"

[compat]
Aqua = "0.8"
LinearAlgebra = "1.10"
PermuteArgs = "1.2.1"
PythonCall = "0.9.23"
Test = "1.10"
Unitful = "1.0"
UnitfulEquivalences = "0.2"
Expand All @@ -18,7 +21,8 @@ julia = "1.10"
[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "LinearAlgebra", "Test"]
test = ["Aqua", "LinearAlgebra", "PythonCall", "Test"]
10 changes: 9 additions & 1 deletion docs/src/api.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# API Reference

## Dimensionless numbers
```@docs
plasma_beta
```

## Otherwise undocumented functions
This section will be removed once the documentation is complete.
```@autodocs
Modules = [PlasmaFormulary]
```
Pages = ["frequencies.jl", "lengths.jl", "misc.jl", "speeds.jl"]
```
3 changes: 2 additions & 1 deletion src/PlasmaFormulary.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module PlasmaFormulary

using Unitful
using UnitfulEquivalences
using Unitful: μ0, ε0, c, q
using Unitful: k, ħ
using Unitful: me, mp, u
using Unitful: Velocity, Mass, BField, Density, Charge
using UnitfulEquivalences
using PermuteArgs

@derived_dimension NumberDensity Unitful.𝐋^-3

Expand Down
15 changes: 13 additions & 2 deletions src/dimensionless.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@ Compute the plamsa beta (β), the ratio of thermal pressure to magnetic pressure
- `T`: The temperature of the plasma.
- `n`: The particle density of the plasma.
- `B`: The magnetic field in the plasma.

# Example
```jldoctest
julia> plasma_beta(1e6u"K", 1e19u"m^-3", 0.2u"T")
0.008674873511172188
```

# References
- [PlasmaPy Documentation](https://docs.plasmapy.org/en/stable/api/plasmapy.formulary.dimensionless.beta.html)
- [Wikipedia](https://en.wikipedia.org/wiki/Plasma_beta)
"""
function plasma_beta(T::EnergyOrTemp, n::NumberDensity, B::Unitful.BField)
function plasma_beta end
@permute_args function plasma_beta(T::EnergyOrTemp, n::NumberDensity, B::Unitful.BField)
p_th = thermal_pressure(T, n)
p_B = magnetic_pressure(B)
return p_th / p_B |> upreferred
end
end
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ using Test
using Aqua
using Unitful
using LinearAlgebra
using PythonCall

units = pyimport("astropy.units")
formulary = pyimport("plasmapy.formulary")

@testset "PlasmaFormulary.jl" begin
@testset "Code quality (Aqua.jl)" begin
Expand All @@ -28,4 +32,13 @@ using LinearAlgebra
@test plasma_frequency(1e19u"m^-3", 1, Unitful.mp / Unitful.u) ≈ 4163294534.0u"s^-1"
@test plasma_frequency(1e19u"m^-3") ≈ 1.783986365e11u"s^-1"
end

@testset "dimensionless.jl" begin
T = 2.0u"eV"
n = 1e19u"m^-3"
B = 0.1u"T"
@test plasma_beta(T, n, B) == plasma_beta(n, B, PlasmaFormulary.temperature(T)) == plasma_beta(n, T, B)

@test pyconvert(Float64, pyfloat(formulary.lengths.Debye_length(10 * units.eV, 1e19 / units.m^3) / units.m)) ≈ ustrip(u"m", PlasmaFormulary.debye_length(1e19 * u"m^-3", 10 * u"eV")) rtol=1e-3
end
end
Loading