# Maxwell diffraction build — v0.3

## What runs now

The **Diffraction lab** tab evolves electric and magnetic fields on a 224 × 144
staggered Yee grid in real time. Select zero, one, or two slits; vary aperture
width and spacing, wavelength, and TMz/TEz polarization. The source is coherent
and monochromatic. Each cell is 30 nm wide, so changing wavelength changes the
physical ratio of wavelength to slit geometry. The detector plot is an average
of electric-field intensity over roughly six optical periods. The field picture
overlays a little instantaneous amplitude on the averaged intensity; the
carrier is never stepped at a human playback rate.

The **3D Maxwell result** tab embeds the result of a separate 72 × 96 × 24
voxel simulation. The Python engine advances all six vector field components,
with two finite three-dimensional apertures in a conducting screen. The plot
shows a central-depth slice of time-averaged intensity and a transverse
detector profile. The underlying full volume and final Ez field are saved in
`results/maxwell3d_fields.npz` and the run can be regenerated with
`python run_maxwell3d.py`.

## Numerical formulation

Both solvers use a Yee-style staggered curl update in normalized vacuum units,
where ε₀ = μ₀ = c = Δx = 1. For 3D the leapfrog rule is

```text
H^(n+1/2) = H^(n-1/2) − Δt curl_forward E^n
E^(n+1)   = E^n + (Δt/ε) curl_backward H^(n+1/2)
```

The Courant factors are 0.48/√2 in 2D and 0.46 in 3D, below their respective
vacuum limits. Conducting cells zero electric-field components after the update.
The outer boundary is a graded **lossy sponge**, not a perfectly matched layer.
Consequently weak boundary reflections and numerical dispersion remain. The
3D screen's zero-all-E cell mask approximates a perfect conductor rather than
enforcing every tangential interface component at its exact staggered location.

There is no material dispersion, measured refractive index, polarization of
matter, thermal emission, quantum description, or full spectral broadband
illumination in the new FDTD mode. The earlier sphere-and-block tab continues
to use direct-light ray tracing and does not secretly gain wave scattering.
RGB rendering maps a simulated single wavelength through the CIE standard
observer; visible brightness comes from time-averaged simulated |E|², with
contrast adjusted for display. Thus the image is a physics-derived numerical
projection, not a calibrated retinal prediction or photograph.

## Validation

- `python -m unittest discover -s tests -v`: 27 checks, including the 3D
  Courant limit, source-free magnetic divergence, periodic plane-wave temporal
  recurrence, field past a 3D aperture, and standalone PNG equality.
- `node tools/check_maxwell.cjs`: opaque screen has zero downstream detector
  energy; a single slit transmits; double-slit total detector intensity exceeds
  single-slit; the central interference lobe exceeds an adjacent trough; both
  polarizations are finite and transmit.
- `node tools/check_optics.cjs`: existing ray optics checks still pass.
- `node --check web/maxwell.js`, plus full standalone script syntax check.

At 1100 2D time steps, summed detector signals in relative units were zero
for a closed screen, 0.0465 for one slit, and 0.1405 for two slits; the central
double-slit detector intensity was 0.00302 versus 0.000802 in an adjacent
trough. The 3D 620-step result reaches a nonzero detector with several lobes.
These checks establish a functioning discrete Maxwell demonstration. They do
not establish convergence to a continuous solution or experimental agreement.

## Run

Open `Rotor_Spectral_Studio.html` directly in a modern browser and select
**Diffraction lab**. It is a single offline HTML file. Its 3D result is
precomputed; the interactive mode is 2D. To regenerate the full vector run:

```bash
python run_maxwell3d.py
python tools/build_studio.py
```

The Python script requires NumPy and Matplotlib; browser use requires neither.

References: [Meep introduction](https://meep.readthedocs.io/en/latest/Introduction/),
[Meep Yee lattice](https://github.com/NanoComp/meep/blob/master/doc/docs/Yee_Lattice.md),
and [Meep absorbing boundary discussion](https://meep.readthedocs.io/en/latest/Perfectly_Matched_Layer/).
