How flaport/fdtd works
Project type and purpose
• This is a Python library (fdtd) implementing a 3-dimensional Finite-Difference Time-Domain electromagnetic simulator.
• It provides a programmable API for defining simulation grids, placing objects, sources, detectors, boundaries (PML, periodic), and running time-stepped Maxwell’s equations updates.
• It optionally targets GPU acceleration via a PyTorch backend, but defaults to NumPy on CPU.
File structure
Top-level:
• setup files (.gitignore, pyproject.toml, Makefile, CI/workflows) – packaging & CI.
• README.md + docs/ – user documentation and Sphinx config.
• examples/ – Jupyter notebooks demonstrating use cases.
• fdtd/ – core library:
– backend.py – strategy pattern for selecting NumPy vs Torch.
– grid.py – simulation engine (Grid class holds fields, runs time steps).
– boundaries.py – boundary‐condition classes (PML, periodic).
– objects.py, sources.py, detectors.py – placement of simulation entities.
– fourier.py, waveforms.py, conversions.py, constants.py – utilities/math.
– visualization.py – 2D/3D rendering via matplotlib.
– typing_.py – type definitions for API.
• tests/ – pytest fixtures and unit tests for each module.
README for additional insights
• Detailed explanation of Grid API, field update equations (curl_E, curl_H), boundary updates, PML algorithm.
• Backend selection mechanism (NumPy vs Torch/dtypes/GPU).
• Clear labels: “Grid Engine,” “Backend,” “Objects,” etc.
Detailed capturing of essential elements
• Field arrays (E, H) as internal state.
• Slice‐based “plugin” registration for objects/sources/detectors/boundaries on the Grid.
• Backend selection at initialization and how compute kernels dispatch to either NumPy or Torch.
• Visualization submodule reading the Grid state and calling matplotlib.