Skip to content

Commit

Permalink
added collision frequencies; general restructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
mariomerinomartinez committed Dec 15, 2021
1 parent 2997ec5 commit c43aa97
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 58 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,28 @@ A simple calculator of plasma properties like characteristic lengths and frequen

[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://ep2lab.github.io/PlasmaProperties.jl/stable)
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://ep2lab.github.io/PlasmaProperties.jl/dev)
[![Build status (Github Actions)](https://github.com/ep2lab/PlasmaProperties.jl/workflows/CI/badge.svg)](https://github.com/ep2lab/PlasmaProperties.jl/actions)
[![Build status (Github Actions)](https://github.com/ep2lab/PlasmaProperties.jl/workflows/CI/badge.svg)](https://github.com/ep2lab/PlasmaProperties.jl/actions)

## Usage

Load the `PlasmaProperties` package and the `Unitful` package:

```julia
using PlasmaProperties, Unitful
```

Create a QuasineutralPlasma object. Use a name 'Xe' or 'Ar' to set the ion mass to the correct value for xenon and argon, respectively. Singly-charged ions are assumed. Other values of mass and charge state can be easily added to the package. You can give the values of the plasma density, neutral density, electron temperature, and the fields at creation time, or change them afterwards:

```julia
P = QuasineutralPlasma('Xe', 1e18u"m^-3", 3u"eV")
P.B = 200u"Gauss"
```

The units at creation time are optional; the usual ones are assumed if none are given.

The overloaded `Base.show()` method displays all the information of the plasma when printing `P` in the REPL. You can also use functions to compute a given quantity. E.g. for the electron cyclotron frequency in GHz,

```julia
f_ce(P)
```

6 changes: 3 additions & 3 deletions src/PlasmaProperties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ It builds on Unitful, which provides a simple unit system for physical quantitie
module PlasmaProperties

using Unitful
import Unitful: Length, Time, Mass, Energy, Temperature, BField
import Unitful: Length, Time, Mass, Energy, Temperature, BField, EField
using PhysicalConstants
ε0 = PhysicalConstants.CODATA2018.ε_0 |> u"F/m"
μ0 = PhysicalConstants.CODATA2018.μ_0 |> u"N/A^2"
Expand All @@ -17,9 +17,9 @@ qe = PhysicalConstants.CODATA2018.e |> u"C"
kB = PhysicalConstants.CODATA2018.k_B |> u"J/K"
mu = PhysicalConstants.CODATA2018.m_u |> u"kg"

export Plasma # Plasma object type and constructors
export QuasineutralPlasma # Plasma object type and constructors
export atomic_masses # Atomic masses
export f_ce, f_pe, rLe, λ_De # Calculator functions
export f_ce, f_pe, r_Le, r_Lsi, λ_De, c_s, c_the, ν_ei, ν_ie, ν_ee, χ # Calculator functions
export ε0, μ0, me, qe, kB # Physical constants, reexported from PhysicalConstants

include("auxiliary.jl")
Expand Down
179 changes: 149 additions & 30 deletions src/functions.jl
Original file line number Diff line number Diff line change
@@ -1,67 +1,186 @@
f_c(m,Z,B) = Z*qe*check_or_assume(B,u"Gauss")/check_or_assume(m,u"kg") /(2π) |> u"MHz"
"""
f_c(m,Z,B)
Compute the (unsigned) cyclotron frequency of a charged species in MHz.
If `m` does not have units, it is assumed to be in kg.
If `B` does not have Unitful units, it is assumed to be in Tesla.
"""
f_ce(B)
f_ce(P::Plasma)
f_c(m,Z,B) = abs(Z*qe*check_or_assume(B,u"Gauss")/check_or_assume(m,u"kg") /(2π)) |> u"MHz"

"""
f_pe(m,Z,n)
Compute the plasma frequency of a charged species in MHz.
If `m` does not have units, it is assumed to be in kg.
If `n` does not have Unitful units, it is assumed to be in m^-3.
"""
f_p(m,Z,n) = sqrt(check_or_assume(n,u"m^-3")*Z^2*qe^2/(check_or_assume(m,u"kg")*ε0)) /(2π) |> u"MHz"

Compute the (unsigned) cyclotron frequency of electrons in MHz.
"""
rL(m,Z,B,vperp)
Compute the gyro radius of a charged species in m.
If `m` does not have units, it is assumed to be in kg.
If `B` does not have Unitful units, it is assumed to be in Tesla.
If `vperp` does not have Unitful units, it is assumed to be in m/s.
"""
f_ce(B) = f_c(me,1,B)
f_ce(P::Plasma) = f_ce(P.B)
r_L(m,Z,B,vperp) = abs(check_or_assume(m,u"kg")*check_or_assume(vperp,u"m/s")/(Z*qe*check_or_assume(B,u"Gauss"))) |> u"m"


"""
f_ci(mi,Z,B)
f_ci(P::Plasma)
cth(m,Z,T)
Compute the thermal speed of a charged species in m/s.
This ignores numerical factors and gammae.
"""
c_th(m,Z,T) = sqrt(Z*force_energy_units!(check_or_assume(T,u"eV"))/check_or_assume(m,u"kg")) |> u"m/s"

# ----------------------------------------------------------------------

Compute the cyclotron frequency of ions of mass `mi` in MHz.
"""
f_ce(B)
f_ce(P::QuasineutralPlasma)
Compute the (unsigned) cyclotron frequency of electrons in GHz.
If `B` does not have Unitful units, it is assumed to be in Tesla.
"""
f_ci(mi,Z,B) = f_c(mi,Z,B)
f_ci(P::Plasma) = f_ci(P.mi,P.Z,P.B)
f_ce(B) = f_c(me,1,B) |> u"GHz"
f_ce(P::QuasineutralPlasma) = f_ce(P.B)

f_p(m,Z,n) = sqrt(check_or_assume(n,u"m^-3")*Z^2*qe^2/(check_or_assume(m,u"kg")*ε0)) /(2π) |> u"MHz"
"""
f_ci(mi,Zi,B)
f_ci(P::QuasineutralPlasma)
Compute the (unsigned) cyclotron frequency of ions of mass `mi` in kHz.
If `B` does not have Unitful units, it is assumed to be in Tesla.
"""
f_ci(mi,Zi,B) = f_c(mi,Zi,B) |> u"kHz"
f_ci(P::QuasineutralPlasma) = f_ci(P.mi,P.Zi,P.B)

"""
f_pe(ne)
f_pe(P::Plasma)
f_pe(P::QuasineutralPlasma)
Compute the (unsigned) plasma frequency of electrons in MHz.
Compute the plasma frequency of electrons in GHz.
If `ne` does not have Unitful units, it is assumed to be in m^-3.
"""
f_pe(ne) = f_p(me,1,ne)
f_pe(P::Plasma) = f_pe(P.n)
f_pe(ne) = f_p(me,1,ne) |> u"GHz"
f_pe(P::QuasineutralPlasma) = f_pe(P.np)

"""
f_pi(mi,Z,ni)
f_pi(P::Plasma)
f_pi(P::QuasineutralPlasma)
Compute the plasma frequency of ions of mass `mi` in MHz.
If `ni` does not have Unitful units, it is assumed to be in m^-3.
"""
f_pi(mi,Z,ni) = f_p(mi,Z,ni)
f_pi(P::Plasma) = f_pi(P.mi,P.Z,P.n)

rL(m,Z,B,vperp) = check_or_assume(m,u"kg")*check_or_assume(vperp,u"m/s")/(Z*qe*check_or_assume(B,u"Gauss")) |> u"m"
f_pi(mi,Zi,ni) = f_p(mi,Zi,ni) |> u"kHz"
f_pi(P::QuasineutralPlasma) = f_pi(P.mi,P.Zi,P.np)

"""
rLe(B,vperpe)
r_Le(B,vperpe)
r_Le(P::QuasineutralPlasma)
Compute the electron gyro radius in m.
Compute the electron gyro radius in mm.
If `B` does not have Unitful units, it is assumed to be in Tesla.
If `vperpe` does not have Unitful units, it is assumed to be in m/s.
"""
rLe(B,vperpe) = rL(me,1,B,vperpe)
rLe(P::Plasma) = rLe(P.B,sqrt(P.Te/me))
r_Le(B,vperpe) = r_L(me,1,B,vperpe) |> u"mm"
r_Le(P::QuasineutralPlasma) = r_Le(P.B,sqrt(P.Te/me))

"""
r_Lsi(mi,Z,B,Te)
r_Lsi(P::QuasineutralPlasma)
Compute the sonic ion gyro radius based on the sound speed, in cm.
If `mi` does not have units, it is assumed to be in kg.
If `B` does not have Unitful units, it is assumed to be in Tesla.
If `Te` does not have Unitful units, it is assumed to be in eV.
"""
r_Lsi(mi,Zi,B,Te) = r_L(mi,Zi,B,sqrt(force_energy_units!(check_or_assume(Te,u"eV"))/check_or_assume(mi,u"kg"))) |> u"cm"
r_Lsi(P::QuasineutralPlasma) = r_Lsi(P.mi,P.Zi,P.B,P.Te)

"""
λ_De(ne,Te)
λ_De(P::Plasma)
λ_De(P::QuasineutralPlasma)
Compute the Debye length of the plasm in m.
Compute the Debye length of the plasm in mm.
If ne does not have Unitful units, it is assumed to be in m^-3.
If Te does not have Unitful units, it is assumed to be in eV.
"""
λ_De(ne,Te) = sqrt(ε0*force_energy_units!(check_or_assume(Te,u"eV"))/(check_or_assume(ne,u"m^-3")*qe^2)) |> u"m"
λ_De(P::Plasma) = λ_De(P.n,P.Te)
λ_De(ne,Te) = sqrt(ε0*force_energy_units!(check_or_assume(Te,u"eV"))/(check_or_assume(ne,u"m^-3")*qe^2)) |> u"mm"
λ_De(P::QuasineutralPlasma) = λ_De(P.np,P.Te)

"""
c_s(mi,Zi,Te)
c_s(P::QuasineutralPlasma)
Compute the sound speed of ions in m/s.
This ignores numerical factors and gammae.
"""
c_s(mi,Zi,Te) = c_th(mi,Zi,Te) # Just an alias for cth
c_s(P::QuasineutralPlasma) = c_s(P.mi,P.Zi,P.Te)

"""
c_the(Te)
c_the(P::QuasineutralPlasma)
Compute the thermal speed of electrons in km/s.
This ignores numerical factors and gammae.
"""
c_the(Te) = c_th(me,1,Te) |> u"km/s"
c_the(P::QuasineutralPlasma) = c_the(P.Te)


"""
CoulombLog(ne,Te)
Approximate the Coulomb logarithm.
"""
CoulombLog(np,Te) = 9+0.5*log(1e18u"m^-3"/np * Te^3/1u"eV^3") # approximation

"""
ν_ei(Zi,np,Te)
ν_ei(P::QuasineutralPlasma)
Electron-ion momentum collision frequency in MHz.
"""
function ν_ei(Zi,np,Te)
np = check_or_assume(np,u"m^-3")
Te = force_energy_units!(check_or_assume(Te,u"eV"))
return sqrt(2) * np * Zi^2 * qe^4 * CoulombLog(np,Te) /
(12π^(3/2) * ε0^2 * sqrt(me) * Te^(3/2)) |> u"MHz"
end
ν_ei(P::QuasineutralPlasma) = ν_ei(P.Zi,P.np,P.Te)

"""
ν_ie(mi,Zi,np,Te)
ν_ie(P::QuasineutralPlasma)
Ion-electron momentum collision frequency in MHz.
"""
ν_ie(mi,Zi,np,Te) = me/mi*ν_ei(Zi,np,Te)
ν_ie(P::QuasineutralPlasma) = ν_ie(P.mi,P.Zi,P.np,P.Te)

"""
ν_ee(ne,Te)
ν_ee(P::QuasineutralPlasma)
Electron-electron momentum collision frequency in MHz.
"""
function ν_ee(ne,Te)
ne = check_or_assume(ne,u"m^-3")
Te = force_energy_units!(check_or_assume(Te,u"eV"))
return ne * qe^4 * CoulombLog(ne,Te) /
(12π^(3/2) * ε0^2 * sqrt(me) * Te^(3/2)) |> u"MHz"
end
ν_ee(P::QuasineutralPlasma) = ν_ee(P.np,P.Te)

"""
χ(Zi,np,Te,B)
χ(P::QuasineutralPlasma)
Hall parameter based on the electron-ion collision frequency only.
"""
χ(Zi,np,Te,B) = f_ce(B)/ν_ei(Zi,np,Te) |> Unitful.NoUnits
χ(P::QuasineutralPlasma) = χ(P.Zi,P.np,P.Te,P.B)
82 changes: 58 additions & 24 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,75 @@ const atomic_numbers = Dict([
P = Plasma()
Mutable type holding plasma properties like density, temperature, etc.
The plasma is quasineutral, cold-ion.
The show() method prints a table of the properties and derived quantities.
A name can be specified to quickly select the ion mass and charge.
If units are not given, the default is `mi` in kg, `n` in 1/m^3, `Te` in eV, `B` in Gauss.
"""
mutable struct Plasma
mutable struct QuasineutralPlasma
name::String
mi::Mass
Z::Int
n::ParticleDensity

np::ParticleDensity
Te::Energy

B::BField
end
Plasma(mi,Z,n,Te,B) = Plasma("Custom",
check_or_assume(mi,"kg"),
Z,
check_or_assume(n,u"m^-3"),
force_energy_units!(check_or_assume(Te,u"eV")),
check_or_assume(B,u"Gauss"))
Plasma(name::String,n,Te,B) = Plasma(name,
atomic_masses[name],
atomic_numbers[name],
check_or_assume(n,u"m^-3"),
check_or_assume(Te,u"eV"),
check_or_assume(B,u"Gauss"))

function Base.show(io::IO,P::Plasma)
println(io,P.name," plasma with properties:")
E::EField
nn::ParticleDensity

mi::Mass
Zi::Int
end
QuasineutralPlasma(name::String="Xe",np=1e18u"m^-3",Te=5u"eV";B=0u"Gauss",E=0u"V/m",nn=0u"m^-3") =
QuasineutralPlasma(
name,
check_or_assume(np,u"m^-3"),
check_or_assume(Te,u"eV"),
check_or_assume(B,u"Gauss"),
check_or_assume(E,u"V/m"),
check_or_assume(nn,u"m^-3"),
atomic_masses[name],
atomic_numbers[name],
)

function Base.show(io::IO,P::QuasineutralPlasma)
println(io,P.name," quasineutral plasma")
println(io,"")

println(io,"Plasma density:")
println(io,"n = ",P.np)
println(io,"")

println(io,"Field properties:")
println(io,"B = ",P.B)
println(io,"E = ",P.E)
println(io,"")

println(io,"Cold ion properties:")
println(io,"mi = ",P.mi)
println(io,"Z = ",P.Z)
println(io,"n = ",P.n)
println(io,"Zi = ",P.Zi," (charge number)")
println(io,"c_s = ",c_s(P)," (sound speed based on electron temperature)")
println(io,"f_ci = ",f_ci(P))
println(io,"r_Lsi = ",r_Lsi(P)," (ion gyroradius based on sound speed)")
println(io,"")

println(io,"Electron properties:")
println(io,"Te = ",P.Te)
println(io,"B = ",P.B)
println(io,"c_the = ",c_the(P))
println(io,"f_ce = ",f_ce(P))
println(io,"r_Le = ",r_Le(P))
println(io,"f_pe = ",f_pe(P))
println(io,"rLe = ",rLe(P))
println(io,"λ_De = ",λ_De(P))
println(io,"")

println(io,"Cold neutral properties:")
println(io,"nn = ",P.nn)
println(io,"")

println(io,"Collisional properties:")
println(io,"ν_ei = ",ν_ei(P))
println(io,"ν_ie = ",ν_ie(P))
println(io,"ν_ee = ",ν_ee(P))
println(io,"χ = ",χ(P)," (Hall parameter based on ν_ei only)")
println(io,"")
end

0 comments on commit c43aa97

Please sign in to comment.