Examples
2D Photonic Crystals
Triangular Lattice Rods (TM mode)
Source: examples/101_triangular_rods.jl
Dielectric rods (ε=12) in air, radius r=0.2a.

lat = hexagonal_lattice(1.0)
air = Dielectric(1.0)
rod = Dielectric(12.0)
geo = Geometry(lat, air, [(Circle([0.0, 0.0], 0.2), rod)])
solver = Solver(TMWave(), geo, (64, 64); cutoff=7)
kpath = simple_kpath_hexagonal(npoints=30)
bands = compute_bands(solver, kpath; bands=1:8)
The TM mode shows a clear band gap between bands 1 and 2.
Square Lattice Rods (TE/TM comparison)
Source: examples/103_square_rods.jl

lat = square_lattice(1.0)
geo = Geometry(lat, air, [(Circle([0.0, 0.0], 0.2), rod)])
solver_te = Solver(TEWave(), geo, (64, 64); cutoff=7)
solver_tm = Solver(TMWave(), geo, (64, 64); cutoff=7)
This example also demonstrates iterative solvers:
# KrylovKit (Arnoldi iteration)
solver = Solver(TMWave(), geo, (64, 64), KrylovKitMethod())
# LOBPCG (Block CG)
solver = Solver(TMWave(), geo, (64, 64), LOBPCGMethod())2D Phononic Crystals
Steel/Epoxy (SH and P-SV modes)
Source: examples/201_phononic_steel_epoxy.jl
Steel cylinders in epoxy matrix.
epoxy = IsotropicElastic(ρ=1180.0, λ=4.43e9, μ=1.59e9)
steel = IsotropicElastic(ρ=7800.0, λ=1.15e11, μ=8.28e10)
lat = square_lattice(0.01) # 1 cm period
geo = Geometry(lat, epoxy, [(Circle([0.0, 0.0], 0.004), steel)])
solver_sh = Solver(SHWave(), geo, (64, 64); cutoff=7)
solver_psv = Solver(PSVWave(), geo, (64, 64); cutoff=7)
This example also compares Dense, KrylovKit, and LOBPCG methods for phononic problems.
Solver Comparison (Dense vs LOBPCG)
Source: examples/207_solver_simple.jl, examples/208_solver_comparison.jl
Benchmark Dense and LOBPCG solvers for phononic band structure calculations.
# Dense solver (default, exact)
solver_dense = Solver(PSVWave(), geo, (64, 64); cutoff=15)
# LOBPCG solver (faster for large problems)
solver_lobpcg = Solver(PSVWave(), geo, (64, 64), LOBPCGMethod(); cutoff=15)
bands = compute_bands(solver, kpath; bands=1:10)LOBPCG becomes faster than Dense for cutoff ≥ 12. See LOBPCGMethod for details.
1D Structures
Bragg Reflector
Source: examples/301_bragg_reflector.jl
Quarter-wave stack of two dielectric materials.

