Examples¶
Band frequencies are normalized as \(\omega a/(2\pi c)\). Shaded intervals mark gaps shared by the displayed polarizations along the sampled symmetry path. The Brillouin-zone inset shows the lattice's reciprocal cell and the path. The fcc examples use the conventional cubic period for \(a\).
Electromagnetic mode fields¶
These maps show electric and impedance-scaled magnetic intensities for the first TM band at X in the square lattice of alumina rods.

View source
"""Electric and magnetic mode intensities for a square lattice of rods."""
import matplotlib.pyplot as plt
from morpho import (
BlochPoints,
Geometry,
Solver,
plot_field,
reconstruct_fields,
)
def main():
a1, a2 = (1.0, 0.0), (0.0, 1.0)
sampling = BlochPoints(a1, a2, points=[(0.5, 0.0)])
def eps_rf(eps_r, x, y):
eps_r[x**2 + y**2 <= 0.2**2] = 8.9
geometry = Geometry(a1, a2, 65, 65, eps_rf=eps_rf)
solution = Solver(geometry, sampling, P=7, Q=7, pol="TM").run(n_bands=1)
fields = reconstruct_fields(solution)
_, axes = plt.subplots(1, 2, figsize=(9, 4), tight_layout=True)
plot_field(fields, field="E", ax=axes[0], cmap="magma")
plot_field(fields, field="H", ax=axes[1], cmap="magma")
axes[0].set_title("TM at X: electric field |E|²")
axes[1].set_title("TM at X: magnetic field |Z₀H|²")
plt.show()
if __name__ == "__main__":
main()
See electromagnetic fields for reconstruction and normalization.
Two-dimensional square lattice of dielectric rods¶
This example models alumina rods in air on a square lattice. The lattice constant is normalized to \(a=1\), the rod radius is \(0.2a\), and the rod relative permittivity is 8.9. The real-space dielectric grid has \(129\times129\) samples. The plane-wave expansion uses orders \(P=Q=9\) and samples the symmetry path \(\Gamma\)–X–M–\(\Gamma\) with 100 points per segment. The plot shows the first four TM bands in blue and TE bands in red. Its calculated TM gap-to-midgap ratio is 31.45%, compared with 31.4% in the book.
The structure is from Chapter 5, Figure 2 of Photonic Crystals: Molding the Flow of Light.

View source
"""Band structure of dielectric rods on a square lattice (2D)."""
import matplotlib.pyplot as plt
from morpho import BrillouinZonePath as BZPath
from morpho import Geometry, Solver, find_band_gaps, plot_bands, plot_brillouin_zone
from morpho import SymmetryPoint as SPoint
def main():
# Textbook reference: Chapter 5, Figure 2, alumina rods in air.
a = 1.0
radius = 0.2 * a
eps_rod = 8.9
n_grid = 129
pwe_order = 9
points_per_segment = 100
a1, a2 = (a, 0.0), (0.0, a)
Gamma = SPoint((0.0, 0.0), "Γ")
X = SPoint((0.5, 0.0), "X")
M = SPoint((0.5, 0.5), "M")
symmetry_points = [Gamma, X, M, Gamma]
path = BZPath(a1, a2, symmetry_points, points_per_segment=points_per_segment)
def eps_rf(eps_r, x, y):
mask = x**2 + y**2 <= radius**2
eps_r[mask] = eps_rod
geometry = Geometry(a1, a2, n_grid, n_grid, eps_rf=eps_rf)
tm_solver = Solver(geometry, path, P=pwe_order, Q=pwe_order, pol="TM")
te_solver = Solver(geometry, path, P=pwe_order, Q=pwe_order, pol="TE")
tm_solution = tm_solver.run(n_bands=4, store_modes=False)
te_solution = te_solver.run(n_bands=4, store_modes=False)
for gap in find_band_gaps(tm_solution, n_bands=2):
print(
f"TM path gap: {gap.lower:.4f}–{gap.upper:.4f}; gap-to-midgap {100 * gap.gap_to_midgap_ratio:.2f}%"
)
_, axis = plt.subplots(figsize=(7, 5), tight_layout=True)
plot_bands((tm_solution, te_solution), n_bands=4, ax=axis, lw=1.4)
plot_brillouin_zone(
tm_solution.path, ax=axis, inset=True, inset_bounds=(0.32, 0.12, 0.30, 0.25)
)
axis.set_ylim(0.0, 0.8)
plt.show()
if __name__ == "__main__":
main()
Two-dimensional triangular lattice of air columns¶
This example places air columns in a dielectric substrate with relative permittivity 13. The triangular lattice constant is normalized to \(a=1\), and the column radius is \(0.48a\). The real-space grid has \(129\times129\) samples; the plane-wave expansion uses orders \(P=Q=9\). The symmetry path is \(\Gamma\)–M–K–\(\Gamma\), sampled at 100 points per segment. The yellow region is the gap shared by the TM and TE bands along the sampled path. The plot shows the first six bands for each polarization. The calculated gap-to-midgap ratio is 18.82%, close to the book's 18.6% result.
This structure is in Chapter 5, Figure 10 (page 76) of Photonic Crystals: Molding the Flow of Light.

