{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# This file is part of nannos\n# License: GPLv3\n%matplotlib notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# One dimensional grating\n\nConvergence.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nimport nannos as nn" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will study the 1D metallic grating as in :cite:p:`Li1993`.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def convergence_study(form, psi, Nh):\n ts0 = []\n tsm1 = []\n ns = []\n for nh in Nh:\n lattice = nn.Lattice(1, 2**9)\n eps_metal = (0.22 + 6.71j) ** 2\n epsgrid = lattice.ones() * 1\n hole = lattice.stripe(0.5, 0.5)\n epsgrid[hole] = eps_metal\n sup = lattice.Layer(\"Superstrate\")\n sub = lattice.Layer(\"Substrate\", epsilon=eps_metal)\n grating = lattice.Layer(\"Grating\", thickness=1)\n grating.epsilon = epsgrid\n stack = [sup, grating, sub]\n pw = nn.PlaneWave(wavelength=1, angles=(30, 0, psi))\n sim = nn.Simulation(stack, pw, nh, formulation=form)\n R, T = sim.diffraction_efficiencies()\n Ri, Ti = sim.diffraction_efficiencies(orders=True)\n R0 = sim.get_order(Ri, 0)\n Rm1 = sim.get_order(Ri, -1)\n ts0.append(R0)\n tsm1.append(Rm1)\n ns.append(sim.nh)\n return np.array(ns), 100 * np.array(ts0), 100 * np.array(tsm1)\n\n\ndef run(psi):\n Nh = range(5, 125, 2)\n fig, ax = plt.subplots(2, 1, figsize=(2.0, 3.0))\n title = \"TM\" if psi == 0 else \"TE\"\n ns, ts0, tsm1 = convergence_study(\"original\", psi, Nh)\n ax[0].plot(ns, ts0, \"-o\", label=\"original\", c=\"#dd803d\", ms=1)\n ax[1].plot(ns, tsm1, \"-o\", label=\"original\", c=\"#dd803d\", ms=1)\n ns_tan, ts0_tan, tsm1_tan = convergence_study(\"tangent\", psi, Nh)\n ax[0].plot(\n ns_tan, ts0_tan, \"--s\", label=\"tangent\", c=\"#4a4082\", ms=2, mew=0.4, mfc=\"None\"\n )\n ax[1].plot(\n ns_tan, tsm1_tan, \"--s\", label=\"tangent\", c=\"#4a4082\", ms=2, mew=0.4, mfc=\"None\"\n )\n ax[0].set_title(\"order 0\")\n ax[1].set_title(\"order -1\")\n ax[0].legend()\n ax[1].legend()\n ax[0].set_xlabel(\"number of harmonics\")\n ax[0].set_ylabel(\"diffraction efficiency (%)\")\n ax[1].set_ylabel(\"diffraction efficiency (%)\")\n plt.suptitle(title, weight=\"bold\", size=8)\n plt.tight_layout()\n plt.pause(0.1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For TE polarization the two formulations are equivalent:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "run(psi=90)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can see that in TM polarization, the convergence is greatly\nimproved by using proper Fourier factorization rules implemented by the\n``tangent`` formulation.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "run(psi=0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import nannos.utils.jupyter\n%nannos_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 }