Elliptical holes#

Convergence checks.

import matplotlib.pyplot as plt
import numpy as np

import nannos as nn

We will study the convergence on a benchmark case from [Schuster2007]. First we define the main function that performs the simulation.

def array_ellipse(nh, formulation, psi):
    wl = 500 + 1e-6  # avoid Wood-Rayleigh anomaly
    d = 1000
    Nx = 2**9
    Ny = 2**9
    lattice = nn.Lattice(([d, 0], [0, d]), discretization=(Nx, Ny))
    pw = nn.PlaneWave(wavelength=wl, angles=(0, 0, psi))
    epsgrid = lattice.ones() * (1.75 + 1.5j) ** 2
    ell = lattice.ellipse((0.5 * d, 0.5 * d), (1000 / 2, 500 / 2), rotate=45)
    epsgrid[ell] = 1

    sup = lattice.Layer("Superstrate", epsilon=1)
    sub = lattice.Layer("Substrate", epsilon=1.5**2)
    st = lattice.Layer("Structured", thickness=50)
    st.epsilon = epsgrid

    sim = nn.Simulation([sup, st, sub], pw, nh, formulation=formulation)
    order = (0, 0)
    R, T = sim.diffraction_efficiencies(orders=True)
    r = sim.get_order(R, order)
    return R, T, r, sim


#
# sim = array_ellipse(100, "original")
# lay = sim.get_layer("Structured")
# lay.plot()
# plt.show()

Perform the simulation for different formulations and number of retained harmonics:

NH = [100, 200, 300, 400, 500, 600]
formulations = ["original", "tangent"]


def run_convergence(psi):
    nhs = {f: [] for f in formulations}
    rs = {f: [] for f in formulations}

    for nh in NH:
        print("============================")
        print("number of harmonics = ", nh)
        print("============================")
        for formulation in formulations:
            Ri, Ti, r, sim = array_ellipse(nh, formulation=formulation, psi=psi)
            R = np.sum(Ri)
            T = np.sum(Ti)
            print("formulation = ", formulation)
            print("nh0 = ", nh)
            print("nh = ", sim.nh)
            print("r = ", r)
            print("R = ", R)
            print("T = ", T)
            print("R+T = ", R + T)
            print("-----------------")
            nhs[formulation].append(sim.nh)
            rs[formulation].append(r)

    return nhs, rs

Plot the results:

markers = {"original": "^", "tangent": "o"}
colors = {
    "original": "#d4b533",
    "tangent": "#4cb7c6",
}

plt.ion()

for psi in [45, -45]:
    nhs, rs = run_convergence(psi)
    plt.figure(figsize=(2, 2))

    for formulation in formulations:
        plt.plot(
            nhs[formulation],
            rs[formulation],
            "-",
            color=colors[formulation],
            marker=markers[formulation],
            label=formulation,
        )
        plt.pause(0.1)
    plt.legend()
    plt.xlabel("number of Fourier harmonics $n_h$")
    plt.ylabel("$R_{0,0}$")
    t = "" if psi == 45 else "-"
    plt.title(rf"$\psi = {t}45\degree$")
    plt.ylim(0.16, 0.2)
    plt.tight_layout()
    plt.show()
  • $\psi = 45\degree$
  • $\psi = -45\degree$

Out:

