Band structure calculation of a photonic crystal slab#

In this notebook, we simulate a photonic crystal slab consisting of a square lattice of air holes in a dielectric slab. Our goal is to compute the band structure of this photonic crystal slab, as found in:

Shanhui Fan and J. D. Joannopoulos, “Analysis of guided resonances in photonic crystal slabs,” Phys. Rev. B 65, 235112 (2002).

To this end, we excite the structure with several PointDipole sources, and we measure the response with several FieldTimeMonitor monitors. We excite modes with a fixed Bloch wavevector by using Bloch boundary conditions. We then use the ResonanceFinder to find the resonant frequencies. By sweeping the Bloch wavevector, we obtain the full band structure of the photonic crystal slab.

See also the api reference for ResonanceFinder here.

# standard python imports
import numpy as np
import matplotlib.pyplot as plt
import xarray as xr

import tidy3d as td
from tidy3d import web
from tidy3d.plugins.resonance import ResonanceFinder

We will randomly position our sources and monitors. Here, we seed the random number generator to guarantee reproducible results.

rng = np.random.default_rng(12345)

Now we define the parameters for the simulation, structure, sources, and monitors.

We take the dipole polarization to be Hz and the symmetry to be (0,0,1) in order to excite only modes which are even with respect to the xy mirror plane.

# Simulation parameters
runtime_fwidth = 200.0  # in units of 1/frequency bandwidth of the source
t_start_fwidth = 5.0  # time to start monitoring after source has decayed, units of 1/frequency bandwidth
dPML = 1.0  # space between PhC slabs and PML, in unit of longest wavelength of interest

# Structure parameters (um)
a_lattice = 1  # lattice constant "a"
r_hole = 0.2 * a_lattice  # radius of the air holes
t_slab = 0.5 * a_lattice  # slab thickness
ep_slab = 12  # dielectric constant of the slab
ep_hole = 1  # dielectric constant of the holes

# Frequency range of interest (Hz)
freq_range_unitless = np.array((0.1, 0.43))  # in units of c/a
freq_scale = (
    td.constants.C_0 / a_lattice
)  # frequency scale determined by the lattice constant
freq_range = freq_range_unitless * freq_scale
lambda_range = (td.constants.C_0 / freq_range[1], td.constants.C_0 / freq_range[0])

# Gaussian pulse parameters
freq0 = np.sum(freq_range) / 2  # central frequency
freqw = 0.3 * (freq_range[1] - freq_range[0])  # pulse width

# Runtime
run_time = runtime_fwidth / freqw
print(f"Total runtime = {(run_time*1e12):.2f} ps")
t_start = t_start_fwidth / freqw

# Simulation size
spacing = dPML * lambda_range[-1]  # space between PhC slabs and PML
sim_size = Lx, Ly, Lz = (a_lattice, a_lattice, 2 * spacing + t_slab)

# Number of k values to sample, per edge of the irreducible Brillouin zone
Nk = 4

# Number of dipoles and monitors
num_dipoles = 7
num_monitors = 2

# Dipole polarization and symmetry
polarization = "Hz"
symmetry = (0, 0, 1)

Total runtime = 6.74 ps

We define the materials and structures in terms of the above parameters. We take the photonic crystal slab to be lying in the xy plane. Because the photonic crystal slab is periodic in the x and y directions, we only need to simulate a single unit cell, containing the dielectric slab and a single air hole.

mat_slab = td.Medium(permittivity=ep_slab, name="mat_slab")
mat_hole = td.Medium(permittivity=ep_hole, name="mat_hole")

