diff --git a/docs/src/basics/components/detectors.md b/docs/src/basics/components/detectors.md index 7e796a313..87c77aaad 100644 --- a/docs/src/basics/components/detectors.md +++ b/docs/src/basics/components/detectors.md @@ -25,6 +25,30 @@ Detector After solving a system containing a `Detector`, the methods listed below can be used in order to analyze the stored data. If no data is obtained during the tracing procedure, an error message will be stored. +## Reading out a detector + +A detector stores *hits*. The following rules define what a readout computes. + +1. A hit holds the values of the ray or beamlet at the moment of the solve. Solving again, or moving a source or any other component, does not change hits that are already stored. +2. Any kinematic call on the detector (e.g. [`translate3d!`](@ref) or [`rotate3d!`](@ref)) empties it, also when it is moved as part of an [`ObjectGroup`](@ref), since its hits would no longer lie on its surface. +3. A detector can hold the hits of solves that follow each other in time side by side. It is up to the user when to evaluate them. [`spot_diagram`](@ref) shows all hits, which is harmless. [`electric_field`](@ref), [`intensity`](@ref) and [`optical_power`](@ref) superpose all hits **coherently**. This is right for beams that exist at the same time, e.g. a beam group or an interferometer. For solves that follow each other in time, the user must know what this computes, or evaluate after each solve and reset the detector (`initialize = true`, [`initialize!`](@ref) or [`empty!`](@ref)). + +```julia +# Reset and evaluate after every solve +for y in ys + translate_to3d!(mirror, [0, y, 0]) + solve_system!(system, source; initialize = true) + push!(powers, optical_power(pd)) +end + +# Solve several times, evaluate once: the spots of all solves +for _ in 1:10 + zrotate3d!(source, deg2rad(1)) + solve_system!(system, source) +end +spots = spot_diagram(pd) +``` + ## Spot diagrams The `spot_diagram` method provides a straight forward way to generate spot diagrams, which are commonly used to perform initial assessments of the optical performance of an imaging setup. diff --git a/ext/BeamletOpticsOpticsBaseExt.jl b/ext/BeamletOpticsOpticsBaseExt.jl index 3c2aa77ce..dd7959e95 100644 --- a/ext/BeamletOpticsOpticsBaseExt.jl +++ b/ext/BeamletOpticsOpticsBaseExt.jl @@ -40,8 +40,9 @@ const _PREFIX = "BeamletOptics/OpticsBase extension" origin = BeamletOptics.position(detector), axes = ) Samples the coherent field of the beamlets hitting a BeamletOptics (BMO) `Detector` into -an [`OpticsBase.PlaneField`](https://StackEnjoyer.github.io/OpticsBase.jl/dev/). Call it after `solve_system!` and before moving any object, solving again or -emptying the detector. Requires `using OpticsBase` (package extension). +an [`OpticsBase.PlaneField`](https://StackEnjoyer.github.io/OpticsBase.jl/dev/). Call it after `solve_system!`. The hits keep the state of +their solve: solving again or moving other objects does not change them, moving the detector +empties it. Requires `using OpticsBase` (package extension). # Arguments diff --git a/skills/beamletoptics/CHECKLIST.md b/skills/beamletoptics/CHECKLIST.md index 336cbfa4b..bb4618acc 100644 --- a/skills/beamletoptics/CHECKLIST.md +++ b/skills/beamletoptics/CHECKLIST.md @@ -8,7 +8,7 @@ - [ ] Lens radius signs follow ISO 10110 (biconvex: `r1 > 0`, `r2 < 0`). - [ ] Geometry assumes +y as the optical axis; rotations are cumulative and relative. - [ ] Sources start **outside** of all elements and point at them. -- [ ] Detectors emptied before every re-solve in a loop (`initialize = true`, `initialize!(system)` or `empty!(detector)`); results read out before the detector is moved. +- [ ] Detectors emptied before every re-solve in a loop (`initialize = true`, `initialize!(system)` or `empty!(detector)`), unless the hits of all solves are wanted together (e.g. the spots of a scan); `electric_field`, `intensity` and `optical_power` superpose all stored hits coherently; moving the detector empties it. - [ ] Beam model fits the question (see below). - [ ] Script was **run**, and the printed numbers were compared with a paraxial or analytic estimate. - [ ] For non-trivial geometry, a rendered image was checked. diff --git a/skills/beamletoptics/SKILL.md b/skills/beamletoptics/SKILL.md index 1cb8c604e..49e0cbd63 100644 --- a/skills/beamletoptics/SKILL.md +++ b/skills/beamletoptics/SKILL.md @@ -28,7 +28,7 @@ When this Skill is active: `λ -> 1.5`, `DiscreteRefractiveIndex(...)` or `SellmeierEquation(...)`. - **Detectors accumulate.** Solve with `solve_system!(system, beam; initialize = true)`, or call `initialize!(system)` (all detectors) or `empty!(detector)` (one) before every `solve_system!` that reuses the detectors; never reset - between sources that should superpose. + between sources that should superpose. Field functions superpose all stored hits coherently; moving the detector empties it. - **All kinematics are relative** (`translate3d!`, `xrotate3d!`, …), angles in radians (`deg2rad`). Use `translate_to3d!` for absolute positioning. - Run the script after writing it. A simulation that "looks right" but was never executed is not done. diff --git a/skills/beamletoptics/WORKFLOW.md b/skills/beamletoptics/WORKFLOW.md index 53acc58a4..e69b36c3b 100644 --- a/skills/beamletoptics/WORKFLOW.md +++ b/skills/beamletoptics/WORKFLOW.md @@ -43,7 +43,8 @@ for y in ys end ``` -- Read everything you need from a detector **before** moving anything or solving again (hits reference beam state). +- Hits are values of the solve: solving again or moving anything but the detector does not change them. Moving the detector (also via a group) empties it. +- A detector holds the hits of consecutive solves side by side; you decide when to evaluate. `spot_diagram` shows all hits; `electric_field`, `intensity`, `optical_power` superpose all hits **coherently**. For solves that follow each other in time, know what this computes, or evaluate after each solve and reset (`initialize = true`). - See `templates/01_singlet_spot_diagram.jl` (focus scan) and `templates/04_michelson_scan.jl` (fringes). ## Interferometers and coherent sums diff --git a/skills/beamletoptics/components/detectors.md b/skills/beamletoptics/components/detectors.md index 70eb3aafd..aef8c4dc4 100644 --- a/skills/beamletoptics/components/detectors.md +++ b/skills/beamletoptics/components/detectors.md @@ -9,8 +9,10 @@ Detector(edge_length, stop = true) it catches beams travelling along −x. - With `stop = false`, beams continue behind the detector. - Stores *hits* of exactly **one** type (Ray, PolarizedRay, GaussianBeamlet or AstigmaticGaussianBeamlet). -- **Accumulates across solves:** solve with `initialize = true`, or call `initialize!(system)` (all detectors of a system, nested groups included) or `empty!(det)` (one detector) before each `solve_system!` that reuses it. By default the solver does not reset detectors: all beams of a beam group, and several sources solved one after another, superpose on purpose. -- Read out all results before moving the detector again. +- **Hits are values** of the beam state at the solve. Solving again, or moving a source, mirror or lens, never changes stored hits. +- **Moving the detector empties it:** every kinematic call on it (also a move of a group containing it) clears its hits. +- **Accumulates across solves:** by default the solver does not reset detectors, so hits of consecutive solves sit side by side and all beams of a beam group, and several sources solved one after another, superpose on purpose. The user decides when to evaluate. To start empty, solve with `initialize = true`, or call `initialize!(system)` (all detectors of a system, nested groups included) or `empty!(det)` (one detector). +- `spot_diagram` shows all stored hits. `electric_field`, `intensity` and `optical_power` superpose **all** stored hits **coherently**, as for beams that exist at the same time. For solves that follow each other in time, know what this computes, or evaluate after each solve and reset (`initialize = true`). ## Readout diff --git a/src/AbstractTypes/AbstractRay.jl b/src/AbstractTypes/AbstractRay.jl index 70de6c51c..0118e446d 100644 --- a/src/AbstractTypes/AbstractRay.jl +++ b/src/AbstractTypes/AbstractRay.jl @@ -129,6 +129,24 @@ end Base.empty!(ray::AbstractRay) = intersection!(ray, nothing) +""" + hit_point(ray::AbstractRay) + +Returns the point where the `ray` ends, i.e. where it hits the surface of its [`Intersection`](@ref). +""" +hit_point(ray::AbstractRay) = position(ray) + length(ray) * direction(ray) + +""" + projection_factor(ray::AbstractRay) + +Returns `|d · n|` of the direction `d` of the `ray` and the normal `n` of the surface it ends on; +`1` if the ray ends without an intersection. +""" +function projection_factor(ray::AbstractRay{T}) where {T} + isnothing(intersection(ray)) && return one(T) + return abs(dot(direction(ray), normal3d(intersection(ray)))) +end + """ translate3d!(::Movable, ray::AbstractRay, offset) diff --git a/src/Beam.jl b/src/Beam.jl index 0bdf06fd6..8b5e47aa9 100644 --- a/src/Beam.jl +++ b/src/Beam.jl @@ -247,7 +247,7 @@ function Base.show(io::IO, ::MIME"text/plain", beam::Beam) println(io, " Intersects with $(typeof(object(intersection(ray))))") println(io, " Pos.: $(position(ray))") println(io, " Dir.: $(direction(ray))") - println(io, " End.: $(position(ray) .+ length(ray) .* direction(ray))") + println(io, " End.: $(hit_point(ray))") end end return nothing diff --git a/src/Gaussian.jl b/src/Gaussian.jl index f152e6b71..6ce768214 100644 --- a/src/Gaussian.jl +++ b/src/Gaussian.jl @@ -302,40 +302,80 @@ function gauss_parameters( ) p0, index = hint chief = gauss.chief.rays[index] - div = gauss.divergence.rays[index] - waist = gauss.waist.rays[index] + w, R, ψ, w0 = gauss_parameters(GaussianSegment(gauss, index), dot(p0 - position(chief), direction(chief))) + return (w, R, ψ + ψ0, w0) +end + +""" + GaussianSegment{T} + +The waist and divergence rays of one segment of a [`GaussianBeamlet`](@ref), as values relative +to its chief ray: on the plane normal to the chief ray at the distance `l` behind its start, an +auxiliary ray with direction `a` crosses at the transverse offset `y0 + l * v` from the chief ray. +Both rays are straight within the segment, hence this holds exactly. `n` is the refractive index +of the segment and `λ` the vacuum wavelength. [`gauss_parameters`](@ref)`(segment, l)` evaluates it, +a [`GaussianBeamletHit`](@ref) stores it. +""" +struct GaussianSegment{T} + y0_w::Point3{T} + v_w::Point3{T} + a_w::Point3{T} + y0_d::Point3{T} + v_d::Point3{T} + a_d::Point3{T} + n::T + λ::T +end + +function GaussianSegment(gauss::GaussianBeamlet{T}, index::Integer) where {T} + chief = gauss.chief.rays[index] + p, d = position(chief), direction(chief) + y0_w, v_w, a_w = _crossing(p, d, gauss.waist.rays[index]) + y0_d, v_d, a_d = _crossing(p, d, gauss.divergence.rays[index]) + return GaussianSegment{T}(y0_w, v_w, a_w, y0_d, v_d, a_d, refractive_index(chief), wavelength(gauss)) +end + +# Offset `y0 + l v` from the chief ray (start `p`, direction `d`) at which `ray` crosses the plane +# normal to `d` at the distance `l` behind `p`, and the direction of `ray` +function _crossing(p, d, ray) + a = direction(ray) + c = dot(d, a) + return position(ray) + dot(p - position(ray), d) / c * a - p, a / c - d, a +end + +# Height and slope of an auxiliary ray with the offset `y0 + l v` and the direction `a`: the slope +# is tan(π/2 − θ) = cot θ of the angle θ between the offset and `a` +function _height_slope(y0, v, a, l) + y = y0 + l * v + h = norm(y) + ŷ = y / h + return h, dot(ŷ, a) / norm(cross(ŷ, a)) +end + +""" + gauss_parameters(segment::GaussianSegment, l) + +Returns `(w, R, ψ, w0)` of the [`GaussianSegment`](@ref) at the distance `l` behind the start of +its chief ray, as [`gauss_parameters`](@ref)`(gauss, z)` does, but with the Gouy phase `ψ` relative +to the local waist of the segment. +""" +function gauss_parameters(s::GaussianSegment, l::Real) #= - Divergence ray height and slope (same for waist ray) - - find divergence ray "height" and "slope" at intersection point y0 with target plane at p0 of chief ray - - ray height "y_d" is length between p0 and y0 - - ray slope "m_d" is angle between vector p0 -> y0 and divergence ray direction -> gives unambiguous angle for signed ray slope calculation - - fails if y_d is zero -> catch R=Inf, ψ=0 and H=λ/π + Height y and slope m of the divergence and waist rays on the plane at l + - the height is the distance between the chief ray and the crossing point of the ray + - the slope is the cotangent of the angle between the offset and the ray direction, which + gives the signed slope + - fails if a height is zero -> catch R=Inf, ψ=0 and H=λ/π =# - intersection_len = line_plane_distance3d(p0, - direction(chief), - position(div), - direction(div)) - y0 = position(div) + intersection_len * direction(div) - p0 - y_d = norm(y0) - y0 /= y_d - m_d = tan(π / 2 - angle3d(y0, direction(div))) - # Waist ray height and slope - intersection_len = line_plane_distance3d(p0, - direction(chief), - position(waist), - direction(waist)) - y0 = position(waist) + intersection_len * direction(waist) - p0 - y_w = norm(y0) - y0 /= y_w - m_w = tan(π / 2 - angle3d(y0, direction(waist))) + y_d, m_d = _height_slope(s.y0_d, s.v_d, s.a_d, l) + y_w, m_w = _height_slope(s.y0_w, s.v_w, s.a_w, l) # Beam parameters as per Arnaud (1985) and DeJager (1992) - n = refractive_index(chief) + n = s.n H = abs(n * (y_w * m_d - y_d * m_w)) # Test optical invariant - λ = wavelength(gauss) + λ = s.λ if !isapprox(H, λ / π, atol = Config.get_invariant_threshold()) H = λ / π - # println("H not fulfilled at z=$z") end E_kt = y_d * m_d + y_w * m_w F_kt = sqrt(m_d^2 + m_w^2) @@ -349,7 +389,7 @@ function gauss_parameters( isnan(ψ) && (ψ = zero(ψ)) isnan(w0) && (w0 = w) R < 0 && (ψ = -ψ) - return (w, R, ψ + ψ0, w0) + return (w, R, ψ, w0) end """ @@ -437,7 +477,7 @@ _local_gouy_start(gauss::GaussianBeamlet{T}, index::Integer) where {T} = function _local_gouy_end(gauss::GaussianBeamlet{T}, index::Integer) where {T} ray = rays(gauss.chief)[index] return gauss_parameters(gauss, zero(T), zero(T); - hint = (position(ray) + length(ray) * direction(ray), index))[3] + hint = (hit_point(ray), index))[3] end """ diff --git a/src/OpticalComponents/Beamsplitters/ThinBeamsplitter.jl b/src/OpticalComponents/Beamsplitters/ThinBeamsplitter.jl index 11d99d6ab..d386471cb 100644 --- a/src/OpticalComponents/Beamsplitters/ThinBeamsplitter.jl +++ b/src/OpticalComponents/Beamsplitters/ThinBeamsplitter.jl @@ -74,7 +74,7 @@ Base.isvalid(bs::AbstractBeamsplitter) = reflectance(bs)^2 + transmittance(bs)^2 @inline function _beamsplitter_transmitted_beam( ::AbstractBeamsplitter, ::Beam{T, R}, ray::R) where {T <: Real, R <: Ray{T}} - pos = position(ray) + length(ray) * direction(ray) + pos = hit_point(ray) dir = direction(ray) return Beam(Ray(pos, dir, wavelength(ray))) end @@ -82,7 +82,7 @@ end @inline function _beamsplitter_reflected_beam( ::AbstractBeamsplitter, ::Beam{T, R}, ray::R) where {T <: Real, R <: Ray{T}} normal = normal3d(intersection(ray)) - pos = position(ray) + length(ray) * direction(ray) + pos = hit_point(ray) dir = reflection3d(direction(ray), normal) return Beam(Ray(pos, dir, wavelength(ray))) end @@ -90,7 +90,7 @@ end @inline function _beamsplitter_transmitted_beam(bs::AbstractBeamsplitter, ::Beam{T, R}, ray::R) where {T <: Real, R <: PolarizedRay{T}} J = SPBasis(transmittance(bs), 0, 0, transmittance(bs)) - pos = position(ray) + length(ray) * direction(ray) + pos = hit_point(ray) dir = direction(ray) E0 = _calculate_global_E0(bs, ray, dir, J) return Beam(PolarizedRay(pos, dir, wavelength(ray), E0)) @@ -100,7 +100,7 @@ end ray::R) where {T <: Real, R <: PolarizedRay{T}} J = SPBasis(-reflectance(bs), 0, 0, reflectance(bs)) normal = normal3d(intersection(ray)) - pos = position(ray) + length(ray) * direction(ray) + pos = hit_point(ray) in_dir = direction(ray) out_dir = reflection3d(in_dir, normal) E0 = _calculate_global_E0(bs, ray, out_dir, J) diff --git a/src/OpticalComponents/Detectors/Detector.jl b/src/OpticalComponents/Detectors/Detector.jl index bb5a215b3..160ff4728 100644 --- a/src/OpticalComponents/Detectors/Detector.jl +++ b/src/OpticalComponents/Detectors/Detector.jl @@ -31,6 +31,9 @@ is placed on the user. This function should be called `empty!`. A single detecto detectors of a [`System`](@ref) or [`ObjectGroup`](@ref) with [`initialize!`](@ref), which calls `empty!` on every `AbstractDetector`. The solver does not reset detectors unless asked to (keyword `initialize` of [`solve_system!`](@ref)), since the beams of a beam group and several sources solved one after another are meant to superpose. + +Every kinematic function empties a detector, since the stored data belong to the pose of the detector during the solve, see +[`translate3d!`](@ref)`(::Movable, ::AbstractDetector, offset)`. A subtype gets this from its `empty!` method without further code. """ abstract type AbstractDetector{T} <: AbstractObject{T} end @@ -46,6 +49,32 @@ end initialize!(d::AbstractDetector) = (empty!(d); nothing) +""" + translate3d!(::Movable, detector::AbstractDetector, offset) + +Empties the `detector` (see `empty!`) and moves it by `offset`. Its hits lie on the surface +where it was during the solve, hence they are discarded when it moves. All kinematic functions +are derived from this one and [`rotate3d!`](@ref)`(::Movable, ::AbstractDetector, R)`, so each of +them empties the detector, also when it moves as a member of an [`ObjectGroup`](@ref). +""" +function translate3d!(::Movable, d::AbstractDetector, offset) + empty!(d) + translate3d!(shape_trait_of(d), d, offset) + return nothing +end + +""" + rotate3d!(::Movable, detector::AbstractDetector, R::AbstractMatrix) + +Empties the `detector` (see `empty!`) and rotates it by `R` about its `position`, see +[`translate3d!`](@ref)`(::Movable, ::AbstractDetector, offset)`. +""" +function rotate3d!(::Movable, d::AbstractDetector, R::AbstractMatrix) + empty!(d) + rotate3d!(shape_trait_of(d), d, R) + return nothing +end + """ AbstractDetectorHit @@ -72,62 +101,76 @@ abstract type AbstractDetectorHit end AbstractRayHit{T} <: AbstractDetectorHit Abstract supertype for detector hits produced by [`AbstractRay`](@ref)s. -Provides a common interface for extracting positional and optical path -information from rays stored in a detector hit. Currently the following concrete types are implemented: - [`RayHit`](@ref) - [`PolarizedRayHit`](@ref) -# Implementation reqs. - -Subtypes of `AbstractRayHit` must implement the following: +A hit stores the values of the ray at the moment it hit the detector, not the ray itself: a +new solve of the beam or a move of any object does not change it. -## Fields - -- `ray`: stores the `AbstractRay` that has intersected the detector -- `opl`: stores the [`optical_path_length`](@ref) of the parent beam (incl. the ray) - -## Functions +# Implementation reqs. -The interface provides the following functions for the fields above: +Subtypes of `AbstractRayHit` must implement the following functions: -- `position`: returns the `ray` position -- `direction`: returns the `ray` direction -- `length`: returns the `ray` length -- `optical_path_length`: returns the `opl` -- `wavenumber`: returns the `ray` wavenumber -- `hit_point`: returns the R³ point of intersection -- `projection_factor`: returns the scalar projection between the surface normal and ray dir. +- `hit_point`: the R³ point of intersection +- `direction`: the direction of the ray +- `optical_path_length`: the optical path length of the beam up to the hit point (incl. its parents) +- `wavelength`: the vacuum wavelength of the ray +- `wavenumber`: the vacuum wavenumber `2π / λ` +- `refractive_index`: the refractive index in front of the detector +- `projection_factor`: `|d · n|` of the ray direction `d` and the surface normal `n`; `1` if the + ray ended without an intersection """ abstract type AbstractRayHit{T} <: AbstractDetectorHit end -position(hit::AbstractRayHit) = position(hit.ray) -direction(hit::AbstractRayHit) = direction(hit.ray) - -length(hit::AbstractRayHit) = length(hit.ray) +hit_point(hit::AbstractRayHit) = hit.p +direction(hit::AbstractRayHit) = hit.d optical_path_length(hit::AbstractRayHit) = hit.opl -wavenumber(hit::AbstractRayHit) = wavenumber(hit.ray) - -hit_point(hit::AbstractRayHit) = position(hit) + length(hit.ray) * direction(hit) +wavelength(hit::AbstractRayHit) = hit.λ +wavenumber(hit::AbstractRayHit) = wavenumber(wavelength(hit)) +refractive_index(hit::AbstractRayHit) = hit.n +projection_factor(hit::AbstractRayHit) = hit.proj -function projection_factor(hit::AbstractRayHit) - abs(dot(direction(hit), normal3d(intersection(hit.ray)))) -end +""" + RayHit(ray::Ray, opl) -"Stores a [`Ray`](@ref) hit" +Stores the hit of a [`Ray`](@ref) as values: hit point `p`, direction `d`, optical path length `opl` +of the beam up to the hit point, wavelength `λ`, refractive index `n` and projection factor `proj`. +""" struct RayHit{T} <: AbstractRayHit{T} - ray::Ray{T} + p::Point3{T} + d::Point3{T} opl::T + λ::T + n::T + proj::T end -"Stores a [`PolarizedRay`](@ref) hit" +RayHit(ray::Ray{T}, opl::Real) where {T} = + RayHit{T}(hit_point(ray), direction(ray), opl, wavelength(ray), refractive_index(ray), projection_factor(ray)) + +""" + PolarizedRayHit(ray::PolarizedRay, opl) + +Stores the hit of a [`PolarizedRay`](@ref) as values: those of a [`RayHit`](@ref) and the field +vector `E` of the ray in global coordinates. +""" struct PolarizedRayHit{T} <: AbstractRayHit{T} - ray::PolarizedRay{T} + p::Point3{T} + d::Point3{T} opl::T + λ::T + n::T + proj::T + E::Point3{Complex{T}} end -polarization(hit::PolarizedRayHit) = polarization(hit.ray) +PolarizedRayHit(ray::PolarizedRay{T}, opl::Real) where {T} = + PolarizedRayHit{T}(hit_point(ray), direction(ray), opl, wavelength(ray), refractive_index(ray), + projection_factor(ray), polarization(ray)) + +polarization(hit::PolarizedRayHit) = hit.E """ AbstractBeamletHit @@ -141,19 +184,23 @@ abstract type AbstractBeamletHit{T} <: AbstractDetectorHit end """ GaussianBeamletHit{T} <: AbstractBeamletHit{T} -Stores a [`GaussianBeamlet`], where `l0` represents the length of the parent beam -up until the current beam section, identified by the `id` index, `Δl0` the optical -minus the geometric path and `ψ0` the Gouy phase that the beam has collected up to there. +Stores the segment of a [`GaussianBeamlet`](@ref) that hit the detector as values, without a +reference to the beamlet: `p0` and `d0` are start and direction of the segment, `l_seg` its +length, `l0` the length of the beam (including its parents) up to `p0`, `Δl0` the optical minus +the geometric path and `ψ0` the Gouy phase that the beam has collected up to there. `segment` +holds the waist and divergence rays of the segment (see [`BeamletOptics.GaussianSegment`](@ref)), +from which the field follows as from the beamlet itself, see [`gauss_parameters`](@ref). +`E_amp` is the field amplitude times the beam radius, `E0 w0` of the source. """ struct GaussianBeamletHit{T} <: AbstractBeamletHit{T} - gauss::GaussianBeamlet{T} l0::T - id::Int Δl0::T ψ0::T - # Cache p0::Point3{T} d0::Point3{T} + l_seg::T + segment::GaussianSegment{T} + E_amp::Complex{T} sqrt_proj::T w_max::T end @@ -161,13 +208,13 @@ end """ AstigmaticGaussianBeamletHit{T} <: AbstractBeamletHit{T} -Stores an [`AstigmaticGaussianBeamlet`], where `l0` represents the length of the parent beam -up until the current beam section, identified by the `id` index. +Stores the segment of an [`AstigmaticGaussianBeamlet`](@ref) that hit the detector as values, +without a reference to the beamlet: `p0` and `d0` are start and direction of the segment, +`l_seg` its length, `l0` the length of the beam (including its parents) up to `p0`, `λ` the +wavelength and `E_pol` the polarization of the chief ray of the segment. """ struct AstigmaticGaussianBeamletHit{T} <: AbstractBeamletHit{T} - agb::AstigmaticGaussianBeamlet{T} l0::T - id::Int # Cache p0::Point3{T} d0::Point3{T} @@ -188,31 +235,20 @@ struct AstigmaticGaussianBeamletHit{T} <: AbstractBeamletHit{T} E_ref_amp::Complex{T} sqrt_proj::T w_max::T + l_seg::T + λ::T + E_pol::Point3{Complex{T}} end -position(hit::GaussianBeamletHit) = position(hit.gauss.chief.rays[hit.id]) -direction(hit::GaussianBeamletHit) = direction(hit.gauss.chief.rays[hit.id]) -wavelength(hit::GaussianBeamletHit) = wavelength(hit.gauss.chief.rays[hit.id]) -refractive_index(hit::GaussianBeamletHit) = refractive_index(hit.gauss.chief.rays[hit.id]) +direction(hit::AbstractBeamletHit) = hit.d0 +wavelength(hit::GaussianBeamletHit) = hit.segment.λ +wavelength(hit::AstigmaticGaussianBeamletHit) = hit.λ +refractive_index(hit::GaussianBeamletHit) = hit.segment.n +refractive_index(hit::AstigmaticGaussianBeamletHit) = hit.n_eff -position(hit::AstigmaticGaussianBeamletHit) = position(hit.agb.c.rays[hit.id]) -direction(hit::AstigmaticGaussianBeamletHit) = direction(hit.agb.c.rays[hit.id]) -wavelength(hit::AstigmaticGaussianBeamletHit) = wavelength(hit.agb.c.rays[hit.id]) -refractive_index(hit::AstigmaticGaussianBeamletHit) = refractive_index(hit.agb.c.rays[hit.id]) +hit_point(hit::AbstractBeamletHit) = hit.p0 + hit.l_seg * hit.d0 -function hit_point(hit::GaussianBeamletHit) - position(hit) + length(hit.gauss.chief.rays[hit.id]) * direction(hit) -end -function hit_point(hit::AstigmaticGaussianBeamletHit) - position(hit) + length(hit.agb.c.rays[hit.id]) * direction(hit) -end - -function projection_factor(hit::GaussianBeamletHit) - abs(dot(direction(hit), normal3d(intersection(hit.gauss.chief.rays[hit.id])))) -end -function projection_factor(hit::AstigmaticGaussianBeamletHit) - abs(dot(direction(hit), normal3d(intersection(hit.agb.c.rays[hit.id])))) -end +projection_factor(hit::AbstractBeamletHit) = hit.sqrt_proj^2 """ Detector <: AbstractDetector @@ -257,10 +293,12 @@ of a **left-handed** (x, z) surface coordinate system, where incoming beams inte deterministic. !!! warning "Reading hits" - Read the hits of the detector before moving any object or solving again. - The hits refer to the rays and beams of the current solve, which a new call of - [`solve_system!`](@ref) replaces (child beams and all rays after the first are new objects), - and moving objects afterwards leaves the stored hits inconsistent with the system. + A hit stores the values of the ray or beamlet at the moment of the solve, in world coordinates. + Solving again or moving a source or another object does not change the stored hits. Moving the + detector itself empties it, since its hits would no longer lie on its surface. The hits of + consecutive solves are kept side by side, and it is up to the user when to evaluate them: + [`spot_diagram`](@ref) shows all of them, whereas [`electric_field`](@ref), [`intensity`](@ref) and + [`optical_power`](@ref) superpose all of them coherently, as for beams that exist at the same time. # Fields @@ -473,18 +511,19 @@ needs to evaluate the field of that segment at any point near it. [`Detector`](@ one per beamlet that hits them; it can also be built for any traced segment, e.g. to sample a beamlet on a plane of one's own. `l0` is the length of the beam (including its parents) up to the start of the segment. The projection factor is `1` if the segment ends without an -intersection. +intersection. The hit keeps no reference to `g`: a new solve of `g` does not change it. """ function GaussianBeamletHit(g::GaussianBeamlet{R}, id::Integer) where {R} ray = g.chief.rays[id] l0 = _length_before(g.chief, id) p0 = position(ray) d0 = direction(ray) - sqrt_proj = _projection_factor(ray) + segment = GaussianSegment(g, id) + l_seg = length(ray) # Beam radius at the end of the segment, for the auto-limits of the field plots - l_end = isfinite(length(ray)) ? l0 + length(ray) : l0 - w_max, _, _, _ = gauss_parameters(g, l_end) - return GaussianBeamletHit(g, l0, Int(id), _path_excess_before(g, id), _gouy_before(g, id), p0, d0, sqrt_proj, w_max) + w_max = first(gauss_parameters(segment, isfinite(l_seg) ? l_seg : zero(R))) + return GaussianBeamletHit{R}(l0, _path_excess_before(g, id), _gouy_before(g, id), p0, d0, l_seg, + segment, electric_field(g) * beam_waist(g), sqrt(projection_factor(ray)), w_max) end """ @@ -498,7 +537,8 @@ area within the segments since the start of the root beam; the Gouy phase is fol there as well, i.e. a child beamlet continues its parent. [`Detector`](@ref)s store one per beamlet that hits them; it can also be built for any traced segment, e.g. to sample a beamlet on a plane of one's own. The projection factor is -`1` if the segment ends without an intersection. +`1` if the segment ends without an intersection. The hit keeps no reference to `agb`: a new +solve of `agb` does not change it. """ function AstigmaticGaussianBeamletHit(agb::AstigmaticGaussianBeamlet{R}, id::Integer) where {R} # Pre-calculate cache @@ -506,7 +546,7 @@ function AstigmaticGaussianBeamletHit(agb::AstigmaticGaussianBeamlet{R}, id::Int p0 = position(chief) d0 = direction(chief) k0 = 2π / wavelength(chief) - sqrt_proj = _projection_factor(chief) + sqrt_proj = sqrt(projection_factor(chief)) # Parabasal parameters at segment start (p0) h1, u1, h2, u2, _ = parabasal_ray_parameters(agb, p0, id) @@ -546,9 +586,9 @@ function AstigmaticGaussianBeamletHit(agb::AstigmaticGaussianBeamlet{R}, id::Int w_max = max(norm(H1), norm(H2)) n_eff = refractive_index(agb, id) - return AstigmaticGaussianBeamletHit( - agb, R(l0), Int(id), p0, d0, h1, u1, h2, u2, gouy0, ρ1, ρ2, k0, R(Δl), - n_eff, E_ref_amp, sqrt_proj, w_max) + return AstigmaticGaussianBeamletHit{R}( + R(l0), p0, d0, h1, u1, h2, u2, gouy0, ρ1, ρ2, k0, R(Δl), + n_eff, E_ref_amp, sqrt_proj, w_max, length(chief), wavelength(chief), E_vec) end # Geometric length of `beam` (including its parents) up to the start of ray `id` @@ -561,12 +601,6 @@ function _length_before(beam::Beam{T}, id::Integer) where {T} return l end -# √|d·n| of a ray ending on a surface with normal n; 1 without an intersection -function _projection_factor(ray::AbstractRay{T}) where {T} - isnothing(intersection(ray)) && return one(T) - return sqrt(abs(dot(direction(ray), normal3d(intersection(ray))))) -end - function interact3d(::AbstractSystem, d::Detector, g::GaussianBeamlet{R}, id::Int) where {R} push!(d, GaussianBeamletHit(g, id)) if stop(d) diff --git a/src/OpticalComponents/Detectors/DetectorUtils.jl b/src/OpticalComponents/Detectors/DetectorUtils.jl index 6e3b03e29..72c2e231c 100644 --- a/src/OpticalComponents/Detectors/DetectorUtils.jl +++ b/src/OpticalComponents/Detectors/DetectorUtils.jl @@ -171,7 +171,7 @@ function calc_local_pos( # Use cached parabasal parameters at segment start # Propagate to detector (end of segment) # chief segment length - l_seg = length(rays(hit.agb.c)[hit.id]) + l_seg = hit.l_seg h1 = (hit.h1 + l_seg * hit.u1) * crop_factor h2 = (hit.h2 + l_seg * hit.u2) * crop_factor diff --git a/src/OpticalComponents/Detectors/FieldCalculation.jl b/src/OpticalComponents/Detectors/FieldCalculation.jl index 755bac505..f2a1d0db0 100644 --- a/src/OpticalComponents/Detectors/FieldCalculation.jl +++ b/src/OpticalComponents/Detectors/FieldCalculation.jl @@ -92,13 +92,18 @@ function beamlet_hit_field(hit::GaussianBeamletHit{G}, p::AbstractArray) where { l1 = _pseudo_dot(v, hit.d0) # Transverse distance r - r_vec = v - l1 * hit.d0 - r = norm(r_vec) - - # Distance along beam - z = hit.l0 + l1 - - return _segment_field(hit.gauss, r, z, hit.p0 + l1 * hit.d0, hit.id, hit.l0, hit.Δl0, hit.ψ0) + r = norm(v - l1 * hit.d0) + + # Beam radius, curvature and Gouy phase from the waist and divergence rays of the segment + w, curv, ψ, _ = gauss_parameters(hit.segment, l1) + ψ += hit.ψ0 + + # Optical path up to the point, l0 + l1 along the beam. The curvature term is a geometric + # length like l1, hence it enters with the wavenumber n k0 of the medium as well. + k0 = wavenumber(hit.segment.λ) + n = hit.segment.n + opl = hit.l0 + l1 + hit.Δl0 + (n - 1) * l1 + return hit.E_amp / w * exp(-r^2 / w^2) * cis(k0 * opl + ψ + n * k0 * r^2 * curv / 2) end function beamlet_hit_field(hit::AstigmaticGaussianBeamletHit{G}, p::AbstractArray) where {G} @@ -151,7 +156,7 @@ function beamlet_hit_polarization(hit::AstigmaticGaussianBeamletHit) # `beamlet_hit_field` already carries the complex amplitude `E_ref_amp` (magnitude of the # polarization of the segment and phase of its largest component), so dividing it out # keeps amplitude and phase from being counted twice. - E = polarization(rays(hit.agb.c)[hit.id]) + E = hit.E_pol iszero(hit.E_ref_amp) && return zero(E) return E / hit.E_ref_amp end @@ -308,7 +313,7 @@ function electric_field( hit_data = map(hits) do hit dir = direction(hit) - p_hit = position(hit) + length(hit) * dir + p_hit = hit_point(hit) proj = projection_factor(hit) k = wavenumber(hit) opl = optical_path_length(hit) @@ -375,7 +380,7 @@ function electric_field( hit_data = map(hits) do hit dir = direction(hit) - p_hit = position(hit) + length(hit) * dir + p_hit = hit_point(hit) E0 = polarization(hit) k = wavenumber(hit) opl = optical_path_length(hit) diff --git a/src/OpticalComponents/Lenses.jl b/src/OpticalComponents/Lenses.jl index 802d1dd9c..dd75902d5 100644 --- a/src/OpticalComponents/Lenses.jl +++ b/src/OpticalComponents/Lenses.jl @@ -66,7 +66,7 @@ function interact3d(system::AbstractSystem, end # Calculate new dir. and pos. ndir, TIR = refraction3d(direction(ray), normal, n1, n2) - npos = position(ray) + length(ray) * direction(ray) + npos = hit_point(ray) # In case of TIR, update hint and n2 if TIR hint = Hint(optic) @@ -87,7 +87,7 @@ function interact3d(system::AbstractSystem, optic::AbstractRefractiveOptic, ::Beam{T, R}, ray::R) where {T <: Real, R <: PolarizedRay{T}} lambda = wavelength(ray) normal = normal3d(intersection(ray)) - raypos = position(ray) + length(ray) * direction(ray) + raypos = hit_point(ray) if isentering(ray) # Entering optic n1 = refractive_index(ray) diff --git a/src/OpticalComponents/Mirrors/Mirrors.jl b/src/OpticalComponents/Mirrors/Mirrors.jl index 6f56afa65..c9cb01c4e 100644 --- a/src/OpticalComponents/Mirrors/Mirrors.jl +++ b/src/OpticalComponents/Mirrors/Mirrors.jl @@ -39,7 +39,7 @@ function interact3d(::AbstractSystem, ::Beam{T, R}, ray::R) where {T <: Real, R <: Ray{T}} normal = normal3d(intersection(ray)) - npos = position(ray) + length(ray) * direction(ray) + npos = hit_point(ray) ndir = reflection3d(direction(ray), normal) return BeamInteraction{T, R}(nothing, Ray{T}(npos, ndir, nothing, wavelength(ray), refractive_index(ray))) @@ -56,7 +56,7 @@ function interact3d(::AbstractSystem, ::Beam{T, R}, ray::R) where {T <: Real, R <: PolarizedRay{T}} normal = normal3d(intersection(ray)) - npos = position(ray) + length(ray) * direction(ray) + npos = hit_point(ray) ndir = reflection3d(direction(ray), normal) # Jones reflection matrix J = SPBasis(-1, 0, 0, 1) diff --git a/src/OpticalComponents/Polarizers/LinearPolarizer.jl b/src/OpticalComponents/Polarizers/LinearPolarizer.jl index e65787a71..e2d55bc64 100644 --- a/src/OpticalComponents/Polarizers/LinearPolarizer.jl +++ b/src/OpticalComponents/Polarizers/LinearPolarizer.jl @@ -96,7 +96,7 @@ function _is_film_interface(lp::LinearPolarizer, from, ray::AbstractRay) nrm = normal3d(intersection(ray)) abs(dot(nrm, y)) ≥ 0.5 || return false c = position(lp) - p = position(ray) + length(ray) * direction(ray) + p = hit_point(ray) if from === lp.front return dot(p - c, y) > -thickness(lp.front) / 2 else @@ -117,7 +117,7 @@ function _film_interface(system::AbstractSystem, lp::LinearPolarizer, from, to, n2 = refractive_index(to, λ) normal = -normal3d(intersection(ray)) ndir, TIR = refraction3d(direction(ray), normal, n1, n2) - npos = position(ray) + length(ray) * direction(ray) + npos = hit_point(ray) if TIR hint = Hint(lp, shape(from)) n = n1 @@ -141,7 +141,7 @@ function _film_interface(system::AbstractSystem, lp::LinearPolarizer, from, to, n1 = refractive_index(from, λ) n2 = refractive_index(to, λ) normal = -normal3d(intersection(ray)) - npos = position(ray) + length(ray) * direction(ray) + npos = hit_point(ray) in_dir = direction(ray) θi = angle3d(in_dir, -normal) rs, rp, ts, tp = fresnel_coefficients(θi, n2 / n1) diff --git a/src/OpticalComponents/Polarizers/PolarizationFilter.jl b/src/OpticalComponents/Polarizers/PolarizationFilter.jl index 2512a8e04..e10ce4196 100644 --- a/src/OpticalComponents/Polarizers/PolarizationFilter.jl +++ b/src/OpticalComponents/Polarizers/PolarizationFilter.jl @@ -62,7 +62,7 @@ function interact3d(::AbstractSystem, polfilter::PolarizationFilter, ::Beam{T, R}, ray::R) where {T <: Real, R <: PolarizedRay{T}} - npos = position(ray) + length(ray) * direction(ray) + npos = hit_point(ray) ndir = direction(ray) E0 = _calculate_global_E0(polfilter, ray, ndir, polfilter.JMat) @@ -83,7 +83,7 @@ function interact3d( ray::R ) where {T <: Real, R <: Ray{T}} # unpolarized rays (e.g. beamlet auxiliary rays) pass through the ideal filter unchanged - npos = position(ray) + length(ray) * direction(ray) + npos = hit_point(ray) ndir = direction(ray) return BeamInteraction{T, R}(nothing, Ray{T}(npos, ndir, nothing, wavelength(ray), refractive_index(ray))) diff --git a/test/Components/TestDetector.jl b/test/Components/TestDetector.jl index 56019df9b..9ef431b70 100644 --- a/test/Components/TestDetector.jl +++ b/test/Components/TestDetector.jl @@ -357,6 +357,130 @@ end end end +@testset "Hits are values" begin + # https://github.com/JuliaPhysics/BeamletOptics.jl/issues/42: a hit holds no reference to the + # beam that made it, hence a vector of hits is one block of memory + for H in (BMO.RayHit, BMO.PolarizedRayHit, BMO.GaussianBeamletHit, BMO.AstigmaticGaussianBeamletHit) + @test isbitstype(H{Float64}) + end +end + +@testset "A new solve does not change the stored hits" begin + # https://github.com/JuliaPhysics/BeamletOptics.jl/issues/42 + @testset "Beam rotated between solves" begin + pd = Detector(50mm) + translate3d!(pd, [0, 100mm, 0]) + system = System([pd]) + beam = Beam([0.0, 0, 0], [0.0, 1, 0]) + for _ in 1:5 + solve_system!(system, beam) + zrotate3d!(beam, deg2rad(1)) + end + # the hit of the i-th solve lies 100 mm · tan((i − 1)°) to the side + xs = sort(abs.(first.(spot_diagram(pd)))) + @test xs ≈ 100mm .* tan.(deg2rad.(0:4)) atol = 1e-12 + end + E0 = [1.0, 0, 0] + beams = ( + "Beam" => () -> Beam([0.0, 0, 0], [0.0, 1, 0], 1e-6), + "Beam of PolarizedRays" => () -> Beam([0.0, 0, 0], [0.0, 1, 0], 1e-6, E0), + "GaussianBeamlet" => () -> GaussianBeamlet([0.0, 0, 0], [0.0, 1, 0], 1e-6, 1mm), + "AstigmaticGaussianBeamlet" => () -> AstigmaticGaussianBeamlet([0.0, 0, 0], [0.0, 1, 0], 1e-6, 1mm)) + # the hit is on the first ray, on the second ray behind a mirror, or on a child beam + for (label, beam) in beams, path in (:direct, :mirror, :splitter) + @testset "$label, $path" begin + pd = Detector(20mm) + system = System([pd]) + if path === :mirror + m = RoundPlanoMirror(30mm, 5mm) + zrotate3d!(m, deg2rad(45)) + translate3d!(m, [0, 50mm, 0]) + zrotate3d!(pd, deg2rad(90)) + translate3d!(pd, [100mm, 50mm, 0]) + push!(system, m) + else + translate3d!(pd, [0, 150mm, 0]) + end + if path === :splitter + bs = ThinBeamsplitter(30mm) + zrotate3d!(bs, deg2rad(45)) + translate3d!(bs, [0, 50mm, 0]) + push!(system, bs) + end + b = beam() + solve_system!(system, b) + before = only(BMO.hits(pd)) + # move the source and the mirror or splitter, the beam still hits the detector + translate3d!(b, [0, 0, 0.5mm]) + path === :mirror && translate3d!(m, [5mm, 0, 0]) + path === :splitter && translate3d!(bs, [0, 10mm, 0]) + solve_system!(system, b) + @test BMO.hit_count(pd) == 2 + @test first(BMO.hits(pd)) === before + @test BMO.hit_point(last(BMO.hits(pd)))[3] ≈ 0.5mm + end + end + @testset "Field of a stored GaussianBeamletHit" begin + # free space from the waist: E0 w0 / w(L) · exp(i (k L − atan(L / z_R))) on the axis + λ, w0, L = 1e-6, 0.5mm, 300mm + pd = Detector(20mm) + translate3d!(pd, [0, L, 0]) + system = System([pd]) + gb = GaussianBeamlet([0.0, 0, 0], [0.0, 1, 0], λ, w0) + solve_system!(system, gb) + hit = only(BMO.hits(pd)) + translate3d!(gb, [0, 0, 1mm]) + solve_system!(system, gb) + z_R = π * w0^2 / λ + w = w0 * sqrt(1 + (L / z_R)^2) + E = electric_field(gb) * w0 / w * cis(2π / λ * L - atan(L / z_R)) + # the waist and divergence rays give the Gouy phase to about 1e-7 rad + @test BMO.beamlet_hit_field(first(BMO.hits(pd)), BMO.Point3(0.0, L, 0.0)) ≈ E rtol = 1e-6 + @test first(BMO.hits(pd)) === hit + end +end + +@testset "Moving a detector empties it" begin + pivot = [1mm, 2mm, 3mm] + R = BMO.rotate3d([0.0, 0, 1], 0.1) + moves = ( + "translate3d!" => pd -> translate3d!(pd, [0, 1mm, 0]), + "translate_to3d!" => pd -> translate_to3d!(pd, [0, 120mm, 0]), + "reset_translation3d!" => pd -> reset_translation3d!(pd), + "rotate3d!(R)" => pd -> rotate3d!(pd, R), + "rotate3d!(R, pivot)" => pd -> rotate3d!(pd, R, pivot), + "rotate3d!(axis, θ)" => pd -> rotate3d!(pd, [0.0, 0, 1], 0.1), + "rotate3d!(axis, θ, pivot)" => pd -> rotate3d!(pd, [0.0, 0, 1], 0.1, pivot), + "xrotate3d!" => pd -> xrotate3d!(pd, 0.1), + "yrotate3d!" => pd -> yrotate3d!(pd, 0.1), + "zrotate3d!" => pd -> zrotate3d!(pd, 0.1), + "align3d!" => pd -> align3d!(pd, [0.1, 1, 0]), + "reset_rotation3d!" => pd -> reset_rotation3d!(pd), + "translate3d! of a group" => pd -> translate3d!(ObjectGroup([pd]), [0, 1mm, 0]), + "zrotate3d! of a group" => pd -> zrotate3d!(ObjectGroup([pd]), 0.1)) + for (label, move!) in moves + @testset "$label" begin + pd = Detector(50mm) + translate3d!(pd, [0, 100mm, 0]) + solve_system!(System([pd]), Beam([0.0, 0, 0], [0.0, 1, 0])) + @test BMO.hit_count(pd) == 1 + move!(pd) + @test isnothing(BMO.hits(pd)) + end + end + @testset "Moving other objects keeps the hits" begin + pd = Detector(50mm) + translate3d!(pd, [0, 100mm, 0]) + lens = ThinLens(80mm, 80mm, 4mm, 1.5) + translate3d!(lens, [0, 50mm, 0]) + beam = Beam([0.0, 0, 0], [0.0, 1, 0]) + solve_system!(System([lens, pd]), beam) + translate3d!(lens, [1mm, 0, 0]) + translate3d!(beam, [0, 0, 1mm]) + @test BMO.hit_count(pd) == 1 + end +end + end # TESTSET end # MODULE \ No newline at end of file diff --git a/test/TestOpticsBaseExt.jl b/test/TestOpticsBaseExt.jl index 90e2d9ec6..8f930ffc6 100644 --- a/test/TestOpticsBaseExt.jl +++ b/test/TestOpticsBaseExt.jl @@ -454,18 +454,18 @@ end end @testset "PlaneField of one traced beamlet segment" begin - det = trace!(detector_at(zdet), agb_at()) - hit = only(BMO.hits(det)) + agb = agb_at() + det = trace!(detector_at(zdet), agb) fd = PlaneField(det; size = (48, 48), spacing = (w0 / 6, w0 / 6), progress = false) - fb = PlaneField(hit.agb, hit.id; size = (48, 48), spacing = (w0 / 6, w0 / 6), + fb = PlaneField(agb, length(BMO.rays(agb.c)); size = (48, 48), spacing = (w0 / 6, w0 / 6), origin = fd.origin, axes = fd.axes) @test fb.E == fd.E && fb.H == fd.H @test fb.origin == fd.origin && fb.axes == fd.axes && fb.n == fd.n # stigmatic beamlets too - det = trace!(detector_at(zdet), BMO.GaussianBeamlet([0.0, 0, 0], [0.0, 1, 0], λ, w0; P0)) - hit = only(BMO.hits(det)) + gb = BMO.GaussianBeamlet([0.0, 0, 0], [0.0, 1, 0], λ, w0; P0) + det = trace!(detector_at(zdet), gb) fd = PlaneField(det; size = (32, 32), spacing = (w0 / 4, w0 / 4), progress = false) - fb = PlaneField(hit.gauss, hit.id; size = (32, 32), spacing = (w0 / 4, w0 / 4), + fb = PlaneField(gb, length(BMO.rays(gb.chief)); size = (32, 32), spacing = (w0 / 4, w0 / 4), origin = fd.origin, axes = fd.axes) @test fb.E == fd.E end