C1050 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

C10 · Lesson 50 · Electromagnetics lab

A one-dimensional FDTD simulator in Python

In this lab you'll build the simulator from lesson 49 and use it as a virtual test bench. A few lines of NumPy step Maxwell's equations across a thousand cells; a Gaussian pulse launched into the grid travels, meets a block of dielectric, and splits into a reflected and a transmitted pulse. Measuring them gives the reflection coefficient, which you can compare with the formula from lesson 31, and timing the pulse inside the dielectric gives its speed. When the simulation and the theory agree to a percent, you have a tool you can trust on problems that have no formula.

  • The analytic version of what your simulator will show: a pulse arrives from the left at a dielectric starting at z = 0. Drag t to watch it hit.
  • After the hit, a reflected pulse of Γ times the height heads back (inverted, for a denser medium), and a transmitted pulse of τ times the height continues, narrower and slower by the refractive index n.
  • Change εr and watch the split change. Your FDTD run should reproduce Γ to about 1%.

Predict

A pulse in vacuum hits a dielectric with εr = 4. What is the transmitted pulse's peak, relative to the incident one?

Name it

The simulator

In normalized units (c = 1, cells of size 1, fields scaled so that E and H have the same size in a vacuum wave), one Yee step with Courant number S is

H[k] += S * (E[k+1] - E[k])          for k = 0 .. N-2
E[k] += S / eps[k] * (H[k] - H[k-1]) for k = 1 .. N-2

leaving E[0] and E[N−1] at zero (metal walls). In NumPy each line is one slice operation. A soft source adds a Gaussian to E at one cell each step, e−((n−40)/12)2, which launches a pulse each way; recording E at a probe cell gives a time trace.

Measuring

  • Reflection: put the dielectric's edge to the right of the source and a probe between them. The probe sees the incident pulse pass, then the reflection come back; Γ is the ratio of their peaks (with sign).
  • Speed: fill the grid with the dielectric, and time the pulse's peak between two probes a known distance apart: speed = distance / steps × S, in units of c.

Make the grid long enough that pulses bouncing off the end walls don't reach the probes during the measurement.

Worked example

The probe sees an incident peak of 0.98 and, later, a reflected peak of −0.33. What is the medium?

Show the solution
  1. Reflection coefficient. Γ=−0.330.98=−0.337
  2. Refractive index. n=1−Γ1+Γ=1.3370.663=2.02
  3. Permittivity. εr=n2≈4.1 The simulator's slightly slow waves inside the dielectric blur the last digit.

Answer a dielectric with n ≈ 2.02 and εr ≈ 4.1.

Worked example

A pulse's peak passes probes 200 cells apart 400 steps apart, at S = 1. How fast is it?

Show the solution
  1. Speed. At S = 1 a wave in free space moves one cell per step, so 200 cells in 400 steps is 0.5c.
  2. The medium. n=2 εr=n2=4

Answer it travels at 0.5c, so the medium has n = 2 and εr = 4.

Check

A pulse in vacuum enters a dielectric with εr = 4. What is the transmitted peak relative to the incident peak?

Check

A pulse's peak takes 200 steps to travel 100 cells at Courant number 0.5. What is its speed, as a fraction of c?

Check

Write step(E, H, eps, S=1.0): one Yee update of the NumPy arrays E and H in place (H first, then E, with E[0] and E[-1] left at zero), returning them.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write reflection(er): simulate a 1000-cell grid, vacuum up to cell 600 and εr = er from there, with a soft Gaussian source at cell 400 (centered at step 40, width 12) and a probe at cell 500, for 700 steps at S = 1. Return the reflected peak divided by the incident peak (the largest-magnitude values in the first 200 and the remaining steps, with their signs).

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write wave_speed(er): fill an 1000-cell grid with εr = er, launch the same Gaussian at cell 200 (S = 1), record E at probes at cells 400 and 600 for 900 steps, and return the speed as a fraction of c from the steps between the two probes' peaks.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why does a soft source launch pulses in both directions, and why does the measurement need a long grid?

Practice

Keep practicing

5 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.