{ "cells": [ { "cell_type": "markdown", "id": "bd45434d", "metadata": { "papermill": { "duration": 0.001346, "end_time": "2026-05-27T19:59:02.510210+00:00", "exception": false, "start_time": "2026-05-27T19:59:02.508864+00:00", "status": "completed" }, "tags": [] }, "source": [ "# Rectangular Dielectric Waveguide Modes\n", "\n", "This notebook solves a dielectric core inside cladding, classifies guided modes, and plots transverse and longitudinal fields." ] }, { "cell_type": "code", "execution_count": 1, "id": "c33a4d96", "metadata": { "execution": { "iopub.execute_input": "2026-05-27T19:59:02.516568Z", "iopub.status.busy": "2026-05-27T19:59:02.516386Z", "iopub.status.idle": "2026-05-27T19:59:03.251287Z", "shell.execute_reply": "2026-05-27T19:59:03.250599Z" }, "papermill": { "duration": 0.737451, "end_time": "2026-05-27T19:59:03.251854+00:00", "exception": false, "start_time": "2026-05-27T19:59:02.514403+00:00", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "from palacetoolkit.mode_solver import WaveguideModeSolver\n", "from palacetoolkit.utils import write_and_finalize_gmsh\n", "from palacetoolkit.viz import view_mesh\n", "\n", "import gmsh\n", "import numpy as np\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 2, "id": "216a1ceb", "metadata": { "execution": { "iopub.execute_input": "2026-05-27T19:59:03.258093Z", "iopub.status.busy": "2026-05-27T19:59:03.257842Z", "iopub.status.idle": "2026-05-27T19:59:03.264005Z", "shell.execute_reply": "2026-05-27T19:59:03.263462Z" }, "papermill": { "duration": 0.011741, "end_time": "2026-05-27T19:59:03.264843+00:00", "exception": false, "start_time": "2026-05-27T19:59:03.253102+00:00", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "def _set_lc_for_dielectric(a_core, b_core, lc_core, lc_clad):\n", " pts = gmsh.model.getEntities(0)\n", " for _, ptag in pts:\n", " coord = gmsh.model.getValue(0, ptag, [])\n", " in_core = (abs(coord[0]) <= a_core / 2 + 1e-10 and abs(coord[1]) <= b_core / 2 + 1e-10)\n", " gmsh.model.mesh.setSize([(0, ptag)], lc_core if in_core else lc_clad)\n", "\n", "\n", "def make_dielectric_waveguide_mesh(a_core, b_core, a_clad, b_clad, nx_core=16, ny_core=8, nx_clad=8, ny_clad=8, filename=None):\n", " gmsh.initialize()\n", " gmsh.option.setNumber(\"General.Verbosity\", 0)\n", " gmsh.model.add(\"dielectric_waveguide\")\n", "\n", " clad = gmsh.model.occ.addRectangle(-a_clad / 2, -b_clad / 2, 0, a_clad, b_clad)\n", " core = gmsh.model.occ.addRectangle(-a_core / 2, -b_core / 2, 0, a_core, b_core)\n", " _, outmap = gmsh.model.occ.fragment([(2, clad)], [(2, core)])\n", " gmsh.model.occ.synchronize()\n", "\n", " core_surfs = [tag for _, tag in outmap[1]]\n", " clad_surfs = [tag for _, tag in outmap[0] if tag not in core_surfs]\n", "\n", " gmsh.model.addPhysicalGroup(2, core_surfs, tag=1, name=\"core\")\n", " gmsh.model.addPhysicalGroup(2, clad_surfs, tag=2, name=\"cladding\")\n", "\n", " all_surfs = [(2, t) for t in core_surfs + clad_surfs]\n", " outer_bnd = gmsh.model.getBoundary(all_surfs, oriented=False, combined=True)\n", " pec_tags = [abs(tag) for _, tag in outer_bnd]\n", " gmsh.model.addPhysicalGroup(1, pec_tags, tag=1, name=\"PEC\")\n", "\n", " lc_core = min(a_core / nx_core, b_core / ny_core)\n", " lc_clad = max(lc_core * max(nx_core / nx_clad, ny_core / ny_clad), 1.5 * lc_core)\n", " _set_lc_for_dielectric(a_core, b_core, lc_core, lc_clad)\n", "\n", " gmsh.model.mesh.generate(2)\n", " return write_and_finalize_gmsh(filename, prefix=\"wg_diel_\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "b05177fc", "metadata": { "execution": { "iopub.execute_input": "2026-05-27T19:59:03.267746Z", "iopub.status.busy": "2026-05-27T19:59:03.267612Z", "iopub.status.idle": "2026-05-27T19:59:03.270540Z", "shell.execute_reply": "2026-05-27T19:59:03.270115Z" }, "papermill": { "duration": 0.004997, "end_time": "2026-05-27T19:59:03.270922+00:00", "exception": false, "start_time": "2026-05-27T19:59:03.265925+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Guided-mode window: 5.4414 < kn < 10.8828\n" ] } ], "source": [ "a_core, b_core = 1.0, 0.5\n", "a_clad, b_clad = 4.0, 3.0\n", "eps_core, eps_clad = 4.0, 1.0\n", "mu = 1.0\n", "\n", "k0_cutoff_approx = np.pi / a_core / np.sqrt(eps_core - eps_clad)\n", "omega = 3.0 * k0_cutoff_approx\n", "\n", "kn_min = omega * np.sqrt(mu * eps_clad)\n", "kn_max = omega * np.sqrt(mu * eps_core)\n", "print(f\"Guided-mode window: {kn_min:.4f} < kn < {kn_max:.4f}\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "ce38bb09", "metadata": { "execution": { "iopub.execute_input": "2026-05-27T19:59:03.273263Z", "iopub.status.busy": "2026-05-27T19:59:03.273150Z", "iopub.status.idle": "2026-05-27T19:59:14.003479Z", "shell.execute_reply": "2026-05-27T19:59:14.003062Z" }, "papermill": { "duration": 10.732601, "end_time": "2026-05-27T19:59:14.004469+00:00", "exception": false, "start_time": "2026-05-27T19:59:03.271868+00:00", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading mesh file: /tmp/wg_diel_7ttrgedl.msh\n", "Groups to render transparent: ['air_none', 'air_plastic_enclosure']\n", "\n", "Mesh loaded successfully with 2 cell blocks\n", "Found 3122 triangles total\n", "Physical group tags in mesh: {1: 'core', 2: 'cladding'}\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "