diff --git a/src/physics/particles.jl b/src/physics/particles.jl index 05bb5de1..c312bb7d 100644 --- a/src/physics/particles.jl +++ b/src/physics/particles.jl @@ -378,6 +378,21 @@ function toroidal_intersection(r1::Real, z1::Real, r2::Real, z2::Real, px::Real, return t end +""" + toroidal_intersections(wallr::Vector{T}, wallz::vector{T}, p::vector{T}, v:vector{T}) where {T<:Real} + +Returns the first time of intersection between a moving particle and a wall in toroidal geometry + + - `wallr`: Vector with r coordinates of the wall (must be closed) + - `wallz`: Vector with z coordinates of the wall (must be closed) + - `p`: Vector with current position (3D) of the particle in Cartesian coordinates. + - `v`: Vector with current velocity components of the particle +""" +function toroidal_intersection(wallr::Vector{T}, wallz::Vector{T}, p::Vector{T}, v::Vector{T}) where {T<:Real} + @assert length(p) == length(v) == 3 + return toroidal_intersection(wallr, wallz, p[1], p[2], p[3], v[1], v[2], v[3]) +end + """ toroidal_intersections(wallr::Vector{T}, wallz::vector{T}, px::Real, py::Real, pz::Real, vx::Real, vy::Real, vz::Real) where {T<:Real} diff --git a/test/physics/particles/test_toroidal_intersection.jl b/test/physics/particles/test_toroidal_intersection.jl new file mode 100644 index 00000000..80a1ddc9 --- /dev/null +++ b/test/physics/particles/test_toroidal_intersection.jl @@ -0,0 +1,16 @@ +using IMAS +using Test +@testset "Test toroical_intersection" begin + test_cases = [ + ([1.0, 4.0, 4.0, 1.0, 1.0], [-1.0, -1.0, 1.0, 1.0, -1.0], [6.0, 0.0, 0.0], [-1.0, 0.0, 0.0], [4.0,0.0,0.0]) + ] + for (r_box, z_box, origin, direction, expected) in test_cases + @testset "origin=$origin, direction=$direction, r_box=$r_box, z_box=$z_box" begin + # println("--- x0=$x0, y0=$y0, dx=$dx, dy=$dy, r_min=$r_min, r_max=$r_max ---") + t = IMAS.toroidal_intersection(r_box, z_box, origin, direction) + test_result = origin .+ direction .* t + println("--- Result | expected: $test_result | $expected ---") + @test test_result ≈ expected + end + end +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index e5db99ed..617167f0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,4 +11,6 @@ else include("runtests_extract.jl") include("runtests_plot_recipes.jl") + + include("physics/particles/test_toroidal_intersection.jl") end