slab = td.Structure(
        center=(0, 0, 0),
        size=(td.inf, td.inf, t_slab),

hole = td.Structure(
        center=(0, 0, 0),

structures = [slab, hole]

We will excite the photonic crystal slab with several PointDipole sources. Each dipole will have a random position and phase.

dipole_positions = rng.uniform(
    [-Lx / 2, -Ly / 2, 0], [Lx / 2, Ly / 2, 0], [num_dipoles, 3]

dipole_phases = rng.uniform(0, 2 * np.pi, num_dipoles)

pulses = []
dipoles = []
for i in range(num_dipoles):
    pulse = td.GaussianPulse(freq0=freq0, fwidth=freqw, phase=dipole_phases[i])
            name="dipole_" + str(i),

We create FieldTimeMonitors to record the field as a function of time at several random locations within the photonic crystal slab. Crucially, we start the monitors after the source pulse has decayed.

monitor_positions = rng.uniform(
    [-Lx / 2, -Ly / 2, 0], [Lx / 2, Ly / 2, 0], [num_monitors, 3]

monitors_time = []
for i in range(num_monitors):
            size=(0, 0, 0),
            name="monitor_time_" + str(i),

We will perform 3*Nk different simulations, each with different Bloch boundary conditions, as we sweep the Bloch wavevector over the boundary of the irreducible Brillouin zone. We sweep over three lines, namely \(\Gamma X\), \(XM\), and \(M\Gamma\). We use a PML in the z direction.

Here, we simply define all of the boundary conditions we will use and put them into a single array.

bspecs_gammax = []
bspecs_xm = []
bspecs_mgamma = []
for i in range(Nk):
            x=td.Boundary.bloch((1 / 2) * i / Nk),
            x=td.Boundary.bloch(1 / 2),
            y=td.Boundary.bloch((1 / 2) * i / Nk),
            x=td.Boundary.bloch((1 / 2) * (1 - i / Nk)),
            y=td.Boundary.bloch((1 / 2) * (1 - i / Nk)),
bspecs = bspecs_gammax + bspecs_xm + bspecs_mgamma

Now we define the simulations we want to run.

sims = {}
for i in range(3 * Nk):
    sims[f"sim_{i}"] = td.Simulation(
        center=(0, 0, 0),

Let’s check that the structure and source look correct. The source spectrum must fill the entire frequency range of interest.

fig, ax = plt.subplots(1, 2, tight_layout=True, figsize=(10, 4))
sims["sim_0"].plot(z=0.0, ax=ax[0])
sims["sim_0"].plot(x=0, freq=freq0, ax=ax[1])

f, (ax1, ax2) = plt.subplots(1, 2, tight_layout=True, figsize=(8, 4))
plot_time = 5 / freqw
ax1 = (
    .source_time.plot(times=np.linspace(0, plot_time, 1001), val="abs", ax=ax1)
ax1.set_xlim(0, plot_time)
ax2 = (
        times=np.linspace(0, sims["sim_0"].run_time, 10001), val="abs", ax=ax2
ax2.hlines(1.5e-15, freq_range[0], freq_range[1], linewidth=10, color="g", alpha=0.4)
ax2.legend(("source spectrum", "measurement"))


Now we run the simulations as a Batch.

We set verbose=True to keep track of the status of the jobs in the Batch.

# initialize a batch and run them all
batch = td.web.Batch(simulations=sims, verbose=True)

# run the batch and store all of the data in the `data/` dir.
batch_data ="data")

[11:42:02] Created task 'sim_0' with task_id 'fdve-6fa2d798-495b-4972-b3fc-3cee3b67f859v1'. 
[11:42:06] Created task 'sim_1' with task_id 'fdve-08a2554a-c938-4a68-b24c-ced47b18d48cv1'. 
[11:42:09] Created task 'sim_2' with task_id 'fdve-767289f2-a3be-462f-b77a-e155f17f37a8v1'. 
[11:42:11] Created task 'sim_3' with task_id 'fdve-23d277ad-39c1-42f9-85c2-39cf887e5e47v1'. 
[11:42:14] Created task 'sim_4' with task_id 'fdve-7a224d9f-9b97-4fc7-92b1-1073312964cfv1'. 
[11:42:17] Created task 'sim_5' with task_id 'fdve-64eb8903-a050-443c-96a3-46b80d77221bv1'. 
[11:42:19] Created task 'sim_6' with task_id 'fdve-8ff69772-7490-43f5-bdc7-3ecca7dd71d5v1'. 
[11:42:21] Created task 'sim_7' with task_id 'fdve-b50ad591-561c-4c83-933c-9d2b29164fdcv1'. 
[11:42:24] Created task 'sim_8' with task_id 'fdve-96a02be8-e74e-42e7-8f58-ff5f768addf3v1'. 
[11:42:26] Created task 'sim_9' with task_id 'fdve-79417f79-693e-4a85-bd0f-4ce56b758f52v1'. 
[11:42:29] Created task 'sim_10' with task_id 'fdve-aa5f4604-12a0-4707-bd6d-9d52ab0b87a6v1'.
[11:42:31] Created task 'sim_11' with task_id 'fdve-64adf0a7-85df-4570-9953-7737b63bcd4cv1'.
[11:42:50] Started working on Batch.                                                     
[11:43:28] Batch complete.                                                               

Now that the simulations are complete, we can analyze the data. Let’s first look at one of the FieldTimeMonitors to make sure the source has decayed.

plt.title("FieldTimeMonitor data")

[11:43:39] loading SimulationData from data/fdve-08a2554a-c938-4a68-b24c-ced47b18d48cv1.hdf5
[11:43:39] loading SimulationData from data/fdve-08a2554a-c938-4a68-b24c-ced47b18d48cv1.hdf5

We see that the source has mostly decayed by the time we switch on the monitors, and the remaining data shows decay and oscillation due to the resonances inside the system.

Looking at the Fourier transform of this data, we can see resonances at the band frequencies.

df = 1 / np.amax(batch_data["sim_1"].monitor_data["monitor_time_0"].Hz.t)
minn = int(freq_range[0] / df)
maxn = int(freq_range[1] / df)
spectrum = np.fft.fft(batch_data["sim_1"].monitor_data["monitor_time_0"].Hz.squeeze())
    np.linspace(freq_range[0], freq_range[1], maxn - minn),
plt.title("Spectrum at single wavevector")
plt.xlabel("Frequency (Hz)")

[11:43:39] loading SimulationData from data/fdve-08a2554a-c938-4a68-b24c-ced47b18d48cv1.hdf5
[11:43:39] loading SimulationData from data/fdve-08a2554a-c938-4a68-b24c-ced47b18d48cv1.hdf5

We use the ResonanceFinder plugin to find the band frequencies.

We first construct a ResonanceFinder object storing our parameters, and then call run() on our list of FieldTimeData objects. This will add up the signals from all of the monitors before searching for resonances. The ResonanceFinder class has additional methods in case the signal takes another form; see the api reference here.

The run() method returns an xr.Dataset containing the decay rate, Q factor, amplitude, phase, and estimation error for each resonance as a function of frequency.

resonance_finder = ResonanceFinder(freq_window=tuple(freq_range))
resonance_data =["sim_1"].data)

[11:43:39] loading SimulationData from data/fdve-08a2554a-c938-4a68-b24c-ced47b18d48cv1.hdf5
decay Q amplitude phase error
9.788257e+13 7.428270e+11 413.968741 0.008960 2.039637 0.000035
1.061235e+14 9.531281e+10 3497.922685 0.028086 -3.058134 0.000009
1.131267e+14 2.127627e+12 167.039520 0.036952 1.800998 0.000046
1.191562e+14 1.151269e+12 325.154501 0.020891 -2.067634 0.000032
1.372965e+14 1.087938e+12 396.465361 0.022803 -0.422145 0.000066

We see the four resonances from the previous figure. All four have reasonable Q factors, amplitudes, and errors, so they are likely to represent physical resonances. Note that in order to accurately obtain the Q factor for high-Q modes, it may be necessary to run the simulation for a longer time.

Now we are ready to compute the band structure. We run the resonance finder at every Bloch wavevector.

resonance_finder = ResonanceFinder(freq_window=tuple(freq_range))
resonance_datas = []
for i in range(3 * Nk):
    sim_data = batch_data[f"sim_{i}"]

[11:43:50] loading SimulationData from data/fdve-6fa2d798-495b-4972-b3fc-3cee3b67f859v1.hdf5
[11:43:50] loading SimulationData from data/fdve-08a2554a-c938-4a68-b24c-ced47b18d48cv1.hdf5
[11:44:00] loading SimulationData from data/fdve-767289f2-a3be-462f-b77a-e155f17f37a8v1.hdf5
[11:44:17] loading SimulationData from data/fdve-23d277ad-39c1-42f9-85c2-39cf887e5e47v1.hdf5
[11:44:25] loading SimulationData from data/fdve-7a224d9f-9b97-4fc7-92b1-1073312964cfv1.hdf5
[11:44:34] loading SimulationData from data/fdve-64eb8903-a050-443c-96a3-46b80d77221bv1.hdf5
[11:44:43] loading SimulationData from data/fdve-8ff69772-7490-43f5-bdc7-3ecca7dd71d5v1.hdf5
[11:44:51] loading SimulationData from data/fdve-b50ad591-561c-4c83-933c-9d2b29164fdcv1.hdf5
[11:45:03] loading SimulationData from data/fdve-96a02be8-e74e-42e7-8f58-ff5f768addf3v1.hdf5
[11:45:13] loading SimulationData from data/fdve-79417f79-693e-4a85-bd0f-4ce56b758f52v1.hdf5
[11:45:24] loading SimulationData from data/fdve-aa5f4604-12a0-4707-bd6d-9d52ab0b87a6v1.hdf5
[11:45:36] loading SimulationData from data/fdve-64adf0a7-85df-4570-9953-7737b63bcd4cv1.hdf5

We define a function to filter resonances based on their Q, amplitude, and error.

def filter_resonances(resonance_data, minQ, minamp, maxerr):
    resonance_data = resonance_data.where(abs(resonance_data.Q) > minQ, drop=True)
    resonance_data = resonance_data.where(resonance_data.amplitude > minamp, drop=True)
    resonance_data = resonance_data.where(resonance_data.error < maxerr, drop=True)
    return resonance_data

We plot the band structure with the light line overlaid.

for i in range(3 * Nk):
    resonance_data = resonance_datas[i]
    resonance_data = filter_resonances(
        resonance_data=resonance_data, minQ=0, minamp=0.001, maxerr=100
    freqs = resonance_data.freq.to_numpy()
    Qs = resonance_data.Q.to_numpy()
    plt.scatter(np.full(len(freqs), (1 / 2) * i / Nk), freqs / 3e14, color="blue")

lightx = np.linspace(0, 0.5, 100)
lighty1 = lightx
lighty3 = (0.5 - lightx) * np.sqrt(2)

plt.plot(lightx, lighty1, color="blue", alpha=0.2)
plt.plot(1 + lightx, lighty3, color="blue", alpha=0.2)

plt.ylim(0, freq_range_unitless[1])

plt.title("Band diagram")
plt.ylabel("Frequency (c/a)")
plt.xticks([0, 0.5, 1, 1.5], ["$\Gamma$", "X", "M", "$\Gamma$"])
plt.xlim(0, 1.5)


The bandstructure we obtained matches the expected result from the paper. If we were seeing too many resonances, we could change the parameters to our filter_resonances function to eliminate the spurious ones. If we were seeing too few resonances even before filtering, we might have to change the parameters of the ResonanceFinder, for example decreasing rcond or increasing init_num_freqs. If the ResonanceFinder takes too long, we can decrease init_num_freqs. There can also be resonances on the light line associated with Wood’s anomaly; we filter those out here based on their small amplitude.