Skip to content

Commit 59cb7dc

Browse files
Splitter escapetime (#203)
* Add FiniteSplitterWall to obstacles. * Add FiniteSplitterWall to exports. * Fix FiniteSplitterWall typo. * Make FiniteSplitterWall mutable. * Fix FiniteSplitterWall color. * Make FiniteSplitterWalls render dashed. * Fix FiniteSplitterWall normal function. * Impement distance_init for FiniteSplitterWalls. * Add finite collisions to FiniteSplitterWalls. * Add FiniteSplitterWall test. * Update Project.toml and CHANGELOG.md. * Add FiniteSplitterWall to docs. * Add raysplitting to the escapetime! function. * Fix typo. * Add ray-splitting escapetime test. * Increment patch version. Co-authored-by: owend <[email protected]>
1 parent 6b4be52 commit 59cb7dc

File tree

3 files changed

+58
-24
lines changed

3 files changed

+58
-24
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DynamicalBilliards"
22
uuid = "4986ee89-4ee5-5cef-b6b8-e49ba721d7a5"
33
repo = "https://github.com/JuliaDynamics/DynamicalBilliards.jl.git"
4-
version = "3.12.0"
4+
version = "3.12.1"
55

66
[deps]
77
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"

src/timeevolution/highleveltimes.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ escapetime(p, bd, t; warning = false) =
2323
escapetime(bd::Billiard, t; kwargs...) =
2424
escapetime(randominside(bd), bd, t; kwargs...)
2525

26-
function escapetime!(p::AbstractParticle{T}, bd::Billiard{T}, t;
26+
function escapetime!(p::AbstractParticle{T}, bd::Billiard{T}, t, raysplitters = nothing;
2727
warning::Bool=false)::T where {T<:AbstractFloat}
2828

2929
ei = escapeind(bd)
@@ -32,10 +32,13 @@ function escapetime!(p::AbstractParticle{T}, bd::Billiard{T}, t;
3232
end
3333

3434
totalt = zero(T); count = zero(t); t_to_write = zero(T)
35+
isray = !isa(raysplitters, Nothing)
36+
isray && acceptable_raysplitter(raysplitters, bd)
37+
raysidx = raysplit_indices(bd, raysplitters)
3538

3639
while count < t
3740

38-
i, tmin, pos, vel = bounce!(p, bd)
41+
i, tmin, pos, vel = bounce!(p, bd, raysidx, raysplitters)
3942
t_to_write += tmin
4043

4144
if isperiodic(i, bd)

test/raysplt_tests.jl

+52-21
Original file line numberDiff line numberDiff line change
@@ -126,36 +126,67 @@ end
126126

127127
billiards_testset("RAY Stays inside", identity; caller = inside_antidot)
128128

129-
@testset "FiniteSplitterWall" begin
130-
bdr = billiard_rectangle(1.0, 1.0)
131-
splitter = FiniteSplitterWall([0.5,0.0], [0.5,1.0], [-1.0,0.0])
132-
bd = Billiard(splitter, bdr...)
133-
134-
refraction(ϕ, pflag, ω) = pflag ? 0.5ϕ : 2.0ϕ
135-
transmission(ϕ, pflag, ω) = begin
129+
test_refraction(ϕ, pflag, ω) = pflag ? 0.5ϕ : 2.0ϕ
130+
test_transmission(ϕ, pflag, ω) = begin
136131
if pflag
137132
0.5*exp(-(ϕ)^2/2/8)^2)
138133
else
139134
abs(ϕ) < π/4 ? 0.5*exp(-(ϕ)^2/2/4)^2) : 0.0
140135
end
141136
end
142137

143-
N = 500
144-
rs = (RaySplitter([1], transmission, refraction),)
145-
ps = particlebeam(0.01, 0.5, 0, N, 0)
146-
positions = []
138+
@testset "FiniteSplitterWall" begin
139+
bdr = billiard_rectangle(1.0, 1.0)
140+
splitter = FiniteSplitterWall([0.5,0.0], [0.5,1.0], [-1.0,0.0])
141+
bd = Billiard(splitter, bdr...)
142+
143+
N = 500
144+
rs = (RaySplitter([1], test_transmission, test_refraction),)
145+
ps = particlebeam(0.01, 0.5, 0, N, 0)
146+
positions = []
147+
148+
for p in ps
149+
ct, pos, vel = evolve!(p, bd, 2, rs)
150+
push!(positions, pos[end][1])
151+
reset_billiard!(bd)
152+
end
153+
154+
particles_on_left = length(filter(x ->x < 0.4, positions))
155+
particles_on_right = length(filter(x -> x > 0.6, positions))
156+
particles_in_middle = length(filter(x -> 0.4 <= x <= 0.6, positions))
147157

148-
for p in ps
149-
ct, pos, vel = evolve!(p, bd, 2, rs)
150-
push!(positions, pos[end][1])
151-
reset_billiard!(bd)
158+
@test 0.3N < particles_on_left < 0.7N
159+
@test 0.3N < particles_on_right < 0.7N
160+
@test particles_in_middle == 0
152161
end
153162

154-
particles_on_left = length(filter(x ->x < 0.4, positions))
155-
particles_on_right = length(filter(x -> x > 0.6, positions))
156-
particles_in_middle = length(filter(x -> 0.4 <= x <= 0.6, positions))
163+
@testset "Ray-splitting escapetime" begin
164+
verts = [[0.0,0.0], [0.0,1.0], [1.0,1.0], [1.0,0.0]]
165+
bdr = []
166+
167+
# create rect billiard where vertical walls are doors
168+
for i in eachindex(verts)
169+
s = verts[i]
170+
e = verts[mod1(i+1, length(verts))]
171+
w = s - e
172+
n = [-w[2], w[1]]
173+
push!(bdr, FiniteWall(s, e, n, mod1(i, 2)==1))
174+
end
175+
176+
splitter = FiniteSplitterWall([0.75,0.0], [0.75,1.0], [-1.0,0.0])
177+
bd = Billiard(splitter, bdr...)
178+
179+
N = 500
180+
rs = (RaySplitter([1], test_transmission, test_refraction),)
181+
ps = particlebeam(0.01, 0.5, 0, N, 0)
182+
ts = []
183+
184+
for p in ps
185+
push!(ts, escapetime!(p, bd, 3, rs))
186+
reset_billiard!(bd)
187+
end
157188

158-
@test 0.3N < particles_on_left < 0.7N
159-
@test 0.3N < particles_on_right < 0.7N
160-
@test particles_in_middle == 0
189+
mean_t = +(ts...)/N
190+
expected_mean_t = 0.5 * 1 + 0.5 * 0.75 * 2
191+
@test abs(expected_mean_t - mean_t) < 0.2
161192
end

0 commit comments

Comments
 (0)