Meep Download Release notes F AQ Meep manual Introduction Installation Tutorial Reference C++ Tutorial C++ Reference Acknowledgements License and Copyright Meep T utorial From AbInitio In this page, we'll go through a couple of simple examples that illustrate the process ofcomputing fields, transmission/reflection spectra, and resonant modes in Meep. All of the examples here are two-dimensional calculations, simply because they ar e quicker than 3d computations and they illustrate most of the essential features, but of course Meep can d o similar calculations in 3d. This tutorial uses the libctl/Scheme scripting interface to Meep, which is what we expect most users to employ most of the time. There is also a C++ interface that may give additional flexibility in some situations; that is described in the C++ tutorial. In order to convert the HDF5 output files of Meep into images of the fields and so on, this tutorial uses our free h5utils programs. (Y ou could also use any other program, such as Matlab (http://www .mathworks.com/access/helpd esk/help/techdoc/ref/hdf5read.html) , that supports reading HDF5 files.) Contents 1 The ctl file 2 Fields in a waveguide 2.1 A straight waveguide 2.2 A 90° bend 2.2.1 Output tips and tricks 3 Transmission spectrum around a waveguide bend 4 Modes of aring resonator 4.1 Exploiting symmetry 5 More examples 6 Editors and ctl The ctl file The use of Meep revol ves around the control file, abbreviated "ctl" and typically called something like foo.ctl (although you can use any file name you wish). The ctl file specifies the geometry you wish to stud y, the current sources, the outputs computed, and everything else specific to y our calculation. Rather than a flat, inflexible file format, however, the ctl file is actually written in a scripting language. This means that it can b e everything from a simple sequence of commands setting the geometry, etcetera, to a full-fledged program with us er input, loops, and anything else that you might need. Don't worry , though—simple things are simple (you don't need to be a Real Programmer (http://catb.org/esr/jar gon/html/R/Real-Programmer.html) ), and even there you will appreciate the flexibility that a scripting language gives you. (e.g. you can input things in any order, without regard for whites pace, insert comments where you please, omit things when reasonable defaults are available...) The ctl file is actually implemented on top of the libctl library, a set of utilities that are in turn built on top of the Scheme language. Thus, there are three sources of possible commands and syntax for a ctl file: Scheme, a powerful and beautiful programming language developed at MIT , which has a particularly simple syntax: all statements are of the form (function arguments...). We run Scheme under the GNU Guile interpreter (designed to be plugged into programs as a scripting and extension language). Y ou don't
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
his page, we'll go through a couple of simple examples that illustrate the process of
mputing fields, transmission/reflection spectra, and resonant modes in Meep. All of themples here are two-dimensional calculations, simply because they are quicker than 3d
mputations and they illustrate most of the essential features, but of course Meep can doilar calculations in 3d.
s tutorial uses the libctl/Scheme scripting interface to Meep, which is what we expect
st users to employ most of the time. There is also a C++ interface that may give
itional flexibility in some situations; that is described in the C++ tutorial.
rder to convert the HDF5 output files of Meep into images of the fields and so on, this
rial uses our free h5utils programs. (You could also use any other program, such as
3 Transmission spectrum around a waveguide bend4 Modes of a ring resonator
4.1 Exploiting symmetry
5 More examples
6 Editors and ctl
he ctl file
use of Meep revolves around the control file, abbreviated "ctl" and typically called something like foo.ctlhough you can use any file name you wish). The ctl file specifies the geometry you wish to study, the current
rces, the outputs computed, and everything else specific to your calculation. Rather than a flat, inflexible file
mat, however, the ctl file is actually written in a scripting language. This means that it can be everything from a
ple sequence of commands setting the geometry, etcetera, to a full-fledged program with user input, loops, and
thing else that you might need.
n't worry, though—simple things are simple (you don't need to be a Real Programmer
p://catb.org/esr/jargon/html/R/Real-Programmer.html) ), and even there you will appreciate the flexibility that a
pting language gives you. (e.g. you can input things in any order, without regard for whitespace, insert
mments where you please, omit things when reasonable defaults are available...)
ctl file is actually implemented on top of the libctl library, a set of utilities that are in turn built on top of the
eme language. Thus, there are three sources of possible commands and syntax for a ctl file:
Scheme, a powerful and beautiful programming language developed at MIT, which has a particularly simple
syntax: all statements are of the form (function arguments...). We run Scheme under the GNU
Guile interpreter (designed to be plugged into programs as a scripting and extension language). You don't
need to know much Scheme for a basic ctl file, but it is always there if you need it; you can learn more about
it from these Guile and Scheme links.
libctl, a library that we built on top of Guile to simplify communication between Scheme and scientificcomputation software. libctl sets the basic tone of the interface and defines a number of useful functions
(such as multi-variable optimization, numeric integration, and so on). See the libctl manual pages.
Meep itself, which defines all the interface features that are specific to FDTD calculations. This manual is
primarily focused on documenting these features.
his point, please take a moment to leaf through the libctl tutorial to get a feel for the basic style of the interface,
ore we get to the Meep-specific stuff below. (If you've used MPB, all of this stuff should already be familiar,
ough Meep is somewhat more complex because it can perform a wider variety of computations.)
ay, let's continue with our tutorial. The Meep program is normally invoked by running something like the
owing at the Unix command-line (herein denoted by the unix% prompt):
x% meep foo.ctl >& foo.out
ch reads the ctl file foo.ctl and executes it, saving the output to the file foo.out. However, if you invoke
ep with no arguments, you are dropped into an interactive mode in which you can type commands and see their
ults immediately. If you do that now, you can paste in the commands from the tutorial as you follow it and see
at they do.
elds in a waveguide
our first example, let's examine the field pattern excited by a localized CW source in a waveguide— first
ight, then bent. Our waveguide will have (non-dispersive) and width 1. That is, we pick units of
gth so that the width is 1, and define everything in terms of that (see also units in meep).
traight waveguide
ore we define the structure, however, we have to define the computational cell. We're going to put a source at
end and watch it propagate down the waveguide in the x direction, so let's use a cell of length 16 in the x
ction to give it some distance to propagate. In the y direction, we just need enough room so that the boundaries
ow) don't affect the waveguide mode; let's give it a size of 8. We now specify these sizes in our ctl file via theometry-lattice variable:
e name geometry-lattice comes from MPB, where it can be used to define a more general periodicce. Although Meep supports periodic structures, it is less general than MPB in that affine grids are not
ported.) set! is a Scheme command to set the value of an input variable. The last no-size parameter says
the computational cell has no size in the z direction, i.e. it is two-dimensional.
w, we can add the waveguide. Most commonly, the structure is specified by a list of geometric objects, stored
e, we gave the source a frequency of 0.15, and specified a continuous-c which is just a fixed-frequency sinusoid exp( " i#t ) that (by default) is
ed on at t = 0. Recall that, in Meep units, frequency is specified in units of , which is equivalent to the inverse of vacuum wavelength. Thus, 0.15 corresponds to a vacuum wavelength of ut 1 / 0.15 = 6.67, or a wavelength of about 2 in the material—thus, our waveguide is half a
velength wide, which should hopefully make it single-mode. (In fact, the cutoff for single-mode behavior in this
veguide is analytically solvable, and corresponds to a frequency of 1/2 % 11 or roughly 0.15076.) Note also that to
cify a J z, we specify a component Ez (e.g. if we wanted a magnetic current, we would specify Hx, Hy, or Hz).
current is located at ( " 7,0), which is 1 unit to the right of the left edge of the cell—we always want to leave a
e space between sources and the cell boundaries, to keep the boundary conditions from interfering with them.
aking of boundary conditions, we want to add absorbing boundaries around our cell. Absorbing boundaries in
ep are handled by perfectly matched layers (PML)— which aren't really a boundary condition at all, but rather atious absorbing material added around the edges of the cell. To add an absorbing layer of thickness 1 around all
s of the cell, we do:
t! pml-layers (list (make pml (thickness 1.0))))
l-layers is a list of pml objects—you may have more than one pml object if you want PML layers only onain sides of the cell, e.g. (make pml (thickness 1.0) (direction X) (side High)) specifies
ML layer on only the + x side. Now, we note an important point: the PML layer is inside the cell, overlapping
atever objects you have there. So, in this case our PML overlaps our waveguide, which is what we want so that itproperly absorb waveguide modes. The finite thickness of the PML is important to reduce numerical
ections; see perfectly matched layers for more information.
ep will discretize this structure in space and time, and that is specified by a single variable, resolution, that
es the number of pixels per distance unit. We'll set this resolution to 10, which corresponds to around 67
els/wavelength, or around 20 pixels/wavelength in the high-dielectric material. (In general, at least 8
els/wavelength in the highest dielectric is a good idea.) This will give us a cell.
t! resolution 10)
w, we are ready to run the simulation! We do this by calling the run-until function. The first argument ton-until is the time to run for, and the subsequent arguments specify fields to output (or other kinds of
0000.00.h5 and ez-000200.00.h5 (notice that the file names include the time at which they were
put). If we were running a tutorial.ctl file, then the outputs will be tutorial-eps-000000.00.h5tutorial-ez-000200.00.h5. In any case, we can now analyze and visualize these files with a wideety of programs that support the HDF5 format, including our own h5utils, and in particular the h5topnggram to convert them to PNG images.
x% h5topng -S3 eps-000000.00.h5
s will create eps-000000.00.png, where the -S3 increases the image scale by 3 (so that it is around 450
els wide, in this case). In fact, precisely this command is what created the dielectric image above. Much moreresting, however, are the fields:
x% h5topng -S3 -Zc dkbluered -a yarg -A eps-000000.00.h5 ez-000200.00.h5
efly, the -Zc dkbluered makes the color scale go from dark blue (negative) to white (zero) to dark red
sitive), and the -a/-A options overlay the dielectric function as light gray contours. This results in the image:
e, we see that the the source has excited the waveguide mode, but has also excited radiating fields propagating
y from the waveguide. At the boundaries, the field quickly goes to zero due to the PML layers. If we look
efully (click on the image to see a larger view), we see somethinge else—the image is "speckled" towards thet side. This is because, by turning on the current abruptly at t = 0, we have excited high-frequency componentsy high order modes), and we have not waited long enough for them to die away; we'll eliminate these in the
t section by turning on the source more smoothly.
90° bend
w, we'll start a new simulation where we look at the fields in a bent waveguide, and we'll do a couple of other
gs differently as well. If you are running Meep interactively, you will want to get rid of the old structure and
ds so that Meep will re-initialize them:
set-meep)
n let's set up the bent waveguide, in a slightly bigger computational cell, via:
itive y being downwards in h5topng, and thus the block
ize 12&1 is centered at ( " 2, " 3.5). Also shown in green
he source plane at x = " 7 (see below).
also need to shift our source to y = " 3.5 so that it is still
de the waveguide. While we're at it, we'll make a couple
ther changes. First, a point source does not couple veryciently to the waveguide mode, so we'll expand this into a
source the same width as the waveguide by adding a
ze property to the source (a future version of Meep will
w you to use a current with the exact field pattern asmputed by MPB). Second, instead of turning the source on
denly at t = 0 (which excites many other frequenciesause of the discontinuity), we will ramp it on slowly
hnically, Meep uses a tanh turn-on function) over a time
portional to the width of 20 time units (a little over
e periods). Finally, just for variety, we'll specify the
cuum) wavelength instead of the frequency; again,
l use a wavelength such that the waveguide is half a
velength wide.
ally, we'll run the simulation. Instead of running output-efield-z only at the end of the simulation,
wever, we'll run it at every 0.6 time units (about 10 times per period) via (at-every 0.6 output-ield-z). By itself, this would output a separate file for every different output time, but instead we'll use
ther feature of Meep to output to a single three-dimensional HDF5 file, where the third dimension is time:
e, "ez" determines the name of the output file, which will be called ez.h5 if you are running interactively or
be prefixed with the name of the file name for a ctl file (e.g. tutorial-ez.h5 for tutorial.ctl). If weh5ls on this file (a standard utility, included with HDF5, that lists the contents of the HDF5 file), we get:
x% h5ls ez.h5Dataset {161, 161, 330/Inf}
t is, the file contains a single dataset ez that is a 162&162&330 array, where the last dimension is time. (This is
er a large file, 69MB; later, we'll see ways to reduce this size if we only want images.) Now, we have a number
hoices of how to output the fields. To output a single time slice, we can use the same h5topng command as
ore, but with an additional -t option to specify the time index: e.g. h5topng -t 229 will output the last
e slice, similar to before. Instead, let's create an animation of the fields as a function of time. First, we have to
ate images for all of the time slices:
x% h5topng -t 0:329 -R -Zc dkbluered -a yarg -A eps-000000.00.h5 ez.h5
s is similar to the command before, with two new options: -t 0:329 outputs images for all time indices from329, i.e. all of the times, and the the -R flag tells h5topng to use a consistent color scale for every image
tead of scaling each image independently). Then, we have to convert these images into an animation in some
mat. For this, we'll use the free ImageMagick convert program (although there is other software that will do
trick as well).
x% convert ez.t*.png ez.gif
e, we are using an animated GIF format for the output, which is not the most efficient animation format (e.g.mpg, for MPEG format, would be better), but it is unfortunately the only format supported by this Wiki
ware. This results in the following animation :
clear that the transmission around the bend is rather low for this frequency and structure—
h large reflection and large radiation loss are clearly visible. Moreover, since we operating arebarely below the cutoff for single-mode behavior, we are able to excite a second leaky mode
r the waveguide bend, whose second-order mode pattern (superimposed with the fundamental
de) is apparent in the animation. At right, we show a field snapshot from a simulation with a
er cell along the y direction, in which you can see that the second-order leaky mode decays
y, leaving us with the fundamental mode propagating downward.
ead of doing an animation, another interesting possibility is to make an image from ae. Here is the y = " 3.5 slice, which gives us an image of the fields in the first waveguide
nch as a function of time.
x% h5topng -0y -35 -Zc dkbluered ez.h5
e, the -0y -35 specifies the y = " 3.5 slice, where we have multiplied by 10 (our resolution)et the pixel coordinate.
tput tips and tricks
ove, we outputted the full 2d data slice at every 0.6 time units, resulting in a 69MB file. This is not too bad byay's standards, but you can imagine how big the output file would get if we were doing a 3d simulation, or even
rger 2d simulation—one can easily generate gigabytes of files, which is not only wasteful but is also slow.
ead, it is possible to output more efficiently if you know what you want to look at.
create the movie above, all we really need are the images corresponding to each time. Images can be stored
ch more efficiently than raw arrays of numbers—to exploit this fact, Meep allows you to output PNG images
ead of HDF5 files. In particular, instead of output-efield-z as above, we can use (output-png EzZc dkbluered"), where Ez is the component to output and the "-Zc dkbluered" are options for
topng (which is the program that is actually used to create the image files). That is:
n-until 200 (at-every 0.6 (output-png Ez "-Zc bluered")))
output a PNG file file every 0.6 time units, which can then be combined with convert as above to create a
vie. The movie will be similar to the one before, but not identical because of how the color scale is determined.
ore, we used the -R option to make h5topng use a uniform color scale for all images, based on the
imum/maximum field values over all time steps. That is not possible, here, because we output an image beforewing the field values at future time steps. Thus, what output-png does is to set its color scale based on the
imum/maximum field values from all past times—therefore, the color scale will slowly "ramp up" as the source
s on.
above command outputs zillions of .png files, and it is somewhat annoying to have them clutter up our
ctory. Instead, we can use the following command before run-until:
e-output-directory)
s will put all of the output files (.h5, .png, etcetera) into a newly-created subdirectory, called by default
lename -out/ if our ctl file is filename .ctl.
at if we want to output an slice, as above? To do this, we only really wanted the values at y = " 3.5, and
efore we can exploit another powerful Meep output feature—Meep allows us to output only a subset of the
mputational cell. This is done using the in-volume function, which (like at-every and to-appended) is
ther function that modifies the behavior of other output functions. In particular, we can do:
first argument to in-volume is a volume, specified by (volume (center ...) (size ...)),
ch applies to all of the nested output functions. (Note that to-appended, at-every, and in-volume aremulative regardless of what order you put them in.) This creates the output file ez-slice.h5 which contains a
aset of size 162&330 corresponding to the desired slice.
ansmission spectrum around a waveguide bend
ove, we computed the field patterns for light propagating around a waveguide bend. While this is pretty, theults are not quantitatively satisfying. We'd like to know exactly how much power makes it around the bend, how
ch is reflected, and how much is radiated away. How can we do this?
basic principles were described in the Meep introduction; please re-read that section if you have forgotten.ically, we'll tell Meep to keep track of the fields and their Fourier transforms in a certain region, and from this
mpute the flux of electromagnetic energy as a function of #. Moreover, we'll get an entire spectrum of the
smission in a single run, by Fourier-transforming the response to a short pulse. However, in order to normalizetransmission (to get transmission as a fraction of incident power), we'll have to do two runs, one with and one
hout a bend.
s control file will be more complicated than before, so you'll definitely want it as a separate file rather than
ng it interactively. See the bend-flux.ctl file included with Meep in its examples/ directory.
ove, we hard-coded all of the parameters like the cell size, the waveguide width, etcetera. For serious work,
wever, this is inefficient—we often want to explore many different values of such parameters. For example, we
y want to change the size of the cell, so we'll define it as:
fine-param sx 16) ; size of cell in X directionfine-param sy 32) ; size of cell in Y directiont! geometry-lattice (make lattice (size sx sy no-size)))
tice that a semicolon ";" begins a comment, which is ignored by Meep.) define-param is a libctl feature to
ne variables that can be overridden from the command line. We could now do meep sx=17 tut-wvg-nd-trans.ctl to change the X size to 17, without editing the ctl file, for example. We'll also define a couple
arameters to set the width of the waveguide and the "padding" between it and the edge of the computational:
fine-param pad 4) ; padding distance between waveguide and cell edgefine-param w 1) ; width of waveguide
rder to define the waveguide positions, etcetera, we will now have to use arithmetic. For example, the y center
he horizontal waveguide will be given by -0.5 * (sy - w - 2*pad). At least, that is what theression would look like in C; in Scheme, the syntax for 1 + 2 is (+ 1 2), and so on, so we will define the
ical and horizontal waveguide centers as:
fine wvg-ycen (* -0.5 (- sy w (* 2 pad)))) ; y center of horiz. wvgfine wvg-xcen (* 0.5 (- sx w (* 2 pad)))) ; x center of vert. wvg
w, we have to make the geometry, as before. This time, however, we really want two geometries: the bend, and
a straight waveguide for normalization. We could do this with two separate ctl files, but that is annoying.ead, we'll define a parameter no-bend? which is true for the straight-waveguide case and false for the
d.
fine-param no-bend? false) ; if true, have straight waveguide, not bend
w, we define the geometry via two cases, with an if statement—the Scheme syntax is (if predicate? if-ue if-false ).
t automatically. The boundary conditions and resolution are set as before, except that now we'll use set-ram! so that we can override the resolution from the command line.:
ally, we have to specify where we want Meep to compute the flux spectra, and at what frequencies. (This mustdone after specifying the geometry, sources, resolution, etcetera, because all of the field parameters are
alized when flux planes are created.)
fine-param nfreq 100) ; number of frequencies at which to compute fluxfine trans ; transmitted flux
compute the fluxes through a line segment twice the width of the waveguide, located at the beginning or end of
waveguide. (Note that the flux lines are separated by 1 from the boundary of the cell, so that they do not lie
hin the absorbing PML regions.) Again, there are two cases: the transmitted flux is either computed at the right
he bottom of the computational cell, depending on whether the waveguide is straight or bent.
e, the fluxes will be computed for 100 (nfreq) frequencies centered on fcen, from fcen-df/2 to
en+df/2. That is, we only compute fluxes for frequencies within our pulse bandwidth. This is important
ause, to far outside the pulse bandwidth, the spectral power is so low that numerical errors make the computed
es useless.
w, as described in the Meep introduction, computing reflection spectra is a bit tricky because we need to separate
incident and reflected fields. We do this in Meep by saving the Fourier-transformed fields from the
malization run (no-bend?=true), and loading them, negated , before the other runs. The latter subtracts therier-transformed incident fields from the Fourier transforms of the scattered fields; logically, we might subtract
e after the run, but it turns out to be more convenient to subtract the incident fields first and then accumulate the
rier transform. All of this is accomplished with two commands, save-flux (after the normalization run) and
ad-minus-flux (before the other runs). We can call them as follows:
s uses a file called refl-flux.h5, or actually bend-flux-refl-flux.h5 (the ctl file name is used as a
fix) to store/load the Fourier transformed fields in the flux planes. The (run-sources+ 500) runs the
ulation until the Gaussian source has turned off (which is done automatically once it has decayed for a fewdard deviations), plus an additional 500 time units.
y do we keep running after the source has turned off? Because we must give the pulse time to propagatempletely across the cell. Moreover, the time required is a bit tricky to predict when you have complex structures,
ause there might be resonant phenomena that allow the source to bounce around for a long time. Therefore, it is
venient to specify the run time in a different way: instead of using a fixed time, we require that the | E z |2 at the
of the waveguide must have decayed by a given amount (e.g. 1/1000) from its peak value. We can do this via:
at are we plotting here? The transmission is the transmitted flux (second column of bend.dat) divided by the
dent flux (second column of bend0.dat), to give us the fraction of power transmitted. The reflection is the
ected flux (third column of bend.dat) divided by the incident flux (second column of bend0.dat); we alsoe to multiply by " 1 because all fluxes in Meep are computed in the positive-coordinate direction by default, and
want the flux in the " x direction. Finally, the loss is simply 1 - transmission - reflection.
should also check whether our data is converged, by increasing the resolution and cell size and seeing by how
ch the numbers change. In this case, we'll just try doubling the cell size:
ain, we must run both simulations in order to get the normalization right. The results are included in the plot
ve as dotted lines—you can see that the numbers have changed slightly for transmission and loss, probably
mming from interference between light radiated directly from the source and light propagating around the
veguide. To be really confident, we should probably run the simulation again with an even bigger cell, but we'llit enough for this tutorial.
odes of a ring resonator
described in the Meep introduction, another common task for FDTD simulation is to find the resonant modes—
uencies and decay rates—of some electromagnetic cavity structure. (You might want to read that introduction
in to recall the basic computational strategy.) Here, we will show how this works for perhaps the simplest
mple of a dielectric cavity: a ring resonator, which is simply a waveguide bent into a circle. (This can be alsond in the examples/ring.ctl file included with Meep.) In fact, since this structure has cylindrical
mmetry, we can simulate it much more efficiently by using cylindrical coordinates, but for illustration here we'll
use an ordinary 2d simulation.
before, we'll define some parameters to describe the geometry, so that we can easily change the structure:
er objects in the geometry list take precedence over (lie "on top of") earlier objects, so the second air () cylinder cuts a circular hole out of the larger cylinder, leaving a ring of width w.
w, we don't know the frequency of the mode(s) ahead of time, so we'll just hit the structure with a broad
ussian pulse to excite all of the (TM polarized) modes in a chosen bandwidth:
fine-param fcen 0.15) ; pulse center frequencyfine-param df 0.1) ; pulse width (in frequency)t! sources (list
ally, we are ready to run the simulation. The basic idea is to run until the sources are finished, and then to run for
me additional period of time. In that additional period, we'll perform some signal-processing on the fields at soment with harminv to identify the frequencies and decay rates of the modes that were excited:
n-sources+ 300(at-beginning output-epsilon)(after-sources (harminv Ez (vector3 (+ r 0.1)) fcen df)))
signal-processing is performed by the harminv function, which takes four arguments: the field componente Ez) and position (here (r + 0.1,0)) to analyze, and a frequency range given by a center frequency and
dwidth (here, the same as the source pulse). Note that we wrap harminv in (after-sources ...), since
only want to analyze the frequencies in the source-free system (the presence of a source will distort the
lysis). At the end of the run, harminv prints a series of lines (beginning with harminv0:, to make it easy toep for) listing the frequencies it found:
re are six columns (in addition to the label), comma-delimited for easy import into other programs. The
aning of these columns is as follows. Harminv analyzes the fields f (t ) at the given point, and expresses this as a
complex amplitudes an and complex frequencies #n. The six columns relate to these quantities. The first column
he real part of #n, expressed in our usual 2$ c units, and the second column is the imaginary part—a negative
ginary part corresponds to an exponential decay. This decay rate, for a cavity, is more often expressed as a
ensionless "lifetime" Q, defined by:
s the number of optical periods for the energy to decay by exp( " 2$ ), and 1 / Q is the fractional bandwidth at
-maximum of the resonance peak in Fourier domain.) This Q is the third column of the output. The fourth and
h columns are the absolute value | an | and complex amplitudes an. The last column is a crude measure of the
r in the frequency (both real and imaginary)...if the error is much larger than the imaginary part, for example,
n you can't trust the Q to be accurate. Note: this error is only the uncertainty in the signal processing, and tells
nothing about the errors from finite resolution, finite cell size, and so on!
interesting question is how long should we run the simulation, after the sources are turned off, in order to
lyze the frequencies. With traditional Fourier analysis, the time would be proportional to the frequencyolution required, but with harminv the time is much shorter. Here, for example, there are three modes. The last
a Q of 1677, which means that the mode decays for about 2000 periods or about 2000/0.175 = 104 time units.
have only analyzed it for about 300 time units, however, and the estimated uncertainty in the frequency is 10 " 7
h an actual error of about 10 " 6, from below)! In general, you need to increase the run time to get more
uracy, and to find very high Q values, but not by much—in our own work, we have successfully found Q = 109
des by analyzing only 200 periods.
his case, we found three modes in the specified bandwith, at frequencies of 0.118, 0.147, and 0.175, with
esponding Q values of 81, 316, and 1677. (As was shown by Marcatilli in 1969, the Q of a ring resonatoreases exponentially with the product of # and ring radius.) Now, suppose that we want to actually see the field
erns of these modes. No problem: we just re-run the simulation with a narrow-band source around each mode
output the field at the end.
articular, to output the field at the end we might add an (at-end output-efield-z) argument to our
n-sources+ function, but this is problematic: we might be unlucky and output at a time when the E z field is
ost zero (i.e. when all of the energy is in the magnetic field), in which case the picture will be deceptive. Instead,
he end of the run we'll output 20 field snapshots over a whole period 1/fcen by appending the command:
ch of these modes is, of course, doubly-degenerate according to the representations of the symmetry
up. The other mode is simply a slight rotation of this mode to make it odd through the x axis, whereas we
ited only the even modes due to our source symmetry. Equivalently, one can form clockwise and counter-
ckwise propagating modes by taking linear combinations of the even/odd modes, corresponding an angular 'endence for m = 3, 4, and 5 in this case.)
may have noticed, by the way, that when you run with the narrow-bandwidth source, harminv gives you
htly different frequency and Q estimates, with a much smaller error estimate—this is not too strange, since by
iting a single mode you generate a cleaner signal that can be analyzed more accurately. For example, the narrow-
dwidth source for the # = 0.175 mode gives:
ch differs by about 0.000001 (10 " 6) from the earlier estimate; the difference in Q is, of course, larger because a
ll absolute error in # gives a larger relative error in the small imaginary frequency.
ploiting symmetry
his case, because we have a mirror symmetry plane (the x axis) that preserves both the structure and the sources,can exploit this mirror symmetry to speed up the computation. (See also exploiting symmetry in Meep.) Inicular, everything about the input file is the same except that we add a single line, right after we specify the
useful to have emacs use its scheme-mode for editing ctl files, so that hitting tab indents nicely, and so on.acs does this automatically for files ending with ".scm "; to do it for files ending with ".ctl" as well, add the
identally, emacs scripts are written in "elisp," a language closely related to Scheme.)
ou don't use emacs (or derivatives such as Aquamacs), it would be good to find another editor that supports a
eme mode. For example, jEdit (http://www.jedit.org/) is a free/open-source cross-platform editor with Scheme-
tax support. Another option is GNU gedit (http://projects.gnome.org/gedit/) (for GNU/Linux and Unix); in fact,
Hessam Moosavi Mehr has donated a hilighting mode for Meep/MPB (http://github.com/hessammehr/meepmpb-hlight) that specially highlights the Meep/MPB keywords.
rieved from "http://ab-initio.mit.edu/wiki/index.php/Meep_Tutorial"
egories: Meep | Meep examples
This page was last modified 05:19, 29 September 2012.This page has been accessed 294,122 times.Privacy policyAbout AbInitioDisclaimers