OpticsBase.jl

OpticsBase.jl logo
OpticsBase.OpticsBase — Module
OpticsBase

Minimal interface package for coupling optical solvers, i.e. numerical solutions of Maxwell's equations. There is a single exchange format, PlaneField: the tangential electric and magnetic field sampled on a plane in 3D space. By the surface equivalence theorem it determines the field on both sides of the plane, so every solver (beamlets, BPM, angular spectrum, FDTD, FEM, RCWA, ...) can produce and consume it.

OpticsBase contains no solver code and no solver interface. Solvers couple by function composition: a package offers methods that return a PlaneField and methods that take one.

All quantities are in SI units. See the "Conventions" page of the documentation for the binding time, phase, power and polarization conventions.

source

A chain of solvers

Every solver package offers methods that return a PlaneField and methods that take one. A chain is plain function composition:

using BeamletOptics, BeamletFibers, OpticsBase

f1 = PlaneField(detector; size = (256, 256), spacing = (0.25e-6, 0.25e-6))  # beamlets → field
f2, stats = propagate(f1, fiber, FDBPM(dz = 1e-6); grid)                   # BPM through a fiber
src = WavefrontBeamletDecomposition(f2)                                     # field → beamlets

There is no solver interface to implement, no traits and no converter registry. A new solver package only needs to read and write the fields of PlaneField according to the Conventions.

Reference

OpticsBase.PlaneField — Type
PlaneField(E, H, spacing, origin, axes, λ; n = 1, R = Inf)
PlaneField(E, spacing, origin, axes, λ; n = 1, R = Inf)

Monochromatic, coherent electromagnetic field given by its tangential components E and H on a regularly sampled plane in 3D space. This is the only exchange format of OpticsBase: solvers hand fields to each other as PlaneFields.

The first form takes both fields and is exact for any field. The second form takes E only and fills in H for a local plane wave along the reference direction of each sample (n if R = Inf, otherwise the ray of the reference sphere through the sample, see reference_phase), with E completed to be transverse to that direction. It is exact for a wave travelling along the reference direction; for a plane wave at the angle θ to it, H is off by the order of 1 − cos θ. With an nx × ny matrix E the field is scalar and is put into Eu (Ev = 0).

Arguments

  • E: nx × ny × 2 array of (Eu, Ev), the electric field along the plane axes u, v, in [V/m] (peak amplitude, not RMS).
  • H: nx × ny × 2 array of (Hu, Hv) in [A/m] (peak amplitude).
  • spacing: sample spacings (Δu, Δv) in [m]. Sample (i, j) sits at (coordinates(f, 1)[i], coordinates(f, 2)[j]), with the origin at the fftshift center (see coordinates).
  • origin: center of the plane in global coordinates in [m].
  • axes: 3 × 3 matrix with the columns u, v, n. Orthonormal to within 1e-6 (axes computed in single precision are accepted) and right-handed (u × v = n). n is the positive normal: power counts the flux along +n as positive, and forward is the part travelling towards the +n side. u fixes the polarization basis.
  • λ: vacuum wavelength in [m].
  • n: real refractive index of the medium at the plane.
  • R: radius of the reference sphere in [m], see reference_phase. Inf: no reference sphere. R > 0: diverging from the point origin − R n; R < 0: converging to origin + |R| n.

Medium

The plane must lie in a homogeneous, isotropic, lossless and non-magnetic medium of index n, at least across the sampled region. E and H themselves are exact in any medium, but n enters the E-only constructor, forward/backward, reference_phase and the normal components below. A plane through an inhomogeneous structure, e.g. a fiber cross-section, has no single n: place it in the surrounding medium instead.

