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

Add constructor for ADLChargeDriftModel #369

Merged
merged 9 commits into from
Feb 5, 2024

Conversation

fhagemann
Copy link
Collaborator

This PR improves the convenience of the ADLChargeDriftModel constructor and closes #252.

Previously, the ADLChargeDriftModel was always constructed from a config file. Now:

  • it can also be constructed from a dictionary in a Julia session
  • parameters in the config file or the config dict can have units
  • the syntax of the config file/dict is checked before parsing it
  • single parameter values can be overwritten using keyword arguments (with/without units), e.g.
ADLChargeDriftModel(e100μ0 = 40000u"cm^2/(V*s)", h100β = 2, h111E0 = 50u"V/cm")

Comment on lines 165 to 168
const defaultADLfile = joinpath(get_path_to_example_config_files(), "ADLChargeDriftModel/drift_velocity_config.yaml")
function ADLChargeDriftModel(configfilename::AbstractString = defaultADLfile; kwargs...)
ADLChargeDriftModel(parse_config_file(configfilename); kwargs...)
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If no config file is provided, the default ADLChargeDriftModel parameters are loaded as basis.

Comment on lines +61 to +65
@inline _parse_value(::Type{T}, x::Quantity, unit::Unitful.Units) where {T} = begin
if dimension(x) != dimension(unit) throw(ConfigFileError("The quantity '$(x)' cannot be converted to unit '$(unit)'")) end
T(to_internal_units(float(x)))
end
@inline _parse_value(::Type{T}, s::String, unit::Unitful.Units) where {T} = _parse_value(T, uparse(s), unit)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

_parse_value now also checks whether the passed value has the correct dimensions and throws a ConfigFileError if it doesn't

Comment on lines +153 to +159
@testset "Modify mobility parameters using keyword arguments" begin
cdm = ADLChargeDriftModel{Float64}(e100μ0 = 40000u"cm^2/(V*s)", e111μn = 5u"cm^2/(V*s)", h100β = 2, h111E0 = 50u"V/cm")
@test cdm.electrons.axis100.mu0 == 4.0 # internal unit is m^2/(V*s)
@test cdm.electrons.axis111.mun == 0.0005 # internal unit is m^2/(V*s)
@test cdm.holes.axis100.beta == 2.0 # no unit conversion
@test cdm.holes.axis111.E0 == 5000.0 # internal unit is V/m
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Internally, the parameter values are stored in internal_units

@fhagemann fhagemann merged commit 1677a03 into JuliaPhysics:main Feb 5, 2024
7 checks passed
@fhagemann fhagemann deleted the ADLChargeDriftModel branch February 5, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add constructor method for ADLChargeDriftModel (and others)
1 participant