OPTICSIN 5 MINUTES

E09 / AN INTERACTIVE OPTICS LESSON

Update a neighbour.
Watch a wave emerge.

Solve Maxwell’s coupled field equations with staggered samples, then find out why time steps, pixels, and computational boundaries are part of the physics calculation.

12–15-minute lesson · 25–30-minute Python lab
Prerequisites & recommended learning resources ↓

Computed illustration from this lesson’s numerical model.
COMPUTED FROM THE LESSON MODEL

CONCEPTS IN THIS EPISODE

See this episode in the concept map ↓

E09 / WHY LEARN THIS?

When can you trust a simulated electromagnetic field?

A device with reflections, interfaces, or wavelength-scale features may need Maxwell's coupled fields rather than a prescribed phase mask. Computing those fields still does not make every plotted ripple physical: the grid, time step, and artificial boundaries can change the result.

What you gain: Build a time-domain Maxwell solver and test its stability, propagation error, and boundary reflections before interpreting a simulated device response.

BEFORE E09 / PREREQUISITES

Check your starting point.

Useful earlier lessons: E01, E07

  • Coupled electric and magnetic fields. Recognize the coupling between changing electric and magnetic fields.Used here: The solver advances both fields in alternating updates.
  • Derivatives on a sampled grid. Approximate a derivative with neighboring samples and read partial derivatives as local rates of change.Used here: The Yee grid replaces spatial and temporal derivatives by staggered differences.
Need a refresher? Open the recommended reading.

Use the indicated sections for an unfamiliar idea, then return to this lesson.

For the notebook: Use neighboring array slices and a time loop; distinguish field samples, probes, and recorded traces.
NumPy · The absolute basics for beginners ↗

Developed in this lesson: Construct a Yee update, test its time-step limit, and measure boundary reflections and PML performance.

Browse all prerequisites and learning resources →

Maxwell on a grid

Watch the story, then use the experiment below to test the ideas yourself.

5:16 · E09 · Maxwell on a gridWatch on YouTube ↗

The film’s logic, step by step.

How do local field updates produce a wave simulation, and how do we know it is accurate?

Follow the film’s argument, then open an explanation where a step feels too fast. Times are approximate; select one to replay that part of the film.

Logic flow

  1. 0:00

    Start with physics the earlier shortcuts miss

    A pulse couples into a ring and repeatedly leaks out. Resolving propagation, reflection, and fine geometry together motivates solving Maxwell’s equations on a grid.

  2. 0:30

    Connect electric and magnetic changes locally

    The curl of E drives H, and the curl of H drives E. A localized field disturbance spreads because neighbouring field differences update one another.

  3. 1:09

    Place fields where centred differences belong

    Spatial derivatives naturally live between samples. Yee’s grid staggers E and H in space, and leapfrogging staggers them in time, giving an explicit local update.

    Open the missing step →
  4. 1:56

    Separate stability from numerical dispersion

    A sufficiently small time step prevents unstable growth. A sufficiently fine spatial grid is a separate requirement for phase speed and geometry to converge.

    Open the missing step →
  5. 2:41

    Notice that a truncated domain reflects

    Stopping the mesh creates an artificial boundary. Ordinary absorption can itself reflect, so an open-domain simulation needs a boundary matched to the outgoing waves.

    Open the missing step →
  6. 3:04

    Stretch coordinates into a decaying region

    PML transforms outgoing oscillations into decaying waves while preserving the ideal interface match. Discretization and finite thickness still require convergence checks.

    Open the missing step →
  7. 3:59

    Excite a band and extract a spectrum

    A broadband pulse contains many frequencies. Fourier analysis of recorded fields, with source normalization and suitable flux monitors, estimates the device’s response across that band.

    Open the missing step →
  8. 4:47

    Treat full wave as a converging numerical model

    Cell size, geometry representation, simulation duration, and PML all affect accuracy. Once the forward model is trustworthy, E10 differentiates it to improve a design.

Unpack the difficult steps

Why move H half a cell and half a time step away from E?

1:15 · Replay this part

∂E/∂x |x+Δx/2 ≈ [E(x+Δx) − E(x)]/Δx