View source
"""Band structure of air columns on a triangular lattice (2D)."""
import matplotlib.pyplot as plt
import numpy as np
from morpho import BrillouinZonePath as BZPath
from morpho import Geometry, Solver, find_band_gaps, plot_bands, plot_brillouin_zone
from morpho import SymmetryPoint as SPoint
def main():
# Textbook reference: Chapter 5, Figure 10, triangular air columns.
a = 1.0
radius = 0.48 * a
eps_dielectric = 13.0
n_grid = 129
pwe_order = 9
points_per_segment = 100
a1 = (a, 0.0)
a2 = (-a / 2, np.sqrt(3) * a / 2)
Gamma = SPoint((0.0, 0.0), "Γ")
M = SPoint((0.5, 0.0), "M")
K = SPoint((1 / 3, 1 / 3), "K")
path = BZPath(a1, a2, [Gamma, M, K, Gamma], points_per_segment=points_per_segment)
def eps_rf(eps_r, x, y):
eps_r[:] = eps_dielectric
distance_squared = np.full(x.shape, np.inf)
for i in range(-1, 2):
for j in range(-1, 2):
center_x = i * a1[0] + j * a2[0]
center_y = i * a1[1] + j * a2[1]
distance_squared = np.minimum(
distance_squared,
(x - center_x) ** 2 + (y - center_y) ** 2,
)
air_columns = distance_squared <= radius**2
eps_r[air_columns] = 1.0
geometry = Geometry(a1, a2, n_grid, n_grid, eps_rf=eps_rf)
tm_solver = Solver(geometry, path, P=pwe_order, Q=pwe_order, pol="TM")
te_solver = Solver(geometry, path, P=pwe_order, Q=pwe_order, pol="TE")
tm_solution = tm_solver.run(n_bands=6, store_modes=False)
te_solution = te_solver.run(n_bands=6, store_modes=False)
for gap in find_band_gaps((tm_solution, te_solution)):
print(
f"Shared TM/TE path gap: {gap.lower:.4f}–{gap.upper:.4f}; gap-to-midgap {100 * gap.gap_to_midgap_ratio:.2f}%"
)
_, axis = plt.subplots(figsize=(7, 5), tight_layout=True)
plot_bands((tm_solution, te_solution), n_bands=6, ax=axis, lw=1.4)
plot_brillouin_zone(
tm_solution.path, ax=axis, inset=True, inset_bounds=(0.32, 0.12, 0.30, 0.25)
)
axis.set_ylim(0.0, 0.8)
plt.show()
if __name__ == "__main__":
main()
Three-dimensional simple-cubic dielectric rod network¶
The unit cell has normalized lattice constant \(a=1\). Dielectric rods of width \(0.2a\) and relative permittivity 2.34 run along the three cubic axes in an air background. The dielectric grid has \(64^3\) samples, and the plane-wave expansion uses orders \(P=Q=R=3\). The band path is D–Z–\(\Gamma\)–Z–T–X, with 40 points per segment.

