Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jwscook committed May 4, 2022
0 parents commit 954403f
Show file tree
Hide file tree
Showing 99 changed files with 8,155 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
julia-version: ['1.7']
julia-arch: [x64]
os: [ubuntu-latest]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: "Set up Julia"
uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}

- name: "Build package"
uses: julia-actions/julia-buildpkg@latest

- name: "Run tests"
uses: julia-actions/julia-runtest@latest

- name: "Process coverage report"
uses: julia-actions/julia-processcoverage@v1

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
file: ./lcov.info
25 changes: 25 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Documentation

on:
push:
branches:
- main
tags: '*'
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
with:
version: '1.6'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
run: julia --project=docs/ docs/make.jl

12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.DS_Store
docs/derivation_notes.lyx~
docs/#derivation_notes.lyx#
docs/stringchanger.sh
stringchanger.sh
statprof
profile.pb.gz
derivation_*.txt
*.pdf
*.sh
*.jld
*.jld2
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 J W S Cook

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
36 changes: 36 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name = "LinearMaxwellVlasov"
uuid = "b1137d70-0135-468f-bb3e-ace6f597c457"
authors = ["James Cook <[email protected]>"]
version = "0.1.0"

[deps]
CommonSubexpressions = "bbf7d656-a473-5ed7-a52c-81e309532950"
DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"
HCubature = "19dc6840-f33b-545b-b366-655c7e3ffd49"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Memoize = "c03570c3-d221-55d1-a50c-7939bbd78826"
MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
CommonSubexpressions = "≥ 0.3"
DualNumbers = "≥ 0.6.5"
HCubature = "≥ 1.5.0"
Memoize = "≥ 0.4.4"
QuadGK = "≥ 2.4.1"
SpecialFunctions = "≥ 1.5.1"
StaticArrays = "≥ 1.2.7"

[extras]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UnitTestDesign = "239896fa-e45a-40e8-9993-3c434b0bc450"

[targets]
test = ["Dates", "ForwardDiff", "InteractiveUtils", "Random", "Statistics", "Test", "UnitTestDesign"]
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# LinearMaxwellVlasov.jl