============================
number of harmonics =  100
============================
formulation =  original
nh0 =  100
nh =  97
r =  0.17932439123769817
R =  0.21515074693924205
T =  0.43383852610020557
R+T =  0.6489892730394476
-----------------
formulation =  tangent
nh0 =  100
nh =  97
r =  0.1734865968306067
R =  0.2094287189710893
T =  0.4452348309046451
R+T =  0.6546635498757344
-----------------
============================
number of harmonics =  200
============================
formulation =  original
nh0 =  200
nh =  197
r =  0.1786218180180061
R =  0.21467135614446942
T =  0.4357577344352613
R+T =  0.6504290905797308
-----------------
formulation =  tangent
nh0 =  200
nh =  197
r =  0.17457561890528195
R =  0.2104314956181236
T =  0.4424307431022378
R+T =  0.6528622387203614
-----------------
============================
number of harmonics =  300
============================
formulation =  original
nh0 =  300
nh =  293
r =  0.17819846373023115
R =  0.21432898456661173
T =  0.43675889938964857
R+T =  0.6510878839562603
-----------------
formulation =  tangent
nh0 =  300
nh =  293
r =  0.17481781136318597
R =  0.21088386223761516
T =  0.4427555037649916
R+T =  0.6536393660026067
-----------------
============================
number of harmonics =  400
============================
formulation =  original
nh0 =  400
nh =  385
r =  0.17794295536831278
R =  0.21413192473442116
T =  0.4373867488249467
R+T =  0.6515186735593679
-----------------
formulation =  tangent
nh0 =  400
nh =  385
r =  0.1753323851101718
R =  0.21136880191718027
T =  0.44154066471594755
R+T =  0.6529094666331279
-----------------
============================
number of harmonics =  500
============================
formulation =  original
nh0 =  500
nh =  497
r =  0.1776966314413575
R =  0.21393385297317583
T =  0.437928517069359
R+T =  0.6518623700425348
-----------------
formulation =  tangent
nh0 =  500
nh =  497
r =  0.17512852957630132
R =  0.21126676595831564
T =  0.4423924521810901
R+T =  0.6536592181394058
-----------------
============================
number of harmonics =  600
============================
formulation =  original
nh0 =  600
nh =  593
r =  0.17761068811836273
R =  0.21386973143079885
T =  0.4381744023749637
R+T =  0.6520441338057625
-----------------
formulation =  tangent
nh0 =  600
nh =  593
r =  0.17525736266559172
R =  0.2113963696485769
T =  0.44199796676423975
R+T =  0.6533943364128166
-----------------
/builds/nannos/nannos.gitlab.io/nannos/examples/basic/plot_ellipse.py:115: UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown
  plt.pause(0.1)
/builds/nannos/nannos.gitlab.io/nannos/examples/basic/plot_ellipse.py:123: UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown
  plt.show()
============================
number of harmonics =  100
============================
formulation =  original
nh0 =  100
nh =  97
r =  0.18258253665287305
R =  0.21817891654210536
T =  0.41464786756520505
R+T =  0.6328267841073104
-----------------
formulation =  tangent
nh0 =  100
nh =  97
r =  0.17236019218992216
R =  0.20957403181107903
T =  0.4366676674859195
R+T =  0.6462416992969986
-----------------
============================
number of harmonics =  200
============================
formulation =  original
nh0 =  200
nh =  197
r =  0.1791049757291866
R =  0.21567155595422802
T =  0.4214226719302606
R+T =  0.6370942278844887
-----------------
formulation =  tangent
nh0 =  200
nh =  197
r =  0.1717869733081966
R =  0.20943628066392136
T =  0.43824457150304863
R+T =  0.64768085216697
-----------------
============================
number of harmonics =  300
============================
formulation =  original
nh0 =  300
nh =  293
r =  0.178265956595537
R =  0.21489419802089202
T =  0.4231025916746494
R+T =  0.6379967896955414
-----------------
formulation =  tangent
nh0 =  300
nh =  293
r =  0.17197187418930343
R =  0.2095338624331602
T =  0.43772346853455246
R+T =  0.6472573309677127
-----------------
============================
number of harmonics =  400
============================
formulation =  original
nh0 =  400
nh =  385
r =  0.17745718861034476
R =  0.21428207178797123
T =  0.4248286708905992
R+T =  0.6391107426785705
-----------------
formulation =  tangent
nh0 =  400
nh =  385
r =  0.1720556129891946
R =  0.20962620461681056
T =  0.437292676451358
R+T =  0.6469188810681685
-----------------
============================
number of harmonics =  500
============================
formulation =  original
nh0 =  500
nh =  497
r =  0.17671119584012407
R =  0.213727700690124
T =  0.4263518124191665
R+T =  0.6400795131092905
-----------------
formulation =  tangent
nh0 =  500
nh =  497
r =  0.1724087787355883
R =  0.20998030394150807
T =  0.43662940553224017
R+T =  0.6466097094737482
-----------------
============================
number of harmonics =  600
============================
formulation =  original
nh0 =  600
nh =  593
r =  0.17642271922953626
R =  0.2134796022798559
T =  0.427157808785154
R+T =  0.6406374110650099
-----------------
formulation =  tangent
nh0 =  600
nh =  593
r =  0.17230439849618107
R =  0.20993505001710233
T =  0.4368742538838769
R+T =  0.6468093039009792
-----------------

Total running time of the script: ( 3 minutes 56.302 seconds)

Estimated memory usage: 1770 MB

Gallery generated by Sphinx-Gallery