Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse charge densities in units of Coulomb per volume #446

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/example_config_files/public_ivc_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,4 @@ surroundings:
- -0.05
charge_density:
name: constant
value: 0 # Reasonable density: +2e-11 # => 2*10⁻¹1 C/m³
value: 0C/m^3 # Reasonable density: +2e-11 # => 2*10⁻¹¹ C/m³
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@ surroundings:
- -0.05
charge_density:
name: constant
value: 0 # Reasonable density: +2e-11 # => 2*10⁻¹1 C/m³
value: 0C/m^3 # Reasonable density: +2e-11 # => 2*10⁻¹¹ C/m³
2 changes: 1 addition & 1 deletion src/ChargeDensities/ConstantChargeDensity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ end


function ChargeDensity(T::DataType, t::Val{:constant}, dict::AbstractDict, input_units::NamedTuple)
ρ::T = haskey(dict, "value") ? _parse_value(T, dict["value"], input_units.length^(-3)) : T(0)
ρ::T = haskey(dict, "value") ? _parse_value(T, dict["value"], internal_charge_unit * input_units.length^(-3)) : T(0)
ConstantChargeDensity{T}( ρ )
end
4 changes: 2 additions & 2 deletions src/ChargeDensities/CylindricalChargeDensity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ end

function ChargeDensity(T::DataType, t::Val{:cylindrical}, dict::AbstractDict, input_units::NamedTuple)
offsets, gradients = zeros(T,3), zeros(T,3)
density_unit = input_units.length^(-3)
density_gradient_unit = input_units.length^(-4)
density_unit = internal_charge_density * input_units.length^(-3)
density_gradient_unit = internal_charge_density * input_units.length^(-4)
if prod(map(k -> k in ["r","z"], collect(keys(dict)))) @warn "Only r and z are supported in the cylindrical charge density model.\nChange the charge density model in the config file or remove all other entries." end
if haskey(dict, "r")
if haskey(dict["r"], "init") offsets[1] = _parse_value(T, dict["r"]["init"], density_unit) end
Expand Down
4 changes: 2 additions & 2 deletions src/ChargeDensities/LinearChargeDensity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ end

function ChargeDensity(T::DataType, t::Val{:linear}, dict::AbstractDict, input_units::NamedTuple)
offsets, gradients = zeros(T,3), zeros(T,3)
density_unit = input_units.length^(-3)
density_gradient_unit = input_units.length^(-4)
density_unit = internal_charge_unit * input_units.length^(-3)
density_gradient_unit = internal_charge_unit * input_units.length^(-4)
if prod(map(k -> k in ["x","y","z"], collect(keys(dict)))) @warn "Only x, y and z are supported in the linear charge density model.\nChange the charge density model in the config file or remove all other entries." end
if haskey(dict, "x")
if haskey(dict["x"], "init") offsets[1] = _parse_value(T, dict["x"]["init"], density_unit) end
Expand Down
4 changes: 2 additions & 2 deletions test/test_real_detectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ end
sim = Simulation{T}(SSD_examples[:Cone2D])
timed_calculate_electric_potential!(sim, convergence_limit = 1e-6, device_array_type = device_array_type, refinement_limits = missing, verbose = false)

sim_alt = Simulation{T}(SSD_examples[:Cone2D])
sim_alt = Simulation{T}(SSD_examples[:ConeSym])
timed_calculate_electric_potential!(sim_alt, convergence_limit = 1e-6, device_array_type = device_array_type, refinement_limits = missing, verbose = false)

# Test equal initial grid spacing in r and z, no matter the phi range
@test sim.electric_potential.grid.r == sim_alt.electric_potential.grid.r
@test sim.electric_potential.grid.z == sim_alt.electric_potential.grid.z

idx = findall(pt -> SolidStateDetectors.is_pn_junction_point_type(pt), sim.point_types.data)
idx = findall(pt -> pt & SolidStateDetectors.bulk_bit > 0, sim.point_types.data)
@test maximum(abs.(sim_alt.electric_potential.data[idx] .- sim.electric_potential.data[idx])) .< T(0.2)
end
@timed_testset "SigGen PPC" begin
Expand Down
Loading