View source
"""Band structure of a simple-cubic dielectric rod network (3D)."""
import matplotlib.pyplot as plt
import numpy as np
from morpho import BrillouinZonePath as BZPath
from morpho import Geometry, Solver, plot_bands, plot_brillouin_zone
from morpho import SymmetryPoint as SPoint
def main():
a = 1.0
rod_width = 0.2 * a
eps_rod = 2.34
n_grid = 64
pwe_order = 3
a1, a2, a3 = (a, 0.0, 0.0), (0.0, a, 0.0), (0.0, 0.0, a)
Gamma = SPoint((0.0, 0.0, 0.0), "Γ")
Z = SPoint((0.0, 0.0, 0.5), "Z")
X = SPoint((0.5, 0.0, 0.0), "X")
D = SPoint((0.5, 0.5, 0.5), "D")
T = SPoint((0.5, 0.0, 0.5), "T")
path = BZPath(a1, a2, a3, [D, Z, Gamma, Z, T, X], points_per_segment=40)
def eps_rf(eps_r, x, y, z):
edge = a / 2 - rod_width / 2
rod_x = (np.abs(y) >= edge) & (np.abs(z) >= edge)
rod_y = (np.abs(x) >= edge) & (np.abs(z) >= edge)
rod_z = (np.abs(x) >= edge) & (np.abs(y) >= edge)
eps_r[rod_x | rod_y | rod_z] = eps_rod
geometry = Geometry(a1, a2, a3, n_grid, n_grid, n_grid, eps_rf=eps_rf)
solver = Solver(geometry, path, P=pwe_order, Q=pwe_order, R=pwe_order)
solution = solver.run(store_modes=False)
_, axis = plt.subplots(figsize=(5, 4), tight_layout=True)
plot_bands(solution, ax=axis, lw=0.8)
zone_axis = plot_brillouin_zone(
solution.path, ax=axis, inset=True, inset_bounds=(0.0, 0.01, 0.30, 0.27)
)
zone_axis.view_init(elev=35, azim=-45)
axis.set_ylim(0.0, 1.6)
plt.show()
if __name__ == "__main__":
main()
Three-dimensional fcc close-packed dielectric spheres¶
This example places close-packed spheres with relative permittivity 13 in air. With the cubic supercell lattice constant normalized to \(a=1\), each sphere has radius \(a/(2\sqrt{2})\), so its diameter equals the fcc nearest-neighbor distance. The real-space grid has \(49^3\) samples; the plane-wave expansion uses orders \(P=Q=R=7\). It samples X–U–L–\(\Gamma\)–X–W–K with 20 points per segment and plots up to 64 bands. The book reports no complete photonic band gap for this structure.
This structure is in Chapter 6, Figure 2 of Photonic Crystals: Molding the Flow of Light.

