Skip to content

Commit

Permalink
Bugfixes in massless charged particle plots.
Browse files Browse the repository at this point in the history
  • Loading branch information
michakraus committed Jun 30, 2021
1 parent e0ca512 commit 5c49a6f
Showing 1 changed file with 62 additions and 50 deletions.
112 changes: 62 additions & 50 deletions src/massless_charged_particle_plots.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
module MasslessChargedParticlePlots

using GeometricIntegrators.Common
using GeometricIntegrators.Equations
using GeometricIntegrators.Solutions
using GeometricProblems.Diagnostics

using LaTeXStrings
using Measures: mm
using RecipesBase
Expand All @@ -17,7 +22,7 @@ module MasslessChargedParticlePlots
* `ylims=:auto`: ylims for solution plot
"""
@userplot Plot_Massless_Charged_Particle
@recipe function f(p::Plot_Massless_Charged_Particle; nplot=1, nt=:auto, xlims=:auto, ylims=:auto, elims=:auto)
@recipe function f(p::Plot_Massless_Charged_Particle; nplot=1, nt=:auto, xlims=:auto, ylims=:auto, elims=:auto, latex=true)
if length(p.args) != 2 || !(typeof(p.args[1]) <: Solution) || !(typeof(p.args[2]) <: Equation)
error("Massless charged particle plots should be given two arguments: a solution and a parameter tuple. Got: $(typeof(p.args))")
end
Expand All @@ -33,7 +38,7 @@ module MasslessChargedParticlePlots
nt = ntime(sol)
end

H, ΔH = compute_energy_error(sol.t, sol.q, params);
H, ΔH = compute_invariant_error(sol.t, sol.q, (t,q) -> equ.invariants[:h](t,q,params))

size := (800,300)
layout := (1,2)
Expand Down Expand Up @@ -61,12 +66,13 @@ module MasslessChargedParticlePlots
seriestype := :scatter
end

if backend() == Plots.PlotlyJSBackend()
xguide := "x₁"
yguide := "x₂"
else
if latex
xguide := L"x_1"
yguide := L"x_2"
else
# if backend() == Plots.PlotlyJSBackend()
xguide := "x₁"
yguide := "x₂"
end
xlims := xlims
ylims := ylims
Expand All @@ -76,12 +82,12 @@ module MasslessChargedParticlePlots

@series begin
subplot := 2
if backend() == Plots.PlotlyJSBackend()
xguide := "t"
yguide := "[H(t) - H(0)] / H(0)"
else
if latex
xguide := L"t"
yguide := L"[H(t) - H(0)] / H(0)"
else
xguide := "t"
yguide := "[H(t) - H(0)] / H(0)"
end
xlims := (sol.t[0], Inf)
ylims := elims
Expand All @@ -104,7 +110,7 @@ module MasslessChargedParticlePlots
* `ylims=:auto`: ylims for solution plot
"""
@userplot Plot_Massless_Charged_Particle_Solution
@recipe function f(p::Plot_Massless_Charged_Particle_Solution; nplot=1, nt=:auto, xlims=:auto, ylims=:auto)
@recipe function f(p::Plot_Massless_Charged_Particle_Solution; nplot=1, nt=:auto, xlims=:auto, ylims=:auto, latex=true)
if length(p.args) != 2 || !(typeof(p.args[1]) <: Solution) || !(typeof(p.args[2]) <: Equation)
error("Massless charged particle plots should be given two arguments: a solution and a parameter tuple. Got: $(typeof(p.args))")
end
Expand Down Expand Up @@ -136,22 +142,23 @@ module MasslessChargedParticlePlots
legend := :none
size := (400,400)

if backend() == Plots.PlotlyJSBackend() || backend() == Plots.GRBackend()
# if backend() == Plots.PlotlyJSBackend() || backend() == Plots.GRBackend()
guidefontsize := 18
tickfontsize := 12
else
guidefontsize := 14
tickfontsize := 10
end
# else
# guidefontsize := 14
# tickfontsize := 10
# end

# solution
@series begin
if backend() == Plots.PlotlyJSBackend()
xguide := "x₁"
yguide := "x₂"
else
if latex
xguide := L"x_1"
yguide := L"x_2"
else
# if backend() == Plots.PlotlyJSBackend()
xguide := "x₁"
yguide := "x₂"
end

