Skip to content

Commit d8b9bba

Browse files
authored
Merge pull request JuliaPhysics#441 from JuliaPhysics/dev
Minor update in painting algorithm for `CylindricalGrid`
2 parents 7a4f984 + c227571 commit d8b9bba

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

src/ConstructiveSolidGeometry/SurfacePrimitives/ConeMantle.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ function intersection(cm::ConeMantle{T,Tuple{T,T}}, l::Line{T}) where {T}
230230
end
231231
ints1 = obj_l.origin + λ1 * obj_l.direction
232232
ints2 = obj_l.origin + λ2 * obj_l.direction
233+
# Could be reintroduced as sanity check
234+
# ints1 = ints1 * ifelse(abs(ints1.z) <= cm.hZ, one(T), T(NaN))
235+
# ints2 = ints2 * ifelse(abs(ints2.z) <= cm.hZ, one(T), T(NaN))
233236
return _transform_into_global_coordinate_system(ints1, cm),
234237
_transform_into_global_coordinate_system(ints2, cm)
235238
end

src/ConstructiveSolidGeometry/SurfacePrimitives/TorusMantle.jl

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -214,33 +214,36 @@ Calculates the intersections of a `Line` with a `TorusMantle`.
214214
function intersection(tm::TorusMantle{T}, l::Line{T}) where {T}
215215
obj_l = _transform_into_object_coordinate_system(l, tm) # direction is not normalized
216216

217-
L1 = obj_l.origin.x
218-
L2 = obj_l.origin.y
219-
L3 = obj_l.origin.z
220-
D1 = obj_l.direction.x
221-
D2 = obj_l.direction.y
222-
D3 = obj_l.direction.z
217+
let T2 = Float64 # will this work on 32bit-machines?
223218

224-
R = tm.r_torus
225-
r = tm.r_tube
219+
L1::T2 = obj_l.origin.x |> T2
220+
L2::T2 = obj_l.origin.y |> T2
221+
L3::T2 = obj_l.origin.z |> T2
222+
D1::T2 = obj_l.direction.x |> T2
223+
D2::T2 = obj_l.direction.y |> T2
224+
D3::T2 = obj_l.direction.z |> T2
226225

227-
A = L1^2 + L2^2 + L3^2 + R^2 - r^2
228-
B = 2*(L1*D1 + L2*D2 + L3*D3)
229-
C = D1^2 + D2^2 + D3^2
226+
R::T2 = tm.r_torus |> T2
227+
r::T2 = tm.r_tube |> T2
230228

231-
a = (2*B*C) / C^2
232-
b = (2*A*C + B^2 - 4*R^2*(D1^2 + D2^2)) / C^2
233-
c = (2*A*B - 8*R^2*(L1*D1 + L2*D2)) / C^2
234-
d = (A^2 - 4*R^2*(L1^2 + L2^2)) / C^2
229+
A::T2 = L1^2 + L2^2 + L3^2 + R^2 - r^2
230+
B::T2 = 2*(L1*D1 + L2*D2 + L3*D3)
231+
C::T2 = D1^2 + D2^2 + D3^2
232+
233+
a::T2 = (2*B*C)
234+
b::T2 = (2*A*C + B^2 - 4*R^2*(D1^2 + D2^2))
235+
c::T2 = (2*A*B - 8*R^2*(L1*D1 + L2*D2))
236+
d::T2 = (A^2 - 4*R^2*(L1^2 + L2^2))
235237

236238
# Solve: `solve (sqrt((L1 + λ*D1)^2 + (L2 + λ*D2)^2)-R)^2 + (L3 + λ*D3)^2 = r^2 for λ`
237239

238240
# λ1, λ2, λ3, λ4 = roots_of_4th_order_polynomial(a, b, c, d) # That does not work for all combinations of a, b, c, d...
239241
# fallback to Polynomials.jl, which is slower... We should improve `roots_of_4th_order_polynomial`...
240242
return broadcast-> _transform_into_global_coordinate_system(obj_l.origin + λ * obj_l.direction, tm),
241-
real.(Polynomials.roots(Polynomial((d, c, b, a, one(T))))))
243+
T.(real.(Polynomials.roots(Polynomial((d, c, b, a, C^2))))))
242244
# pts[.!in.(pts, Ref(tm))] .= Ref(CartesianPoint{T}(NaN,NaN,NaN)) # for Partial Tori: discard all intersection points that are not part of the Torus
243245
# return pts
246+
end
244247
end
245248

246249
# These function compose cross sections of Tori at constant θ and ensure that the height is always positive

src/PotentialCalculation/Painting.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ function paint!(point_types, potential, face::AbstractSurfacePrimitive{T}, geome
117117
eZ = CartesianVector{T}(0,0,1);
118118

119119
widths_ax1 = diff(get_extended_ticks(grid[1]))
120-
widths_ax2 = diff(get_extended_ticks(grid[2]))
120+
# widths_ax2 = diff(get_extended_ticks(grid[2]))
121121
widths_ax3 = diff(get_extended_ticks(grid[3]))
122122
Δw_max_factor = T(1e-5)
123123
#=
124124
Δw_max_factor is chosen by trying out different values for it.
125-
This value seems to be okay if the grid is not to unevenly spaced.
126-
But this can be secured via the `max_ratio`- and the `the max_tick_distance`-keywords.
125+
This value seems to be okay if the grid is not too unevenly spaced.
126+
But this can be secured via the `max_ratio`- and the `max_tick_distance`-keywords.
127127
The critical parameter is `csgtol` inside the `in`-method, which is currently defined through
128128
the widths of the voxel of the grid point next to the calculated intersection point.
129129
It would be probably better to turn this into an `NTuple{3,T}` and pass the widths of the voxel instead
@@ -176,7 +176,8 @@ function paint!(point_types, potential, face::AbstractSurfacePrimitive{T}, geome
176176
i1 = searchsortednearest(ticks[1], pt_cyl[1])
177177
csgtol = Δw_max_factor * max(
178178
widths_ax1[i1], widths_ax1[i1+1],
179-
widths_ax2[i2], widths_ax2[i2+1],
179+
# skip φ (as done in the previous loop)
180+
# widths_ax2[i2], widths_ax2[i2+1])
180181
)
181182
if in(pt_cyl, grid) && abs(pt_cyl[2] - ticks[2][i2]) < T(0.1) && in(pt_car, geometry, csgtol)
182183
point_types[i1, i2, i3] = zero(PointType)

test/test_real_detectors.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ end
143143
end
144144
@timed_testset "Simulate example detector: Toroidal" begin
145145
sim = Simulation{T}(SSD_examples[:CoaxialTorus])
146-
SolidStateDetectors.apply_initial_state!(sim, ElectricPotential)
147146
timed_simulate!(sim, convergence_limit = 1e-5, device_array_type = device_array_type, refinement_limits = [0.2, 0.1, 0.05, 0.02, 0.01],
148147
max_tick_distance = 0.5u"mm", verbose = false)
149148
evt = Event([CartesianPoint{T}(0.0075,0,0)])

0 commit comments

Comments
 (0)