Grating RCWA API¶
rcwa
¶
Differentiable RCWA for 1D-periodic gratings of full-tensor anisotropic media.
Periodic in x, uniform in y, layered in z; each segment has its own 3×3 ε and μ
in any orientation, and incidence may be conical. Layers use the cascade of
:mod:hyperbolic_optics.bcm on 4N × 4N Fourier-space operators, so
everything, the geometry's Fourier coefficients included, is differentiable.
Fourier factorisation¶
Across an x-discontinuity the components Dx, Ey, Ez (and Bx, Hy, Hz) are
continuous. The constitutive relation is therefore first solved for
(Ex, Dy, Dz) in terms of (Dx, Ey, Ez): every product in that form pairs
a discontinuous coefficient with a continuous field, for which Laurent's rule
(a Toeplitz matrix of Fourier coefficients) converges. The result is then
rearranged back into D = [[ε]]·E with the inverse taken only in Fourier
space. This is Li's factorisation for anisotropic lamellar gratings (L. Li,
J. Mod. Opt. 45, 1313 (1998)); for an isotropic medium it reduces to the
familiar inverse rule for Dx and Laurent's rule for Dy and Dz.
factorization="laurent" uses plain Toeplitz matrices of ε (slow for TM
light on high-contrast gratings).
Conventions¶
Fields and time dependence follow :mod:hyperbolic_optics.bcm. Harmonic m
has in-plane wavevector (kx₀ + m·λ/Λ, ky) (normalised by k₀). Every
order's amplitudes are resolved into that order's own p and s: s is
perpendicular to its plane of diffraction, along ẑ × û with û the unit
in-plane wavevector, and p completes the triad with the sign convention of the
planar solver. (At exactly zero in-plane wavevector û is taken along the
plane of incidence.) Results are indexed [..., order, out, in] with 0 = p and
1 = s; R and T are diffraction efficiencies, zero for evanescent orders.
Classes:
-
GratingLayer–One layer:
Ssegments of constant material across one period. -
GratingResult–Complex amplitudes and efficiencies, each
[..., order, out, in].
Functions:
-
uniform_layer–A homogeneous layer,
eps[..., 3, 3]. -
lamellar_layer–Ridge of width
fill(fraction of the period) starting atoffset. -
sampled_layer–A profile sampled at
Sequal-width segments,[..., S, 3, 3]. -
fourier_coefficients–Exact Fourier coefficients
c_m,|m| ≤ max_index, of a step function. -
default_doublings–Doublings that keep the slice error at the planar level as orders are added.
-
solve_grating–Diffraction of a plane wave by a stack of 1D-periodic anisotropic layers.
GratingLayer
¶
Bases: NamedTuple
One layer: S segments of constant material across one period.
Attributes:
-
thickness_um(Array) –Layer thickness in µm,
[...]. -
boundaries(Array) –Segment edges as fractions of the period,
[..., S + 1], increasing, withboundaries[S] − boundaries[0] = 1. -
eps(Array) –Segment permittivity tensors in the lab frame,
[..., S, 3, 3]. -
mu(Array | None) –Segment permeability tensors, same layout;
Nonefor μ = 1. -
edge_width(Array | float) –Optional smoothing, as a fraction of the period: the profile is convolved with a box this wide, which multiplies Fourier coefficient
mbysinc(m · edge_width).0keeps hard edges. A few percent removes the truncation ripple that makes geometry gradients of hyperbolic (high-k) ridges unusable; see docs/user-guide/gratings.md.
GratingResult
¶
Bases: NamedTuple
Complex amplitudes and efficiencies, each [..., order, out, in].
uniform_layer
¶
A homogeneous layer, eps [..., 3, 3].
Source code in hyperbolic_optics/rcwa.py
lamellar_layer
¶
lamellar_layer(
eps_ridge,
eps_groove,
fill,
thickness_um,
offset=0.0,
mu_ridge=None,
mu_groove=None,
edge_width=0.0,
)
Ridge of width fill (fraction of the period) starting at offset.
fill and offset enter the Fourier coefficients analytically, so the
layer is differentiable in both. edge_width smooths the edges (see
:class:GratingLayer).
Source code in hyperbolic_optics/rcwa.py
sampled_layer
¶
A profile sampled at S equal-width segments, [..., S, 3, 3].
Source code in hyperbolic_optics/rcwa.py
fourier_coefficients
¶
Exact Fourier coefficients c_m, |m| ≤ max_index, of a step function.
f(x) = Σ_m c_m exp(2πi·m·x) over one period, with f = values[s] on
[boundaries[s], boundaries[s + 1]). Analytic in the boundaries.
Parameters:
-
values(Array) –[..., S]. -
boundaries(Array) –[..., S + 1]. -
max_index(int) –Highest
|m|.
Returns:
-
Array–[..., 2·max_index + 1], indexm + max_index.
Source code in hyperbolic_optics/rcwa.py
default_doublings
¶
Doublings that keep the slice error at the planar level as orders are added.
The operator's norm grows as kx_max² ∝ max_order² and the fourth-order
start leaves an error ∝ (norm · k₀d)⁵ / 2⁴ᴺ, so holding it fixed takes
2.5 · log₂(max_order / 10) extra doublings beyond ten orders. At 161
orders this is 28 doublings, which brings a lossless grating's energy error
from ~1e-7 (at 20) down to its ~1e-9 rounding floor.
Source code in hyperbolic_optics/rcwa.py
solve_grating
¶
solve_grating(
layers,
period_um,
wavelength_um,
incidence_rad,
eps_incident,
eps_exit,
max_order,
azimuth_rad=0.0,
factorization="li",
doublings=None,
)
Diffraction of a plane wave by a stack of 1D-periodic anisotropic layers.
Parameters:
-
layers(list[GratingLayer]) –:class:
GratingLayers from the incident side down; build them with :func:uniform_layer, :func:lamellar_layeror :func:sampled_layer. -
period_um(Array) –Grating period in µm, along x.
-
wavelength_um(Array) –Vacuum wavelength in µm.
-
incidence_rad(Array) –Polar angle of incidence in the incident medium.
-
eps_incident(Array) –Real, positive permittivity of the incident half-space.
-
eps_exit(Array) –Real, positive permittivity of the exit half-space.
-
max_order(int) –Keep diffraction orders
−max_order … max_order(static). -
azimuth_rad(Array, default:0.0) –Angle of the plane of incidence from the grating vector (x); nonzero gives conical diffraction.
-
factorization(str, default:'li') –"li"(default) or"laurent"(static). -
doublings(int | None, default:None) –Doublings per layer (static), as in :mod:
hyperbolic_optics.bcm. Defaults to :func:default_doublingsformax_order.
Returns:
-
GratingResult–class:
GratingResult;orderslists the orders, andr,t, -
GratingResult–R,Tare[..., order, out, in]with 0 = p and 1 = s. Only the -
GratingResult–zeroth order is incident.
Source code in hyperbolic_optics/rcwa.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |