Skip to content

Add contractor method and scale function to BouleImpurityDensity#484

Merged
fhagemann merged 6 commits intoJuliaPhysics:mainfrom
hervasa2:main
May 14, 2025
Merged

Add contractor method and scale function to BouleImpurityDensity#484
fhagemann merged 6 commits intoJuliaPhysics:mainfrom
hervasa2:main

Conversation

@hervasa2
Copy link
Collaborator

@hervasa2 hervasa2 commented May 9, 2025

User can now construct BouleImpurityDensities from a unitfull vector and value like so:

idm = LinBouleImpurityDensity{T}(pars::Vector{<:Number}, det_z0::Number)

Then units are automatically converted to SSD internal units.
Scaling of BouleImpurityDensities is also now possible with:

scale*idm

Which will scale the correct parameters in the BouleImpurityDensity such the numerical value calculated by get_impurity_density would be scaled accordingly.

I also added a tolerance for the warning when using depletion handling:
""Detector seems not to be not fully depleted at a bias voltage of""...
This warning appears almost every time and should be dropped unless it falls out of the given tolerance

max_tick_distance::Union{Missing, LengthQuantity, Tuple{LengthQuantity, <:Union{LengthQuantity, AngleQuantity}, LengthQuantity}} = missing,
max_distance_ratio::Real = 5,
depletion_handling::Bool = false,
depletion_tol = 0.1,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe final comment: can you allow for this to also have units, so that you can pass depletion_tol = 0.1u“V“, using to_internal_units in the function below?
And add a short description to the docstring what it does.

minimum_applied_potential = minimum(broadcast(c -> c.potential, sim.detector.contacts))
@inbounds for i in eachindex(sim.electric_potential.data)
if sim.electric_potential.data[i] < minimum_applied_potential # p-type
if sim.electric_potential.data[i] < minimum_applied_potential - depletion_tol# p-type
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can use something like to_internal_units or _parse_value here.
(To internal units probably only makes sense if you force the type of depletion_tol to be eather a Real or a Quantity of dimension voltage)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do we need this check at all? It seems to me it slows down the EP calculation just to give a warning that we would like to mostly get rid of. Maybe we could have another keyword like check_for_depletion_overshoots::Bool = false

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could do both: add a depletion_tol and adding a keyword to avoid this check

Copy link
Collaborator

Choose a reason for hiding this comment

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

This check was initially implemented to check for obvious overshoots.

If the detector is not fully depleted but the potential calculation is run with depletion_handling = false, this warning should be more useful. However, it looks like we're only checking for this with depletion_handling = true.

I just ran an example where we expect the detector to NOT be depleted and where such a warning might be useful:

using SolidStateDetectors

# create inverted coax with 0V at point contact and 500V at outer contact
sim = Simulation(SSD_examples[:InvertedCoax])
sim.detector = SolidStateDetector(sim.detector, contact_id = 2, contact_potential = 500)

# calculate electric potential with explicit depletion_handling = false
calculate_electric_potential!(sim, depletion_handling = false)

# check for extreme values in the electric potential
extrema(sim.electric_potential.data)
(-1192.5739f0, 500.00302f0)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, if you are sure that your detector is fully depleted, you can just set depletion_handling = false here to avoid the check and displaying the warning.

@fhagemann
Copy link
Collaborator

To speed this PR up: can you split this into two PRs? This one JUST having the scaling of BouleImpurityDensity and the other one dealing with the depletion_handling and overshoot warning?

These two are code-wise unrelated.

Copy link
Collaborator

@fhagemann fhagemann left a comment

Choose a reason for hiding this comment

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

Are you planning on adding tests on this?
And documentation somewhere in the docs?

minimum_applied_potential = minimum(broadcast(c -> c.potential, sim.detector.contacts))
@inbounds for i in eachindex(sim.electric_potential.data)
if sim.electric_potential.data[i] < minimum_applied_potential # p-type
if sim.electric_potential.data[i] < minimum_applied_potential - depletion_tol# p-type
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, if you are sure that your detector is fully depleted, you can just set depletion_handling = false here to avoid the check and displaying the warning.

@hervasa2
Copy link
Collaborator Author

I don't think we need to add tests or documentations just yet. I would like for it to be fully stable first

@fhagemann
Copy link
Collaborator

But then in general, we should have put this on a separate branch then and merged it once it is finalized..

@hervasa2
Copy link
Collaborator Author

Yes, I already removed the changes to _calculate_potential!. This is PR is thus now only about BouleImpurityDensity constructors and scale methods

@fhagemann fhagemann merged commit c44e498 into JuliaPhysics:main May 14, 2025
9 checks passed
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.

2 participants