-
Notifications
You must be signed in to change notification settings - Fork 53
Surface Grid Refinement #594
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
d864051
44e7dc1
c91b326
1552531
4eae2a2
02b46dd
cb00817
8d73f06
a0724bc
4fc9950
657f72f
23c3833
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ grid: | |
| r: | ||
| to: 9 | ||
| boundaries: inf | ||
| y: | ||
| phi: | ||
| from: 0 | ||
| to: 0 | ||
| boundaries: periodic | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ grid: | |
| r: | ||
| to: 9 | ||
| boundaries: inf | ||
| y: | ||
| phi: | ||
| from: 0 | ||
| to: 180 | ||
| boundaries: periodic | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -174,3 +174,78 @@ end | |||||||||
|
|
||||||||||
| _extend_refinement_limits(rl::Real) = (rl, rl, rl ) | ||||||||||
| _extend_refinement_limits(rl::Tuple{<:Real,<:Real,<:Real}) = rl | ||||||||||
|
|
||||||||||
| @inline function has_surface_points(slice::AbstractArray{PointType})::Bool | ||||||||||
| return any(is_in_inactive_layer, slice) | ||||||||||
| end | ||||||||||
|
|
||||||||||
| function _refine_axis_surface( ax::DiscreteAxis{T, <:Any, <:Any, ClosedInterval{T}}, surface_intervals::AbstractVector{Bool}, min_spacing::T; | ||||||||||
| extra_before::Int = 5, # intervals to refine before first surface interval | ||||||||||
| extra_after::Int = 5 # intervals to refine after last surface interval | ||||||||||
fhagemann marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| ) where {T} | ||||||||||
|
|
||||||||||
| old_ticks = ax.ticks | ||||||||||
| n_int = length(surface_intervals) | ||||||||||
|
|
||||||||||
| # Find first and last surface intervals | ||||||||||
| first_surface = findfirst(surface_intervals) | ||||||||||
| last_surface = findlast(surface_intervals) | ||||||||||
|
|
||||||||||
| if first_surface === nothing || last_surface === nothing | ||||||||||
| return ax # Nothing to refine | ||||||||||
| end | ||||||||||
|
||||||||||
| if first_surface === nothing || last_surface === nothing | |
| return ax # Nothing to refine | |
| end | |
| (isnothing(first_surface) || isnothing(last_surface)) && return ax |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
fhagemann marked this conversation as resolved.
Show resolved
Hide resolved
fhagemann marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any scenario in which some values in ticks might remain undef?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think so, the loop structure guarantees that all entries are written, this just follows the same pattern as _refine_axis function
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,14 +10,13 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pwΔmp2r, pwΔmp2l, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pwΔmp3r, pwΔmp3l, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) where {T, S} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # pww1r = pcs.geom_weights[3][1, in1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pww1r = geom_weights_3[1, in1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pww1l = geom_weights_3[2, in1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pwΔmp1 = geom_weights_3[3, in1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Δ1_ext_inv_l = geom_weights_3[4, in1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Δ1_ext_inv_r = geom_weights_3[4, in1 + 1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Δ1_ext_inv_r = in1 < size(geom_weights_3, 2) ? geom_weights_3[4, in1 + 1] : geom_weights_3[4, in1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # ϵ_ijk: i: 1.RB-Dim. | j: 2.RB-Dim. | k: 3.RB-Dim. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_lll, ϵ_llr, ϵ_lrl, ϵ_lrr, ϵ_rll, ϵ_rlr, ϵ_rrl, ϵ_rrr = get_ϵ_of_oktant( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -168,36 +167,50 @@ end | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r::AbstractArray{T, 3}, ::Type{Cylindrical}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| i1, in1, i2, in2, i3, in3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) where {T} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Cylindrical: inner loop over z (3rd dimension) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| i1_safe = clamp(i1, 1, size(ϵ_r, 3)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in1_safe = clamp(in1, 1, size(ϵ_r, 3)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| i2_safe = clamp(i2, 1, size(ϵ_r, 2)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in2_safe = clamp(in2, 1, size(ϵ_r, 2)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| i3_safe = clamp(i3, 1, size(ϵ_r, 1)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in3_safe = clamp(in3, 1, size(ϵ_r, 1)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # ϵ_r is not transformed into an red-black-4D-array. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # The inner loop (over i1) is along the z-Dimension (Cylindrical Case), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # which is the 3rd dimension for Cylindrical coordinates: (r, φ, z) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return @inbounds begin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ in3, in2, in1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ i3, in2, in1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ in3, i2, in1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ i3, i2, in1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ in3, in2, i1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ i3, in2, i1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ in3, i2, i1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ i3, i2, i1 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[in3_safe, in2_safe, in1_safe], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[i3_safe, in2_safe, in1_safe], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[in3_safe, i2_safe, in1_safe], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[i3_safe, i2_safe, in1_safe], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[in3_safe, in2_safe, i1_safe], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[i3_safe, in2_safe, i1_safe], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[in3_safe, i2_safe, i1_safe], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[i3_safe, i2_safe, i1_safe] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+170
to
+188
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed now? Was it needed before already (is this a bug fix)?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This bit of the code was giving a bound error when adding more grid points around the surface layer. When refining the grid near the surface, some index would fall just outside the valid array range. Previously this did not show up because the grid configurations we used did not hit these boundary cases, but with the refinement introduced in this PR it can occur and leads to a BoundsError. So the clamping would act as a safeguard to keep the indices within the range. In that sense this is effectively a bug fix for boundary handling, but it only became visible with the refinement changes added in this PR
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to work with the extended grid then, to also keep boundary conditions fulfilled? SolidStateDetectors.jl/src/Axes/DiscreteAxis.jl Lines 92 to 123 in f279b07
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a better approach. I’ll check whether we can use the extended grid here instead
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just by looking at the code, I don't fully understand this? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @inline function get_ϵ_of_oktant( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r::AbstractArray{T, 3}, ::Type{Cartesian}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| i1, in1, i2, in2, i3, in3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) where {T} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Cartesian: inner loop over x (1st dimension) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| i1_safe = clamp(i1, 1, size(ϵ_r, 1)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in1_safe = clamp(in1, 1, size(ϵ_r, 1)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| i2_safe = clamp(i2, 1, size(ϵ_r, 2)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in2_safe = clamp(in2, 1, size(ϵ_r, 2)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| i3_safe = clamp(i3, 1, size(ϵ_r, 3)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in3_safe = clamp(in3, 1, size(ϵ_r, 3)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # The inner loop (over i1) is along the x-Dimension (Cartesian Case), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # which is the 1rd dimension for Cartesian coordinates: (x, y, z) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return @inbounds begin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ in1, in2, in3 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ in1, in2, i3 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ in1, i2, in3 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ in1, i2, i3 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ i1, in2, in3 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ i1, in2, i3 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ i1, i2, in3 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ i1, i2, i3 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[in1_safe, in2_safe, in3_safe], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[in1_safe, in2_safe, i3_safe], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[in1_safe, i2_safe, in3_safe], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[in1_safe, i2_safe, i3_safe], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ i1_safe, in2_safe, in3_safe], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ i1_safe, in2_safe, i3_safe], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ i1_safe, i2_safe, in3_safe], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ϵ_r[ i1_safe, i2_safe, i3_safe] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+196
to
+213
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still need to implement this |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -242,4 +255,4 @@ end | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| np::NTuple{6, T}, ::Type{Cartesian}, i::Int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) where {T} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return np | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's here semantically, I would also add this to the
Worldthat we create from it and save it tosim.world.Not necessarily for this PR, but we could think about also allowing to put things like the refinement limits, max/min tick distance etc. in here, so that they do not have to be passed at runtime to the
calculate_potential!methods.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done