Skip to content

az9713/meep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Note: This is a fork of the original NanoComp/meep repository. This fork adds an original Spherical Cow Cloak study (Pendry-style transformation-optics invisibility cloak with full FDTD stability analysis), plus comprehensive documentation including a Four-Approach Cloaking Comparison: 148 Physics Tutorials with theory and code walkthroughs for every Python example and test, an Architecture Guide, a Developer Guide, a User Guide with 10 educational use cases and Windows installation instructions, a Quick Start Explained walkthrough, and a Test Report from running all 148 Python examples and tests. All original source code remains unchanged.

CI Sanitizers Latest Docs Python versions 3.7–3.10 codecov

Meep is a free and open-source software package for electromagnetics simulation via the finite-difference time-domain (FDTD) method spanning a broad range of applications.

Key Features

Spherical Cow Cloak: Transformation-Optics Invisibility Simulation

Featured study -- Can you cloak a spherical cow? This fork investigates Pendry's transformation-optics invisibility cloak using Meep's FDTD engine, pushing it to its stability limits and documenting exactly where and why it breaks.

Cloak field comparison: empty reference, bare sphere, and cloaked sphere showing Ez field patterns

Ez field cross-sections comparing an empty reference (undisturbed plane wave), a bare dielectric sphere (strong scattering shadow), and a cloaked sphere. The cloak bends wavefronts around the object, but heavy regularization required for Yee-grid stability limits the cloaking effectiveness. See the Visualization Guide for a detailed walkthrough of how to read these plots.

What this study covers

  • Transformation optics implementation -- Full Pendry cloak with anisotropic, inhomogeneous epsilon/mu tensors derived from the coordinate mapping r' = R1 + r(R2-R1)/R2, converted from cylindrical to Cartesian coordinates at every grid point
  • Mie theory validation -- Bare-sphere scattering cross-section matches analytical Mie series to <1% error, confirming the simulation methodology is correct
  • Yee grid stability analysis -- Systematic measurement of the FDTD stability boundary: off-diagonal permittivity components exceeding ~1.3x the diagonal cause unconditional instability that cannot be fixed by reducing the Courant number
  • Regularization trade-off -- The minimum stable regularization (eps_min >= 0.55) flattens the gradient-index profile that the cloak relies on, destroying the cloaking effect. This is a fundamental FDTD limitation, not a bug.
  • Alternative approaches -- The 2D cylindrical implementation achieves stable cloaking with full eps+mu tensors, demonstrating that the physics works when the numerics cooperate

Implementations

File Approach Key Result
spherical_cow_cloak.py 3D reduced-parameter cloak Mie-validated scattering; documents Yee grid stability limits
spherical_cow_cloak_2d.py 2D full Pendry cloak (eps+mu) Stable cloaking with anisotropic tensors in 2D
spherical_cow_cloak_viz.py Visualization suite Field maps, scattering spectra, 3D plotly, GIF animation
spherical_cow_cloak_comparison.py Four-approach comparison (3D cancellation, 2D Pendry, multi-shell, carpet) Successfully cloaks a true 3D sphere; head-to-head comparison of all methods

Documentation

Guide What you'll learn
Cloak Simulation Report Full technical analysis: Yee grid stability measurements, Courant number experiments, regularization trade-offs, and 5 mitigation strategies
Visualization Guide How to read the field plots and scattering spectra, relate them to the physics, and judge whether results make sense
Cloaking Comparison Guide Physics behind all four cloaking approaches, how to read comparison plots, and which method to use when

Quick start

# Quick run (3D, ~12 seconds)
python python/examples/spherical_cow_cloak.py --quick --cow-material dielectric

# 2D simulation (full Pendry cloak)
python python/examples/spherical_cow_cloak_2d.py

# Generate all visualizations from saved data
python python/examples/spherical_cow_cloak_viz.py

# Four-approach comparison (3D + 2D, ~5-8 min)
python python/examples/spherical_cow_cloak_comparison.py --method all --quick

Quick Start

Installation via Conda

The fastest way to get started on Linux or macOS is through the conda-forge channel (Windows users: install via WSL2):

conda create -n mp -c conda-forge pymeep
conda activate mp

For MPI-parallel support, install the MPICH variant instead:

conda create -n pmp -c conda-forge pymeep=*=mpi_mpich_*
conda activate pmp

A Minimal 2D Waveguide Simulation

Save the following as my_first_sim.py:

import meep as mp
import matplotlib.pyplot as plt

# Simulation cell: 16 x 8 micrometers with PML absorbing boundaries
cell = mp.Vector3(16, 8)
pml_layers = [mp.PML(1.0)]

