<jupyter_start><jupyter_text>EMEPy Subpixel Techniques  Circular Waveguide Radius Sweep<jupyter_code>import numpy as np
from matplotlib import pyplot as plt
from emepy.tools import circle_to_n
from emepy.fd import MSEMpy

def run(radius=1e-6, subpixel=True, mesh=50):
    x = np.linspace(-1.25e-6, 1.25e-6, mesh)
    y = np.linspace(-1.25e-6, 1.25e-6, mesh)
    n = circle_to_n(
            (0, 0),
            radius,
            x,
            y,
            subpixel,
            3.4,
            1.4,
        )
    xx = ((x)[1:] + (x)[:-1]) / 2
    yy = ((y)[1:] + (y)[:-1]) / 2
    ms = MSEMpy(wl=1.55e-6, n=n, x=xx, y=yy, num_modes=1)
    ms.solve()
    return ms.get_mode()

plt.figure()
run().plot_material()
plt.title("With subpixel")
plt.show()

plt.figure()
run(subpixel=False).plot_material()
plt.title("Without subpixel")
plt.show()
with_smoothing = []
without_smoothing = []
alt = np.linspace(0, 1e-8, 20)

for i, d in enumerate(alt):
    mode1 = run(1e-6, True)
    mode2 = run(1e-6 + d, True)
    mode3 = mode1 - mode2
    mode3.n = mode2.n - mode1.n
    with_smoothing.append(np.real(mode1.neff - mode2.neff))

    mode1 = run(1e-6, False)
    mode2 = run(1e-6 + d, False)
    mode3 = mode1 - mode2
    mode3.n = mode2.n - mode1.n
    without_smoothing.append(np.real(mode1.neff - mode2.neff))

plt.figure()
plt.plot(alt, with_smoothing, label="With smoothing")
plt.plot(alt, without_smoothing, label="Without smoothing")
plt.xlabel("Radius change")
plt.ylabel("delta neff")
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>Rectangular waveguide width sweep<jupyter_code>import numpy as np
from matplotlib import pyplot as plt
from emepy.tools import rectangle_to_n
from emepy.fd import MSEMpy

def run(width=0.55e-6, subpixel=True, mesh=50):
    x, y = (np.linspace(-1.25e-6,1.25e-6,mesh), np.linspace(-1.25e-6,1.25e-6,mesh))
    ms = MSEMpy(wl=1.55e-6, width=width, thickness=0.22e-6, subpixel=subpixel, x=x, y=y)
    # x, y = (np.linspace(-1.25e-6,1.25e-6,mesh), np.linspace(-1.25e-6,1.25e-6,mesh))
    # n = rectangle_to_n((0,0), width, 0.22e-6, x,y, subpixel, 3.4, 1.5)
    # xx = ((x)[1:] + (x)[:-1]) / 2
    # yy = ((y)[1:] + (y)[:-1]) / 2
    # ms = MSEMpy(wl=1.55e-6, n=n, x=xx, y=yy, num_modes=1)
    ms.solve()
    return ms.get_mode()

plt.figure()
run(subpixel=True, mesh=50).plot_material()
plt.title("With subpixel")
plt.show()

plt.figure()
run(subpixel=False, mesh=49).plot_material()
plt.title("Without subpixel")
plt.show()
with_smoothing = []
without_smoothing = []
alt = np.linspace(0, 1e-7, 20)

for i, d in enumerate(alt):
    mode1 = run(0.5e-6, True, mesh=50)
    mode2 = run(0.5e-6 + d, True, mesh=50)
    mode3 = mode1 - mode2
    mode3.n = mode2.n - mode1.n
    with_smoothing.append(np.real(mode1.neff - mode2.neff))

    mode1 = run(0.5e-6, False, mesh=49)
    mode2 = run(0.5e-6 + d, False, mesh=49)
    mode3 = mode1 - mode2
    mode3.n = mode2.n - mode1.n
    without_smoothing.append(np.real(mode1.neff - mode2.neff))

plt.figure()
plt.plot(alt, with_smoothing, label="With smoothing")
plt.plot(alt, without_smoothing, label="Without smoothing")
plt.xlabel("Width change")
plt.ylabel("delta neff")
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17608695652173914, 'fraction_numerical': 0.0577639751552795, 'mean_word_length': 3.3409703504043127, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '409277', 'license': 'MIT', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1373, 'n_words': 265, 'path': 'examples/tutorials/subpixel.ipynb', 'repo_name': 'smartalecH/emepy', 'size': '3220'}