diff --git a/IntegratedVivaldiAntenna.ipynb b/IntegratedVivaldiAntenna.ipynb index 8522db6f..7f9e48da 100644 --- a/IntegratedVivaldiAntenna.ipynb +++ b/IntegratedVivaldiAntenna.ipynb @@ -652,11 +652,13 @@ "p_list = np.linspace(0.05, 0.5, 9) # range of the plasmonic waveguide width\n", "\n", "# create a list of mode solvers\n", - "plasmonic_waveguide_mode_solvers = {f\"p={p:.2f}\": plasmonic_waveguide_mode_solver(p) for p in p_list}\n", + "plasmonic_waveguide_mode_solvers = {\n", + " f\"p={p:.2f}\": plasmonic_waveguide_mode_solver(p) for p in p_list\n", + "}\n", "\n", "# run mode solvers in parallel\n", "batch = web.Batch(simulations=plasmonic_waveguide_mode_solvers)\n", - "plasmonic_waveguide_batch_results = batch.run(path_dir=\"data\")\n" + "plasmonic_waveguide_batch_results = batch.run(path_dir=\"data\")" ] }, { @@ -718,7 +720,9 @@ ], "source": [ "# extract the effective index of the fundamental mode\n", - "n_eff_plasmonic = [result.n_eff[0][0].values for _, result in plasmonic_waveguide_batch_results.items()]\n", + "n_eff_plasmonic = [\n", + " result.n_eff[0][0].values for _, result in plasmonic_waveguide_batch_results.items()\n", + "]\n", "\n", "# plot the effective indices of the silicon waveguide and plasmonic waveguide\n", "plt.plot(p_list, n_eff_plasmonic, c=\"red\", linewidth=3, label=\"plasmonic waveguide\")\n", @@ -971,11 +975,13 @@ "n_eff_list = np.linspace(2.15, 2.5, 8) # effective index range\n", "\n", "# create a list of mode solvers\n", - "hybrid_waveguide_mode_solvers = {f\"n_eff={n_eff:.2f}\": hybrid_waveguide_mode_solver(n_eff) for n_eff in n_eff_list}\n", + "hybrid_waveguide_mode_solvers = {\n", + " f\"n_eff={n_eff:.2f}\": hybrid_waveguide_mode_solver(n_eff) for n_eff in n_eff_list\n", + "}\n", "\n", "# run mode solvers in parallel\n", "batch = web.Batch(simulations=hybrid_waveguide_mode_solvers)\n", - "hybrid_waveguide_batch_results = batch.run(path_dir=\"data\")\n" + "hybrid_waveguide_batch_results = batch.run(path_dir=\"data\")" ] }, { @@ -2471,7 +2477,7 @@ "P0 = np.array(sim_data_antenna[\"power\"].flux) # total radiated power of the antenna\n", "\n", "# angular radiated power of the antenna\n", - "# by default, the power is calculated at 1 meter away from the antenna. \n", + "# by default, the power is calculated at 1 meter away from the antenna.\n", "# The 1e12 factor normalizes the power to unit distance (1 um)\n", "P_e = np.squeeze(\n", " 1e12 * sim_data_antenna[\"n2f_monitor\"].power.sel(f=freq0, phi=0, method=\"nearest\").values\n", diff --git a/LNOIPolarizationSplitterRotator.ipynb b/LNOIPolarizationSplitterRotator.ipynb index 916422bd..46274d3c 100644 --- a/LNOIPolarizationSplitterRotator.ipynb +++ b/LNOIPolarizationSplitterRotator.ipynb @@ -243,7 +243,7 @@ " mode_solver = ModeSolver(\n", " simulation=width_test_sim, plane=plane, mode_spec=width_test_mode_spec, freqs=[freq0]\n", " )\n", - " \n", + "\n", " # add modesolver for this mode solver plane\n", " mode_solvers[f\"plane_x={m:.3f}\"] = mode_solver" ] @@ -397,8 +397,12 @@ "outputs": [], "source": [ "# collect relevant data from batch solve\n", - "modes = np.reshape([mode_data.n_eff.data[0] for _, mode_data in mode_batch.items()], (len(plane_xs), 3))\n", - "te_fracs = np.reshape([mode_data.pol_fraction.te.data[0] for _, mode_data in mode_batch.items()], (len(plane_xs), 3))" + "modes = np.reshape(\n", + " [mode_data.n_eff.data[0] for _, mode_data in mode_batch.items()], (len(plane_xs), 3)\n", + ")\n", + "te_fracs = np.reshape(\n", + " [mode_data.pol_fraction.te.data[0] for _, mode_data in mode_batch.items()], (len(plane_xs), 3)\n", + ")" ] }, { @@ -546,9 +550,9 @@ "\n", "l2_scales = np.linspace(1 / l2_sweep, 500 / l2_sweep, 51)\n", "l2_scale_factors = np.ones((len(l2_scales), 2 * l1_grid_spec.num_cells + l2_grid_spec.num_cells))\n", - "l2_scale_factors[:, l1_grid_spec.num_cells : l1_grid_spec.num_cells + l2_grid_spec.num_cells] = (\n", - " l2_scales[:, None]\n", - ")\n", + "l2_scale_factors[\n", + " :, l1_grid_spec.num_cells : l1_grid_spec.num_cells + l2_grid_spec.num_cells\n", + "] = l2_scales[:, None]\n", "\n", "# define EME simulation\n", "l2_sweep_sim = td.EMESimulation(\n", @@ -1531,7 +1535,7 @@ " (l4_sweep * 2, 2 * (split / 2) + w4), # extend beyond boundary\n", " (0, w3 / 2),\n", " (-l3, w2 / 2),\n", - " (-2 * l3, w2 / 2) # extend beyond boundary\n", + " (-2 * l3, w2 / 2), # extend beyond boundary\n", "]\n", "l4_test_structures = make_ridge_waveguide(l4_test_pts)\n", "\n", @@ -1574,9 +1578,9 @@ "\n", "l4_scales = np.linspace(1 / l4_sweep, 200 / l4_sweep, 61)\n", "l4_scale_factors = np.ones((len(l4_scales), l3_grid_spec.num_cells + l4_grid_spec.num_cells))\n", - "l4_scale_factors[:, l3_grid_spec.num_cells : l3_grid_spec.num_cells + l4_grid_spec.num_cells] = (\n", - " l4_scales[:, None]\n", - ")\n", + "l4_scale_factors[\n", + " :, l3_grid_spec.num_cells : l3_grid_spec.num_cells + l4_grid_spec.num_cells\n", + "] = l4_scales[:, None]\n", "\n", "l4_EME = td.EMESimulation(\n", " center=((l4_sweep - l3) / 2, 0, 0),\n", diff --git a/TaperedWgDispersion.ipynb b/TaperedWgDispersion.ipynb index 98779dbc..8dcad275 100644 --- a/TaperedWgDispersion.ipynb +++ b/TaperedWgDispersion.ipynb @@ -78,7 +78,7 @@ "source": [ "wl_min = 1.2 # Minimum wavelength in dispersion calculation.\n", "wl_max = 2.4 # Maximum wavelength in dispersion calculation.\n", - "wl_steps = 21 # Number of wavelength points in mode calculation.\n", + "wl_steps = 21 # Number of wavelength points in mode calculation.\n", "\n", "wl_d = np.linspace(wl_min, wl_max, wl_steps) # Wavelength range for D calculation.\n", "wl_gvd = np.asarray([1.95]) # Wavelength for GVD calculation." @@ -105,10 +105,14 @@ "\n", "taper = td.Structure(\n", " geometry=td.PolySlab(\n", - " vertices=[[0, -taper_w_in/2], [taper_l, -taper_w_out/2],\n", - " [taper_l, taper_w_out/2], [0, taper_w_in/2]], \n", - " axis=2, \n", - " slab_bounds=(-wg_h / 2, wg_h / 2)\n", + " vertices=[\n", + " [0, -taper_w_in / 2],\n", + " [taper_l, -taper_w_out / 2],\n", + " [taper_l, taper_w_out / 2],\n", + " [0, taper_w_in / 2],\n", + " ],\n", + " axis=2,\n", + " slab_bounds=(-wg_h / 2, wg_h / 2),\n", " ),\n", " medium=mat_si,\n", " name=\"taper_core\",\n", @@ -121,7 +125,7 @@ ")\n", "\n", "sim = td.Simulation(\n", - " center=(taper_l/2, 0, 0),\n", + " center=(taper_l / 2, 0, 0),\n", " size=(1.1 * taper_l, taper_w_out + wl_max, 3),\n", " grid_spec=td.GridSpec.auto(min_steps_per_wvl=15, wavelength=wl_min),\n", " structures=[taper, slab],\n", @@ -181,18 +185,19 @@ "metadata": {}, "outputs": [], "source": [ - "def build_mode(mode_pos_x: float=0, \n", - " wl: np.array=wl_d, \n", - " num_modes: int=1, \n", - " group_index_step: float=0.15) -> ModeSolver:\n", + "def build_mode(\n", + " mode_pos_x: float = 0, wl: np.array = wl_d, num_modes: int = 1, group_index_step: float = 0.15\n", + ") -> ModeSolver:\n", " \"\"\"Builds a ModeSolver object.\"\"\"\n", - " \n", + "\n", " freqs = td.C_0 / wl # Mode frequencies.\n", "\n", - " # Mode specification. \n", - " mode_spec = td.ModeSpec(num_modes=num_modes, \n", - " group_index_step=group_index_step,\n", - " num_pml=[7, 7],)\n", + " # Mode specification.\n", + " mode_spec = td.ModeSpec(\n", + " num_modes=num_modes,\n", + " group_index_step=group_index_step,\n", + " num_pml=[7, 7],\n", + " )\n", "\n", " # Build a mode solver.\n", " mode_solver = ModeSolver(\n", @@ -243,7 +248,7 @@ "# Mode sweep over the group_index_step values.\n", "mode_gis = {}\n", "for gis in gis_values:\n", - " mode_gis[f\"gis={gis}\"] = build_mode(mode_pos_x=taper_l/2, group_index_step=gis)" + " mode_gis[f\"gis={gis}\"] = build_mode(mode_pos_x=taper_l / 2, group_index_step=gis)" ] }, { @@ -392,7 +397,7 @@ "source": [ "# Run the mode solvers in parallel.\n", "batch = web.Batch(simulations=mode_gis)\n", - "batch_gis = batch.run(path_dir=\"data\")\n" + "batch_gis = batch.run(path_dir=\"data\")" ] }, { @@ -423,21 +428,25 @@ "source": [ "fig, ax = plt.subplots(1, 2, figsize=(12, 4), tight_layout=True)\n", "\n", - "batch_gis[f\"gis={gis_values[0]}\"].intensity.isel(f=batch_gis[f\"gis={gis_values[0]}\"].modes_info[\"f\"].size//2, mode_index=0).plot(x='y', y='z', cmap=\"hot\", ax=ax[0])\n", + "batch_gis[f\"gis={gis_values[0]}\"].intensity.isel(\n", + " f=batch_gis[f\"gis={gis_values[0]}\"].modes_info[\"f\"].size // 2, mode_index=0\n", + ").plot(x=\"y\", y=\"z\", cmap=\"hot\", ax=ax[0])\n", "ax[0].set_title(\"Fundamental Mode - $|E|^{2}$\")\n", "ax[0].set_aspect(\"equal\")\n", "\n", "for gis, md in batch_gis.items():\n", - " ax[1].plot(td.C_0 / md.modes_info[\"f\"].squeeze(drop=True).values, \n", - " md.modes_info[\"dispersion (ps/(nm km))\"].squeeze(drop=True).values, \n", - " label=gis)\n", + " ax[1].plot(\n", + " td.C_0 / md.modes_info[\"f\"].squeeze(drop=True).values,\n", + " md.modes_info[\"dispersion (ps/(nm km))\"].squeeze(drop=True).values,\n", + " label=gis,\n", + " )\n", "ax[1].set_ylabel(\"Dispersion (ps/(nm*km))\")\n", "ax[1].set_xlabel(\"Wavelength ($\\\\mu m$)\")\n", "ax[1].set_ylim([-1000, 1000])\n", - "ax[1].set_xlim([wl_d[0], wl_d[-1]]) \n", + "ax[1].set_xlim([wl_d[0], wl_d[-1]])\n", "ax[1].legend(title=\"group_index_step\")\n", "ax[1].grid()\n", - "plt.show() " + "plt.show()" ] }, { @@ -616,8 +625,8 @@ "data_gvd = []\n", "for _, md in batch_gvd.items():\n", " d = md.modes_info[\"dispersion (ps/(nm km))\"].squeeze(drop=True).values\n", - " beta2 = - ((d * wl_gvd **2) / (2 * np.pi * td.C_0)) * 1e12 \n", - " data_gvd.append(beta2) " + " beta2 = -((d * wl_gvd**2) / (2 * np.pi * td.C_0)) * 1e12\n", + " data_gvd.append(beta2)" ] }, { @@ -829,7 +838,7 @@ "ax[0].set_ylabel(\"$\\\\beta_{2}$ ($ps^{2}/m$)\")\n", "ax[0].set_xlabel(\"Mode Plane X-Position (mm)\")\n", "ax[0].set_ylim([-1, 1])\n", - "ax[0].set_xlim([0, 5]) \n", + "ax[0].set_xlim([0, 5])\n", "ax[0].grid()\n", "\n", "# D\n", @@ -838,10 +847,10 @@ "ax[1].set_ylabel(\"D ($ps/(nm \\\\cdot km)$)\")\n", "ax[1].set_xlabel(\"Wavelength ($\\\\mu m$)\")\n", "ax[1].set_ylim([-210, 600])\n", - "ax[1].set_xlim([1.2, 2.4]) \n", + "ax[1].set_xlim([1.2, 2.4])\n", "ax[1].legend(title=\"X-Position\")\n", "ax[1].grid()\n", - "plt.show() " + "plt.show()" ] }, {