A rectangular waveguide is a hollow metal pipe that carries one electromagnetic mode at a time above a cutoff frequency. This case drives the dominant TE10 mode down a standard WR-90 guide (X-band) and reads the two-port S-parameters. An ideal empty guide should pass the mode with almost no reflection — and because the matched empty-guide answer is known in closed form, it is a clean absolute check on the waveguide port.
The structure

A WR-90 guide: broad wall a = 22.86 mm, narrow wall b = 10.16 mm, metal (PEC) walls, hollow air inside. The mode is launched at the left port and collected at the right port. Both end faces are absorbing (CPML); the four side walls are PEC.
What this is
The dominant mode of a rectangular guide is TE10. It only propagates above the
cutoff frequency set by the broad-wall width: f_c = c / (2·a). For WR-90,
a = 22.86 mm gives f_c ≈ 6.557 GHz, so the X-band (8.2–12.4 GHz) sits
comfortably above cutoff and the TE10 mode travels cleanly. Below f_c the mode
is evanescent and the guide rejects it. Filling the whole guide with a
dielectric εr lowers the cutoff to f_c,d = f_c / √εr; the autodiff section
below fills only a short section instead, whose two faces reflect.
What you’ll learn
- Launching the TE10 dominant mode with a mode-matched waveguide port (a one-sided mode injection, not a soft point source).
- The cutoff relation
f_c = c/(2·a)and why X-band propagates in WR-90 while lower frequencies would not. - Reading two-port |S11| (reflection) and |S21| (transmission) against the
exact matched empty-guide answer (
|S11| = 0,|S21| = 1). - Taking a gradient through the FDTD solver with
jax.grad: how|S21|²responds to the guide’s dielectric fill, checked against central finite differences of the same model for one float32 computation. The case has no check against a longer run.
Geometry & materials
import numpy as npC0 = 299_792_458.0
a_wg = 22.86e-3 # WR-90 broad wall (sets the TE10 cutoff)b_wg = 10.16e-3 # WR-90 narrow wallf_c = C0 / (2 * a_wg) # TE10 cutoff: c / (2a) -> 6.557 GHzdx = 1.27e-3 # 18 x 8 cells: both walls land on the gridfreqs = np.linspace(8.2e9, 12.4e9, 21) # X-band sweepThe guide is hollow air inside PEC walls. The only material knob is the optional dielectric fill used in the gradient demonstration below.
Source, ports, boundaries, mesh
- Two TE10 waveguide ports. The left port (
direction="+x") launches the mode; the right port (direction="-x") acts as a matched load. Each port injects the discrete Yee-grid mode profile, so the launcher back-reflection is minimal. - CPML on the propagation axis only (26 cells, 33 mm). That is half a guide wavelength at 8.2 GHz, the depth the calculator’s absorber advisory asks for. Only the two x faces absorb.
- PEC side walls. The four y/z walls are PEC — that is what defines a rectangular guide and its cutoff.
- Uniform 1.27 mm mesh. 18 cells span the broad wall and 8 the narrow wall, so the solved guide is exactly 22.86 × 10.16 mm, with about 24 cells per free-space wavelength at 10 GHz.
A cell size that does not fit a wall-to-wall length to within 1 % is refused: at
1 mm the narrow wall would be solved as 10 mm, 1.57 % short. snap="declared"
accepts such a length with a warning; 1.27 mm needs neither.
Geometry check (before running)
The render above confirms the guide before committing compute: broad wall a, narrow wall b, the two port planes set back from the absorbers, and clearance to the CPML on both ends. An empty WR-90 run at 1.27 mm (about 36k cells with the absorbers, about 6,000 steps for each of the two driven ports) finishes in under a minute on a CPU; the Python process peaked at about 750 MB.
Run
import numpy as np, jax.numpy as jnpfrom rfx.api import Simulationfrom rfx.boundaries.spec import Boundary, BoundarySpec
a_wg, b_wg, dx = 22.86e-3, 10.16e-3, 1.27e-3freqs = np.linspace(8.2e9, 12.4e9, 21)f0 = float(freqs.mean())bandwidth = float(freqs[-1] - freqs[0]) / f0 # 0.41# Lengths along x in whole cells, so the two ports are mirror images on the grid.domain_x = 158 * dx # 200.66 mmport_x, ref_x = 31 * dx, 39 * dx # 39.37 mm and 49.53 mm from each end
sim = Simulation( freq_max=float(freqs[-1]) * 1.1, domain=(domain_x, a_wg, b_wg), dx=dx, boundary=BoundarySpec(x=Boundary(lo="cpml", hi="cpml"), y=Boundary(lo="pec", hi="pec"), z=Boundary(lo="pec", hi="pec")), cpml_layers=26,)port_freqs = jnp.asarray(freqs)sim.add_waveguide_port(port_x, direction="+x", mode=(1, 0), mode_type="TE", freqs=port_freqs, f0=f0, bandwidth=bandwidth, waveform="modulated_gaussian", reference_plane=ref_x, name="left")sim.add_waveguide_port(domain_x - port_x, direction="-x", mode=(1, 0), mode_type="TE", freqs=port_freqs, f0=f0, bandwidth=bandwidth, waveform="modulated_gaussian", reference_plane=domain_x - ref_x, name="right")
result = sim.compute_waveguide_s_matrix(num_periods=200, normalize=False)Run it from the command line:
python scripts/precompute_gallery_artifacts.py --case waveguide_wr90The run prints three notes. Preflight says the top of the band, 12.4 GHz, is above
0.9 of the TE20 cutoff (13.1 GHz): TE20 is odd across the broad wall, so the
symmetric TE10 launch does not excite it in an empty guide, and |S11| stays
smooth to 12.4 GHz. The calculator says that with normalize=False the S21
phase includes Yee dispersion; this page reads magnitudes. The port check finds
the two ports at mirror positions on the grid and reports, as information, the
one-cell shift of the -x port’s source plane that rfx applies by design. Ports
at half-cell positions do not land on mirror nodes, and the check then warns that
they are not mirror images; the block above puts both ports and both reference
planes on whole cells.
Fields
E_z on the broad-wall mid-plane of a source-fed empty guide, captured once the pulse has propagated to mid-guide. The field is a half-sine across the broad wall — peaking at the centre and vanishing at the PEC side walls — travelling in the +x direction, with the next half-cycle of opposite sign following behind. That is the TE10 mode moving down the guide.

