"Fossies" - the Fresh Open Source Software Archive

Member "meep-1.10.0/python/examples/cavity_arrayslice.py" (29 Mar 2018, 1764 Bytes) of package /linux/privat/meep-1.10.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 import meep as mp
    2 import numpy as np
    3 import matplotlib.pyplot as plt
    4 
    5 # set up the geometry
    6 eps = 13
    7 w = 1.2
    8 r = 0.36
    9 d = 1.4
   10 N = 3
   11 sy = 6
   12 pad = 2
   13 dpml = 1
   14 sx = (2 * (pad + dpml + N)) + d - 1
   15 fcen = 0.25
   16 df = 0.2
   17 nfreq = 500
   18 
   19 cell = mp.Vector3(sx, sy, 0)
   20 
   21 blk = mp.Block(size=mp.Vector3(mp.inf, w, mp.inf),
   22                material=mp.Medium(epsilon=eps))
   23 
   24 geometry = [blk]
   25 
   26 for i in range(3):
   27     geometry.append(mp.Cylinder(r, center=mp.Vector3(d / 2 + i)))
   28 
   29 for i in range(3):
   30     geometry.append(mp.Cylinder(r, center=mp.Vector3(d / -2 - i)))
   31 
   32 sim = mp.Simulation(cell_size=cell,
   33                     geometry=geometry,
   34                     sources=[],
   35                     boundary_layers=[mp.PML(dpml)],
   36                     resolution=20)
   37 
   38 # add sources
   39 sim.sources = [mp.Source(mp.GaussianSource(fcen, fwidth=df),
   40                mp.Hz, mp.Vector3())]
   41 
   42 # run until sources are finished (and no later)
   43 sim._run_sources_until(0, [])
   44 
   45 # get 1D and 2D array slices
   46 xMin = -0.25 * sx
   47 xMax = +0.25 * sx
   48 yMin = -0.15 * sy
   49 yMax = +0.15 * sy
   50 
   51 # 1D slice of Hz data
   52 size_1d = mp.Vector3(xMax - xMin)
   53 center_1d = mp.Vector3((xMin + xMax) / 2)
   54 slice1d = sim.get_array(mp.Volume(center_1d, size=size_1d), component=mp.Hz)
   55 
   56 # 2D slice of Hz data
   57 size_2d = mp.Vector3(xMax - xMin, yMax - yMin)
   58 center_2d = mp.Vector3((xMin + xMax) / 2, (yMin + yMax) / 2)
   59 slice2d = sim.get_array(mp.Volume(center_2d, size=size_2d), component=mp.Hz)
   60 
   61 # plot 1D slice
   62 plt.subplot(1, 2, 1)
   63 x1d = np.linspace(xMin, xMax, len(slice1d))
   64 plt.plot(x1d, slice1d)
   65 
   66 # plot 2D slice
   67 plt.subplot(1, 2, 2)
   68 dy = (yMax - yMin) / slice2d.shape[1]
   69 dx = (xMax - xMin) / slice2d.shape[0]
   70 (x2d, y2d) = np.mgrid[slice(xMin, xMax, dx), slice(yMin, yMax, dy)]
   71 plt.contourf(x2d, y2d, slice2d)
   72 plt.colorbar()
   73 plt.show()