Examples

2D Photonic Crystals

Triangular Lattice Rods (TM mode)

Source: examples/101_triangular_rods.jl

Dielectric rods (ε=12) in air, radius r=0.2a.

Triangular lattice structure

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)

TM band structure

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

Square lattice structure

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)

Square lattice TE/TM bands

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)

Phononic bands (SH and P-SV)

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.

Bragg structure

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)

Bragg band structure


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:

CategoryFileDescription
2D Photonic102_triangular_rods_plot.jlTriangular lattice with plotting
2D Photonic104_honeycomb_rods.jlHoneycomb lattice
2D Photonic111_triangular_holes.jlAir holes in dielectric
2D Photonic121_subpixel_comparison.jlConvergence with subpixel averaging
2D Photonic911_joannopoulos_ch5_fig2.jlJoannopoulos Ch5 Fig2 benchmark
2D Photonic912_joannopoulos_ch5_fig10.jlJoannopoulos Ch5 Fig10 benchmark
2D Phononic202_phononic_pb_epoxy_benchmark.jlPb/Epoxy benchmark
2D Phononic203_vasseur2001_benchmark.jlVasseur 2001 benchmark
2D Phononic205_kushwaha1993_benchmark.jlKushwaha 1993 benchmark
2D Phononic207_solver_simple.jlDense vs LOBPCG comparison
2D Phononic208_solver_comparison.jlSolver benchmark across sizes
2D Phononic209_warmstart_benchmark.jlWarm start performance
2D Phononic210_vacuum_phononic.jlVacuum holes (ElasticVoid)
2D Phononic211_kushwaha1993_fig1.jlKushwaha 1993 Fig1
2D Phononic212_kushwaha1993_fig2.jlKushwaha 1993 Fig2
2D Phononic213_tanaka2000_vacuum_al.jlTanaka 2000 Al/vacuum
2D Phononic214_maldovan2006_phoxonic.jlMaldovan 2006 phoxonic
2D Phononic216_si_epoxy_square.jlDobrzynski 2017 Ch.5 Fig.20A: Si/Epoxy
2D Phononic217_carbon_epoxy_square_section.jlDobrzynski 2017 Ch.5 Fig.3A: C/Epoxy square-section
2D Phononic218_carbon_epoxy_square.jlDobrzynski 2017 Ch.5 Fig.2A: C/Epoxy
1D Photonic311_joannopoulos_ch4_fig2.jlJoannopoulos Ch4 Fig2
1D Elastic302_elastic_superlattice.jlElastic wave superlattice
3D Photonic411_joannopoulos_ch6_fig3.jlFCC lattice benchmark
3D Photonic412_joannopoulos_ch6_fig8.jlDiamond lattice
3D Photonic413_mpb_diamond.jlMPB diamond comparison
3D Photonic901_mpb_benchmark.jlMPB benchmark
Topology701_zak_phase_1d.jl1D Zak phase calculation
Topology702_wilson_loop_2d.jl2D Wilson loop spectrum
Topology703_wilson_fragile.jlWilson loop for de Paz 2019 (fragile topology)
Defect501_defect_mode.jlDefect states and LDOS
Defect511_supercell_study.jlSupercell size study
TMM601_tmm_bragg_mirror.jlBragg mirror spectrum
TMM602_tmm_fabry_perot.jlFabry-Pérot cavity
TMM603_tmm_phononic.jlPhononic superlattice
TMM604_tmm_vs_pwe.jlTMM vs PWE comparison
Utility801_plot_structures.jlStructure visualization