Conventions

  • Time convention exp(−iωt); a plane wave is exp(i(k·r − ωt)).
  • The physical fields are E .* reference_phase(f) and H .* reference_phase(f). They contain the full spatial phase, including the absolute optical path from the reference point of the chain (set by the first solver, typically the source).
  • The normal components are not stored. They follow from Maxwell's curl equations on the plane (non-magnetic medium): En = i Z₀/(k₀ n²) (∂u Hv − ∂v Hu) and Hn = −i/(k₀ Z₀) (∂u Ev − ∂v Eu), with k₀ = 2π/λ, applied to the physical fields.
  • A field that does not fit a single plane is a Vector{PlaneField}: a closed Huygens surface (normals outward), a spectrum (one field per line, common time origin t = 0) or mutually incoherent components (powers add). The vector has no meaning of its own; the function that returns or takes it documents which one it is. See the "Conventions" page.

Fields

  • E, H, spacing, origin, axes, λ, n, R: as above. origin is an SVector{3}, axes an SMatrix{3, 3}. The fields are the public API; there are no accessor functions.

Arrays and geometry have independent precision. The geometry type T (of spacing, origin, axes, λ, n, R) follows from spacing, origin, axes and λ, so a Float32 field can sit at a Float64 position. E and H keep their own (complex, floating point) element type and are stored in the array type A of similar(E) (e.g. Array or a GPU array); an argument that already has that type is stored without a copy, any other (e.g. a view) is copied.

source
OpticsBase.VACUUM_IMPEDANCE — Constant
VACUUM_IMPEDANCE

Impedance of free space Z₀ = μ₀ c = 376.730313668 Ω (CODATA 2018, the same literal as BeamletOptics' Z_vacuum).

source
OpticsBase.coordinates — Function
coordinates(f::PlaneField, d)

Sample positions along u (d = 1) or v (d = 2) in [m], relative to f.origin: sample i sits at (i − 1 − N÷2) Δ, with N the number of samples and Δ the spacing along that axis. The origin is the fftshift center, so there is always a sample at 0. The global position of sample (i, j) is f.origin + u coordinates(f, 1)[i] + v coordinates(f, 2)[j].

source
OpticsBase.reference_phase — Function
reference_phase(f::PlaneField)

nx × ny array of the phase factor of the reference sphere, exp(i s k₀ n (√(ρ² + R²) − |R|)) with s = sign(R), ρ the distance from f.origin in the plane and k₀ = 2π/λ. Multiplying f.E and f.H by it gives the physical fields. The factor is 1 at the origin and everywhere if R = Inf. It has the element type and array type of f.E.

The reference sphere keeps curved wavefronts cheap to sample: only the deviation from the sphere is stored. A beam converging to a focus at the distance F behind the plane has R = −F, one diverging from a point at the distance F before it has R = F. The rays of the sphere are also the local reference directions of the E-only constructor and of forward/backward.

source
OpticsBase.power — Function
power(f::PlaneField)

Net power through the plane in [W]: the time-averaged Poynting flux along n, P = ½ Re ∫ (E × H*)·n dA = ½ Re ∫ (Eu Hv* − Ev Hu*) dA, as a Riemann sum over the samples. Exact, with no paraxial factor; negative if more power travels along −n than along n. The reference phase cancels, so R does not enter.

source
OpticsBase.forward — Function
forward(f::PlaneField)
backward(f::PlaneField)

Part of f travelling forward (along the reference direction, dn > 0) or backward, as a PlaneField on the same plane. Each sample is split as a pair of local plane waves with the transverse direction of the reference direction (see the E-only constructor of PlaneField): with the tangential admittance M of the forward wave (Ht = M Et; the backward wave has −M), E± = ½ (Et ± M⁻¹ Ht) and H± = ±M E±. For R = Inf the reference direction is n and this is E± = ½ (Et ∓ (Z₀/n) n × Ht). forward(f) + backward(f) restores f, and the powers of the parts add up to power(f).

The split is exact for waves along the reference direction. A plane wave at the angle θ to it leaks a spurious backward amplitude of the order (1 − cos θ)/2 (exactly that for s-polarization), so forward is meant for fields that may contain both directions. A consumer that knows its input travels one way should take f.E directly. An exact split per plane wave of the angular spectrum needs an FFT and belongs in a solver.

source