Skip to content

A binary grating: where the diffraction orders go

RCWA binary_grating_orders.py

A plane wave hits a periodic slab at normal incidence: a high-index ridge filling half of each unit cell. While the period is shorter than the wavelength only the straight-through beam exists, and the slab acts as a uniform layer; that is the regime metasurfaces work in. Once the period passes one wavelength the \(\pm1\) orders open, and the same slab sends most of the light it transmits sideways.

Animation over the grating period from 0.55 to 2 wavelengths. Top: transmitted zeroth order, the sum of the two first orders and the reflectance against the period, with a marker moving along the curves; the first orders are flat at zero until the period reaches one wavelength and then switch on. Bottom: the field intensity in a vertical slice through the cell, repeated to fill the width, with the high-index ridges outlined in white and light entering from the top.

Top: the efficiencies against the period. Bottom: \(|E|^2\) on a vertical slice through the cell, in units of the incident intensity.

The problem

The scalar Helmholtz equation in a cell of period \(\Lambda\), with Floquet periodicity in \(x\) and \(y\), a plane wave coming in from below and radiation conditions top and bottom:

\[\nabla\!\cdot\nabla u + k_0^2\,\varepsilon(x)\,u = 0 .\]

The grating equation decides which orders escape as propagating waves:

\[\sin\theta_m = \sin\theta_i + m\,\frac{\lambda}{\Lambda} \qquad\Longrightarrow\qquad \text{order } m \text{ propagates} \iff \left|m\,\frac{\lambda}{\Lambda}\right| \le 1 .\]

So the \(\pm1\) orders switch on at \(\Lambda=\lambda\), the Rayleigh anomaly.

The jNO code

The term list is the weak form you would hand jno.fem, with nothing RCWA-specific in it:

rc = jno.rcwa(
    [
        jno.np.inner(grad(u), grad(v)) - K0**2 * eps * u * v,  # ∇u·∇v − k₀²ε u v = 0
        -1j * K0 * u(*top) * v(*top),  # radiation out through the top
        -(1j * K0 * u(*bottom) - 2j * K0) * v(*bottom),  # plane wave in, radiation out at the bottom
        u(*left) - u(*right),  # Floquet periodicity in x
        u(*front) - u(*back),  # and in y
    ],
    orders=orders,
    grid=grid,
)  # rc.spec holds what was inferred from the list
sol = rc.solve()

jno.rcwa reads everything else from the list: the period from the Floquet ties, the ambients from the two radiation faces, the layers and \(\varepsilon\) from the volume coefficient, the wavelength from \(\varepsilon\) in the superstrate, and the polarization from the equation (the ridges run along \(y\), so the scalar field is \(E_y\), TE). Only the truncation is yours: orders Fourier terms and a grid to sample \(\varepsilon\) on. Because eps is an analytic jno.fn, it is sampled on that grid directly, and the mesh only carries the tags. rc.spec shows what was inferred:

RcwaSpec(period=(1.5, 0.3), layers=3, wavelength=1.0, k_in=(0.0, 0.0), source_face='bottom')
rc.spec.polarization       (0j, (1+0j))   # E along y

Result

Λ = 0.6: grating equation allows m ∈ [0]
  R = 0.00323   T = 0.99677   R + T = 1.000000
Λ = 1.5: grating equation allows m ∈ [-1, 0, 1]
  R = 0.84594   T = 0.15406   R + T = 1.000000
  T(-1) = 0.06879   T(+0) = 0.01648   T(+1) = 0.06879

At \(\Lambda=1.5\) the reflectance is within \(2\times10^{-3}\) of an independent RCWA with exact Fourier coefficients (0.8441). The script asserts:

check holds to
energy conservation \(R+T=1\) (lossless) \(10^{-15}\)
orders outside \(\lvert m\lambda/\Lambda\rvert\le1\) carry no power exactly 0.0
mirror symmetry \(T(+1)=T(-1)\) at normal incidence \(10^{-10}\)
the propagating orders sum to \(T\) \(10^{-6}\)

Every efficiency is a differentiable JAX scalar, so a jno.np.parameter in eps turns this into an inverse-design problem; see RCWA.

Full script

The whole script, as it runs in the tests
"""Binary dielectric grating: where the diffraction orders go, with ``jno.rcwa``.

A plane wave at normal incidence hits a periodic slab, a high-index ridge filling half of each cell. Order m
propagates when |m λ/Λ| ≤ 1 (the grating equation); sweeping the period Λ through λ switches the ±1 orders
on, the Rayleigh anomaly. The problem is the scalar-Helmholtz term list ``jno.fem`` would take; ``jno.rcwa``
reads period, ambients, layers, ε and wavelength out of it. Only the truncation (``orders``, ``grid``) is ours.
"""

