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$
============================
number of harmonics =  100
============================
formulation =  original
nh0 =  100
nh =  97
r =  0.17932439123769936
R =  0.21515074693924352
T =  0.4338385261002055
R+T =  0.6489892730394491
-----------------
formulation =  tangent
nh0 =  100
nh =  97
r =  0.17621602350830357
R =  0.211910430137424
T =  0.43936256668932616
R+T =  0.6512729968267501
-----------------
============================
number of harmonics =  200
============================
formulation =  original
nh0 =  200
nh =  197
r =  0.17862181801800542
R =  0.2146713561444691
T =  0.43575773443526516
R+T =  0.6504290905797343
-----------------
formulation =  tangent
nh0 =  200
nh =  197
r =  0.17616788969044037
R =  0.21213490853620054
T =  0.4401310706963403
R+T =  0.6522659792325408
-----------------
============================
number of harmonics =  300
============================
formulation =  original
nh0 =  300
nh =  293
r =  0.17819846373023124
R =  0.21432898456661192
T =  0.4367588993896496
R+T =  0.6510878839562615
-----------------
formulation =  tangent
nh0 =  300
nh =  293
r =  0.17585848435853796
R =  0.21188982193127195
T =  0.4407413986576125
R+T =  0.6526312205888845
-----------------
============================
number of harmonics =  400
============================
formulation =  original
nh0 =  400
nh =  385
r =  0.17794295536831
R =  0.2141319247344193
T =  0.43738674882495365
R+T =  0.651518673559373
-----------------
formulation =  tangent
nh0 =  400
nh =  385
r =  0.17640773225506357
R =  0.212470429078704
T =  0.439782907337681
R+T =  0.6522533364163849
-----------------
============================
number of harmonics =  500
============================
formulation =  original
nh0 =  500
nh =  497
r =  0.17769663144135817
R =  0.21393385297317524
T =  0.4379285170693545
R+T =  0.6518623700425297
-----------------
formulation =  tangent
nh0 =  500
nh =  497
r =  0.17607882894831722
R =  0.21219367309704026
T =  0.4406679147491671
R+T =  0.6528615878462074
-----------------
============================
number of harmonics =  600
============================
formulation =  original
nh0 =  600
nh =  593
r =  0.17761068811836203
R =  0.21386973143079877
T =  0.43817440237496513
R+T =  0.6520441338057639
-----------------
formulation =  tangent
nh0 =  600
nh =  593
r =  0.17618672613291
R =  0.21234017463895552
T =  0.44040563873502275
R+T =  0.6527458133739783
-----------------
============================
number of harmonics =  100
============================
formulation =  original
nh0 =  100
nh =  97
r =  0.18258253665287355
R =  0.21817891654210606
T =  0.4146478675652059
R+T =  0.632826784107312
-----------------
formulation =  tangent
nh0 =  100
nh =  97
r =  0.16905807960477426
R =  0.20703150564147685
T =  0.44438428276747804
R+T =  0.6514157884089549
-----------------
============================
number of harmonics =  200
============================
formulation =  original
nh0 =  200
nh =  197
r =  0.179104975729187
R =  0.21567155595422857
T =  0.4214226719302581
R+T =  0.6370942278844867
-----------------
formulation =  tangent
nh0 =  200
nh =  197
r =  0.17050332986430866
R =  0.20839758143215192
T =  0.4412222217519794
R+T =  0.6496198031841314
-----------------
============================
number of harmonics =  300
============================
formulation =  original
nh0 =  300
nh =  293
r =  0.17826595659553793
R =  0.2148941980208922
T =  0.4231025916746515
R+T =  0.6379967896955436
-----------------
formulation =  tangent
nh0 =  300
nh =  293
r =  0.17109234507591514
R =  0.2088494973206414
T =  0.43983055437584506
R+T =  0.6486800516964865
-----------------
============================
number of harmonics =  400
============================
formulation =  original
nh0 =  400
nh =  385
r =  0.17745718861034304
R =  0.21428207178796874
T =  0.42482867089060206
R+T =  0.6391107426785708
-----------------
formulation =  tangent
nh0 =  400
nh =  385
r =  0.1712592537848024
R =  0.20903015319437868
T =  0.4393043407964724
R+T =  0.6483344939908511
-----------------
============================
number of harmonics =  500
============================
formulation =  original
nh0 =  500
nh =  497
r =  0.1767111958401227
R =  0.21372770069012353
T =  0.4263518124191673
R+T =  0.6400795131092909
-----------------
formulation =  tangent
nh0 =  500
nh =  497
r =  0.1715733339023212
R =  0.20933751036766404
T =  0.43871715418540536
R+T =  0.6480546645530694
-----------------
============================
number of harmonics =  600
============================
formulation =  original
nh0 =  600
nh =  593
r =  0.17642271922953545
R =  0.21347960227985482
T =  0.42715780878515275
R+T =  0.6406374110650076
-----------------
formulation =  tangent
nh0 =  600
nh =  593
r =  0.1716295044559934
R =  0.2094069145134945
T =  0.43854347854078685
R+T =  0.6479503930542814
-----------------

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

Estimated memory usage: 2856 MB

Gallery generated by Sphinx-Gallery