.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/basic/plot_square_patch.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_square_patch.py: Dielectric patch array ====================== Transmission spectrum. .. GENERATED FROM PYTHON SOURCE LINES 15-26 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from matplotlib.colors import ListedColormap from scipy.constants import c, e, h import nannos as nn .. GENERATED FROM PYTHON SOURCE LINES 28-29 Results are compared to the reference :cite:p:`Tikhodeev2002`. .. GENERATED FROM PYTHON SOURCE LINES 29-39 .. code-block:: Python eps_quartz = 2.132 eps_active = 3.97 N = 2**7 period = 0.68 l_patch = 0.8 * period .. GENERATED FROM PYTHON SOURCE LINES 40-41 Define the lattice .. GENERATED FROM PYTHON SOURCE LINES 41-45 .. code-block:: Python lattice = nn.Lattice(([period, 0], [0, period]), discretization=(N, N)) .. GENERATED FROM PYTHON SOURCE LINES 46-47 Define the slab layer with a square patch .. GENERATED FROM PYTHON SOURCE LINES 47-68 .. code-block:: Python epsilon = lattice.ones() * eps_quartz square = lattice.square(center=(0.5 * period, 0.5 * period), width=l_patch) epsilon[square] = eps_active slab = lattice.Layer("Slab", thickness=0.12) slab.epsilon = epsilon cmap = ListedColormap(["#dddddd", "#73a0e8"]) plt.figure(figsize=(3, 2.5)) im = slab.plot(cmap=cmap) cbar = plt.colorbar(im[0], ticks=[eps_quartz, eps_active]) plt.xlabel(r"$x$ ($\mu$m)") plt.ylabel(r"$y$ ($\mu$m)") plt.title(r"$\varepsilon$") plt.axis("scaled") plt.tight_layout() plt.show() .. image-sg:: /examples/basic/images/sphx_glr_plot_square_patch_001.png :alt: $\varepsilon$ :srcset: /examples/basic/images/sphx_glr_plot_square_patch_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 69-70 Define the simulation .. GENERATED FROM PYTHON SOURCE LINES 70-92 .. code-block:: Python sup = lattice.Layer("Superstrate", epsilon=1) sub = lattice.Layer("Substrate", epsilon=eps_quartz) stack = [sup, slab, sub] def compute_transmission(fev): w = h * c / e / (fev * 1e-6) pw = nn.PlaneWave(wavelength=w, angles=(0, 0, 90)) sim = nn.Simulation(stack, pw, 100, formulation="original") R, T = sim.diffraction_efficiencies() print(f"f = {fev}eV") print("T = ", T) return T freqsev = np.linspace(1, 2.6, 101) fev_adapted, transmission = nn.adaptive_sampler( compute_transmission, freqsev, max_bend=10, max_x_rel=0.001, max_df=0.005 ) .. rst-class:: sphx-glr-script-out .. code-block:: none f = 1.0eV T = 0.875079841479671 f = 1.016eV T = 0.8733086223140683 f = 1.032eV T = 0.8715383631793254 f = 1.048eV T = 0.8697632452161226 f = 1.064eV T = 0.8679753643630375 f = 1.08eV T = 0.8661639185691241 f = 1.096eV T = 0.8643139580601631 f = 1.112eV T = 0.8624043894850065 f = 1.1280000000000001eV T = 0.8604046400838723 f = 1.1440000000000001eV T = 0.8582687627131041 f = 1.16eV T = 0.8559242630674468 f = 1.176eV T = 0.853248908507815 f = 1.192eV T = 0.8500162551486128 f = 1.208eV T = 0.8457424321117241 f = 1.224eV T = 0.8391067025346531 f = 1.24eV T = 0.8237634300182944 f = 1.256eV T = 0.8386779297361336 f = 1.272eV T = 0.8588077634164764 f = 1.288eV T = 0.8636751296187558 f = 1.304eV T = 0.8657239751848143 f = 1.32eV T = 0.8667531922358099 f = 1.336eV T = 0.8673049000582131 f = 1.3519999999999999eV T = 0.8676023288070067 f = 1.3679999999999999eV T = 0.867755635682578 f = 1.384eV T = 0.867826078859081 f = 1.4eV T = 0.8678507527654894 f = 1.416eV T = 0.8678536045987653 f = 1.432eV T = 0.8678508873425411 f = 1.448eV T = 0.8678540863103513 f = 1.464eV T = 0.86787159396402 f = 1.48eV T = 0.8679097202856495 f = 1.496eV T = 0.8679733303581473 f = 1.512eV T = 0.8680662633974666 f = 1.528eV T = 0.8681916195246092 f = 1.544eV T = 0.8683519654283142 f = 1.56eV T = 0.8685494917004616 f = 1.576eV T = 0.8687861459781006 f = 1.592eV T = 0.8690637648599786 f = 1.608eV T = 0.8693842359783003 f = 1.624eV T = 0.8697497500218311 f = 1.6400000000000001eV T = 0.8701632865790704 f = 1.6560000000000001eV T = 0.8706297494237245 f = 1.6720000000000002eV T = 0.8711592140740528 f = 1.6880000000000002eV T = 0.8717790347907778 f = 1.704eV T = 0.8726033789586823 f = 1.72eV T = 0.8749303101689936 f = 1.736eV T = 0.875209108674189 f = 1.752eV T = 0.874018101264678 f = 1.768eV T = 0.8748855705530771 f = 1.784eV T = 0.8761956741227044 f = 1.8eV T = 0.8772752161166499 f = 1.816eV T = 0.8784981407096406 f = 1.832eV T = 0.8783193204583583 f = 1.8479999999999999eV T = 0.87913143638086 f = 1.8639999999999999eV T = 0.8803321548944225 f = 1.88eV T = 0.8816844652984465 f = 1.896eV T = 0.8831262937824182 f = 1.912eV T = 0.8846306402673378 f = 1.928eV T = 0.8861822333849293 f = 1.944eV T = 0.8877707163615692 f = 1.96eV T = 0.8893880420072322 f = 1.976eV T = 0.8910272821706133 f = 1.992eV T = 0.8926819992532338 f = 2.008eV T = 0.8943458647504972 f = 2.024eV T = 0.8960123897023824 f = 2.04eV T = 0.8976747001143647 f = 2.056eV T = 0.899325317703472 f = 2.072eV T = 0.9009559161569054 f = 2.088eV T = 0.9025570236568881 f = 2.104eV T = 0.9041176360673845 f = 2.12eV T = 0.9056246911735147 f = 2.136eV T = 0.9070623292829234 f = 2.152eV T = 0.9084108220304947 f = 2.168eV T = 0.9096449750081104 f = 2.184eV T = 0.9107316723219699 f = 2.2eV T = 0.9116259735256356 f = 2.216eV T = 0.9122646683665366 f = 2.232eV T = 0.9125551512430047 f = 2.248eV T = 0.9123551829951925 f = 2.2640000000000002eV T = 0.9114336793410751 f = 2.2800000000000002eV T = 0.9093886409693751 f = 2.2960000000000003eV T = 0.9054580357168606 f = 2.3120000000000003eV T = 0.8980276458916097 f = 2.3280000000000003eV T = 0.8831396572552425 f = 2.3440000000000003eV T = 0.8491994955129943 f = 2.3600000000000003eV T = 0.763570988661018 f = 2.3760000000000003eV T = 0.7584567496138948 f = 2.3920000000000003eV T = 0.9124831849670401 f = 2.408eV T = 0.9472430348192934 f = 2.424eV T = 0.9525365054953068 f = 2.44eV T = 0.9465871455188564 f = 2.456eV T = 0.7412617636861561 f = 2.472eV T = 0.9639128776982578 f = 2.488eV T = 0.9632136370015142 f = 2.504eV T = 0.9625908360098736 f = 2.52eV T = 0.96321837683802 f = 2.536eV T = 0.9638868276185957 f = 2.552eV T = 0.9652453162011098 f = 2.568eV T = 0.96503451064423 f = 2.584eV T = 0.9650926772357361 f = 2.6eV T = 0.9652127678832587 f = 1.216eV T = 0.8428785851695566 f = 1.232eV T = 0.8336026432436981 f = 1.248eV T = 0.7837331290594014 f = 1.28eV T = 0.86183396094491 f = 1.296eV T = 0.8648868907819696 f = 1.312eV T = 0.8663202608944343 f = 1.712eV T = 0.8732795543975511 f = 1.728eV T = 0.888214618514185 f = 1.744eV T = 0.8738705943543547 f = 1.76eV T = 0.8743181340505738 f = 1.776eV T = 0.8756338213489687 f = 1.824eV T = 0.8787597228461658 f = 1.8559999999999999eV T = 0.8797059517126271 f = 2.2720000000000002eV T = 0.910587314753518 f = 2.2880000000000003eV T = 0.9077303861140447 f = 2.3040000000000003eV T = 0.90234185732466 f = 2.3200000000000003eV T = 0.8919461925042316 f = 2.3360000000000003eV T = 0.8699183521015544 f = 2.3520000000000003eV T = 0.815589316681806 f = 2.3680000000000003eV T = 0.7153337600487691 f = 2.3840000000000003eV T = 0.8556882895073519 f = 2.416eV T = 0.9514215369225753 f = 2.432eV T = 0.9513811712493273 f = 2.448eV T = 0.926387963870859 f = 2.464eV T = 0.9575863177373318 f = 2.48eV T = 0.9638122666273472 f = 2.544eV T = 0.9666385977220846 f = 2.56eV T = 0.9650219553682995 f = 1.228eV T = 0.8366596015649678 f = 1.236eV T = 0.8295699219383965 f = 1.244eV T = 0.8138594679113729 f = 1.252eV T = 0.8180195246027361 f = 1.264eV T = 0.8530967050692031 f = 1.284eV T = 0.8628572593658421 f = 1.292eV T = 0.8643397263927852 f = 1.716eV T = 0.8738552175580628 f = 1.724eV T = 0.8777889940327103 f = 1.732eV T = 0.8816670208448514 f = 1.74eV T = 0.8740767096821042 f = 1.748eV T = 0.8739035028594004 f = 2.3240000000000003eV T = 0.8879662472807288 f = 2.3320000000000003eV T = 0.8772302140410604 f = 2.3400000000000003eV T = 0.8607699705810344 f = 2.3480000000000003eV T = 0.8344419195438209 f = 2.3560000000000003eV T = 0.7918638033140023 f = 2.3720000000000003eV T = 0.7217260878368489 f = 2.3800000000000003eV T = 0.8095009420161203 f = 2.3880000000000003eV T = 0.8896614477468741 f = 2.4000000000000004eV T = 0.9369536974663364 f = 2.42eV T = 0.9522731948212323 f = 2.436eV T = 0.9496810879189841 f = 2.444eV T = 0.9405550658490183 f = 2.452eV T = 0.8782826521076641 f = 2.46eV T = 0.9252157493644315 f = 2.468eV T = 0.9628398924617436 f = 2.476eV T = 0.9640038365299946 f = 2.528eV T = 0.9634404320358981 f = 2.548eV T = 0.9656956601055311 f = 2.556eV T = 0.9650776959993574 f = 1.238eV T = 0.8269715864139365 f = 1.242eV T = 0.8196171289469852 f = 1.246eV T = 0.8047294942663055 f = 1.25eV T = 0.7925021808831064 f = 1.254eV T = 0.8308281807399327 f = 1.26eV T = 0.8478708494845185 f = 1.268eV T = 0.8564640721618737 f = 1.276eV T = 0.8605261679804405 f = 1.722eV T = 0.8759522900864198 f = 1.726eV T = 0.8814806420706693 f = 1.73eV T = 0.8896384699870566 f = 1.738eV T = 0.8744263865675015 f = 2.3640000000000003eV T = 0.7344930580830582 f = 2.3740000000000006eV T = 0.7369171494729554 f = 2.3900000000000006eV T = 0.9022704535971096 f = 2.3960000000000004eV T = 0.9273378337045731 f = 2.412eV T = 0.9498349608534649 f = 2.428eV T = 0.952258784604358 f = 2.4379999999999997eV T = 0.948368624452553 f = 2.442eV T = 0.9441138079826908 f = 2.4459999999999997eV T = 0.9351643086980231 f = 2.45eV T = 0.910599672244609 f = 2.4539999999999997eV T = 0.8068868013608411 f = 2.458eV T = 0.8535677107137496 f = 2.4619999999999997eV T = 0.9489040580393502 f = 2.466eV T = 0.9612079442052016 f = 2.4699999999999998eV T = 0.9635896315856931 f = 2.54eV T = 0.9653315057983358 f = 1.245eV T = 0.8099241274035947 f = 1.2469999999999999eV T = 0.7972016418487191 f = 1.249eV T = 0.7637016225848388 f = 1.251eV T = 0.807882010726431 f = 1.2530000000000001eV T = 0.8253062730436738 f = 1.255eV T = 0.8351695551755751 f = 1.258eV T = 0.8440082674293623 f = 1.262eV T = 0.8507997891292914 f = 1.266eV T = 0.8549453070957892 f = 1.27eV T = 0.8577329209102207 f = 1.7229999999999999eV T = 0.8767241639779254 f = 1.725eV T = 0.8793007948680457 f = 1.7269999999999999eV T = 0.884537858385385 f = 1.729eV T = 0.8907578125360167 f = 1.7309999999999999eV T = 0.885643912924382 f = 1.734eV T = 0.8770604200833987 f = 2.3660000000000005eV T = 0.7226947284435292 f = 2.37eV T = 0.7145325028051333 f = 2.3980000000000006eV T = 0.9326652271568051 f = 2.404eV T = 0.9431942238265526 f = 2.4139999999999997eV T = 0.9507336212483538 f = 2.418eV T = 0.9519275978640516 f = 2.434eV T = 0.9506577161568968 f = 2.441eV T = 0.9454561432306491 f = 2.445eV T = 0.9381582585674206 f = 2.447eV T = 0.9313522398553993 f = 2.449eV T = 0.9197502740591198 f = 2.453eV T = 0.8492344731662907 f = 2.457eV T = 0.7884725694262412 f = 2.461eV T = 0.9401540892032634 f = 2.463eV T = 0.9542294853247199 f = 2.465eV T = 0.9597639596296397 f = 2.469eV T = 0.9632880167636726 f = 2.532eV T = 0.9635703403388872 f = 2.5460000000000003eV T = 0.9661319241251238 f = 1.733eV T = 0.8788550629193908 f = 1.7349999999999999eV T = 0.8759307715741134 f = 1.737eV T = 0.8747385613914042 f = 2.365eV T = 0.7281765951458781 f = 2.369eV T = 0.7139973968125348 f = 2.3710000000000004eV T = 0.7170898239180566 f = 2.373eV T = 0.7283892865065307 f = 2.4059999999999997eV T = 0.9454384420187295 f = 2.41eV T = 0.9486877073573503 f = 2.451eV T = 0.8975471710364511 f = 2.455eV T = 0.7579412492487018 f = 2.459eV T = 0.8989414162983563 f = 2.467eV T = 0.9621800536482643 f = 2.5380000000000003eV T = 0.9643477684883892 f = 2.542eV T = 0.9665132321638428 f = 2.362eV T = 0.7486560100870004 f = 2.3670000000000004eV T = 0.7183206747796664 .. GENERATED FROM PYTHON SOURCE LINES 93-94 Figure 4 from :cite:p:`Tikhodeev2002`. .. GENERATED FROM PYTHON SOURCE LINES 94-103 .. code-block:: Python plt.figure() plt.plot(fev_adapted * 1000, transmission, c="#be4c83") plt.ylim(0.4, 1) plt.xlabel("frequency (meV)") plt.ylabel("Transmissivity") plt.tight_layout() .. image-sg:: /examples/basic/images/sphx_glr_plot_square_patch_002.png :alt: plot square patch :srcset: /examples/basic/images/sphx_glr_plot_square_patch_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 104-105 Plot the fields at the resonant frequency of 2456meV .. GENERATED FROM PYTHON SOURCE LINES 105-118 .. code-block:: Python fev = 2.456 w = h * c / e / (fev * 1e-6) # /1000 pw = nn.PlaneWave(wavelength=w, angles=(0, 0, 90)) sim = nn.Simulation(stack, pw, 151, formulation="tangent") E, H = sim.get_field_grid("Superstrate", shape=(N, N)) Ex, Ey, Ez = E[:, :, :, 0] Hx, Hy, Hz = H[:, :, :, 0] nE2 = np.abs(Ex) ** 2 + np.abs(Ey) ** 2 # + np.abs(Ez)**2 nH2 = np.abs(Hx) ** 2 + np.abs(Hy) ** 2 # + np.abs(Hz)**2 .. GENERATED FROM PYTHON SOURCE LINES 119-120 Electric field .. GENERATED FROM PYTHON SOURCE LINES 120-136 .. code-block:: Python extent = [0, period, 0, period] x, y = np.linspace(0, period, N), np.linspace(0, period, N) plt.figure() plt.imshow(epsilon.real, cmap="Greys", origin="lower", extent=extent) plt.imshow(nE2, alpha=0.9, origin="lower", extent=extent) plt.colorbar() s = 3 plt.quiver(x[::s], y[::s], Ex[::s, ::s].real, Ey[::s, ::s].real, color="w") plt.xlabel(r"$x$ ($\mu$m)") plt.ylabel(r"$y$ ($\mu$m)") plt.title("$E$") plt.tight_layout() plt.show() .. image-sg:: /examples/basic/images/sphx_glr_plot_square_patch_003.png :alt: $E$ :srcset: /examples/basic/images/sphx_glr_plot_square_patch_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 137-138 Magnetic field .. GENERATED FROM PYTHON SOURCE LINES 138-149 .. code-block:: Python plt.figure() plt.imshow(epsilon.real, cmap="Greys", origin="lower", extent=extent) plt.imshow(nH2, alpha=0.9, origin="lower", extent=extent) plt.colorbar() plt.quiver(x[::s], y[::s], Hx[::s, ::s].real, Hy[::s, ::s].real, color="w") plt.xlabel(r"$x$ ($\mu$m)") plt.ylabel(r"$y$ ($\mu$m)") plt.title("$H$") plt.tight_layout() plt.show() .. image-sg:: /examples/basic/images/sphx_glr_plot_square_patch_004.png :alt: $H$ :srcset: /examples/basic/images/sphx_glr_plot_square_patch_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 41.911 seconds) **Estimated memory usage:** 546 MB .. _sphx_glr_download_examples_basic_plot_square_patch.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_square_patch.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_square_patch.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_square_patch.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_square_patch.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_