From 6003eaa0fc9aa5a5aadb6d827c48515596ef029c Mon Sep 17 00:00:00 2001 From: Andeloth Date: Wed, 14 Feb 2024 10:57:47 -0700 Subject: [PATCH] update for new version of meep which can't use the meep gds reader functions --- book/files/mmi2x2.gds | Bin 1398 -> 822 bytes book/pages/scattering_parameters.ipynb | 370 +++++++++++++------------ 2 files changed, 187 insertions(+), 183 deletions(-) diff --git a/book/files/mmi2x2.gds b/book/files/mmi2x2.gds index c6daa8c08e2b8fae5562be533627f48de800fd6b..c4acc02550d46651a1fd7e74db9317a353b27794 100644 GIT binary patch delta 162 zcmeyywT&%`fsKKQDS|BPVw!pv&t*lF&4Z21>U ommT^GW=8?_vEtOXF)El*9EX{ck1)pKl(S&^!N$(Oz{0`+08lM)|A35{on2fUy0~cdc%FOmaz7-Ym?6J=&wHMn^PHR)4q^BNtsty^Lxd(8xPZ&~ zXVgOX;NB9@j4HQo?=IXQy+3N-`E>Q&!PAFmRi^9e&h>g5$##Oc2DsB90=P3FfGcy6 zenaHffykF5k>h>ipIwW~jz33y7Sr^aGo%g(wv5qp>QvA*VmMuY{8<9&EkI=eHAk&-E?kq@T#-1wmw*X z(e1Ad)^ARmnfB@?v-t^}d!x@OeLUp}Yd-4tJH77e^0n2@LXzBghPV#Y=l#Fln2SVy z=;G)n{Y5=(&i~t~yBKIjqg7e@nC9v;mE%O@_uKzd0^!StwRYVYbO4 zpFfCv-zIIMcOQHDI9b?)D6bzU>RUINjJrkpcxe;kqMn;*6O)}HeY~`Zl}vAQ;7#B> zcoXvU@lt(P)U!Tyb`$dS@lyS2rWYBln17P~^Q3<}FU+r2)SLg&3hOgJBmMKeRR2__ j2ik|MZ=`>|d-{0Ef4!(T|LsHbpC|qE-PhNf9LM+zb4F_n diff --git a/book/pages/scattering_parameters.ipynb b/book/pages/scattering_parameters.ipynb index b79156f..94ae85c 100644 --- a/book/pages/scattering_parameters.ipynb +++ b/book/pages/scattering_parameters.ipynb @@ -78,13 +78,25 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[32m2024-02-14 10:23:37.620\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mgplugins.gmeep\u001b[0m:\u001b[36m\u001b[0m:\u001b[36m39\u001b[0m - \u001b[1mMeep '1.28.0' installed at ['/home/andeloth/miniconda3/envs/photonics/lib/python3.11/site-packages/meep']\u001b[0m\n" + ] + } + ], "source": [ "# Imports\n", "import meep as mp \n", "import numpy as np\n", "import matplotlib.pyplot as plt \n", - "import os" + "import os\n", + "from pathlib import Path\n", + "from gplugins.gmeep.get_meep_geometry import get_meep_geometry_from_component\n", + "from gdsfactory.read import import_gds\n", + "import gdsfactory as gf" ] }, { @@ -97,27 +109,15 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 53, "metadata": {}, "outputs": [], "source": [ - "res = 40 # the resolution of the simulation in pixels/um\n", + "res = 20 # the resolution of the simulation in pixels/um\n", "sim_is_3D = False # Turn this to false for a 2D simulation\n", "\n", - "pwd = os.path.abspath('')\n", - "gds_file = f\"{pwd}/../images/mmi2x2.gds\" # The name of our gds file\n", - "\n", - "# Here we define the layer numbers for each part of our gds\n", - "geometry_L = 1\n", - "cell_L = 2\n", - "port1_L = 4\n", - "port2_L = 3\n", - "port3_L = 5\n", - "port4_L = 6\n", - "source1_L = 8\n", - "source2_L = 7\n", - "source3_L = 9\n", - "source4_L = 10\n", + "pwd = Path(os.path.abspath(''))\n", + "gds_file = pwd.parent / \"files/mmi2x2.gds\" # The name of our gds file\n", "\n", "# The Parameters for the frequencies we'll be using\n", "lcen = 1.55 # Center wavelength\n", @@ -139,8 +139,6 @@ "# Sets the min and max values for the cell and the silicon. Our simulation will be centered at y=0\n", "cell_zmax = 0.5*cell_thickness if sim_is_3D else 0\n", "cell_zmin = -0.5 * cell_thickness if sim_is_3D else 0\n", - "si_zmax = 0.5 * t_Si if sim_is_3D else 10 # In a 2D simulation, the geometry still has to have a thickness or it won't show up\n", - "si_zmin = -0.5 * t_Si if sim_is_3D else -10\n", "\n", "# Create a 2D array to hold the S-Parameters for the device\n", "n_ports = 4 # The number of ports, also the size of our array\n", @@ -157,35 +155,58 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, - "outputs": [ - { - "ename": "", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31mThe Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click here for more info. View Jupyter log for further details." - ] - } - ], + "outputs": [], + "source": [ + "from gdsfactory.technology import LayerLevel, LayerStack\n", + "layers = dict(core=LayerLevel(\n", + " layer=(1,0),\n", + " thickness=t_Si,\n", + " zmin=0.0,\n", + " material=\"si\",\n", + " mesh_order=2,\n", + " sidewall_angle=0,\n", + " width_to_z=0.5,\n", + " orientation=\"100\",)\n", + " )\n", + "layer_stack = LayerStack(layers=layers)\n", + "\n", + "mmi_comp = import_gds(gds_file)\n", + "geometry = get_meep_geometry_from_component(mmi_comp, is_3d=sim_is_3D, wavelength=lcen, layer_stack=layer_stack)\n", + "# Use this to modify the material of the loaded geometry if needed.\n", + "# geometry = [mp.Prism(geom.vertices, geom.height, geom.axis, geom.center, material=mp.Medium(index=3.45)) for geom in geometry]" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [], "source": [ - "###################################################\n", + "# ###################################################\n", "# Now we actually import the geometry\n", - "geometry = mp.GDSII_prisms(silicon, gds_file, geometry_L, zmax=si_zmax, zmin=si_zmin) # Gets the geometry of the mmi\n", - "cell = mp.GDSII_vol(fname = gds_file, layer = cell_L, zmax=cell_zmax, zmin=cell_zmin) # cell geometry. We use mp.GDSII_vol() instead of mp.GDSII_prims() because they return different types\n", - "port1 = mp.GDSII_vol(fname = gds_file, layer = port1_L, zmax=cell_zmax, zmin=cell_zmin) # Port geometry\n", - "port2 = mp.GDSII_vol(fname = gds_file, layer = port2_L, zmax=cell_zmax, zmin=cell_zmin)\n", - "port3 = mp.GDSII_vol(fname = gds_file, layer = port3_L, zmax=cell_zmax, zmin=cell_zmin)\n", - "port4 = mp.GDSII_vol(fname = gds_file, layer = port4_L, zmax=cell_zmax, zmin=cell_zmin)\n", - "source1 = mp.GDSII_vol(fname = gds_file, layer = source1_L, zmax=cell_zmax, zmin=cell_zmin) # Source Geometry\n", - "source2 = mp.GDSII_vol(fname = gds_file, layer = source2_L, zmax=cell_zmax, zmin=cell_zmin)\n", - "source3 = mp.GDSII_vol(fname = gds_file, layer = source3_L, zmax=cell_zmax, zmin=cell_zmin)\n", - "source4 = mp.GDSII_vol(fname = gds_file, layer = source4_L, zmax=cell_zmax, zmin=cell_zmin)\n", + "cell_x = 32\n", + "cell_y = 6\n", + "cell_z = 3\n", + "\n", + "port_xsize = 0\n", + "port_ysize = 1.2\n", + "port_zsize = 0.8\n", + "\n", + "port_size = mp.Vector3(port_xsize, port_ysize, port_zsize) if sim_is_3D else mp.Vector3(port_xsize, port_ysize, 0)\n", + "cell = mp.Vector3(cell_x, cell_y, cell_z) if sim_is_3D else mp.Vector3(cell_x, cell_y, 0)\n", + "\n", + "port1 = mp.Volume(center=mp.Vector3(-14,-0.75,0), size=port_size)\n", + "port2 = mp.Volume(center=mp.Vector3(-14,0.75,0), size=port_size)\n", + "port3 = mp.Volume(center=mp.Vector3(14,0.75,0), size=port_size)\n", + "port4 = mp.Volume(center=mp.Vector3(14,-0.75,0), size=port_size)\n", + "source1 = mp.Volume(center=port1.center+mp.Vector3(x=0.5),size=port_size)\n", + "source2 = mp.Volume(center=port4.center-mp.Vector3(x=0.5), size=port_size)\n", "\n", "if sim_is_3D: # Sets up the oxide cladding for a three d simulation (Not used in a 2D simulation)\n", " oxide_center = mp.Vector3(z=-0.5 * t_oxide)\n", - " oxide_size = mp.Vector3(cell.size.x, cell.size.y, t_oxide)\n", + " oxide_size = mp.Vector3(cell.x, cell.y, t_oxide)\n", " oxide_layer = [mp.Block(material=oxide, center=oxide_center, size=oxide_size)]\n", " geometry = geometry + oxide_layer\n" ] @@ -207,41 +228,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 74, "metadata": {}, - "outputs": [ - { - "ename": "", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31mFailed to start the Kernel. \n", - "\u001b[1;31mKernel Python 3.9.6 is not usable. Check the Jupyter output tab for more information. \n", - "\u001b[1;31mView Jupyter log for further details." - ] - } - ], + "outputs": [], "source": [ "# Set up the first source for the simulation. I'll start with port1 (the lower left)\n", "sources = [\n", " mp.EigenModeSource(\n", " src = mp.GaussianSource(fcen, fwidth=df),\n", - " size=source1.size, # Here we input the geometry for our first source\n", - " center=source1.center,\n", + " volume=source1,\n", " eig_band=1,\n", - " eig_parity = mp.NO_PARITY if 3D else mp.EVEN_Y + mp.ODD_Z,\n", + " eig_parity = mp.NO_PARITY if sim_is_3D else mp.EVEN_Y + mp.ODD_Z,\n", " eig_match_freq = True,\n", - "\n", " )\n", "]\n", "\n", "# Create Simulation\n", "sim = mp.Simulation(\n", " resolution=res, # The resolution, defined further up\n", - " cell_size=cell.size, # The cell size, taken from the gds\n", + " cell_size=cell, # The cell size, taken from the gds\n", " boundary_layers=[mp.PML(dpml)], # the perfectly matched layers, with a diameter as defined above\n", " sources = sources, # The source(s) we just defined\n", - " geometry = geometry # The geometry, from above\n", + " geometry = geometry, # The geometry, from above\n", + " default_material=mp.Medium(index=1.444)\n", ")\n" ] }, @@ -257,7 +266,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 75, "metadata": { "tags": [ "hide-output" @@ -265,26 +274,38 @@ }, "outputs": [ { - "ename": "", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31mFailed to start the Kernel. \n", - "\u001b[1;31mKernel Python 3.9.6 is not usable. Check the Jupyter output tab for more information. \n", - "\u001b[1;31mView Jupyter log for further details." - ] + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data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z4cSQmJmLz5s147LHHAAAzZszA4cOH8fXXXyMwMFDlFhKRkhhqiMirvfHGG8jOzsbRo0dRXFyMhx9+GF9//TUSEhLUbhoRKYyhhoi8mhAC48aNg8FgwLfffotnnnkGixcvVrtZRKQChhoi8nrHjh3D8OHDcfvtt6O0tBQBAQFqN4mIVMAThYnI6+Xn5yMkJASnT59GZWWl2s0hIpVwTw0RebXCwkKMGTMGn3/+OZYuXQoA+O9//wudTqdyy4hIadxTQ0Re68qVK5g1axbmzp2LsWPHIi8vD8XFxdi4caPaTSMiFXBPDRF5reeeew6ffvopDh8+jJCQEADAm2++iQULFuDbb7/FwIED1W0gESmKoYaIvNK+ffswfvx4fPnll7jjjjvavJeWlobm5mYehiLyMww1RERE5BN4Tg0RERH5BIYaIiIi8gkMNUREROQTGGqIiIjIJzDUEBERkU9gqCEiIiKfwFBDREREPoGhhoiIiHwCQw0RERH5BIYaIiIi8gkMNUREROQTGGqIiIjIJ/x/gLa0PrWx0kQAAAAASUVORK5CYII=", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" } ], "source": [ - "# Adds mode monitors at each of the ports to track the energy that goes in or out, then adds them to a list\n", - "modeMonitors = []\n", - "modeMonitors.append(sim.add_mode_monitor(fcen, 0,1, mp.ModeRegion(volume=port1))) # Adds mode monitor for the frequency fcen, at only that frequency\n", - "modeMonitors.append(sim.add_mode_monitor(fcen, 0,1, mp.ModeRegion(volume=port2)))\n", - "modeMonitors.append(sim.add_mode_monitor(fcen, 0,1, mp.ModeRegion(volume=port3)))\n", - "modeMonitors.append(sim.add_mode_monitor(fcen, 0,1, mp.ModeRegion(volume=port4)))\n", + "# Adds mode monitors at each of the ports to track the energy that goes in or out\n", + "modeMonitors = [\n", + " sim.add_mode_monitor(fcen, 0,1, mp.ModeRegion(volume=port1)),\n", + " sim.add_mode_monitor(fcen, 0,1, mp.ModeRegion(volume=port2)),\n", + " sim.add_mode_monitor(fcen, 0,1, mp.ModeRegion(volume=port3)),\n", + " sim.add_mode_monitor(fcen, 0,1, mp.ModeRegion(volume=port4))\n", + "]\n", "\n", "# Plot the simulation\n", - "sim.plot2D() # No parameters are needed for a 2D simulation. \n" + "plot_plane = mp.Volume(center=mp.Vector3(z=0.2), size=mp.Vector3(cell.x, cell.y, 0))\n", + "sim.plot2D(output_plane=plot_plane if sim_is_3D else None) # No parameters are needed for a 2D simulation. \n" ] }, { @@ -292,12 +313,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "As we see from the output of sim.plot2D(), our simulation is set up correctly. The red is our source, the blue are our 4 mode monitors, an the black is the geometry. We are ready to run the simulation! Actually running the simulation is the most computationally intense part of this, so it may take some time. The until_after_sources parameter for sim.run() means the run the simulation until 100 meep time units after the sources have turned off. This makes sure the all of the light has time to propagate through the mmi." + "As we see from the output of sim.plot2D, our simulation is set up correctly. The red is our source, the blue are our 4 mode monitors, an the black is the geometry. We are ready to run the simulation! Actually running the simulation is the most computationally intense part of this, so it may take some time. The until_after_sources parameter for sim.run() means the run the simulation until 100 meep time units after the sources have turned off. This makes sure the all of the light has time to propagate through the mmi." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "metadata": { "tags": [ "hide-output" @@ -305,14 +326,25 @@ }, "outputs": [ { - "ename": "", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31mFailed to start the Kernel. \n", - "\u001b[1;31mKernel Python 3.9.6 is not usable. Check the Jupyter output tab for more information. \n", - "\u001b[1;31mView Jupyter log for further details." + "name": "stderr", + "output_type": "stream", + "text": [ + "Warning: grid volume is not an integer number of pixels; cell size will be rounded to nearest pixel.\n" ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "21ddcdfd95394b24a1e5c6ef151b8dbe", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "FloatProgress(value=0.0, description='0% done ', max=177.5)" + ] + }, + "metadata": {}, + "output_type": "display_data" } ], "source": [ @@ -330,17 +362,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 79, "metadata": {}, "outputs": [ { - "ename": "", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31mFailed to start the Kernel. \n", - "\u001b[1;31mKernel Python 3.9.6 is not usable. Check the Jupyter output tab for more information. \n", - "\u001b[1;31mView Jupyter log for further details." + "name": "stderr", + "output_type": "stream", + "text": [ + "Warning: grid volume is not an integer number of pixels; cell size will be rounded to nearest pixel.\n", + "Warning: grid volume is not an integer number of pixels; cell size will be rounded to nearest pixel.\n", + "Warning: grid volume is not an integer number of pixels; cell size will be rounded to nearest pixel.\n", + "Warning: grid volume is not an integer number of pixels; cell size will be rounded to nearest pixel.\n", + "Warning: grid volume is not an integer number of pixels; cell size will be rounded to nearest pixel.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[32m2024-02-14 10:56:43.082\u001b[0m | \u001b[33m\u001b[1mWARNING \u001b[0m | \u001b[36mgdsfactory.config\u001b[0m:\u001b[36mshowwarning\u001b[0m:\u001b[36m281\u001b[0m - \u001b[33m\u001b[1mCasting complex values to real discards the imaginary part\u001b[0m\n", + "\n", + "-----------------------------------------------------------------\n", + "\n", + "S params:\n", + "Port1(Lower Left, S11): 0.256003+0.044099j \n", + "Port2(Upper Left, S12): -0.162642-0.176894j \n", + "Port3(Upper Right, S13): -2.190592-1.832865j \n", + "Port4(Lower Right, S14): 1.329497-2.040702j\n", + "\n", + "-----------------------------------------------------------------\n", + "\n", + "0.008247651255583325\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/tmp/ipykernel_21496/664415321.py:10: ComplexWarning: Casting complex values to real discards the imaginary part\n", + " s_params[0] = [port1_coeff, port2_coeff, port3_coeff, port4_coeff]\n" ] } ], @@ -348,21 +408,20 @@ "#############################################################\n", "alphas = [[1,1,0,0,0], [1,1,0,0,0],[1,1,0,0,1],[1,1,0,0,1]] # This array holds the values for forwards and backward propagation for each soure. The 5th number is for the total input\n", "# Finds the S parameters\n", - "input_coeff = sim.get_eigenmode_coefficients(modeMonitors[0], [1], eig_parity=mp.NO_PARITY if 3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[0][4]] # This is the amount of light from the source that enters the device\n", - "port1_coeff = sim.get_eigenmode_coefficients(modeMonitors[0], [1], eig_parity=mp.NO_PARITY if 3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[0][0]]\n", - "port2_coeff = sim.get_eigenmode_coefficients(modeMonitors[1], [1], eig_parity=mp.NO_PARITY if 3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[0][1]]\n", - "port3_coeff = sim.get_eigenmode_coefficients(modeMonitors[2], [1], eig_parity=mp.NO_PARITY if 3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[0][2]]\n", - "port4_coeff = sim.get_eigenmode_coefficients(modeMonitors[3], [1], eig_parity=mp.NO_PARITY if 3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[0][3]]\n", + "input_coeff = sim.get_eigenmode_coefficients(modeMonitors[0], [1], eig_parity=mp.NO_PARITY if sim_is_3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[0][4]] # This is the amount of light from the source that enters the device\n", + "port1_coeff = sim.get_eigenmode_coefficients(modeMonitors[0], [1], eig_parity=mp.NO_PARITY if sim_is_3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[0][0]]\n", + "port2_coeff = sim.get_eigenmode_coefficients(modeMonitors[1], [1], eig_parity=mp.NO_PARITY if sim_is_3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[0][1]]\n", + "port3_coeff = sim.get_eigenmode_coefficients(modeMonitors[2], [1], eig_parity=mp.NO_PARITY if sim_is_3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[0][2]]\n", + "port4_coeff = sim.get_eigenmode_coefficients(modeMonitors[3], [1], eig_parity=mp.NO_PARITY if sim_is_3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[0][3]]\n", "# Store the S parameters in s_params\n", "s_params[0] = [port1_coeff, port2_coeff, port3_coeff, port4_coeff]\n", - "input_params[0] = input_coeff\n", "\n", "\n", "# Prints out the S parameters\n", "print(\"\\n-----------------------------------------------------------------\\n\")\n", - "print(\"S params: Port1(Lower Left, S11): {:.6f} Port2(Upper Left, S12): {:.6f} Port3(Upper Right, S13): {:.6f} Port4(Lower Right, S14): {:.6f}\".format(port1_coeff, port2_coeff, port3_coeff, port4_coeff))\n", + "print(f\"S params:\\nPort1(Lower Left, S11): {port1_coeff:.6f} \\nPort2(Upper Left, S12): {port2_coeff:.6f} \\nPort3(Upper Right, S13): {port3_coeff:.6f} \\nPort4(Lower Right, S14): {port4_coeff:.6f}\")\n", "print(\"\\n-----------------------------------------------------------------\\n\")\n", - "\n" + "print(np.abs(input_coeff))\n" ] }, { @@ -379,18 +438,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31mFailed to start the Kernel. \n", - "\u001b[1;31mKernel Python 3.9.6 is not usable. Check the Jupyter output tab for more information. \n", - "\u001b[1;31mView Jupyter log for further details." - ] - } - ], + "outputs": [], "source": [ "# Calculates the transmittance based off of the S parameters\n", "port1_trans = abs(port1_coeff) ** 2 / abs(input_coeff) ** 2\n", @@ -400,7 +448,7 @@ "\n", "# Calculates the Insertion loss as a percent and in dB\n", "insertionLoss = 1-(port2_trans + port3_trans + port4_trans)\n", - "insertionLoss_dB = 10*math.log10(insertionLoss) \n", + "insertionLoss_dB = 10*np.log10(insertionLoss) \n", "\n", "# Prints the Transmittance\n", "print(\"\\n-----------------------------------------------------------------\\n\")\n", @@ -422,18 +470,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31mFailed to start the Kernel. \n", - "\u001b[1;31mKernel Python 3.9.6 is not usable. Check the Jupyter output tab for more information. \n", - "\u001b[1;31mView Jupyter log for further details." - ] - } - ], + "outputs": [], "source": [ "# Reset the simulation in order to run it again and visulaize the fields\n", "sim.reset_meep()\n", @@ -442,8 +479,8 @@ "sources = [\n", " mp.EigenModeSource(\n", " src=mp.ContinuousSource(fcen, fwidth=df),\n", - " size=source1.size,\n", - " center=source1.center,\n", + " size=port1.size,\n", + " center=port1.center,\n", " eig_band=1,\n", " eig_parity=mp.EVEN_Y + mp.ODD_Z,\n", " eig_match_freq=True,\n", @@ -466,13 +503,13 @@ "\n", "# Gets data\n", "eps_data = sim.get_epsilon() # Epsilon Data / The Geometry / An array that holds what materials are where\n", - "ez_data = numpy.real(sim.get_efield_z()) # Values for the component of the E-field in the z direction (in/out of screen)\n", + "ez_data = np.real(sim.get_efield_z()) # Values for the component of the E-field in the z direction (in/out of screen)\n", "\n", "# Creates the plot\n", "plt.figure(dpi=200)\n", - "plt.imshow(numpy.transpose(eps_data), interpolation=\"spline36\", cmap=\"binary\")\n", + "plt.imshow(np.transpose(eps_data), interpolation=\"spline36\", cmap=\"binary\")\n", "plt.imshow(\n", - " numpy.flipud(numpy.transpose(ez_data)),\n", + " np.flipud(np.transpose(ez_data)),\n", " interpolation=\"spline36\",\n", " cmap=\"RdBu\",\n", " alpha=0.9,\n", @@ -499,37 +536,26 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31mFailed to start the Kernel. \n", - "\u001b[1;31mKernel Python 3.9.6 is not usable. Check the Jupyter output tab for more information. \n", - "\u001b[1;31mView Jupyter log for further details." - ] - } - ], + "outputs": [], "source": [ "\n", "# Set up the rest of the sources for the simulation.\n", "sources = [\n", " mp.EigenModeSource(\n", " src = mp.GaussianSource(fcen, fwidth=df),\n", - " size=source2.size, # Here we input the geometry for our first source\n", - " center=source2.center,\n", + " size=port2.size, # Here we input the geometry for our first source\n", + " center=port2.center,\n", " eig_band=1,\n", - " eig_parity = mp.NO_PARITY if 3D else mp.EVEN_Y + mp.ODD_Z,\n", + " eig_parity = mp.NO_PARITY if sim_is_3D else mp.EVEN_Y + mp.ODD_Z,\n", " eig_match_freq = True,\n", "\n", " ),\n", " mp.EigenModeSource(\n", " src = mp.GaussianSource(fcen, fwidth=df),\n", - " size=source3.size, # Here we input the geometry for our first source\n", - " center=source3.center,\n", + " size=port3.size, # Here we input the geometry for our first source\n", + " center=port3.center,\n", " eig_band=1,\n", - " eig_parity = mp.NO_PARITY if 3D else mp.EVEN_Y + mp.ODD_Z,\n", + " eig_parity = mp.NO_PARITY if sim_is_3D else mp.EVEN_Y + mp.ODD_Z,\n", " eig_match_freq = True,\n", " eig_kpoint = mp.Vector3(-1,0,0),\n", " direction = mp.NO_DIRECTION\n", @@ -537,10 +563,10 @@ " ),\n", " mp.EigenModeSource(\n", " src = mp.GaussianSource(fcen, fwidth=df),\n", - " size=source4.size, # Here we input the geometry for our first source\n", - " center=source4.center,\n", + " size=port4.size, # Here we input the geometry for our first source\n", + " center=port4.center,\n", " eig_band=1,\n", - " eig_parity = mp.NO_PARITY if 3D else mp.EVEN_Y + mp.ODD_Z,\n", + " eig_parity = mp.NO_PARITY if sim_is_3D else mp.EVEN_Y + mp.ODD_Z,\n", " eig_match_freq = True,\n", " eig_kpoint = mp.Vector3(-1,0,0),\n", " direction = mp.NO_DIRECTION\n", @@ -553,18 +579,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31mFailed to start the Kernel. \n", - "\u001b[1;31mKernel Python 3.9.6 is not usable. Check the Jupyter output tab for more information. \n", - "\u001b[1;31mView Jupyter log for further details." - ] - } - ], + "outputs": [], "source": [ "\n", "\n", @@ -595,11 +610,11 @@ "\n", " #############################################################\n", " # Finds the S parameters\n", - " port1_coeff = sim.get_eigenmode_coefficients(modeMonitors[0], [1], eig_parity=mp.NO_PARITY if 3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[i+1][0]]\n", - " port2_coeff = sim.get_eigenmode_coefficients(modeMonitors[1], [1], eig_parity=mp.NO_PARITY if 3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[i+1][1]]\n", - " port3_coeff = sim.get_eigenmode_coefficients(modeMonitors[2], [1], eig_parity=mp.NO_PARITY if 3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[i+1][2]]\n", - " port4_coeff = sim.get_eigenmode_coefficients(modeMonitors[3], [1], eig_parity=mp.NO_PARITY if 3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[i+1][3]]\n", - " input_coeff = sim.get_eigenmode_coefficients(modeMonitors[i+1], [1], eig_parity=mp.NO_PARITY if 3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[i+1][4]] # This is the total amount of light that entered the devie\n", + " port1_coeff = sim.get_eigenmode_coefficients(modeMonitors[0], [1], eig_parity=mp.NO_PARITY if sim_is_3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[i+1][0]]\n", + " port2_coeff = sim.get_eigenmode_coefficients(modeMonitors[1], [1], eig_parity=mp.NO_PARITY if sim_is_3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[i+1][1]]\n", + " port3_coeff = sim.get_eigenmode_coefficients(modeMonitors[2], [1], eig_parity=mp.NO_PARITY if sim_is_3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[i+1][2]]\n", + " port4_coeff = sim.get_eigenmode_coefficients(modeMonitors[3], [1], eig_parity=mp.NO_PARITY if sim_is_3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[i+1][3]]\n", + " input_coeff = sim.get_eigenmode_coefficients(modeMonitors[i+1], [1], eig_parity=mp.NO_PARITY if sim_is_3D else mp.EVEN_Y + mp.ODD_Z).alpha[0, 0, alphas[i+1][4]] # This is the total amount of light that entered the devie\n", "\n", " # Store the S parameters in s_params\n", " index = 1+i \n", @@ -611,18 +626,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31mFailed to start the Kernel. \n", - "\u001b[1;31mKernel Python 3.9.6 is not usable. Check the Jupyter output tab for more information. \n", - "\u001b[1;31mView Jupyter log for further details." - ] - } - ], + "outputs": [], "source": [ "print(\"S-Params:\")\n", "for i in range(n_ports):\n",