# A dielectric waveguide (epsilon=12) running along the x-axis
geometry = [
    mp.Block(size=mp.Vector3(mp.inf, 1, mp.inf),
             center=mp.Vector3(),
             material=mp.Medium(epsilon=12))
]

# Gaussian pulse source exciting the Hz field at one end of the guide
sources = [
    mp.Source(mp.GaussianSource(frequency=0.15, fwidth=0.1),
              component=mp.Hz,
              center=mp.Vector3(-7))
]

sim = mp.Simulation(cell_size=cell,
                    boundary_layers=pml_layers,
                    geometry=geometry,
                    sources=sources,
                    resolution=10)

sim.run(until=100)

# Plot the Hz field
sim.plot2D(fields=mp.Hz)
plt.savefig("waveguide_hz.png", dpi=150)
print("Field plot saved to waveguide_hz.png")

Run the simulation with:

python my_first_sim.py

For more examples and step-by-step tutorials, see the online manual.

Test Status

We ran all 148 Python files from python/examples/ and python/tests/ against pymeep 1.31.0 on Python 3.13 with NumPy 2.x under WSL2. See guides/TEST_REPORT.md for the full report.

Result Count Pct
Pass 76 51%
Fail 25 17%
Timeout 47 32%

None of the 25 failures are bugs in meep itself. All are caused by environment issues:

Root Cause Files Fix
Missing parameterized package 10 pip install parameterized
NumPy 2.x removed APIs 2 np.trapznp.trapezoid, np.complex_np.complex128
Missing h5topng tool 2 sudo apt install h5utils
Missing data files 2 Needs pre-generated data or companion script
Scripts requiring CLI args 3 Not bugs — run with required arguments
Outdated example API calls 4 Needs upstream fixes (API signature changes)
Missing optional packages 2 pip install gdspy / pip install jax

The 47 timeouts are due to CPU contention from parallel batch execution, not actual hangs. Files that timed out in one run frequently passed in the other.

Quick fix for the most common issue:

pip install parameterized    # fixes 10 of 25 failures
sudo apt install h5utils     # fixes 2 more

Documentation

Resource Description
guides/tutorials/ 148 Physics Tutorials: deep-dive theory + code walkthroughs for every Python example and test
guides/QUICKSTART_EXPLAINED.md Quick Start Explained: physics, simulation setup, and results walkthrough
guides/USER_GUIDE.md User Guide: installation, tutorials, and 10 worked use cases
guides/DEVELOPER_GUIDE.md Developer Guide: building from source, testing, and contributing
guides/ARCHITECTURE.md Architecture Documentation: system design, diagrams, and code reference
guides/TEST_REPORT.md Test Report: results from running all 148 Python examples and tests
guides/CLOAK_SIMULATION_REPORT.md Cloak Report: FDTD limitations, Yee grid stability analysis, and mitigation strategies
guides/CLOAK_VISUALIZATION_GUIDE.md Visualization Guide: how to read field plots and scattering spectra with physics interpretation
CLAUDE.md AI Assistant Guide: instructions for Claude Code
Online Manual Full documentation on Read the Docs

Platform Support

Platform Support Notes
Linux Full Install via Conda or build from source
macOS Full Install via Conda or build from source
Windows Via WSL2 or Docker No native Conda package — see USER_GUIDE.md for setup instructions

Conda packages are the recommended path for new users on Linux and macOS. Windows users should use WSL2 (Ubuntu) or Docker. Building from source gives the most flexibility for advanced configurations (MPI, custom prefix, debug builds).

Building from Source

For users who need custom build options such as MPI parallelization, OpenMP threading, or debug symbols, Meep can be built from source using GNU Autotools. The build requires several external libraries: FFTW3, GSL, LAPACK, HDF5, harminv, libctl, and MPB.

sh autogen.sh
./configure --enable-maintainer-mode --prefix=$HOME/local \
  --with-libctl=$HOME/local/share/libctl
make -j$(nproc)
make check

Full instructions including dependency installation, configure options, and CI build details are in guides/DEVELOPER_GUIDE.md.

Project Structure

src/              - C++ core FDTD engine (libmeep)
python/           - Python interface and SWIG bindings
scheme/           - Scheme/Guile interface
tests/            - C++ test suite
libpympb/         - Python MPB eigenmode solver bindings
guides/           - Project guides (architecture, developer, user, test report)
guides/tutorials/ - 148 physics tutorials (theory + code walkthroughs)

Citing Meep

We kindly request that you cite the following paper in any published work for which you used Meep:

About

Fork of NanoComp/meep with a Spherical Cow Cloak study (Pendry transformation-optics invisibility cloak, FDTD stability analysis) and comprehensive documentation (148 physics tutorials, Architecture/Developer/User Guides, 10 educational use cases)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors