"Fossies" - the Fresh Open Source Software Archive

Member "meep-1.10.0/python/examples/ring-cyl.py" (12 May 2018, 2847 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 # Calculating 2d ring-resonator modes using cylindrical coordinates,
    2 # from the Meep tutorial.
    3 from __future__ import division
    4 
    5 import meep as mp
    6 import argparse
    7 
    8 def main(args):
    9 
   10     n = 3.4     # index of waveguide
   11     w = 1       # width of waveguide
   12     r = 1       # inner radius of ring
   13     pad = 4     # padding between waveguide and edge of PML
   14     dpml = 32    # thickness of PML
   15 
   16     sr = r + w + pad + dpml  # radial size (cell is from 0 to sr)
   17     dimensions = mp.CYLINDRICAL
   18     cell = mp.Vector3(sr, 0, 0)
   19 
   20     # in cylindrical coordinates, the phi (angular) dependence of the fields
   21     # is given by exp(i m phi), where m is given by:
   22     m = args.m
   23 
   24     geometry = [mp.Block(center=mp.Vector3(r + (w / 2)),
   25                          size=mp.Vector3(w, mp.inf, mp.inf),
   26                          material=mp.Medium(index=n))]
   27 
   28     pml_layers = [mp.PML(dpml)]
   29     resolution = 20
   30 
   31     # If we don't want to excite a specific mode symmetry, we can just
   32     # put a single point source at some arbitrary place, pointing in some
   33     # arbitrary direction.  We will only look for Ez-polarized modes.
   34 
   35     fcen = args.fcen  # pulse center frequency
   36     df = args.df      # pulse frequency width
   37     sources = [mp.Source(src=mp.GaussianSource(fcen, fwidth=df),
   38                          component=mp.Ez,
   39                          center=mp.Vector3(r + 0.1))]
   40 
   41     # note that the r -> -r mirror symmetry is exploited automatically
   42 
   43     sim = mp.Simulation(cell_size=cell,
   44                         geometry=geometry,
   45                         boundary_layers=pml_layers,
   46                         resolution=resolution,
   47                         sources=sources,
   48                         dimensions=dimensions,
   49                         m=m)
   50 
   51     sim.run(mp.after_sources(mp.Harminv(mp.Ez, mp.Vector3(r + 0.1), fcen, df)),
   52             until_after_sources=200)
   53 
   54     # Output fields for one period at the end.  (If we output
   55     # at a single time, we might accidentally catch the Ez field when it is
   56     # almost zero and get a distorted view.)  We'll append the fields
   57     # to a file to get an r-by-t picture.  We'll also output from -sr to -sr
   58     # instead of from 0 to sr.
   59     sim.run(mp.in_volume(mp.Volume(center=mp.Vector3(), size=mp.Vector3(2 * sr)),
   60                          mp.at_beginning(mp.output_epsilon),
   61                          mp.to_appended("ez", mp.at_every(1 / fcen / 20, mp.output_efield_z))),
   62             until=1 / fcen)
   63 
   64 if __name__ == '__main__':
   65     parser = argparse.ArgumentParser()
   66     parser.add_argument('-fcen', type=float, default=0.15, help='pulse center frequency')
   67     parser.add_argument('-df', type=float, default=0.1, help='pulse frequency width')
   68     parser.add_argument('-m', type=int, default=3, help='phi (angular) dependence of the fields given by exp(i m phi)')
   69     args = parser.parse_args()
   70     main(args)