Maxwell
Maxwell is a differentiable full-wave electromagnetic solver with a native CUDA FDTD runtime and a PyTorch interface.
Maxwell (witwin-maxwell on PyPI, imported as witwin.maxwell) solves Maxwell's equations on a 3D Yee grid. The time-domain solver (FDTD) runs as hand-written CUDA kernels, and the whole workflow stays in PyTorch: you build a scene from tensors, run it, read fields as tensors, and call loss.backward() to get adjoint gradients with respect to materials, geometry and supported source inputs.
Use Maxwell when you need full-wave fields rather than ray or circuit approximations: antennas and arrays, waveguides and RF ports, scattering and radar cross section, photonic and metasurface unit cells, SAR and exposure, and gradient-based inverse design of any of these.
What it looks like#
import witwin.maxwell as mw
scene = mw.Scene(
domain=mw.Domain(bounds=((-0.64, 0.64), (-0.64, 0.64), (-0.64, 0.64))),
grid=mw.GridSpec.uniform(0.025),
boundary=mw.BoundarySpec.pml(num_layers=8),
device="cuda",
)
scene.add_structure(mw.Structure(name="box", geometry=mw.Box(position=(0, 0, 0), size=(0.24, 0.24, 0.24)), material=mw.Material(eps_r=4.0)))
scene.add_source(mw.PointDipole(position=(0, 0, -0.2), polarization="Ez", source_time=mw.GaussianPulse(frequency=1.5e9, fwidth=0.5e9)))
scene.add_monitor(mw.FluxMonitor("flux_up", axis="z", position=0.3, frequencies=(1.5e9,)))
result = mw.Simulation.fdtd(scene, frequencies=[1.5e9]).run()
print(result.monitor("flux_up")["flux"])Positions and sizes are in metres and frequencies in hertz. The Quickstart runs this scene end to end and plots the field.
What Maxwell covers#
| Area | Included |
|---|---|
| Solvers | FDTD (primary, full featured), FDFD (limited, experimental), electrostatic and capacitance solves |
| Sources | Point dipoles, plane waves, Gaussian beams, mode sources, TFSF, uniform and custom current or field sources |
| Materials | Isotropic and tensor media, conductive, Debye, Drude, Lorentz, nonlinear, modulated, 2D sheets, graphene, surface impedance, ferrites |
| Boundaries | PML (CPML), periodic, Bloch, PEC, PMC, Mur, mixed per face, symmetry |
| Outputs | Point, plane, flux, time-domain, mode, diffraction and closed-surface monitors; near-to-far field, directivity, RCS, S-parameters, SAR |
| RF | Mode, wave, lumped and terminal ports; R/L/C elements; Touchstone networks; SPICE-style circuits; thin wires |
| Gradients | PyTorch autograd through a native CUDA adjoint for supported material, geometry and source inputs |
| Scale | Multi-GPU FDTD and experimental batched execution of scene variants |
Note
Maxwell needs an NVIDIA GPU. FDTD and FDFD both reject scenes whose device is not CUDA.
Where to go next#
Requirements, the pip install command, and how to check the CUDA kernels load.
Run a dipole next to a dielectric box, read flux, plot the field, take a gradient.
The Scene, Simulation, Result model, grid and units, and how gradients work.
Task-oriented pages: materials, sources, ports, far field, batch runs.
Complete worked examples with code and expected output.
Every public class and function in witwin.maxwell.