The difference of two neighbouring E samples estimates a derivative at their midpoint. Storing the relevant H component there aligns the Maxwell update with that centred derivative. In time, E at step n updates H from n − 1/2 to n + 1/2; that new H then updates E from n to n + 1. Neither update needs a simultaneous global solve in the basic explicit scheme.

This structure gives second-order differences for smooth fields on the standard grid. Interfaces, curved boundaries, dispersive materials, and source placement need additional care. A single scalar ε per cell describes the simple nondispersive material model in the film, not every electromagnetic material.

Why can a simulation be stable and still give the wrong wave speed?

1:56 · Replay this part

Δt ≤ 1 / [vmax √(Δx⁻² + Δy⁻² + Δz⁻²)]
2D square grid in vacuum: cΔt/Δx ≤ 1/√2

For the standard explicit Yee scheme in a simple lossless medium, the Courant bound keeps the discrete update’s wave modes from growing spuriously. Use only the active dimensions in the formula. The film’s circle-inside-a-diamond picture gives intuition; the numerical stability condition is a property of the update equations.

Below that bound, finite differences still have a dispersion relation different from Maxwell’s continuous one. Phase speed depends on wavelength and direction. Resolve the shortest relevant wavelength inside the highest-index material, then refine further until the observable converges. Ten to twenty cells per wavelength is a starting estimate, not an accuracy certificate; resonances and small gaps often demand more.

How can an absorbing region avoid reflecting at its entrance?

3:12 · Replay this part

x̃ = x + (i/ω)∫ σ(s) ds
e^(ikx̃) = e^(ikx) exp[−(k/ω)∫ σ(s) ds]

With the chosen time convention, a positive imaginary coordinate stretch makes an outgoing plane wave decay. The transformed Maxwell equations include matched electric and magnetic responses, so their ideal continuum interface retains the original wave impedance. Simply adding electric loss to an ordinary material does not make that same match.

The equation above explains the mechanism for the simple outgoing-wave case. A finite discretized PML is not reflection-free for every problem. Use a gradual profile, enough thickness, and space between the structure and absorber; repeat with changed PML settings. Grazing incidence, evanescent fields, and some inhomogeneous or backward-wave media need particular care.

How can one short pulse give many wavelengths, and what limits the result?

4:09 · Replay this part

linear response: Eout(ω) = H(ω) Ein(ω)
frequency resolution scale: Δf ~ 1/Trecord

In a linear time-invariant system, different frequencies respond independently. A pulse probes the frequencies where its source spectrum has useful power. Transform the measured fields in time and normalize to the incident spectrum; transmission and reflection require power flux or mode amplitudes, not an arbitrary single field sample.

Finite recording time broadens spectral features and can truncate a resonator’s long tail. A very narrow resonance needs a long run even if the excitation is brief. Check source bandwidth, monitor definitions, residual stored energy, and record-length convergence before trusting a spectrum.

Further reading for these explanations

Explore the full experiment →

What to notice first.

Maxwell’s equations couple electric and magnetic fields through spatial derivatives. In one dimension, with E along z and propagation along x, the magnetic field lies along y. In normalized units, the two update equations connect neighboring samples rather than solving for an entire field at once.

Hᵧ ← Hᵧ + S ΔₓE_z   ·   E_z ← E_z + (S/ε) ΔₓHᵧ

Here S = c₀Δt/Δx is the Courant number, ε is relative permittivity, and Δₓ means a difference between adjacent samples without division by Δx. The electric field is stored at integer positions and times. The magnetic field is half a cell away and half a time step behind. Updating H first and E second advances them in a leapfrog.

Staggering is not a plotting inconvenience. The difference of two values approximates a derivative at their midpoint, so the other field naturally belongs there. The same idea applies in time. For a physical wave traveling in +x with these axis conventions, Hᵧ = −nE_z; opposite signs do not mean opposite propagation directions.

The browser computes a real 1D finite-difference time-domain (FDTD) simulation on a Yee grid. A soft electric source launches pulses both left and right. The left edge always absorbs. The right edge can be a wall, an abrupt electric-loss layer, or a matched graded CPML. A dielectric interface can be inserted at x = 8.

