Skip to content
Merged
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
7 changes: 7 additions & 0 deletions docs/src/basics/components/detectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ Detector(::Real, ::Bool)
Detector
```

Whether a detector stops the beams can be switched later, e.g. to let the beams pass a screen that has been placed for a first check of the setup:

```@docs
BeamletOptics.stop
BeamletOptics.stop!
```

After solving a system containing a `Detector`, the methods listed below can be used in order to analyze the stored data. If no hits are stored, the readouts return zero or empty results.

## Reading out a detector
Expand Down
2 changes: 1 addition & 1 deletion skills/beamletoptics/components/detectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Detector(edge_length, stop = true)
- An infinitely thin square screen at the origin in the x-z plane. Its normal points along −y, so beams
travelling along +y hit it. Orient it like any other object, e.g. after `zrotate3d!(det, deg2rad(90))`
it catches beams travelling along −x.
- With `stop = false`, rays and beamlets continue unchanged behind the detector, e.g. to sample a beam on an intermediate plane.
- With `stop = false`, rays and beamlets continue unchanged behind the detector, e.g. to sample a beam on an intermediate plane. `BeamletOptics.stop!(d, false)` switches an existing detector from the next solve on (stored hits stay), `BeamletOptics.stop(d)` reads it.
A beamlet that the detector clips only partly ends there, as at any object: make the detector larger than the beamlet.
- Stores *hits* of exactly **one** type (Ray, PolarizedRay, GaussianBeamlet or AstigmaticGaussianBeamlet).
- **Hits are values** of the beam state at the solve. Solving again, or moving a source, mirror or lens, never changes stored hits.
Expand Down
2 changes: 2 additions & 0 deletions src/Exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public properties, default_properties
public relaunch!, GaussianBeamletHit, AstigmaticGaussianBeamletHit
# own detector samplings, see AbstractDetectorSampling
public AbstractDetectorSampling, sample_points, DetectorSamples
# whether a detector stops the beams, e.g. a switch in a GUI
public stop, stop!
# optional part of the shape interface, see AbstractShape
public bounding_sphere_of, AbstractBoundingSphere, NoBoundingSphere, SingleBoundingSphere, MultiBoundingSphere
# own assembly types of separate parts, see AbstractObjectGroup
Expand Down
14 changes: 13 additions & 1 deletion src/OpticalComponents/Detectors/Detector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Additionally, continued tracing can be configured via the `stop` flag where
- `false` indicates continued tracing: rays and beamlets pass the detector unchanged
- `true` stops the incoming beams as with any hard target

It can be changed later via [`stop!`](@ref).

!!! warning "Partly clipped beamlets"
A beamlet whose rays hit the detector only partly ends there, as at any other object, also
with `stop = false`. To sample a beamlet on an intermediate plane, make the detector larger
Expand All @@ -112,9 +114,19 @@ The number of hits stored in the detector `d`, `0` before the first solve and af
"""
length(d::Detector) = isnothing(hits(d)) ? 0 : length(hits(d))

"Allows continued tracing if set to false"
"""
stop(d::Detector) -> Bool
stop!(d::Detector, stop::Bool)

Returns or sets whether the detector `d` stops the beams that hit it, see [`Detector`](@ref): with
`false`, rays and beamlets pass it. A change applies from the next solve on; the hits stored by
earlier solves are kept.
"""
stop(d::Detector) = d.stop

"""Sets whether the detector `d` stops the beams that hit it, see [`stop`](@ref)."""
stop!(d::Detector, new::Bool) = (d.stop = new; nothing)

"""
local_axes(pd::Detector) -> (x̂, ẑ)

Expand Down
25 changes: 25 additions & 0 deletions test/Components/TestDetector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,31 @@ end
@test BMO.polarization(rays(beam)[2]) == BMO.polarization(rays(beam)[1])
end

@testset "The stop of a detector can be switched after it is built" begin
d1 = Detector(20mm)
d2 = Detector(20mm)
translate_to3d!(d1, [0.0, 0.10, 0.0])
translate_to3d!(d2, [0.0, 0.20, 0.0])
system = System([d1, d2])
@test BMO.stop(d1)
beam = Beam(Ray([0.0, 0.0, 0.0], [0.0, 1.0, 0.0]))
solve_system!(system, beam)
@test (length(d1), length(d2)) == (1, 0)
# The beam passes d1 from the next solve on, its earlier hit is kept
@test isnothing(BMO.stop!(d1, false))
@test !BMO.stop(d1)
@test length(d1) == 1
beam = Beam(Ray([0.0, 0.0, 0.0], [0.0, 1.0, 0.0]))
solve_system!(system, beam)
@test (length(d1), length(d2)) == (2, 1)
@test length(rays(beam)) == 2
# And stops there again
BMO.stop!(d1, true)
beam = Beam(Ray([0.0, 0.0, 0.0], [0.0, 1.0, 0.0]))
solve_system!(system, beam)
@test (length(d1), length(d2)) == (3, 1)
end

@testset "Beamlets pass a detector with stop = false" begin
# The field on a later detector is the same with and without the passed detector,
# for a beamlet along +y and one along +x
Expand Down
Loading