View source
"""Band structure of close-packed dielectric spheres on an fcc lattice."""
from itertools import product
import matplotlib.pyplot as plt
import numpy as np
from morpho import BrillouinZonePath as BZPath
from morpho import Geometry, Solver, plot_bands, plot_brillouin_zone
from morpho import SymmetryPoint as SPoint
def primitive_vectors(a):
"""Return fcc primitive vectors for a cubic supercell of side ``a``."""
return (
(a / 2, a / 2, 0.0),
(0.0, a / 2, a / 2),
(a / 2, 0.0, a / 2),
)
def symmetry_path(a1, a2, a3, points_per_segment=20):
"""Follow X-U-L-Γ-X-W-K using reciprocal primitive coordinates."""
points = [
SPoint((1 / 2, 1 / 2, 0.0), "X"),
SPoint((5 / 8, 5 / 8, 1 / 4), "U"),
SPoint((1 / 2, 1 / 2, 1 / 2), "L"),
SPoint((0.0, 0.0, 0.0), "Γ"),
SPoint((1 / 2, 1 / 2, 0.0), "X"),
SPoint((3 / 4, 1 / 2, 1 / 4), "W"),
SPoint((3 / 4, 3 / 8, 3 / 8), "K"),
]
return BZPath(a1, a2, a3, points, points_per_segment=points_per_segment)
def periodic_sphere_mask(x, y, z, lattice_vectors, radius, basis_offsets):
"""Mark points inside spheres at every site of a periodic fcc basis."""
a1, a2, a3 = (np.asarray(vector) for vector in lattice_vectors)
distance_squared = np.full(x.shape, np.inf)
for i, j, k in product((-1, 0, 1), repeat=3):
translation = i * a1 + j * a2 + k * a3
for offset in basis_offsets:
center = translation + np.asarray(offset)
distance_squared = np.minimum(
distance_squared,
(x - center[0]) ** 2 + (y - center[1]) ** 2 + (z - center[2]) ** 2,
)
return distance_squared <= radius**2
def main():
# Textbook reference: Chapter 6, Figure 2, close-packed dielectric spheres.
# The cubic supercell lattice constant is normalized to a=1.
a = 1.0
a1, a2, a3 = primitive_vectors(a)
path = symmetry_path(a1, a2, a3, points_per_segment=20)
# Close-packed spheres have diameter equal to the fcc nearest-neighbor
# distance a/sqrt(2). They have epsilon=13 and are embedded in air.
n_grid = 49
pwe_order = 7
radius = a / (2 * np.sqrt(2))
eps_sphere = 13.0
def eps_rf(eps_r, x, y, z):
sphere = periodic_sphere_mask(x, y, z, (a1, a2, a3), radius, ((0.0, 0.0, 0.0),))
eps_r[sphere] = eps_sphere
geometry = Geometry(a1, a2, a3, n_grid, n_grid, n_grid, eps_rf=eps_rf)
solver = Solver(geometry, path, P=pwe_order, Q=pwe_order, R=pwe_order)
solution = solver.run(n_bands=64, store_modes=False)
_, axis = plt.subplots(figsize=(6, 5), tight_layout=True)
plot_bands(solution, n_bands=64, ax=axis, lattice_constant=a, lw=0.8)
zone_axis = plot_brillouin_zone(
solution.path, ax=axis, inset=True, inset_bounds=(0.0, 0.0, 0.36, 0.30)
)
zone_axis.view_init(elev=25, azim=-105)
axis.set_ylim(0.0, 1.0)
print("Structure: fcc close-packed spheres, epsilon=13 in air")
print(f"Plane-wave cutoff: {pwe_order} x {pwe_order} x {pwe_order}")
print(f"Sampled {len(solution.wn)} points on X-U-L-Γ-X-W-K")
print("The book reports no complete photonic band gap for this structure.")
plt.show()
if __name__ == "__main__":
main()
Three-dimensional diamond lattice of air spheres¶
This example places overlapping air spheres in a dielectric background with relative permittivity 13. The diamond lattice is represented by two interpenetrating fcc sublattices, with basis positions \((0,0,0)\) and \((a/4,a/4,a/4)\). The sphere radius is \(0.325a\), the real-space grid has \(49^3\) samples, and the plane-wave expansion uses orders \(P=Q=R=7\). The path is X–U–L–\(\Gamma\)–X–W–K with 20 points per segment. The yellow region marks the gap between bands two and three; along this sampled path, the calculated gap-to-midgap ratio is 28.96%, compared with 29.6% in the book.
This structure is in Chapter 6, Figure 3 of Photonic Crystals: Molding the Flow of Light.

