Conversation
|
Should be ready to go. This has extensive tests that should cover almost every line. |
bclyons12
left a comment
There was a problem hiding this comment.
I made a bunch of suggestions to Julia-fy the code, but does the existing toroidal_intersection() do what you want?
src/geometry.jl
Outdated
| t_interval_z = [0.0 Inf] | ||
| end | ||
| else | ||
| t_interval_z = sort![(z_min - z0) / dz, (z_max - z0) / dz] |
There was a problem hiding this comment.
| t_interval_z = sort![(z_min - z0) / dz, (z_max - z0) / dz] | |
| t_interval_z = sort([(z_min - z0) / dz, (z_max - z0) / dz]) |
There was a problem hiding this comment.
sort!([(z_min - z0) / dz, (z_max - z0) / dz]) at the every least, but sort(@SVector[(z_min - z0) / dz, (z_max - z0) / dz]) would be better.
src/geometry.jl
Outdated
| crossing = zeros(Float64, 4) # +1 -> into domain | ||
| # -1 -> out of | ||
| # 0 -> no crossing | ||
| into_domain = [1.0, -1.0] |
There was a problem hiding this comment.
All these small, fixed-sized arrays should either be Tuples or SVector/MVector from StaticArrays.jl. This will avoid unnecessary allocations.
There was a problem hiding this comment.
| into_domain = [1.0, -1.0] | |
| into_domain = Tuple([1.0, 1.0]) |
src/geometry.jl
Outdated
| if (r0 > r_min && r0 < r_max) | ||
| return [[0.0 Inf];] | ||
| else | ||
| return zeros(Float64, 0) |
There was a problem hiding this comment.
You want an empty array? Float64[] is more idiomatic.
There was a problem hiding this comment.
| return zeros(Float64, 0) | |
| return Float64[] |
src/geometry.jl
Outdated
| if dx == 0 && dy == 0 | ||
| # Handle vertical ray | ||
| if (r0 > r_min && r0 < r_max) | ||
| return [[0.0 Inf];] |
There was a problem hiding this comment.
[0.0 Inf] will give you a 1x2 Matrix
There was a problem hiding this comment.
| return [[0.0 Inf];] | |
| return [0.0 Inf] |
src/geometry.jl
Outdated
| t_crossings[2*(i_ref-1) + 1] = t1 >= 0 ? t1/ (dx^2 + dy^2) : Inf | ||
| t_crossings[2*(i_ref-1) + 2] = t2 >= 0 ? t2/ (dx^2 + dy^2) : Inf | ||
| crossing[2*(i_ref-1) + 1] = t1 >= 0 ? into_domain[i_ref]*sign(x0*dx + dx^2*t1 + y0 * dy + dy^2*t1) : 0.0 | ||
| crossing[2*(i_ref-1) + 2] = t2 >= 0 ? into_domain[i_ref]*sign(x0*dx + dx^2*t2 + y0 * dy + dy^2*t2) : 0.0 |
There was a problem hiding this comment.
If this ever becomes computationally intensive, there are plenty of redundant FLOPs here that could be avoided.
There was a problem hiding this comment.
This is run once per beam so it should not come up too often and cost negligible time compared to the actual raytracing.
src/geometry.jl
Outdated
| append!(crossing, 1.0) | ||
| end | ||
| i_sort = sortperm(t_crossings) | ||
| intervals = zeros(Float64, 0) |
src/geometry.jl
Outdated
| end | ||
| end | ||
| if length(intervals) % 2 != 0 | ||
| throw(ErrorException("Somehow only found odd number of intersections which is impossible.")) |
There was a problem hiding this comment.
Make sure grazing intersections are properly handled.
There was a problem hiding this comment.
For my specific use-case grazing intersection can raise an error. A beam that hits the rectangular flux matrix parallel to one of its boundaries indicates an error in how the beam is set up.
src/geometry.jl
Outdated
|
|
||
| function solve_r_intersect(x0::T, y0::T, dx::T, dy::T, r_min::T, r_max::T) where {T<:Real} | ||
| r0 = sqrt(x0^2 + y0^2) | ||
| t_crossings = zeros(Float64, 4) |
There was a problem hiding this comment.
| t_crossings = zeros(Float64, 4) | |
| t_crossings = Float64[] |
src/geometry.jl
Outdated
| append!(crossing, 1.0) | ||
| end | ||
| i_sort = sortperm(t_crossings) | ||
| intervals = zeros(Float64, 0) |
There was a problem hiding this comment.
| intervals = zeros(Float64, 0) | |
| intervals = Float64[] |
|
As far as I can tell |
|
IMAS.jl/src/physics/particles.jl Lines 296 to 379 in ad841d4 |
|
@bclyons12 you were right, the existing routines do what I need to do. I am not sure why I didn't want to use them initially. I almost everything. Now all this PR does is add another dispatch to the |
|
(I also tested the regression test in |
This adds to geometry routines that compute intersections between a ray and a torus with a rectangular cross section.
Still work in progress because I need to remove
ray_rect_intersectionsince that is untested LLM code that I don't need.