Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/physics/particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
16 changes: 16 additions & 0 deletions test/physics/particles/test_toroidal_intersection.jl
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ else
include("runtests_extract.jl")

include("runtests_plot_recipes.jl")

include("physics/particles/test_toroidal_intersection.jl")
end