.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/basic/plot_1d_grating.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_basic_plot_1d_grating.py: One dimensional grating ========================= Convergence. .. GENERATED FROM PYTHON SOURCE LINES 15-22 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import nannos as nn .. GENERATED FROM PYTHON SOURCE LINES 24-25 We will study the 1D metallic grating as in :cite:p:`Li1993`. .. GENERATED FROM PYTHON SOURCE LINES 25-80 .. code-block:: Python def convergence_study(form, psi, Nh): ts0 = [] tsm1 = [] ns = [] for nh in Nh: lattice = nn.Lattice(1, 2**9) eps_metal = (0.22 + 6.71j) ** 2 epsgrid = lattice.ones() * 1 hole = lattice.stripe(0.5, 0.5) epsgrid[hole] = eps_metal sup = lattice.Layer("Superstrate") sub = lattice.Layer("Substrate", epsilon=eps_metal) grating = lattice.Layer("Grating", thickness=1) grating.epsilon = epsgrid stack = [sup, grating, sub] pw = nn.PlaneWave(wavelength=1, angles=(30, 0, psi)) sim = nn.Simulation(stack, pw, nh, formulation=form) R, T = sim.diffraction_efficiencies() Ri, Ti = sim.diffraction_efficiencies(orders=True) R0 = sim.get_order(Ri, 0) Rm1 = sim.get_order(Ri, -1) ts0.append(R0) tsm1.append(Rm1) ns.append(sim.nh) return np.array(ns), 100 * np.array(ts0), 100 * np.array(tsm1) def run(psi): Nh = range(5, 125, 2) fig, ax = plt.subplots(2, 1, figsize=(2.0, 3.0)) title = "TM" if psi == 0 else "TE" ns, ts0, tsm1 = convergence_study("original", psi, Nh) ax[0].plot(ns, ts0, "-o", label="original", c="#dd803d", ms=1) ax[1].plot(ns, tsm1, "-o", label="original", c="#dd803d", ms=1) ns_tan, ts0_tan, tsm1_tan = convergence_study("tangent", psi, Nh) ax[0].plot( ns_tan, ts0_tan, "--s", label="tangent", c="#4a4082", ms=2, mew=0.4, mfc="None" ) ax[1].plot( ns_tan, tsm1_tan, "--s", label="tangent", c="#4a4082", ms=2, mew=0.4, mfc="None" ) ax[0].set_title("order 0") ax[1].set_title("order -1") ax[0].legend() ax[1].legend() ax[0].set_xlabel("number of harmonics") ax[0].set_ylabel("diffraction efficiency (%)") ax[1].set_ylabel("diffraction efficiency (%)") plt.suptitle(title, weight="bold", size=8) plt.tight_layout() plt.pause(0.1) .. GENERATED FROM PYTHON SOURCE LINES 81-82 For TE polarization the two formulations are equivalent: .. GENERATED FROM PYTHON SOURCE LINES 82-86 .. code-block:: Python run(psi=90) .. image-sg:: /examples/basic/images/sphx_glr_plot_1d_grating_001.png :alt: TE, order 0, order -1 :srcset: /examples/basic/images/sphx_glr_plot_1d_grating_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 87-90 We can see that in TM polarization, the convergence is greatly improved by using proper Fourier factorization rules implemented by the ``tangent`` formulation. .. GENERATED FROM PYTHON SOURCE LINES 90-93 .. code-block:: Python run(psi=0) .. image-sg:: /examples/basic/images/sphx_glr_plot_1d_grating_002.png :alt: TM, order 0, order -1 :srcset: /examples/basic/images/sphx_glr_plot_1d_grating_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 22.449 seconds) **Estimated memory usage:** 715 MB .. _sphx_glr_download_examples_basic_plot_1d_grating.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/nannos/nannos.gitlab.io/doc?filepath=notebooks/examples/basic/plot_1d_grating.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_1d_grating.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_1d_grating.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_1d_grating.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_