import jax

jax.config.update("jax_enable_x64", True)  # modal eigen-decomposition of a high-contrast stack

import jax.numpy as jnp
import numpy as np

import jno

run = jno.setup(__file__)
WL, EPS_RIDGE, DUTY = 1.0, 11.0, 0.5  # wavelength, ridge permittivity (n ≈ 3.3), ridge fraction of the cell
Z0, Z1, PY = 0.4, 0.6, 0.3  # slab z ∈ (0.4, 0.6) in vacuum; y-period sub-wavelength, so a 1-D grating
K0 = 2 * jnp.pi / WL


def grating(period, orders=160, grid=256):
    """Solve one grating; return its efficiencies and the solution."""
    d = jno.shape.box(0, 0, 0, period, PY, 1.0, size=0.25).domain()  # coarse mesh: ε is sampled on the RCWA grid
    x, y, z, _ = d.variable("interior", split=True)
    left, right, front, back, top, bottom = (
        d.variable(s, split=True) for s in ("left", "right", "front", "back", "top", "bottom")
    )
    u = d.unknown()
    v = u.test()
    grad = lambda w: jno.np.jacobian(w, [x, y, z])
    ridge = jno.fn(lambda x, y, z: jnp.where((Z0 < z) & (z < Z1) & (x < DUTY * period), 1.0, 0.0), [x, y, z])
    eps = 1.0 + (EPS_RIDGE - 1.0) * ridge

    rc = jno.rcwa(
        [
            jno.np.inner(grad(u), grad(v)) - K0**2 * eps * u * v,  # ∇u·∇v − k₀²ε u v = 0
            -1j * K0 * u(*top) * v(*top),  # radiation out through the top
            -(1j * K0 * u(*bottom) - 2j * K0) * v(*bottom),  # plane wave in, radiation out at the bottom
            u(*left) - u(*right),  # Floquet periodicity in x
            u(*front) - u(*back),  # and in y
        ],
        orders=orders,
        grid=grid,
    )  # rc.spec holds what was inferred from the list
    sol = rc.solve()

    real = lambda a: float(jnp.real(jnp.asarray(a)))
    return dict(
        T=real(sol.efficiency("T")),
        R=real(sol.efficiency("R")),
        orders={m: real(sol.order(m, 0)) for m in (-2, -1, 0, 1, 2)},
        sol=sol,
    )


propagating = lambda period: [m for m in (-2, -1, 0, 1, 2) if abs(m * WL / period) <= 1.0]  # the grating equation

# --- two regimes: sub-wavelength (Λ < λ) and diffractive (Λ > λ) ---
SUB, DIF = 0.6, 1.5
res = {P: grating(P) for P in (SUB, DIF)}
for P, r in res.items():
    prop, o = propagating(P), r["orders"]
    print(f"Λ = {P}: grating equation allows m ∈ {prop}")
    print(f"  R = {r['R']:.5f}   T = {r['T']:.5f}   R + T = {r['R'] + r['T']:.6f}")
    print("  " + "   ".join(f"T({m:+d}) = {o[m]:.5f}" for m in (-1, 0, 1)))
    assert abs(r["R"] + r["T"] - 1.0) < 1e-6  # lossless: energy is conserved
    assert all(o[m] < 1e-9 for m in o if m not in prop)  # orders the grating equation forbids are dark
    assert abs(o[+1] - o[-1]) < 1e-6  # mirror symmetry at normal incidence (floor ~1e-10, set by the eigensolve)
    assert abs(sum(o[m] for m in prop) - r["T"]) < 1e-6  # the propagating orders carry all of T
assert res[SUB]["orders"][+1] == 0.0  # below the cutoff the ±1 orders are exactly dark
assert res[DIF]["orders"][+1] + res[DIF]["orders"][-1] > 0.8 * res[DIF]["T"]  # above it they take most of T

# --- sweep the period across the Rayleigh anomaly at Λ = λ (Λ = mλ itself is singular: jno.rcwa raises) ---
periods = np.concatenate([np.linspace(0.55, 0.95, 5), np.linspace(1.05, 1.95, 8)])
sweep = [grating(float(P)) for P in periods]
first_on = next(P for P, r in zip(periods, sweep) if r["orders"][+1] > 1e-6)
assert first_on > WL and all(abs(r["R"] + r["T"] - 1.0) < 1e-6 for r in sweep)
print(f"swept {len(periods)} periods; the ±1 orders first carry power at Λ = {first_on:.2f} (cutoff Λ = λ = {WL})")