.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/plot_phc.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_plot_phc.py: Band diagram of 2D photonic crystal =================================== Calculation of the band diagram of a two-dimensional photonic crystal. .. GENERATED FROM PYTHON SOURCE LINES 15-24 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import protis as pt pi = np.pi .. GENERATED FROM PYTHON SOURCE LINES 25-32 Reference results are taken from :cite:p:`Joannopoulos2008` (Chapter 5 Fig. 2). The structure is a square lattice of dielectric columns, with radius r and dielectric constant :math:`\varepsilon`. The material is invariant along the z direction and periodic along :math:`x` and :math:`y` with lattice constant :math:`a`. We will define the lattie using the class :class:`~protis.Lattice` .. GENERATED FROM PYTHON SOURCE LINES 32-37 .. code-block:: Python a = 1 lattice = pt.Lattice([[a, 0], [0, a]], discretization=2**9) .. GENERATED FROM PYTHON SOURCE LINES 38-39 Define the permittivity .. GENERATED FROM PYTHON SOURCE LINES 39-43 .. code-block:: Python epsilon = lattice.ones() * 1 rod = lattice.circle(center=(0.5, 0.5), radius=0.2) epsilon[rod] = 8.9 .. GENERATED FROM PYTHON SOURCE LINES 44-45 We define here the wavevector path: .. GENERATED FROM PYTHON SOURCE LINES 45-53 .. code-block:: Python Gamma = (0, 0) X = (pi / a, 0) M = (pi / a, pi / a) sym_points = [Gamma, X, M, Gamma] Nb = 21 kpath = pt.init_bands(sym_points, Nb) .. GENERATED FROM PYTHON SOURCE LINES 54-55 Calculate the band diagram: .. GENERATED FROM PYTHON SOURCE LINES 55-71 .. code-block:: Python sim = pt.Simulation(lattice, epsilon=epsilon, nh=100) BD = {} for polarization in ["TE", "TM"]: ev_band = [] for kx, ky in kpath: sim.k = kx, ky sim.solve(polarization, vectors=False) ev_norma = sim.eigenvalues * a / (2 * pi) ev_band.append(ev_norma) BD[polarization] = ev_band BD["TM"] = pt.backend.stack(BD["TM"]).real BD["TE"] = pt.backend.stack(BD["TE"]).real .. GENERATED FROM PYTHON SOURCE LINES 72-73 Plot the bands: .. GENERATED FROM PYTHON SOURCE LINES 73-86 .. code-block:: Python labels = ["$\Gamma$", "$X$", "$M$", "$\Gamma$"] plt.figure() plotTM = pt.plot_bands(sym_points, Nb, BD["TM"], color="#4199b0") plotTE = pt.plot_bands(sym_points, Nb, BD["TE"], xtickslabels=labels, color="#cf5268") plt.annotate("TM modes", (1, 0.05), c="#4199b0") plt.annotate("TE modes", (0.33, 0.33), c="#cf5268") plt.ylim(0, 0.8) plt.ylabel(r"Frequency $\omega a/2\pi c$") plt.tight_layout() .. image-sg:: /examples/images/sphx_glr_plot_phc_001.png :alt: plot phc :srcset: /examples/images/sphx_glr_plot_phc_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.143 seconds) **Estimated memory usage:** 27 MB .. _sphx_glr_download_examples_plot_phc.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/protis/protis.gitlab.io/doc?filepath=notebooks/examples/plot_phc.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_phc.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_phc.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_