Skip to content

Commit

Permalink
Specificy the conductivity tensor (#6)
Browse files Browse the repository at this point in the history
* properly specificy the conductivity tensor

* typo

* bump semver
  • Loading branch information
jwscook authored Jun 27, 2023
1 parent 612d78d commit e56bbc0
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LinearMaxwellVlasov"
uuid = "b1137d70-0135-468f-bb3e-ace6f597c457"
authors = ["James Cook <[email protected]>"]
version = "0.1.4"
version = "0.1.5"

[deps]
CommonSubexpressions = "bbf7d656-a473-5ed7-a52c-81e309532950"
Expand Down
2 changes: 1 addition & 1 deletion src/LinearMaxwellVlasov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export Cache
# Plasmas
export Plasma, NeutralPlasma, isneutral
# Tensors
export tensor, dielectric, electrostaticdielectric
export tensor, dielectric, electrostatictensor, conductivity

__precompile__(true) # precompile dependencies
# precompile for species types
Expand Down
25 changes: 18 additions & 7 deletions src/Tensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,28 @@ function contribution(species::AbstractKineticSpecies, config::Configuration,
end

"""
The dielectric tensor for a given species
The contribution to the dielectric tensor for a given species
"""
function dielectric(species::AbstractSpecies, config::Configuration,
function dielectriccontribution(species::AbstractSpecies, config::Configuration,
cache::Cache=Cache())
return contribution(species, config, cache) * (species.Π / config.frequency)^2
end

"""
The conducivity tensor for a given species
"""
function conductivity(species::AbstractSpecies, config::Configuration,
cache::Cache=Cache())
ϵᵢⱼₛ = dielectriccontribution(species, config, cache)
return -im * config.frequency * ϵ₀ * ϵᵢⱼₛ
end

"""
The dielectric tensor for a given plasma
"""
function dielectric(plasma::AbstractPlasma, config::Configuration,
cache::Cache=Cache())
ϵᵢⱼₛ = species -> dielectric(species, config, cache)
ϵᵢⱼₛ = species -> dielectriccontribution(species, config, cache)
return mapreduce(ϵᵢⱼₛ, +, plasma) + I
end

Expand All @@ -184,10 +193,12 @@ function tensor(plasma::AbstractPlasma, config::Configuration,
end

"""
The electrostatic dielectric tensor for a given plasma
The electrostatic dielectric tensor for a given plasma, a zero valued
determinant of which represents a solution to the linear
poisson-vlasov system of equations
"""
function electrostaticdielectric(plasma::AbstractPlasma, config::Configuration,
function electrostatictensor(plasma::AbstractPlasma, config::Configuration,
cache::Cache=Cache())
ϵₛ = s -> parallel(s, config, 0, UInt64(1), true) * s.Π^2 / config.frequency
return mapreduce(ϵₛ, +, plasma) + 1
return dielectric(plasma, config, cache)
end

8 changes: 4 additions & 4 deletions test/tensors/AnalyticalVsNumerical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ const LMV = LinearMaxwellVlasov
# ζ = kz * vthi / ω
F = ComplexF64(ω, γ)
C = Configuration(F, K, O)
time_a += @elapsed (ta = dielectric(M, C))
time_n += @elapsed (tn = dielectric(S, C))
time_a += @elapsed (ta = conductivity(M, C))
time_n += @elapsed (tn = conductivity(S, C))
@test all(isapprox.(tn, ta, rtol=rtol, atol=atol))
for i in 1:3, j in 1:3
if !isapprox(tn[i, j], ta[i, j], rtol=rtol, atol=atol)
Expand All @@ -67,10 +67,10 @@ const LMV = LinearMaxwellVlasov
C = Configuration(F, K)
for Q (M, S)
try
@inferred dielectric(Q, C)
@inferred conductivity(Q, C)
@test true
catch
@warn "dielectric not inferred for $(nameof(typeof(Q)))"
@warn "conductivity not inferred for $(nameof(typeof(Q)))"
@test_broken false
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/tensors/Basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function performtest()
K = Wavenumber(k=k, θ=0)
C = Configuration((1.1 + 0.1*im)* Πe, K)
output_tensor = tensor(S_num, C)[3,3]
output = electrostaticdielectric(S_num, C)
output = electrostatictensor(S_num, C)[3, 3]
@test output_tensor output
end

Expand All @@ -83,7 +83,7 @@ function performtest()
config = Configuration(0 + im * Πe / 2,
Wavenumber(k=3/2 * Πe / vbeam, θ=0.0))
@test tensor(Plasma([left, right]), config)[3,3] 0 atol=eps()
@test electrostaticdielectric(Plasma([left, right]), config) 0 atol=eps()
@test electrostatictensor(Plasma([left, right]), config)[3, 3] 0 atol=eps()
end
end
performtest()
16 changes: 8 additions & 8 deletions test/tensors/ColdLimit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using LinearMaxwellVlasov
const LMV = LinearMaxwellVlasov


@testset "Cold Limit Dielectrics" begin
@testset "Cold Limit conductivities" begin

mₑ = LMV.mₑ
mi = 1836*mₑ
Expand Down Expand Up @@ -44,13 +44,13 @@ C = Configuration(F, K, O)

tol = 1.0e-3

outputCold = dielectric(cold, C)
outputDelta = dielectric(delta, C)
outputWarm = dielectric(warm, C)
outputMaxwellian = dielectric(maxwellian, C)
outputNumerical = dielectric(numerical, C)
outputCoupled = dielectric(coupled, C)
outputRelativistic = dielectric(relativistic, C)
outputCold = conductivity(cold, C)
outputDelta = conductivity(delta, C)
outputWarm = conductivity(warm, C)
outputMaxwellian = conductivity(maxwellian, C)
outputNumerical = conductivity(numerical, C)
outputCoupled = conductivity(coupled, C)
outputRelativistic = conductivity(relativistic, C)
for i 1:3, j 1:3
expected = outputCold[i, j]
@test expected outputDelta[i, j] rtol=tol atol=tol
Expand Down
2 changes: 1 addition & 1 deletion test/tensors/CoupledVsSeparable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Random.seed!(0)
for params zip(σs, kzs)
(σ, kz) = params
F = ComplexF64(ωr, σ * ωr / 100)
K = Wavenumber(kz=k, k⊥=abs(k))
K = Wavenumber(kz=kz, k⊥=abs(k))
iszero(K) && continue
config = Configuration(F, K)
config.options = Options(quadrature_rtol=1.0e-9, summation_rtol=1e-8)
Expand Down
6 changes: 3 additions & 3 deletions test/tensors/NegativeKPara.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const LMV = LinearMaxwellVlasov
end

@testset "tensors" begin
outputM = dielectric(unitM, C)
outputN = dielectric(unitN, C)
outputR = dielectric(unitR, C)
outputM = conductivity(unitM, C)
outputN = conductivity(unitN, C)
outputR = conductivity(unitR, C)
for i 1:9
@test real(outputN[i]) real(outputM[i]) rtol=1.0e-6
@test imag(outputN[i]) imag(outputM[i]) rtol=1.0e-6
Expand Down
34 changes: 14 additions & 20 deletions test/tensors/RingBeamsAndPancakes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ const LMV = LinearMaxwellVlasov

O = Options()

function f2Dω!(x::Vector{T}, C::Configuration, S, cache) where {T<:Number}
C.frequency = ComplexF64(x[1], x[2])
t = @elapsed output = det(dielectric(S, C, cache))
return output
end

ks_positive = range(0.1, stop=100.0, length=2^3) * k0
ks = sort(vcat(-ks_positive, ks_positive))

Expand All @@ -64,12 +58,12 @@ const LMV = LinearMaxwellVlasov
C = Configuration(F, K, O)
push!(configurations, C)

push!(vals_numerical_rb, dielectric(numerical_rb, C))
push!(vals_ringbeam_rb, dielectric(ringbeam_rb, C))
push!(vals_numerical_rb, conductivity(numerical_rb, C))
push!(vals_ringbeam_rb, conductivity(ringbeam_rb, C))

push!(vals_maxwellian_bp, dielectric(maxwellian_bp, C))
push!(vals_numerical_bp, dielectric(numerical_bp, C))
push!(vals_ringbeam_bp, dielectric(ringbeam_bp, C))
push!(vals_maxwellian_bp, conductivity(maxwellian_bp, C))
push!(vals_numerical_bp, conductivity(numerical_bp, C))
push!(vals_ringbeam_bp, conductivity(ringbeam_bp, C))
end

# these ones are different
Expand All @@ -81,30 +75,30 @@ const LMV = LinearMaxwellVlasov
C = Configuration(F, K, O)
push!(configurations, C)

push!(vals_numerical_rb, dielectric(numerical_rb, C))
push!(vals_ringbeam_rb, dielectric(ringbeam_rb, C))
push!(vals_numerical_rb, conductivity(numerical_rb, C))
push!(vals_ringbeam_rb, conductivity(ringbeam_rb, C))

push!(vals_maxwellian_bp, dielectric(maxwellian_bp, C))
push!(vals_numerical_bp, dielectric(numerical_bp, C))
push!(vals_ringbeam_bp, dielectric(ringbeam_bp, C))
push!(vals_maxwellian_bp, conductivity(maxwellian_bp, C))
push!(vals_numerical_bp, conductivity(numerical_bp, C))
push!(vals_ringbeam_bp, conductivity(ringbeam_bp, C))
end

@testset "Inferred" begin
K = Wavenumber(k=50.0, θ=π/4)
F = ComplexF64(1.0 + im)
C = Configuration(F, K, O)
try
@inferred dielectric(numerical_rb, C)
@inferred conductivity(numerical_rb, C)
@test true
catch
@warn "dielectric not inferred for $(nameof(typeof(numerical_rb)))"
@warn "conductivity not inferred for $(nameof(typeof(numerical_rb)))"
@test_broken false
end
try
@inferred dielectric(ringbeam_rb, C)
@inferred conductivity(ringbeam_rb, C)
@test true
catch
@warn "dielectric not inferred for $(nameof(typeof(ringbeam_rb)))"
@warn "conductivity not inferred for $(nameof(typeof(ringbeam_rb)))"
@test_broken false
end
end
Expand Down

0 comments on commit e56bbc0

Please sign in to comment.