By the end, you can

  1. Explain the spatial and temporal staggering of a Yee update.
  2. Distinguish instability, numerical dispersion, and boundary reflection.
  3. Measure reflection with a reference run and verify an absorber by refinement.

PREDICT BEFORE YOU CHANGE A CONTROL

A layer absorbs light strongly. Does that guarantee it produces little reflection where the wave first enters it?

Change one thing.
Follow what changes.

All plotted fields and curves are calculated from the stated model. Keep the other controls fixed while testing a prediction.

Model: 1D normalized Yee fields with real, nondispersive ε = n² and μ = 1. The PML specialization uses cubic grading with κ = 1 and α = 0. The electric source is bidirectional. The field display clips amplitudes outside ±1; the growth plot reports actual maxima and stops at 10⁶.

  1. Run the matched-boundary case. Watch the field and probe trace, then repeat with a wall and the electric-loss layer at identical sampling.
  2. Insert n = 1.5. Locate the reflected and transmitted pulses. Do not infer reflectance by comparing unrelated instantaneous peaks.
  3. Run the unstable preset. Observe exponential growth and the automatic stop, then reduce S without changing the spatial grid.

The grid has its own limits.

For the vacuum 1D Yee scheme used here, stability requires S ≤ 1. In equal-grid 2D, the corresponding limit is S ≤ 1/√2. These are different bounds: a value that is safe in one dimension can be unstable in two. The notebook labels dimensionality explicitly and seeds a tiny alternating perturbation so an unstable mode becomes visible reproducibly.

Stability is only the first check. A stable grid can give the wrong phase velocity because finite differences have a different dispersion relation from continuous derivatives. Coarse pixels accumulate phase error as the wave travels. Cells must be counted per wavelength inside the highest-index material, not just per vacuum wavelength.

sin²(ωΔt/2) = (S²/n²) Σ_d sin²(k_dΔx/2)

The sum has one term in the browser and two in the optional 2D calculation. Increasing resolution should move numerical results toward the continuum answer. A small-looking pixel size alone is not evidence of convergence.

Absorption and matching solve different problems.

An abrupt electric conductivity dissipates energy but changes wave impedance, so its entrance reflects. A perfectly matched layer modifies the derivative operators in a coordinated way. In the continuum idealization its entrance is matched while waves attenuate inside. CPML realizes the frequency-dependent stretch with memory variables in the time-domain update.

The discrete implementation still has a finite reflection error. Its electric and magnetic loss profiles must be sampled at their actual staggered positions. Grading, layer thickness, resolution, and incidence conditions affect the residual. Calling a region PML is not a substitute for measuring its echo.

The notebook subtracts a larger-domain reference field from a test trace, then gates the reflected arrival. It also compares the dielectric step with Fresnel reflectance. For precise power balance, electric and magnetic fields must be colocated in both space and time before calculating flux; simply squaring an arbitrary field sample can hide staggering error.

Make a prediction before checking the explanation.

Can you explain the change?

1. A 1D vacuum run uses S = 0.9. The same value on an equal-grid 2D vacuum Yee grid is…
2. A strongly absorbing electric-loss layer can reflect because…
3. A stable FDTD run is guaranteed to have accurate phase velocity.

Your own computational experiment.

The standalone notebook builds the model in small steps, draws the results, and checks the calculation against independent predictions. It runs on CPU using NumPy, SciPy, and Matplotlib. No repository clone, GPU, or external dataset is needed.

In Colab, sign in with a Google account and select Runtime → Run all. Save a copy in Drive to retain edits. Saved notebook outputs and downloadable PNG figures provide a fallback if Colab’s output frame cannot load.

A short lab report

  1. Measure an interface. Estimate reflectance for n: 1 → 1.5 with a reference-subtracted, time-gated trace.
  2. Audit the boundary. Compare wall, loss layer, and CPML with identical excitation and a larger-domain reference.
  3. Separate two failures. Create a stable coarse run and an unstable fine run, then explain why each is unreliable.
Compare your reasoning

Measure an interface

Compare with ((1−1.5)/(1+1.5))² = 0.04, then refine the grid. Keep incident normalization and arrival windows fixed physically.

