-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,73 @@ | ||
# TODO: Sound speed | ||
|
||
function Alfven_velocity(B::BField, ρ::Density) | ||
""" | ||
The typical propagation speed of magnetic disturbances in a quasineutral plasma. | ||
References: [PlasmaPy API Documentation](https://docs.plasmapy.org/en/stable/api/plasmapy.formulary.speeds.Alfven_speed.html) | ||
""" | ||
function alfven_velocity(B::BField, ρ::Density) | ||
return B / sqrt(μ0 * ρ) |> upreferred | ||
end | ||
|
||
function Alfven_velocity(B::BField, n::NumberDensity; mass_numb = 1, Z = 1) | ||
ρ = n * (mass_numb * mp + Z * me) | ||
return Alfven_velocity(B, ρ) | ||
function alfven_velocity(B::BField, n::NumberDensity, mass_number) | ||
ρ = n * mass_number * mp | ||
return alfven_velocity(B, ρ) | ||
end | ||
|
||
Alfven_velocity(B::AbstractVector, args...; kwargs...) = | ||
[Alfven_velocity(Bi, args...; kwargs...) for Bi in B] | ||
# TODO: Add docstrings | ||
abstract type ThermalSpeedMethod end | ||
struct MostProbable <: ThermalSpeedMethod end | ||
struct RMS <: ThermalSpeedMethod end | ||
struct MeanMagnitude <: ThermalSpeedMethod end | ||
struct NRL <: ThermalSpeedMethod end | ||
|
||
""" | ||
Alfven_speed(args...; kwargs...) | ||
thermal_speed_coefficients(method::ThermalSpeedMethod, ndim::Int) | ||
The typical propagation speed of magnetic disturbances in a quasineutral plasma. | ||
Get the thermal speed coefficient corresponding to the desired thermal speed definition. | ||
References: [PlasmaPy API Documentation](https://docs.plasmapy.org/en/stable/api/plasmapy.formulary.speeds.Alfven_speed.html) | ||
# Arguments | ||
- `method::ThermalSpeedMethod`: Method to be used for calculating the thermal speed. Valid values are `MostProbable()`, `RMS()`, `MeanMagnitude()`, and `NRL()`. | ||
- `ndim::Val{Int}`: Dimensionality (1D, 2D, 3D) of space in which to calculate thermal speed. Valid values are `Val(1)`, `Val(2)`, or `Val{3}`. | ||
""" | ||
Alfven_speed(args...; kwargs...) = norm(Alfven_velocity(args...; kwargs...)) | ||
|
||
thermal_speed_coefficients(::MostProbable, ::Val{1}) = 0.0 | ||
thermal_speed_coefficients(::MostProbable, ::Val{2}) = 1.0 | ||
thermal_speed_coefficients(::MostProbable, ::Val{3}) = sqrt(2) | ||
thermal_speed_coefficients(::RMS, ::Val{1}) = 1.0 | ||
thermal_speed_coefficients(::RMS, ::Val{2}) = sqrt(2) | ||
thermal_speed_coefficients(::RMS, ::Val{3}) = sqrt(3) | ||
thermal_speed_coefficients(::MeanMagnitude, ::Val{1}) = sqrt(2 / π) | ||
thermal_speed_coefficients(::MeanMagnitude, ::Val{2}) = sqrt(π / 2) | ||
thermal_speed_coefficients(::MeanMagnitude, ::Val{3}) = sqrt(8 / π) | ||
thermal_speed_coefficients(::NRL, ::Val{1}) = 1.0 | ||
thermal_speed_coefficients(::NRL, ::Val{2}) = 1.0 | ||
thermal_speed_coefficients(::NRL, ::Val{3}) = 1.0 | ||
|
||
function thermal_speed( | ||
T::EnergyOrTemp, | ||
mass::Unitful.Mass, | ||
method = "most_probable", | ||
method::ThermalSpeedMethod = MostProbable(), | ||
ndim = 3, | ||
) | ||
coeff = thermal_speed_coefficients(method, ndim) | ||
coeff = thermal_speed_coefficients(method, Val(ndim)) | ||
return coeff * sqrt(k * temperature(T) / mass) | ||
end | ||
|
||
thermal_speed(T::EnergyOrTemp, mass_numb, args...) = | ||
thermal_speed(T, mass_numb * u, args...) | ||
|
||
function thermal_temperature( | ||
V::Unitful.Velocity, | ||
mass::Unitful.Mass, | ||
method = "most_probable", | ||
method::ThermalSpeedMethod = MostProbable(), | ||
ndim = 3, | ||
) | ||
coeff = thermal_speed_coefficients(method, ndim) | ||
coeff = thermal_speed_coefficients(method, Val(ndim)) | ||
return mass * V^2 / (k * coeff^2) |> upreferred | ||
end | ||
|
||
""" | ||
thermal_speed_coefficients(method::String, ndim::Int) | ||
Get the thermal speed coefficient corresponding to the desired thermal speed definition. | ||
# Arguments | ||
- `method::String`: Method to be used for calculating the thermal speed. Valid values are `"most_probable"`, `"rms"`, `"mean_magnitude"`, and `"nrl"`. | ||
- `ndim::Int`: Dimensionality (1D, 2D, 3D) of space in which to calculate thermal speed. Valid values are `1`, `2`, or `3`. | ||
""" | ||
function thermal_speed_coefficients(method::String, ndim::Int) | ||
# Define the coefficient dictionary | ||
_coefficients = Dict( | ||
(1, "most_probable") => 0.0, | ||
(2, "most_probable") => 1.0, | ||
(3, "most_probable") => sqrt(2), | ||
(1, "rms") => 1.0, | ||
(2, "rms") => sqrt(2), | ||
(3, "rms") => sqrt(3), | ||
(1, "mean_magnitude") => sqrt(2 / π), | ||
(2, "mean_magnitude") => sqrt(π / 2), | ||
(3, "mean_magnitude") => sqrt(8 / π), | ||
(1, "nrl") => 1.0, | ||
(2, "nrl") => 1.0, | ||
(3, "nrl") => 1.0, | ||
) | ||
|
||
# Attempt to retrieve the coefficient | ||
try | ||
return _coefficients[(ndim, method)] | ||
catch | ||
throw( | ||
ArgumentError( | ||
"Value for (ndim, method) pair not valid, got '($ndim, $method)'.", | ||
), | ||
) | ||
end | ||
end | ||
|
||
|
||
function electron_thermal_velocity(eot::EnergyOrTemp) | ||
upreferred(sqrt(k * temperature(eot) / me)) | ||
thermal_speed(eot, me, NRL()) | ||
end | ||
|
||
# TODO: Do we need this, or is the thermal_speed function sufficient? | ||
function ion_thermal_velocity(eot::EnergyOrTemp, ion_mass::Unitful.Mass) | ||
upreferred(sqrt(k * temperature(eot) / ion_mass)) | ||
end | ||
thermal_speed(eot, ion_mass, NRL()) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters