-
Notifications
You must be signed in to change notification settings - Fork 52
Refactor ThermalDiffusionLithiumDensity to remove hardcoded parameters #578
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
Merged
fhagemann
merged 14 commits into
JuliaPhysics:main
from
SimonePellegrini:sp/TDLDRefactor
Dec 24, 2025
+199
−27
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
22fa8c6
Refactor ThermalDiffusionLithiumDensity to remove hardcoded parameters
bb4235c
Refactor ThermalDiffusionLithiumDensity to remove hardcoded parameters
cb096eb
Fix lithium diffusion model and YAML parsing
cc3283e
Bug fixes
4030c66
Pass precision type to `ThermalDiffusionLithiumDensityParameters`
fhagemann 7f69bc8
Store `ThermalDiffusionLithiumDensityParameters.H` in units of `cal`
fhagemann 0dfbc85
Revert changes to `Project.toml`
fhagemann 8889f06
Fix order of magnitude of `lithium_density_on_contact`
fhagemann f3ff558
cleaning the code and fixing bugs
186736c
Remove example JSON file for inverted coaxial detectors
5f986fd
Add references to `Thermal_Diffusion_Config.yaml`
fhagemann c1d2a8f
Reorganize code and add docstrings
fhagemann ab8ec08
Remove `in_germanium` from `diffusivity` methods
fhagemann feda000
Update activation energy unit to `cal/mol`
fhagemann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
examples/example_config_files/ThermalDiffusionLithiumDensity/Thermal_Diffusion_Config.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| model: ThermalDiffusionLithiumDensity | ||
| material: HPGe | ||
|
|
||
|
|
||
| annealing_temperature_ranges: | ||
| - T_min: 473K | ||
| T_max: 873K | ||
| D0: 2.5e-7m^2/s | ||
| H: 11800cal | ||
| - T_min: 873K | ||
| T_max: 1273K | ||
| D0: 1.3e-7m^2/s | ||
| H: 10700cal | ||
|
|
||
| experimental_parameters: | ||
| a: 21.27 | ||
fhagemann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| b: 2610 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/ImpurityDensities/ThermalDiffusionLithiumDensityParameters.jl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| function _ThermalDiffusionLithiumParameters( | ||
| config::AbstractDict; | ||
| T::Type = Float32, | ||
| temperature_ranges::AbstractVector{<:AbstractDict} = config["annealing_temperature_ranges"] , | ||
| a::Union{Real, String} = config["experimental_parameters"]["a"], | ||
| b::Union{Real, String} = config["experimental_parameters"]["b"], | ||
| input_units::Union{Missing, NamedTuple} = missing | ||
| ) | ||
|
|
||
| temperature_unit = !ismissing(input_units) ? input_units.temperature : internal_temperature_unit | ||
| diffusivity_unit = !ismissing(input_units) ? | ||
| input_units.length^2 / internal_time_unit : internal_length_unit^2/internal_time_unit | ||
|
|
||
| temp_ranges_parameters = Vector{LithiumDiffusionParameters{T}}() | ||
|
|
||
| for r in temperature_ranges | ||
| push!(temp_ranges_parameters, | ||
| LithiumDiffusionParameters{T}( | ||
| _parse_value(T, r["T_min"], temperature_unit), | ||
| _parse_value(T, r["T_max"], temperature_unit), | ||
| _parse_value(T, r["D0"], diffusivity_unit), | ||
| _parse_value(T, r["H"], u"cal") / ustrip(Unitful.NoUnits, one(T) * u"cal" / internal_energy_unit) # convert to cal internally | ||
| ) | ||
| ) | ||
| end | ||
fhagemann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| diffusion_params = Tuple( | ||
| LithiumDiffusionParameters{T}( | ||
| _parse_value(T, r["T_min"], temperature_unit), | ||
| _parse_value(T, r["T_max"], temperature_unit), | ||
| _parse_value(T, r["D0"], diffusivity_unit), | ||
| _parse_value(T, r["H"], u"cal") / ustrip(Unitful.NoUnits, one(T) * u"cal" / internal_energy_unit) # convert to cal internally | ||
| ) | ||
| for r in temperature_ranges | ||
| ) | ||
|
|
||
| for i in eachindex(diffusion_params) | ||
| if diffusion_params[i].T_max < diffusion_params[i].T_min | ||
| throw(ConfigFileError("Invalid annealing temperature range $i: T_max must be ≥ T_min.")) | ||
| end | ||
| if i>1 && diffusion_params[i-1].T_max != diffusion_params[i].T_min | ||
| throw(ConfigFileError("Annealing temperature ranges must be contiguous and increasing: range $(i-1) ends at a different temperature than range $i starts.")) | ||
| end | ||
| end | ||
|
|
||
|
|
||
| saturation_params = LithiumSaturationParameters{T}( | ||
| _parse_value(T, a, Unitful.NoUnits), _parse_value(T, b, Unitful.NoUnits) | ||
| ) | ||
|
|
||
| return ThermalDiffusionLithiumDensityParameters( | ||
| diffusion_params, | ||
| saturation_params | ||
| ) | ||
| end | ||
|
|
||
|
|
||
| function ThermalDiffusionLithiumParameters(config::AbstractDict, input_units::Union{Missing, NamedTuple} = missing; kwargs...) | ||
| if !haskey(config, "annealing_temperature_ranges") | ||
| throw(ConfigFileError("ThermalDiffusionLithiumDensity config file needs entry 'annealing_temperature_ranges'.")) | ||
| elseif isempty(config["annealing_temperature_ranges"]) | ||
| throw(ConfigFileError("ThermalDiffusionLithiumDensity config file needs at least $minimum_num_of_temp_ranges entries in 'annealing_temperature_ranges'.")) | ||
| end | ||
|
|
||
| for (i, temperature_range) in enumerate(config["annealing_temperature_ranges"]) | ||
| for axis in ("T_min", "T_max", "D0", "H") | ||
| if !haskey(temperature_range, axis) | ||
| throw(ConfigFileError("ThermalDiffusionLithiumDensity config file needs entry 'annealing_temperature_ranges[$i]/$(axis)'.")) | ||
| end | ||
| end | ||
| for k in keys(temperature_range) | ||
| if !(k in ("T_min", "T_max", "D0", "H")) | ||
| @warn "Encountered unexpected key `$(k)` in 'annealing_temperature_ranges[$i]': Allowed keys are `T_min`, `T_max`, `D0` and `H`. Key `$(k)` will be ignored." | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
| if !haskey(config, "experimental_parameters") | ||
| throw(ConfigFileError("ThermalDiffusionLithiumDensity config file needs entry 'experimental_parameters'.")) | ||
| elseif !haskey(config["experimental_parameters"], "a") | ||
| throw(ConfigFileError("ThermalDiffusionLithiumDensity config file needs entry 'experimental_parameters/a'.")) | ||
| elseif !haskey(config["experimental_parameters"], "b") | ||
| throw(ConfigFileError("ThermalDiffusionLithiumDensity config file needs entry 'experimental_parameters/b'.")) | ||
| end | ||
|
|
||
| _ThermalDiffusionLithiumParameters(config; input_units, kwargs...) | ||
| end | ||
|
|
||
| const default_ThermalDiffusionLithiumDensity_config_file = joinpath(get_path_to_example_config_files(), "ThermalDiffusionLithiumDensity/Thermal_Diffusion_Config.yaml") | ||
| function ThermalDiffusionLithiumParameters(config_filename::AbstractString = default_ThermalDiffusionLithiumDensity_config_file, input_units::Union{Missing, NamedTuple} = missing; kwargs...) | ||
| ThermalDiffusionLithiumParameters(parse_config_file(config_filename), input_units; kwargs...) | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.