The same mode in motion: the TE10 wave packet propagates in the +x direction down the guide and into the matched absorber, holding its half-sine profile across the broad wall as it travels.

Result
Across the X-band |S21| sits at about 0 dB and |S11| stays below 0.0062 (−44.2 dB). An empty matched guide above cutoff should pass the TE10 mode with no reflection; the small residual is the port’s, measured below.

Validation & limits
The empty matched guide has an exact answer: |S11| = 0 and |S21| = 1 at every
frequency above cutoff. The figure plots how far rfx is from it, |S11| and
|S21| − 1, in units of 10⁻³.
| Observable, 8.2–12.4 GHz | rfx | Reference | Tolerance | Pass |
|---|---|---|---|---|
| max|S11| | 0.0062 | 0 (exact matched guide) | < 0.02 | yes |
| |S21| | 0.9987 to 1.0006 | 1 (exact matched guide) | > 0.97 | yes |
|S11| rises smoothly from 0.0039 at 8.2 GHz to 0.0062 near the top of the band.
|S21| passes 1 above 12 GHz; a passive guide cannot pass more than it is given,
so that 6×10⁻⁴ is extraction error as well. The calculation is
normalize=False, the modal voltage and current at each port with no reference
run. normalize=True and normalize="flux" divide by a reference run of the
empty guide, which for this structure is the same run. Both return |S11| = 0
by construction: on an empty guide they are not a check of the port’s
reflection.

Reference: the exact matched empty guide (|S11| = 0, |S21| = 1 above
cutoff).
Limit — where the residual comes from. The grid sets it, not the absorber:
rerun the block above with more absorber layers (cpml_layers=32) and |S11|
does not move; a finer cell lowers it.
Autodiff
Fill part of the guide with a dielectric and |S21| responds, and that response
is differentiable. The gradient is taken on a shorter guide than the run above, so
that it is quick: 120 mm long with 12 absorber layers, ports at 30 mm and 80 mm
(reference planes at 40 mm and 70 mm), seven frequencies from 8.2 to 12.4 GHz and
30 periods. A dielectric plug fills the whole cross-section between x = 56 and
64 mm (6 cells, 7.62 mm on this grid). The design variable is its permittivity,
entered through eps_override at εr = 1.5, and the scalar is |S21|² at the
middle frequency, 10.3 GHz. A single jax.value_and_grad call returns
∂|S21|²/∂εr straight through compute_waveguide_s_matrix(normalize="flux", ...)
— the power-flux extraction is on the AD tape, so the gradient flows through the
full modal S-matrix assembly. The code is make_autodiff in
scripts/_gallery_v3_waveguide_figs.py. Its 12 absorber layers are thinner than
the half guide wavelength the absorber advisory asks for; the check below compares
the gradient with finite differences of the same model, so it tests the
differentiation, not the absorber.
The AD gradient is compared against central finite differences (h = 0.05) of the
same model, asking for agreement within 5% and a matching sign.
| Check | AD value | Compared against | rel. error | Sign agrees |
|---|---|---|---|---|
∂|S21|²/∂εr | −0.2149 | central FD −0.2145 (h = 0.05) | 0.0022 (0.22%) | yes |
The gradient agrees to 0.22% with matching sign, inside the 5% this check asks
for. It checks the differentiation of this one computation, not the whole
waveguide family. The waveguide S-matrix is limited in the
support matrix:
its gradient checks were made with 64-bit JAX for normalize="flux", and this
0.22% is a float32 gradient, outside what those checks cover.

The sign is physical. The fill raises the propagation constant, so the filled
section’s TE10 wave impedance is lower than the empty guide’s and both of its
faces reflect. For a plug that fills the cross-section the transmission-line
result is exact: |S21|² = 1 / (1 + ¼·(z − 1/z)²·sin²(β_d·L)), with z = β_0/β_d
the ratio of the filled and empty wave impedances, β_0 and β_d the propagation
constants in the empty and filled guide and L the plug length. For this plug it
falls as εr rises, the sign the solver’s gradient gives.
Limits. The broad-wall width a is not a jax.grad input: a/dx is a
discrete cell count and the analytic mode profile is rebuilt for each width, so
its sensitivity comes from re-meshing and finite differences, alongside the
analytic cutoff relation f_c = c/(2·a) — not from automatic differentiation.
normalize=False and normalize="flux" are differentiable. normalize=True
divides by a separate reference run assembled outside JAX, so it is not: under
jax.grad/jax.jit, a traced
eps_override/sigma_override makes compute_waveguide_s_matrix raise
NotImplementedError before any FDTD run.
Computed with rfx 2.0.0rc1 · 9f1abcc · generated 2026-10-21T23:58:55Z