xlims := xlims
Expand All @@ -173,7 +180,7 @@ module MasslessChargedParticlePlots
* `nplot=1`: plot every `nplot`th time step
"""
@userplot Plot_Massless_Charged_Particle_Energy_Error
@recipe function f(p::Plot_Massless_Charged_Particle_Energy_Error; nplot=1, nt=:auto)
@recipe function f(p::Plot_Massless_Charged_Particle_Energy_Error; nplot=1, nt=:auto, latex=true)
if length(p.args) != 2 || !(typeof(p.args[1]) <: Solution) || !(typeof(p.args[2]) <: Equation)
error("Massless charged particle plots should be given two arguments: a solution and a parameter tuple. Got: $(typeof(p.args))")
end
Expand All @@ -189,27 +196,28 @@ module MasslessChargedParticlePlots
nt = ntime(sol)
end

H, ΔH = compute_energy_error(sol.t, sol.q, params);
H, ΔH = compute_invariant_error(sol.t, sol.q, (t,q) -> equ.invariants[:h](t,q,params))

size := (800,200)
legend := :none
right_margin := 10mm

if backend() == Plots.GRBackend()
# if backend() == Plots.GRBackend()
left_margin := 10mm
bottom_margin := 10mm
end
# end

guidefontsize := 12
tickfontsize := 10

@series begin
if backend() == Plots.PlotlyJSBackend()
xguide := "t"
yguide := "[H(t) - H(0)] / H(0)"
else
if latex
xguide := L"t"
yguide := L"[H(t) - H(0)] / H(0)"
# if backend() == Plots.PlotlyJSBackend()
else
xguide := "t"
yguide := "[H(t) - H(0)] / H(0)"
end

xlims := (sol.t[0], Inf)
Expand All @@ -231,7 +239,7 @@ module MasslessChargedParticlePlots
* `k=0`: index of momentum component (0 plots all components)
"""
@userplot Plot_Massless_Charged_Particle_Momentum_Error
@recipe function f(p::Plot_Massless_Charged_Particle_Momentum_Error; k=0, nplot=1, nt=:auto)
@recipe function f(p::Plot_Massless_Charged_Particle_Momentum_Error; k=0, nplot=1, nt=:auto, latex=true)
if length(p.args) != 2 || !(typeof(p.args[1]) <: Solution) || !(typeof(p.args[2]) <: Equation)
error("Massless charged particle plots should be given two arguments: a solution and a parameter tuple. Got: $(typeof(p.args))")
end
Expand All @@ -258,7 +266,7 @@ module MasslessChargedParticlePlots

right_margin := 10mm

if ntrace == 1 && backend() == Plots.GRBackend()
if ntrace == 1 #&& backend() == Plots.GRBackend()
left_margin := 10mm
end

Expand All @@ -271,10 +279,11 @@ module MasslessChargedParticlePlots
subplot := i
end
if i == Δp.nd || k 0
if backend() == Plots.PlotlyJSBackend()
xguide := "t"
else
if latex
xguide := L"t"
# if backend() == Plots.PlotlyJSBackend()
else
xguide := "t"
end
else
xaxis := false
Expand All @@ -294,10 +303,11 @@ module MasslessChargedParticlePlots
# top_margin := -3mm
# end
# end
if backend() == Plots.PlotlyJSBackend()
yguide := "p" * subscript(i) * "(t) - ϑ" * subscript(i) * "(t)"
else
if latex
yguide := latexstring("p_$i (t) - \\vartheta_$i (t)")
# if backend() == Plots.PlotlyJSBackend()
else
yguide := "p" * subscript(i) * "(t) - ϑ" * subscript(i) * "(t)"
end
xlims := (sol.t[0], Inf)
yformatter := :scientific
Expand All @@ -318,7 +328,7 @@ module MasslessChargedParticlePlots
* `nplot=1`: plot every `nplot`th time step
"""
@userplot Plot_Massless_Charged_Particle_Traces
@recipe function f(p::Plot_Massless_Charged_Particle_Traces; nplot=1, nt=:auto, xlims=:auto, ylims=:auto, elims=:auto)
@recipe function f(p::Plot_Massless_Charged_Particle_Traces; nplot=1, nt=:auto, xlims=:auto, ylims=:auto, elims=:auto, latex=true)
if length(p.args) != 2 || !(typeof(p.args[1]) <: Solution) || !(typeof(p.args[2]) <: Equation)
error("Massless charged particle plots should be given two arguments: a solution and a parameter tuple. Got: $(typeof(p.args))")
end
Expand All @@ -334,7 +344,7 @@ module MasslessChargedParticlePlots
nt = ntime(sol)
end

H, ΔH = compute_energy_error(sol.t, sol.q, params);
H, ΔH = compute_invariant_error(sol.t, sol.q, (t,q) -> equ.invariants[:h](t,q,params))

size := (800,600)
legend := :none
Expand All @@ -343,18 +353,19 @@ module MasslessChargedParticlePlots
# traces
layout := (3,1)

if backend() == Plots.PlotlyJSBackend() || backend() == Plots.GRBackend()
# if backend() == Plots.PlotlyJSBackend() || backend() == Plots.GRBackend()
guidefontsize := 14
tickfontsize := 10
else
guidefontsize := 12
tickfontsize := 10
end
# else
# guidefontsize := 12
# tickfontsize := 10
# end

if backend() == Plots.PlotlyJSBackend()
ylabels = ("x₁", "x₂")
else
if latex
ylabels = (L"x_1", L"x_2")
# if backend() == Plots.PlotlyJSBackend()
else
ylabels = ("x₁", "x₂")
end

lims = (xlims, ylims, elims)
Expand Down Expand Up @@ -391,12 +402,13 @@ module MasslessChargedParticlePlots
# elseif backend() == Plots.GRBackend()
# top_margin := -2mm
# end
if backend() == Plots.PlotlyJSBackend()
xguide := "t"
yguide := "[H(t) - H(0)] / H(0)"
else
if latex
xguide := L"t"
yguide := L"[H(t) - H(0)] / H(0)"
# if backend() == Plots.PlotlyJSBackend()
else
xguide := "t"
yguide := "[H(t) - H(0)] / H(0)"
end
xlims := (sol.t[0], Inf)
ylims := elims
Expand Down

2 comments on commit 5c49a6f

@michakraus
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/39970

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.11 -m "<description of version>" 5c49a6f6abe849a7ad93941017035c83ed3e6466
git push origin v0.1.11

Please sign in to comment.