![CI](https://github.com/jwscook/LinearMaxwellVlasov.jl/workflows/CI/badge.svg)
[![codecov.io](http://codecov.io/github/jwscook/LinearMaxwellVlasov.jl/coverage.svg?branch=main)](http://codecov.io/github/jwscook/LinearMaxwellVlasov.jl?branch=main)

Solutions to the homogeneous linear Vlasov-Maxwell equations.

This code solves for the dispersion relation of the linearised Maxwell-Vlasov equations for an infinite, spatially homogenous plasma. Multiple models of plasma species are available:
1. cold fluid
1. warm fluid with optionally distinct parallel and perpendicular sound speeds
1. kinetic (bi-)Maxwellian with optional parallel drift
1. kinetic parallel Maxwellian with optional drift with "ring" perpendicular drift
1. arbitrary decoupled parallel and perpendicular distribution functions.
1. relativistic species (not battle tested)

It is possible to solve for complex wavenumbers indicative of convective instabilities.

<img src="/misc/equations/LinearisedMaxwellValasov.png" height="50" />

which is far to big to display here. The relationships between the species contribution and the dielectric tensor and perturbed current are

<img src="/misc/equations/Relationship1.png" height="50" />
<img src="/misc/equations/Relationship2.png" height="50" />

References:

Books: Stix, Melrose, Brambilla

Particularly useful and succinct:
Chapter 15, "Electromagnetic Waves in Plasma" by Takayuki Umeda, Nagoya University Japan in book "Wave Propagation", edited by Andrey Petrin, published March 16th 2011 by IntechOpen
https://www.intechopen.com/books/wave-propagation
6 changes: 6 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

[compat]
Documenter = "0.27"

7 changes: 7 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Documenter, LinearMaxwellVlasov

makedocs(sitename="LinearMaxwellVlasov.jl")

deploydocs(
repo = "github.com/jwscook/LinearMaxwellVlasov.jl.git",
)
14 changes: 14 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# LinearMaxwellVlasov.jl Documentation

```@meta
CurrentModule = LinearMaxwellVlasov
```

```@autodocs
Modules = [LinearMaxwellVlasov]
```

## Index

```@index
```
108 changes: 108 additions & 0 deletions examples/BumpOnTail.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using Dates

println("Starting BumpOnTail at ", now())
using LinearMaxwellVlasov
using Random, Profile, StatProfilerHTML
using Optim, Plots, LinearAlgebra, NelderMead
using BenchmarkTools, InteractiveUtils
Plots.gr()
Random.seed!(0)

function run()
mₑ = LinearMaxwellVlasov.mₑ
mi = 1836*mₑ
n0 = 1.0e19
Πe = plasmafrequency(n0, mₑ, -1)
Ωe = 1.0e-8 * Πe
ϵV = 1.0e2
vthe = thermalspeed(ϵV, mₑ)
vd = -6.0 * vthe
λD = vthe / Πe
kD = 2π/λD
ratio = 1.0e-3

fu(v) = exp.(-v.^2/vthe^2) + ratio * exp.(-(v-vd).^2/vthe^2)
f_parallel = FParallelNumerical(fu, -10*vthe + vd, vd + 10*vthe)

electron_and_beam = SeparableVelocitySpecies(Πe, Ωe, f_parallel,
FPerpendicularNumerical(vthe))
Snum = Plasma([electron_and_beam])

electron_max = MaxwellianSpecies(Πe*sqrt(1.0-ratio), Ωe, vthe, vthe)
beam_max = MaxwellianSpecies(Πe*sqrt(ratio), Ωe, vthe, vthe, vd)
Smax = Plasma([electron_max, beam_max])

electron_rb = RingBeamSpecies(Πe*sqrt(1.0-ratio), Ωe, vthe, vthe)
beam_rb = RingBeamSpecies(Πe*sqrt(ratio), Ωe, vthe, vthe, vd)
Srb = Plasma([electron_rb, beam_rb])

plot_it = false
if plot_it
v = Vector(range(-12.0*vthe, stop=12.0*vthe, length=10000))
Plots.plot(v/(Πe/kD), electron_and_beam.Fb.F(v)/vthe, linestyle=:cyan)
Plots.plot!(v/(Πe/kD), electron_and_beam.Fb.dFdv(v), linestyle=:black)
end
function f!(C::Configuration, x::Vector{T}, S) where {T<:Number}
C.frequency = ComplexF64(x[1], x[2])
return abs(tensor(S, C)[3, 3])
end

N = 64
ks = Vector{Float64}(range(1.0e-3, stop=1.0, length=N)) .* 0.08
ks = sort(vcat(-ks, ks))
O = Options()
F = (1.05 + im * 0.1)*Πe
K = Wavenumber()
C = Configuration(F, K, O)

function solve(args)
solutions = Vector()
@show N, args[end]
for i eachindex(ks)
objective, config, lb, ub = args
c = deepcopy(config)
c.wavenumber = Wavenumber(wavenumber=ks[i] * kD,
propagationangle=1.0e-8*π)
neldermeadsol = NelderMead.optimise(x->norm(objective(c, x)),
(ub .+ lb) / 2, (ub .- lb) ./ 1000; stopval=1.0e-4, timelimit=10)
val, minimizer, returncode, numiterations = neldermeadsol
if returncode == :STOPVAL_REACHED
objective(c, minimizer)
push!(solutions, c)
end
end
return solutions
end
f!max(C, x) = f!(C, x, Smax)
f!rb(C, x) = f!(C, x, Srb)
f!num(C, x) = f!(C, x, Snum)
args = Vector{Any}()
push!(args, (f!max, C, [0.9, -0.1]*Πe, [1.5, 0.2]*Πe))
push!(args, (f!rb, C, [0.9, -0.1]*Πe, [1.5, 0.2]*Πe))
push!(args, (f!num, C, [0.9, -0.1]*Πe, [1.5, 0.2]*Πe))

@time for (arg, title) in zip(args, ("Maxwellian", "Ring-Beam", "Quadrature"))
@time solutions = solve(arg)
ω = [solution.frequency for solution in solutions]
Ks = [para(solution.wavenumber) for solution in solutions]

ωanalytical = sqrt.(Πe^2 .+ 3*(Ks*vthe).^2)
dFdv = f_parallel.(ωanalytical ./ Ks, true)
γanalytical = π/2 * ωanalytical * Πe.^2 ./ Ks.^2 .* sign.(Ks) .* dFdv

h = Plots.plot(Ks / kD, ωanalytical ./ Πe,
markercolor=:blue, markershape=:circle,
xlabel="\$Wavenumber [2\\pi / \\lambda_D]\$",
ylabel="\$Frequency [\\Omega_{pe}]\$")
Plots.plot!(Ks / kD, γanalytical ./ Πe,
markercolor=:blue, markershape=:square)
Plots.scatter!(Ks / kD, real.(ω) ./ Πe,
markercolor=:green, markershape=:circle)
Plots.scatter!(Ks / kD, imag.(ω) ./ Πe,
markercolor=:green, markershape=:square)
Plots.plot!(legend=false)
Plots.savefig("$title.pdf")
end
end
run()
println("Ending at ", now())
Loading

0 comments on commit 954403f

Please sign in to comment.