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#

AreaIncluded
SolversFDTD (primary, full featured), FDFD (limited, experimental), electrostatic and capacitance solves
SourcesPoint dipoles, plane waves, Gaussian beams, mode sources, TFSF, uniform and custom current or field sources
MaterialsIsotropic and tensor media, conductive, Debye, Drude, Lorentz, nonlinear, modulated, 2D sheets, graphene, surface impedance, ferrites
BoundariesPML (CPML), periodic, Bloch, PEC, PMC, Mur, mixed per face, symmetry
OutputsPoint, plane, flux, time-domain, mode, diffraction and closed-surface monitors; near-to-far field, directivity, RCS, S-parameters, SAR
RFMode, wave, lumped and terminal ports; R/L/C elements; Touchstone networks; SPICE-style circuits; thin wires
GradientsPyTorch autograd through a native CUDA adjoint for supported material, geometry and source inputs
ScaleMulti-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#