{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# This file is part of protis\n# License: GPLv3\n%matplotlib notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Band diagram of 2D photonic crystal\n\nCalculation of the band diagram of a two-dimensional photonic crystal.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nimport protis as pt\n\npi = np.pi" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Reference results are taken from :cite:p:`Joannopoulos2008` (Chapter 5 Fig. 2).\n\nThe structure is a square lattice of dielectric\ncolumns, with radius r and dielectric constant $\\varepsilon$.\nThe material is invariant along the z direction and periodic along\n$x$ and $y$ with lattice constant $a$.\nWe will define the lattie using the class :class:`~protis.Lattice`\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "a = 1\nlattice = pt.Lattice([[a, 0], [0, a]], discretization=2**9)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the permittivity\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "epsilon = lattice.ones() * 1\nrod = lattice.circle(center=(0.5, 0.5), radius=0.2)\nepsilon[rod] = 8.9" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We define here the wavevector path:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "Gamma = (0, 0)\nX = (pi / a, 0)\nM = (pi / a, pi / a)\nsym_points = [Gamma, X, M, Gamma]\n\nNb = 21\nkpath = pt.init_bands(sym_points, Nb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculate the band diagram:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "sim = pt.Simulation(lattice, epsilon=epsilon, nh=100)\n\nBD = {}\nfor polarization in [\"TE\", \"TM\"]:\n ev_band = []\n for kx, ky in kpath:\n sim.k = kx, ky\n sim.solve(polarization, vectors=False)\n ev_norma = sim.eigenvalues * a / (2 * pi)\n ev_band.append(ev_norma)\n BD[polarization] = ev_band\nBD[\"TM\"] = pt.backend.stack(BD[\"TM\"]).real\nBD[\"TE\"] = pt.backend.stack(BD[\"TE\"]).real" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot the bands:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "labels = [\"$\\Gamma$\", \"$X$\", \"$M$\", \"$\\Gamma$\"]\n\n\nplt.figure()\nplotTM = pt.plot_bands(sym_points, Nb, BD[\"TM\"], color=\"#4199b0\")\nplotTE = pt.plot_bands(sym_points, Nb, BD[\"TE\"], xtickslabels=labels, color=\"#cf5268\")\n\nplt.annotate(\"TM modes\", (1, 0.05), c=\"#4199b0\")\nplt.annotate(\"TE modes\", (0.33, 0.33), c=\"#cf5268\")\nplt.ylim(0, 0.8)\nplt.ylabel(r\"Frequency $\\omega a/2\\pi c$\")\nplt.tight_layout()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import protis.utils.jupyter\n%protis_version_table" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.13" } }, "nbformat": 4, "nbformat_minor": 0 }