CoolFace
Apppublic

jwt625/BPM

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
example_waveguide.py47 linesDownload Raw Back to examples
1#%%2import numpy as np3import matplotlib.pyplot as plt4from bpm.refractive_index import generate_waveguide_n_r25from bpm.mode_solver import slab_mode_source6from bpm.core import run_bpm7from bpm.pml import generate_sigma_x8 9# Simulation parameters10domain_size = 50.0   # um11z_total = 500.0      # um12Nx = 25613Nz = 200014x = np.linspace(-domain_size/2, domain_size/2, Nx)15z = np.linspace(0, z_total, Nz)16 17# Waveguide parameters18l = 5.0   # lateral offset19L = 200.0  # length of S-bend20w = 1.0    # waveguide width21n0 = 1.022n_WG = 1.123 24n_r2 = generate_waveguide_n_r2(x, z, l, L, w, n_WG, n0)25 26# Launch a mode; here we use a mode source with no shift (x0 = 0)27E0 = slab_mode_source(x, w, n_WG, n0, wavelength=0.532, ind_m=0, x0=0)28E = np.zeros((Nx, Nz), dtype=np.complex128)29E[:, 0] = E030 31dx = domain_size / Nx32sigma_x = generate_sigma_x(x, dx, 0.532, domain_size, sigma_max=0.5, pml_factor=5)33 34E_out = run_bpm(E, n_r2, x, z, dx, z[1]-z[0], n0, sigma_x, 0.532)35 36plt.figure(figsize=(8,6))37plt.imshow((np.abs(E_out)**2).T, extent=[x[0], x[-1], z[0], z[-1]],38           origin='lower', aspect='auto', cmap='inferno',39           vmin=0, vmax=0.6)40plt.xlabel("x (um)")41plt.ylabel("z (um)")42plt.title("Waveguide BPM Propagation")43plt.colorbar(label="Intensity")44plt.show()45 46# %%47