Read and plot results
Read monitor data, pick a frequency, get full-grid fields and materials, plot slices, inspect run statistics, and save and reload results.
Simulation.run() returns a Result. This guide shows the common ways to get numbers and pictures out of it. Field and flux data are PyTorch tensors on the scene device; call .detach().cpu().numpy() when you need NumPy. Plane-monitor coordinates (x, y, z) are NumPy arrays. Every member is listed on the Result API page.
Read a monitor#
result.monitor(name) returns a dictionary. The keys depend on the monitor type; the Monitors API lists them per class.
probe = result.monitor("probe") # PointMonitor
ez = probe["data"] # complex phasor of the first requested component
ez_again = probe["Ez"] # the same, by component name
plane = result.monitor("field_xz") # PlaneMonitor on axis="y"
ez_plane = plane["Ez"] # complex tensor, shape (Nx, Nz)
x, z = plane["x"], plane["z"] # sample coordinates, m (NumPy arrays)
flux = result.monitor("flux_up") # FluxMonitor
power = flux["flux"] # real power through the planePlane monitors span the whole grid plane, including PML cells; use the coordinate tensors to crop to the physical domain.
Warning
In 0.5.1, some PlaneMonitor field lists that mix electric and magnetic components, such as ("Ex", "Hy"), return no top-level component keys or coordinates. The samples are still in monitor["components"]["Ex"]["data"]. The full tangential set used for flux, such as ("Ex", "Ey", "Hx", "Hy") on a z plane, works normally. If a key is missing, record E and H components in separate monitors.
Pick a frequency#
With several frequencies, monitor tensors carry a leading frequency axis. result.at(...) returns a view fixed to one frequency:
view = result.at(frequency=1.5e9) # or result.at(freq_index=0)
ez_plane = view.monitor("field_xz")["Ez"]The frequency must match one of result.frequencies (relative tolerance 1e-9).
Full-grid fields and materials#
Run with full_field_dft=True to keep the electric-field spectrum on the whole grid:
sim = mw.Simulation.fdtd(scene, frequencies=[1.5e9], full_field_dft=True)
result = sim.run()
ex, ey, ez = result.E.x, result.E.y, result.E.z
eps = result.material("eps_r") # compiled relative permittivityFDTD and FDFD results store the electric field only; result.H components raise KeyError. Record magnetic fields with an H-only PlaneMonitor or PointMonitor instead.
Plot#
import matplotlib.pyplot as plt
result.plot.field(axis="y", position=0.0, component="Ez") # needs full_field_dft=True
plt.gcf().savefig("field.png", dpi=120, bbox_inches="tight")
result.plot.material("eps_r", axis="z", position=0.0)plot.field draws the field magnitude and the permittivity side by side and calls plt.show(); it returns None, so save the current figure with plt.gcf(). component accepts "abs" (the default) or a component name. For custom figures, plot monitor tensors with Matplotlib directly.
Run statistics#
result.stats() returns a dictionary about the run:
stats = result.stats()
print(stats["steps_run"], stats["dt"], stats["elapsed_s"])
print(stats["time_step"]["limiting_factor"]) # "frequency_resolution" or "material_cfl"
print(stats["cuda_graph_active"])Use it to check the time step, whether early shutoff triggered (shutoff_triggered), the CPML memory mode, and throughput (ms_per_step).
Save and reload#
result.save("run.pt")
restored = mw.Result.load("run.pt", scene=scene)
print(restored.monitor("flux_up")["flux"])save writes a detached CPU snapshot of fields, monitors, ports, circuits, networks and statistics. The scene is not saved, so pass it back to load. Snapshot files use pickle; load them only from sources you trust. For large multi-GPU results, save_sharded and load_sharded write one file per shard.
Engineering quantities#
| Quantity | Where |
|---|---|
| S-parameters, Z and Y, Touchstone | result.network (Networks API) |
| Port voltages, currents and powers | result.port(name), result.ports |
| Far field, directivity, RCS | witwin.maxwell.postprocess (Far field guide) |
| SAR, absorbed power, exposure | result.sar(...), result.power_loss(...), result.incident_power_density(...) (Safety API) |
| Antenna gain and efficiency | result.antenna(...) (Antennas and arrays API) |