Electromagnetics you can differentiate.
Gradients of full-wave FEM results with respect to your geometry and materials, in Python.
Driven, eigenmode and electrostatic problems, from microwave circuits to photonic waveguides, on NGSolve and JAX.
final, the design thresholded at 0.5.Rendered from a rerun of the 3D bendWhere that gradient leads
Which pattern of silicon and oxide, in the 3 µm square where the two guides meet, carries the most 1.55 µm light round the turn?
42 Adam steps on 60 × 60 pixels of 0.05 µm, from 0.5 everywhere, the projection sharpened every 7; one step took a median 147 s on 16 cores. final carries 0.9726 of the power into the output guide's fundamental mode, a loss of 0.121 dB.
It was optimized at 1.55 µm only: over 1.45 to 1.65 µm, |S21|² falls to 0.8254 at 1.65 µm. The tutorial shows the spectrum.
Read the 3D bend tutorialThe media are lossless, so for final the tutorial checks reciprocity, |S12 − S21| = 1.5e-14, and power balance, |S11|² + |S21|² = 0.9730, at most 1: the rest leaves as the guide's second mode or radiation, which the tutorial splits.
What differentiates
Every supported gradient is checked against finite differences. An unsupported one raises an error instead of returning zero; a zero means the physics never reads that input.
337 cells (271 on the direct solver, 66 repeated on BDDC + GMRES), each checked along 3 random directions against fourth-order central differences. How gfem is checked
Full matrix on Capabilities| Problem | Permittivity | Conductivity | Sheet fill | Node coordinates |
|---|---|---|---|---|
| DrivenS-parameters, uniform and adaptive sweep | FD-verified | FD-verified | FD-verified | FD-verified |
| Eigenmodefrequency and Q | FD-verified | FD-verified | FD-verified | FD-verified |
| Electrostaticcapacitance | FD-verified | exact zero | raises NotImplementedError | FD-verified |
| Port mode problemeffective index, impedance and field | FD-verified | FD-verified | FD-verified | FD-verified |
NonDifferentiableError, or the error the cell namespip install gfem
Linux x86_64, macOS arm64 and Windows x86_64; Python 3.12 or later. Importing gfem turns on JAX double precision.