JuliaPhysics/SolidStateDetectors.jl

Expansion of grids to full `2π` for cylindrical grids with `φmin ≠ 0` is incorrect

fhagemann opened this issue · 0 comments

Related to #215.

The expansion of grids to full for cylindrical grids with φmin ≠ 0 is incorrect.

MWE:
Using the example configuration file for the inverted coaxial detector and changing the phi range for the grid

name: Public Inverted Coax
# ...
grid:
  coordinates: cylindrical
  axes:
    r: # ...
    phi:
      from: 30  # not zero !
      to: 90
      boundaries: periodic
    z: # ...
#...
using SolidStateDetectors
sim = Simulation(SSD_examples[:InvertedCoax]) # with the modified config file => phi: [30, 90]
calculate_electric_potential!(sim)
calculate_electric_field!(sim)

For the electric potential, the φ axis seems to be parsed correctly:

sim.electric_potential.grid[2]
0.5235988..1.5707964 (closed–open) - length = 4

sim.electric_potential.grid[2].ticks
4-element Vector{Float32}:
 0.5235988
 0.7853982
 1.0471976
 1.3089969

However, for the electric field, it is expanded to and it looks like the interval for the φ axis is always [0, 2π), while the ticks seem to exceed . This, the interval and the ticks of the axis contradict each other.

sim.electric_field.grid[2]
0.0..6.2831855 (closed–open) - length = 24

sim.electric_field.grid[2].ticks
24-element Vector{Float32}:
 0.5235988
 0.7853982
 1.0471976
 1.3089969
 1.5707964
 1.8325958
 2.0943952
 2.3561945
 2.6179938
 2.8797934
 3.1415927
 3.403392
 3.6651917
 3.926991
 4.1887903
 4.4505897
 4.712389
 4.9741883
 5.2359877
 5.4977875
 5.7595863
 6.0213857
 6.283185
 6.544985

This results in an error when plotting (but I guess there are also errors when trying to interpolate the electric field for the charge drift.)

using Plots
plot(sim.electric_field, full_det = true)
plot_electric_fieldlines!(sim, full_det = true)
knot-vectors must be unique and sorted in increasing order

Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] check_gridded
    @ ~/.julia/packages/Interpolations/Glp9h/src/gridded/gridded.jl:81 [inlined]
  [3] check_gridded
    @ ~/.julia/packages/Interpolations/Glp9h/src/gridded/gridded.jl:83 [inlined]
  [4] Interpolations.GriddedInterpolation(#unused#::Type{Float32}, knots::Tuple{Vector{Float32}, Vector{Float32}, Vector{Float32}}, A::Array{StaticArrays.SVector{3, Float32}, 3}, it::Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}})
    @ Interpolations ~/.julia/packages/Interpolations/Glp9h/src/gridded/gridded.jl:40
  [5] interpolate(#unused#::Type{Float32}, #unused#::Type{StaticArrays.SVector{3, Float32}}, knots::Tuple{Vector{Float32}, Vector{Float32}, Vector{Float32}}, A::Array{StaticArrays.SVector{3, Float32}, 3}, it::Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}})
    @ Interpolations ~/.julia/packages/Interpolations/Glp9h/src/gridded/gridded.jl:149
  [6] interpolate(knots::Tuple{Vector{Float32}, Vector{Float32}, Vector{Float32}}, A::Array{StaticArrays.SVector{3, Float32}, 3}, it::Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}})
    @ Interpolations ~/.julia/packages/Interpolations/Glp9h/src/gridded/gridded.jl:166
  [7] interpolated_vectorfield(vectorfield::Array{StaticArrays.SVector{3, Float32}, 3}, grid::Grid{Float32, 3, Cylindrical, Tuple{SolidStateDetectors.DiscreteAxis{Float32, :r0, :infinite, IntervalSets.ClosedInterval{Float32}}, SolidStateDetectors.DiscreteAxis{Float32, :periodic, :periodic, IntervalSets.Interval{:closed, :open, Float32}}, SolidStateDetectors.DiscreteAxis{Float32, :infinite, :infinite, IntervalSets.ClosedInterval{Float32}}}})
    @ SolidStateDetectors ~/Software/SolidStateDetectors.jl/src/ElectricField/ElectricField.jl:186
  [8] macro expansion
    @ ~/Software/SolidStateDetectors.jl/src/PlotRecipes/ElectricField.jl:162 [inlined]
  [9] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, gdd::SolidStateDetectors.Plot_electric_fieldlines)
    @ SolidStateDetectors ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:289
 [10] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/7ijBv/src/user_recipe.jl:36
 [11] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/7ijBv/src/RecipesPipeline.jl:70
 [12] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/YAlrZ/src/plot.jl:208
 [13] plot!(plt::Plots.Plot, args::Any; kw::Base.Pairs{Symbol, V, Tuple{Vararg{Symbol, N}}, NamedTuple{names, T}} where {V, N, names, T<:Tuple{Vararg{Any, N}}})
    @ Plots ~/.julia/packages/Plots/YAlrZ/src/plot.jl:198
 [14] plot!(args::Any; kw::Base.Pairs{Symbol, V, Tuple{Vararg{Symbol, N}}, NamedTuple{names, T}} where {V, N, names, T<:Tuple{Vararg{Any, N}}})
    @ Plots ~/.julia/packages/Plots/YAlrZ/src/plot.jl:188
 [15] #plot_electric_fieldlines!#359
    @ ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:365 [inlined]
 [16] top-level scope
    @ In[87]:2
 [17] eval
    @ ./boot.jl:373 [inlined]
 [18] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:1196