.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/plot_permittivity_fft.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_tutorials_plot_permittivity_fft.py: Permittivity approximation ========================== Get the Fourier representation of the permittivity as a function of number of harmonics. .. GENERATED FROM PYTHON SOURCE LINES 15-33 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import nannos as nn lattice = nn.Lattice([[1.5, 0], [0.4, 1]], discretization=(2**10, 2**10)) sup = lattice.Layer("Superstrate", epsilon=1) sub = lattice.Layer("Substrate", epsilon=1) hole = lattice.ellipse(center=(1.1, 0.6), radii=(0.2, 0.4), rotate=60) incl = lattice.rectangle(center=(0.5, 0.3), widths=(0.2, 0.4), rotate=-45) epsilon = lattice.ones() * 4 epsilon[hole] = 1 epsilon[incl] = 6 ms = lattice.Layer("Metasurface", thickness=0.5, epsilon=epsilon) pw = nn.PlaneWave(wavelength=1.5, angles=(0, 0, 0)) .. GENERATED FROM PYTHON SOURCE LINES 34-35 Lets first plot the permmitivity we want to approximate .. GENERATED FROM PYTHON SOURCE LINES 35-44 .. code-block:: Python plt.figure() ims = ms.plot(cmap="viridis") plt.xlabel("$x$") plt.ylabel("$y$") plt.colorbar(ims[0], orientation="horizontal") plt.tight_layout() .. image-sg:: /tutorials/images/sphx_glr_plot_permittivity_fft_001.png :alt: plot permittivity fft :srcset: /tutorials/images/sphx_glr_plot_permittivity_fft_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 45-46 Loop through number of harmonics .. GENERATED FROM PYTHON SOURCE LINES 46-58 .. code-block:: Python for n in [3, 5, 7, 11, 21, 41]: sim = nn.Simulation([sup, ms, sub], pw, nh=n**2) eps = sim.get_epsilon(ms) plt.figure(figsize=(2, 2)) approx = plt.pcolormesh(*lattice.grid, eps.real) ims = ms.plot(alpha=0.1, cmap="Greys") plt.xlabel("$x$") plt.ylabel("$y$") plt.colorbar(approx, orientation="horizontal") plt.title(rf"$n_h = {sim.nh}$") plt.tight_layout() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /tutorials/images/sphx_glr_plot_permittivity_fft_002.png :alt: $n_h = 7$ :srcset: /tutorials/images/sphx_glr_plot_permittivity_fft_002.png :class: sphx-glr-multi-img * .. image-sg:: /tutorials/images/sphx_glr_plot_permittivity_fft_003.png :alt: $n_h = 23$ :srcset: /tutorials/images/sphx_glr_plot_permittivity_fft_003.png :class: sphx-glr-multi-img * .. image-sg:: /tutorials/images/sphx_glr_plot_permittivity_fft_004.png :alt: $n_h = 47$ :srcset: /tutorials/images/sphx_glr_plot_permittivity_fft_004.png :class: sphx-glr-multi-img * .. image-sg:: /tutorials/images/sphx_glr_plot_permittivity_fft_005.png :alt: $n_h = 117$ :srcset: /tutorials/images/sphx_glr_plot_permittivity_fft_005.png :class: sphx-glr-multi-img * .. image-sg:: /tutorials/images/sphx_glr_plot_permittivity_fft_006.png :alt: $n_h = 433$ :srcset: /tutorials/images/sphx_glr_plot_permittivity_fft_006.png :class: sphx-glr-multi-img * .. image-sg:: /tutorials/images/sphx_glr_plot_permittivity_fft_007.png :alt: $n_h = 1679$ :srcset: /tutorials/images/sphx_glr_plot_permittivity_fft_007.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 15.720 seconds) **Estimated memory usage:** 1099 MB .. _sphx_glr_download_tutorials_plot_permittivity_fft.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/tutorials/plot_permittivity_fft.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_permittivity_fft.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_permittivity_fft.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_permittivity_fft.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_