lat = lattice_1d(1.0)
mat1 = Dielectric(1.0)
mat2 = Dielectric(12.0)
# Quarter-wave thickness ratio
d1 = 0.5 * sqrt(12) / (1 + sqrt(12))
geo = Geometry(lat, mat1, [(Segment(0.0, d1), mat2)])
solver = Solver(Photonic1D(), geo, 128; cutoff=20)
# Or with iterative solvers
solver = Solver(Photonic1D(), geo, 128, KrylovKitMethod(); cutoff=20)
solver = Solver(Photonic1D(), geo, 128, LOBPCGMethod(); cutoff=20)
3D Photonic Crystals
For 3D photonic crystals, TransverseEM is the recommended wave type. It uses a 2N×2N transverse basis that automatically satisfies ∇·H = 0, eliminating spurious longitudinal modes.
FCC Lattice with Spheres
Source: examples/401_fcc_spheres.jl
Dielectric spheres (ε=12) in air on an FCC lattice.
lat = fcc_lattice(1.0)
air = Dielectric(1.0)
sphere = Dielectric(12.0)
geo = Geometry(lat, air, [(Sphere([0.0, 0.0, 0.0], 0.25), sphere)])
# TransverseEM: recommended for 3D photonic crystals
solver = Solver(TransverseEM(), geo, (16, 16, 16), DenseMethod(); cutoff=5)
# Use 3D k-path
kpath = simple_kpath_fcc(a=1.0, npoints=20)
bands = compute_bands(solver, kpath; bands=1:6)Simple Cubic Lattice with Spheres
Source: examples/402_sc_spheres.jl
lat = cubic_lattice(1.0)
geo = Geometry(lat, air, [(Sphere([0.0, 0.0, 0.0], 0.3), sphere)])
solver = Solver(TransverseEM(), geo, (16, 16, 16), DenseMethod(); cutoff=5)
kpath = simple_kpath_cubic(a=1.0, npoints=20)
bands = compute_bands(solver, kpath; bands=1:6)More Examples
See the examples/ directory in the repository for additional examples:
| Category | File | Description |
|---|---|---|
| 2D Photonic | 102_triangular_rods_plot.jl | Triangular lattice with plotting |
| 2D Photonic | 104_honeycomb_rods.jl | Honeycomb lattice |
| 2D Photonic | 111_triangular_holes.jl | Air holes in dielectric |
| 2D Photonic | 121_subpixel_comparison.jl | Convergence with subpixel averaging |
| 2D Photonic | 911_joannopoulos_ch5_fig2.jl | Joannopoulos Ch5 Fig2 benchmark |
| 2D Photonic | 912_joannopoulos_ch5_fig10.jl | Joannopoulos Ch5 Fig10 benchmark |
| 2D Phononic | 202_phononic_pb_epoxy_benchmark.jl | Pb/Epoxy benchmark |
| 2D Phononic | 203_vasseur2001_benchmark.jl | Vasseur 2001 benchmark |
| 2D Phononic | 205_kushwaha1993_benchmark.jl | Kushwaha 1993 benchmark |
| 2D Phononic | 207_solver_simple.jl | Dense vs LOBPCG comparison |
| 2D Phononic | 208_solver_comparison.jl | Solver benchmark across sizes |
| 2D Phononic | 209_warmstart_benchmark.jl | Warm start performance |
| 2D Phononic | 210_vacuum_phononic.jl | Vacuum holes (ElasticVoid) |
| 2D Phononic | 211_kushwaha1993_fig1.jl | Kushwaha 1993 Fig1 |
| 2D Phononic | 212_kushwaha1993_fig2.jl | Kushwaha 1993 Fig2 |
| 2D Phononic | 213_tanaka2000_vacuum_al.jl | Tanaka 2000 Al/vacuum |
| 2D Phononic | 214_maldovan2006_phoxonic.jl | Maldovan 2006 phoxonic |
| 2D Phononic | 216_si_epoxy_square.jl | Dobrzynski 2017 Ch.5 Fig.20A: Si/Epoxy |
| 2D Phononic | 217_carbon_epoxy_square_section.jl | Dobrzynski 2017 Ch.5 Fig.3A: C/Epoxy square-section |
| 2D Phononic | 218_carbon_epoxy_square.jl | Dobrzynski 2017 Ch.5 Fig.2A: C/Epoxy |
| 1D Photonic | 311_joannopoulos_ch4_fig2.jl | Joannopoulos Ch4 Fig2 |
| 1D Elastic | 302_elastic_superlattice.jl | Elastic wave superlattice |
| 3D Photonic | 411_joannopoulos_ch6_fig3.jl | FCC lattice benchmark |
| 3D Photonic | 412_joannopoulos_ch6_fig8.jl | Diamond lattice |
| 3D Photonic | 413_mpb_diamond.jl | MPB diamond comparison |
| 3D Photonic | 901_mpb_benchmark.jl | MPB benchmark |
| Topology | 701_zak_phase_1d.jl | 1D Zak phase calculation |
| Topology | 702_wilson_loop_2d.jl | 2D Wilson loop spectrum |
| Topology | 703_wilson_fragile.jl | Wilson loop for de Paz 2019 (fragile topology) |
| Defect | 501_defect_mode.jl | Defect states and LDOS |
| Defect | 511_supercell_study.jl | Supercell size study |
| TMM | 601_tmm_bragg_mirror.jl | Bragg mirror spectrum |
| TMM | 602_tmm_fabry_perot.jl | Fabry-Pérot cavity |
| TMM | 603_tmm_phononic.jl | Phononic superlattice |
| TMM | 604_tmm_vs_pwe.jl | TMM vs PWE comparison |
| Utility | 801_plot_structures.jl | Structure visualization |