View source
"""Band structure and gap of air spheres on a diamond lattice (3D)."""
from itertools import product
import matplotlib.pyplot as plt
import numpy as np
from morpho import BrillouinZonePath as BZPath
from morpho import Geometry, Solver, find_band_gaps, plot_bands, plot_brillouin_zone
from morpho import SymmetryPoint as SPoint
def primitive_vectors(a):
"""Return fcc primitive vectors for a cubic supercell of side ``a``."""
return (
(a / 2, a / 2, 0.0),
(0.0, a / 2, a / 2),
(a / 2, 0.0, a / 2),
)
def symmetry_path(a1, a2, a3, points_per_segment=20):
"""Follow X-U-L-Γ-X-W-K using reciprocal primitive coordinates."""
points = [
SPoint((1 / 2, 1 / 2, 0.0), "X"),
SPoint((5 / 8, 5 / 8, 1 / 4), "U"),
SPoint((1 / 2, 1 / 2, 1 / 2), "L"),
SPoint((0.0, 0.0, 0.0), "Γ"),
SPoint((1 / 2, 1 / 2, 0.0), "X"),
SPoint((3 / 4, 1 / 2, 1 / 4), "W"),
SPoint((3 / 4, 3 / 8, 3 / 8), "K"),
]
return BZPath(a1, a2, a3, points, points_per_segment=points_per_segment)
def periodic_sphere_mask(x, y, z, lattice_vectors, radius, basis_offsets):
"""Mark points inside spheres at every site of a periodic fcc basis."""
a1, a2, a3 = (np.asarray(vector) for vector in lattice_vectors)
distance_squared = np.full(x.shape, np.inf)
for i, j, k in product((-1, 0, 1), repeat=3):
translation = i * a1 + j * a2 + k * a3
for offset in basis_offsets:
center = translation + np.asarray(offset)
distance_squared = np.minimum(
distance_squared,
(x - center[0]) ** 2 + (y - center[1]) ** 2 + (z - center[2]) ** 2,
)
return distance_squared <= radius**2
def main():
# Textbook reference: Chapter 6, Figure 3, air spheres in dielectric.
# The conventional cubic supercell lattice constant is normalized to a=1.
a = 1.0
a1, a2, a3 = primitive_vectors(a)
path = symmetry_path(a1, a2, a3, points_per_segment=20)
# Two interpenetrating fcc sublattices form the diamond lattice. The
# radius 0.325a makes neighboring air spheres overlap.
n_grid = 49
pwe_order = 7
radius = 0.325 * a
eps_dielectric = 13.0
basis = ((0.0, 0.0, 0.0), (a / 4, a / 4, a / 4))
def eps_rf(eps_r, x, y, z):
eps_r[:] = eps_dielectric
air = periodic_sphere_mask(x, y, z, (a1, a2, a3), radius, basis)
eps_r[air] = 1.0
geometry = Geometry(a1, a2, a3, n_grid, n_grid, n_grid, eps_rf=eps_rf)
solver = Solver(geometry, path, P=pwe_order, Q=pwe_order, R=pwe_order)
solution = solver.run(n_bands=32, store_modes=False)
for gap in find_band_gaps(solution, n_bands=3, lattice_constant=a):
print(
f"Path gap: {gap.lower:.4f}–{gap.upper:.4f}; gap-to-midgap {100 * gap.gap_to_midgap_ratio:.2f}%"
)
_, axis = plt.subplots(figsize=(6, 5), tight_layout=True)
plot_bands(solution, n_bands=32, ax=axis, lattice_constant=a, lw=0.8)
zone_axis = plot_brillouin_zone(
solution.path, ax=axis, inset=True, inset_bounds=(0.0, 0.0, 0.36, 0.30)
)
zone_axis.view_init(elev=25, azim=-105)
axis.set_ylim(0.0, 1.0)
print("Structure: diamond lattice of air spheres in epsilon=13")
print(f"Sphere radius: {radius / a:.3f}a")
print(f"Plane-wave cutoff: {pwe_order} x {pwe_order} x {pwe_order}")
plt.show()
if __name__ == "__main__":
main()