Skip to content

Commit

Permalink
check chebyshev plasma calculation: good!
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-petersen committed Mar 3, 2024
1 parent 183f5fd commit 1d5b73d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
# FiniteHilbertTransform.jl

[![Test Builds](https://github.com/JuliaStellarDynamics/FiniteHilbertTransform.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/JuliaStellarDynamics/FiniteHilbertTransform.jl/actions/workflows/CI.yml)
[![codecov](https://codecov.io/github/JuliaStellarDynamics/FiniteHilbertTransform.jl/graph/badge.svg?token=LO51PVUTU1)](https://codecov.io/github/JuliaStellarDynamics/FiniteHilbertTransform.jl)
[![codecov](https://codecov.io/github/JuliaStellarDynamics/FiniteHilbertTransform.jl/coverage.svg)](https://codecov.io/github/JuliaStellarDynamics/FiniteHilbertTransform.jl)
[![image](https://github.com/JuliaStellarDynamics/FiniteHilbertTransform.jl/actions/workflows/documentation.yml/badge.svg?branch=documentation)](https://juliastellardynamics.github.io/FiniteHilbertTransform.jl/)
[![image](https://img.shields.io/badge/julia-stable-blue)](https://github.com/JuliaStellarDynamics/OrbitalElements.jl/actions/workflows/devCI.yml)
[![image](http://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/JuliaStellarDynamics/OrbitalElements.jl/blob/v2.0/LICENSE)
[![image](http://img.shields.io/badge/DOI-10.48550/arXiv.2311.10630-blue.svg)](http://dx.doi.org/10.48550/arXiv.2311.10630)

**FiniteHilbertTransform.jl** is a Julia package designed to compute the finite version of the Hilbert transformations. This toolbox is inspired by Tricomi's work on the finite Hilbert transform from 1957. In the context of gravitational dynamics, the finite Hilbert transform may be used as a scheme for analytic continuation to the lower half of the complex plane. See [Fouvry & Prunet (2022)](https://ui.adsabs.harvard.edu/abs/2022MNRAS.509.2443F/abstract), or [Petersen et al. (2024)](https://ui.adsabs.harvard.edu/abs/2023arXiv231110630P/abstract) for details.

Expand All @@ -16,9 +19,10 @@ To invoke Julia in the Terminal, you need to make sure that the `julia` command-
See [here](https://julialang.org/downloads/platform/#optional_add_julia_to_path) for detailed instructions.

Once Julia installed, obtain the `FiniteHilbertTransform.jl` library[^1][^2] and compile it by running:
```
julia -e 'using Pkg; Pkg.add(url="https://github.com/JuliaStellarDynamics/FiniteHilbertTransform.jl.git")'
```

```
julia -e 'using Pkg; Pkg.add(url="https://github.com/JuliaStellarDynamics/FiniteHilbertTransform.jl.git")'
```

---
## Quickstart
Expand Down
Binary file modified examples/plasmademo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 35 additions & 8 deletions examples/run_plasma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Compute coefficients a_k(u) for all values of u by looping over Legendre weights
ComputeALegendre(FHT, tabG)
```
"""
function ComputeALegendre(FHT::FiniteHilbertTransform.LegendreFHT,tabG::Vector{Float64})
function ComputeA(FHT::FiniteHilbertTransform.AbstractFHT,tabG::Vector{Float64})

taba, warnflag = FiniteHilbertTransform.GetaXi(FHT,tabG)

Expand Down Expand Up @@ -117,7 +117,7 @@ ComputeIminusXi([1.0+1.0im, 2.0+2.0im], [0.1, 0.2, 0.3], 10.0, [struct_tabLeg_1,
function ComputeIminusXi(tabomega::Vector{Complex{Float64}},
taba::Vector{Float64},
xmax::Float64,
struct_tabLeg::Vector{FiniteHilbertTransform.LegendreFHT})
struct_tabFHT)

# get constants
K_u = size(taba,1)
Expand All @@ -133,7 +133,7 @@ function ComputeIminusXi(tabomega::Vector{Complex{Float64}},
thr = Threads.threadid()

# compute I-Xi(omg) using the parallel containers
val = FiniteHilbertTransform.GetIminusXi(tabomega[iomega]/xmax,taba,struct_tabLeg[thr])
val = FiniteHilbertTransform.GetIminusXi(tabomega[iomega]/xmax,taba,struct_tabFHT[thr])

# fill in tabIminusXi
tabIminusXi[iomega] = val
Expand Down Expand Up @@ -171,7 +171,7 @@ function setup_legendre_integration(Ku::Int64, qself::Float64, xmax::Float64, PA
tabG = CGFuncPlasma(FHT.tabu, qself, xmax)

# Compute the coefficients for integration
taba, warnflag = ComputeALegendre(FHT, tabG)
taba, warnflag = ComputeA(FHT, tabG)

# Set up the table for integration
FHTlist = [deepcopy(FHT) for k = 1:Threads.nthreads()]
Expand All @@ -180,6 +180,25 @@ function setup_legendre_integration(Ku::Int64, qself::Float64, xmax::Float64, PA
end


function setup_chebyshev_integration(Ku::Int64, qself::Float64, xmax::Float64, PARALLEL::Bool=false)
# Filling in the arrays used in the Chebyshev quadrature
FHT = FiniteHilbertTransform.ChebyshevFHT(Ku)

# Compute the function G(u)
tabG = CGFuncPlasma(FHT.tabu, qself, xmax)

# Compute the coefficients for integration
taba, warnflag = ComputeA(FHT, tabG)

# Set up the table for integration
FHTlist = [deepcopy(FHT) for k = 1:Threads.nthreads()]

return taba, FHTlist
end





"""
get_tabomega(tabOmega::Vector{Float64}, tabEta::Vector{Float64})
Expand Down Expand Up @@ -272,7 +291,7 @@ function parse_commandline()
"--Etamax"
help = "Maximum imaginary frequency"
arg_type = Float64
default = -0.01
default = 3.0
"--Cmode"
help = "Continuation mode for damped calculation (legendre/chebyshev,rational)"
arg_type = String
Expand Down Expand Up @@ -317,6 +336,7 @@ function main()
qself = parsed_args["qSELF"]
xmax = parsed_args["xmax"]
K_u = parsed_args["K_u"]
CMODE = parsed_args["Cmode"]


if (PARALLEL)
Expand All @@ -332,7 +352,14 @@ function main()
# (flat) array of omega values to check
tabomega = get_tabomega(tabOmega,tabEta)

taba,struct_tabLeg = setup_legendre_integration(K_u,qself,xmax,PARALLEL)
if (CMODE=="legendre")
taba,struct_tabLeg = setup_legendre_integration(K_u,qself,xmax,PARALLEL)
elseif (CMODE=="chebyshev")
taba,struct_tabLeg = setup_chebyshev_integration(K_u,qself,xmax,PARALLEL)
else
throw(DomainError(CMODE,"Integration type must be legendre or chebyshev."))
end

@time tabIminusXi = ComputeIminusXi(tabomega,taba,xmax,struct_tabLeg)

epsilon_real = reshape(real.(tabIminusXi),parsed_args["nEta"],parsed_args["nOmega"])
Expand All @@ -341,8 +368,8 @@ function main()


# Plot
contour(tabOmega,tabEta,log10.(epsilon), levels=10, color=:black, #levels=[-2.0, -1.5, -1.0, -0.5, -0.25, 0.0],
xlabel="Re[ω]", ylabel="Im[ω]", xlims=(-4, 4), ylims=(-3, 0),
contour(tabOmega,tabEta,log10.(epsilon), levels=10, color=:black,
xlabel="Re[ω]", ylabel="Im[ω]", xlims=(parsed_args["Omegamin"],parsed_args["Omegamax"]), ylims=(parsed_args["Etamin"],parsed_args["Etamax"]),
clims=(-2, 0), aspect_ratio=:equal, legend=false)
savefig("plasmademo.png")

Expand Down
1 change: 0 additions & 1 deletion src/FiniteHilbertTransform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module FiniteHilbertTransform


# make an abstract FiniteHilbertTransform type
# @WARNING: Should be defined before any basis definition
abstract type AbstractFHT end

# bring in the generic integration tools
Expand Down
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ FiniteHilbertTransform.GettabD!(ϖ,FHT)
@test imag(FHT.tabPLeg[1]) == 0.0
end

@testset "Legendre Damped Frequency: Heaviside checks" begin
ϖ = 0.99 - 0.02im
FiniteHilbertTransform.GettabD!(ϖ,FHT)
@test real(FHT.tabDLeg[1]) -4.48863636973214 atol=tol
ϖ = 1.0 - 0.02im
FiniteHilbertTransform.GettabD!(ϖ,FHT)
@test real(FHT.tabDLeg[1]) -4.605220183488258 atol=tol
ϖ = 1.01 - 0.02im
FiniteHilbertTransform.GettabD!(ϖ,FHT)
@test real(FHT.tabDLeg[1]) -4.498635453116724 atol=tol
ϖ = -1.01 - 0.02im
FiniteHilbertTransform.GettabD!(ϖ,FHT)
@test real(FHT.tabDLeg[1]) 4.498635453116724 atol=tol
end

# check the quadrature approximation
# by checking with all ones, we know the analytic value
@testset "Legendre Quadrature" begin
Expand Down

0 comments on commit 1d5b73d

Please sign in to comment.