Audit the boundary

Subtract fields before squaring. Distinguish amplitude echo ratios from integrated reflected-power estimates.

Separate two failures

The first can accumulate dispersion error; the second violates the time-step stability bound. Refining space without reducing Δt can make stability worse.

Optional deeper extension

Run a compact 2D TMz Yee solver with CPML, compare its residual against a larger domain, and repeat grid-dispersion and Courant tests.

The notebook marks the extension clearly. Complete the core experiment and its checks first.

Instructor notes and assessment rubric ↗ · Model, setup, and reproducibility ↗

Know what the model leaves out.

1D normalized Yee fields with real, nondispersive ε = n² and μ = 1. The PML specialization uses cubic grading with κ = 1 and α = 0. The electric source is bidirectional. The field display clips amplitudes outside ±1; the growth plot reports actual maxima and stops at 10⁶.

Video companion: watch the E09 film above (5:16).

Calculations and concept checks run locally in your browser. Quiz answers are not uploaded or stored.

Keep exploring from this episode.

Highlighted concepts appear in this episode. Select any concept to find related episodes.

In this episodeUnderstanding foundationCross-topic connection

Connections describe ideas, not a required episode order.

SELECTED CONCEPT

Complex field & phase

Keep amplitude and phase together to describe what light does before a detector measures intensity.

Other episodes with this concept

Explore through connected ideas

Foundations & connections

Refresh the foundations

Connected ideas

SELECTED CONCEPT

Fourier representation

Describe a field by its spatial-frequency components. The same representation connects propagation, imaging, reconstruction, and design.

Other episodes with this concept

Foundations & connections

Refresh the foundations

Connected ideas

SELECTED CONCEPT

Wave propagation

Follow a field through space by advancing its components and combining them again.

Other episodes with this concept

Explore through connected ideas

Foundations & connections

Refresh the foundations

Connected ideas

SELECTED CONCEPT

Interference & coherence

Connect field correlations to what survives a camera's averaging: interference, fringe visibility, and speckle.

Other episodes with this concept

Explore through connected ideas

Foundations & connections

Refresh the foundations

Connected ideas

SELECTED CONCEPT

Imaging & resolution

Use point responses and frequency transfer to understand which details an optical image can carry.

Other episodes with this concept

Explore through connected ideas

Foundations & connections

Refresh the foundations

Connected ideas

SELECTED CONCEPT

Holography & phase recovery

Recover information about an optical field using a reference or constraints on intensity measurements.

Other episodes with this concept

Explore through connected ideas

Foundations & connections

Refresh the foundations

Connected ideas

SELECTED CONCEPT

Phase control

Turn a desired phase profile into an optical element, then examine wrapping, quantization, and wavelength dependence.

Other episodes with this concept

Explore through connected ideas

Foundations & connections

Refresh the foundations

Connected ideas

SELECTED CONCEPT

Periodicity & band gaps

Use repetition to connect diffraction directions, Bloch propagation, and frequency bands that a structure rejects.

Other episodes with this concept

Explore through connected ideas

Foundations & connections

Refresh the foundations

Connected ideas

SELECTED CONCEPT

Eigenmodes & resonance

Find field patterns adapted to an operator or structure. Related eigenvalue methods also describe Bloch waves and statistical coherent modes.

Other episodes with this concept

Explore through connected ideas

Foundations & connections

Refresh the foundations

Connected ideas

SELECTED CONCEPT

Sampling & discretization

In this episode

Understand what changes when continuous fields become arrays: sampling limits, computational windows, and derivative approximations.

Other episodes with this concept

Explore through connected ideas

Foundations & connections

Refresh the foundations

Connected ideas

SELECTED CONCEPT

Maxwell & FDTD

In this episode

Evolve coupled electric and magnetic fields on a grid, and test the accuracy of time steps and boundaries.

Explore through connected ideas

Foundations & connections

Refresh the foundations

Connected ideas

SELECTED CONCEPT

Adjoints & inverse design

Use a scalar objective and an adjoint calculation to find how every design parameter changes the result.

Other episodes with this concept

Explore through connected ideas

Foundations & connections

Refresh the foundations

Connected ideas