Sunteți pe pagina 1din 39

Meep

MIT Electromagnetic Equation Propogation


David Roundy, Mihai Ibanescu, Peter Bermel March 1, 2005

Contents
1 Discretizing Maxwells equations 1.0.1 Frequency-dependent epsilon . . . . . 1.0.2 Nonlinear dielectrics . . . . . . . . . . 1.0.3 Anisotropic dielectrics . . . . . . . . . 1.0.4 Putting it all together . . . . . . . . . 1.1 The Yee lattice . . . . . . . . . . . . . . . . . 1.2 Maxwells equations in cylindrical coordinates 2 PML 3 Of polaritons and plasmons 4 Hints for writing nite dierence time domain code 5 Tutorial 5.1 A simple 2D system. . . . . . . . . . . . . . . . . . 5.2 A considerably more complicated 2D example. . . 5.3 Babys First Bandstructure . . . . . . . . . . . . . 5.4 Computing the band structure of an omniguide . . 5.5 Band structure of a polariton . . . . . . . . . . . . 5.6 Energy conservation in cylindrical coordinates . . . 5.7 Energy conservation in one dimension . . . . . . . 5.8 Epsilon of a polaritonic material in one dimension 5.9 Dielectric function of a material with loss and gain 5.10 Nonlinear materials . . . . . . . . . . . . . . . . . . A GNU General Public License 5 5 6 6 6 6 7 9 11 13 15 15 17 21 22 24 25 26 28 29 30 33

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

CONTENTS

Chapter 1

Discretizing Maxwells equations


Maxwells equations in the absense of sources are: dH = c E dt dD = c H dt (1.1) (1.2)

If the material is a simple isotropic dielectric, we can simply write D = E and get on with our lives. Alas, all too often this is not the case! We need to be able to deal with anisotropic dielectrics in which is a tensor quantity, nonlinear materials in which is a function of E itself, and polaritonic and polaronic materials in which is a function of frequency.

1.0.1

Frequency-dependent epsilon
D=
E

In the case of a frequency-dependent , we write +P (1.3)

where P is the polarization as a function of time associated with the frequency dependence of . Actually, in general there will be a set of polarizations, and well need a summation here. For simplicity well only describe the case of a single polarization in this section. The time dependence of a single polarization is given by d2 P dP 2 2 + + 0 P = 0 E (1.4) dt2 dt where , 0 and are material parameters. The energy lost due to the absorption by this resonance is simply U = P 5 dE dt (1.5)

CHAPTER 1. DISCRETIZING MAXWELLS EQUATIONS

In fact, if one sets to be negative, we can model gain eectively in this way, and in this case keeping track of the energy allows us to model a situation in which there is a depleteable population inversion which is causing the gainthis is the situation of gain with saturation.

1.0.2

Nonlinear dielectrics

In nonlinear dielectrics D is typically given by a cubic function of E. D= + |E|


2

(1.6)

1.0.3

Anisotropic dielectrics

In anisotropic dielectrics the dielectric constant is a tensor quantity rather than a scalar quantity. In this case we write (FIXME: how to do a tensor in latex?) D = E E = 1 D (1.7) (1.8) (1.9)

1.0.4

Putting it all together


dH = c E dt dE E = + E dt

Putting it all together, we get a simplied time stepping of something like (1.10)
1

c H
i

d Pi dt

(1.11)

d Pi d 2 Pi + i + 0 2 i Pi = 2 dt dt

0 2 iE

(1.12)

1.1

The Yee lattice

In discretizing Maxwells equations, we need to put E and H on a grid. Because we only need to calculate the curl of these quantities, we only need to know them at limited locationsthis gives us the accuracy of a ne grid while only requiring as much data as a grid twice as coarse. This trick is called the Yee lattice. Figure 1.1 shows the Yee lattice in cylindrical coordinates (with z being to the right). The gray squares indicate the locations at which is stored. The Yee lattice has the property that all the derivatives needed for H are known at the Yee lattice points of E. For example, if you look at the H dH dEz r location. dt depends on dE dz and dr . This is great, because Er is known to the right and left of H , and Ez is known above and below H .

1.2. MAXWELLS EQUATIONS IN CYLINDRICAL COORDINATES

Figure 1.1: Yee lattice in cylindrical coordinates.


E
r

Hz E Hr

Hz E Hr

Ez Er Hz E Hr Ez H Er Hz E Hr

Ez H

Ez

The same principle that the Yee lattice does with space, we also do with time. E and H are known at dierent times, so that the time derivative of E is known at a H time and vice versa.

1.2

Maxwells equations in cylindrical coordinates

Here are Maxwells equations in cylindrical coordinates. We take the elds to be of the form: E(r, , z ) = Em (r, z )eim Without further ado: 1 dHr dE im = Ez c dt dz r 1 dH dEz dEr = c dt dr dz 1 dHz im 1 d(rE ) = Er c dt r r dr (1.13) (1.14) (1.15)

CHAPTER 1. DISCRETIZING MAXWELLS EQUATIONS dEr im dH = Hz c dt r dz dE dHr dHz = c dt dz dr dEz 1 d(rH ) im = Hr c dt r dr r (1.16) (1.17) (1.18)

Chapter 2

PML
PML (Perfectly Matched Layers) is used to provide absorbing boundary conditions in either the z or r direction. PML consists of a material in which some of the eld components are split into two elds, each of which has a conductivity associated with it, which is responsible for the absorption of the PML. PML is a sort of material that contains a set of conductivities r , and z . These conductivities are both E and H conductivitiesyes, we have magnetic monopoles moving around in our PML. Each causes absorption of radiation in the direction it is named after. Thus is small, and almost unnecesary, and is only needed because of the curvature of the radial surface. The value of at a given radius is equal to

(r) =

1 r

r (r)dr
0

(2.1)

If we had a IDTD (Innitesimal Dierence Time Domain) code, PML would be perfectly absorbing, regardless of the variation of with position. However, since meep is a lowly FDTD code, we have to make sure that varies only slowly from one grid point to the next. We do this by making z (for example) vary as z 2 , with a maximum value of max right in front of the boundary. At the edge of the PML region is a metalic boundary condition. The optimal value of max is determined by a tradeo between reection o the metallic boundary, caused by too little a max , and reection o the sigma itself, caused by too large a max , which makes for a large variation of from one grid point to the next. 9

10 Here are the eld equations for a PML material: dHr dt dHz dt dHzr dt dEr dt dEz dt dEzr dt im Ez Hr r dEr = c z Hz dz 1 d(rE ) = c r Hzr r dr im = c Hz Er r dHr =c z Ez dz 1 d(rH ) =c r Ezr r dr = c dHrz dt dHr dt dHz dt dErz dt dEr dt dEz dt

CHAPTER 2. PML

dE z Hrz dz dEz =c r Hr dr im = c Er Hz r dH = c z Erz dz dHz = c r Er dr im = c Hr Ez r =c

(2.2) (2.3) (2.4) (2.5) (2.6) (2.7)

Chapter 3

Of polaritons and plasmons


Most real materials, at least in some frequency range, have polarizations that are not actually instantaneously proportional to the local electric eld. We model these polaritonic and plasmonic eects by introducing one or more additional polarization elds, to be propogated along with the electric and magnetic eld. The polarization eld, P, is a vector eld which exists on the electric eld Yee lattice points. The polarization eld obeys a second order dierential equation, which means that we need to keep track of the polarization at two time steps, in order to integrate it. dP d2 P + + 2 P = 2 E dt2 dt To this, we need add one more term to maxwells equation for E: c H =

(3.1)

dE dP + (3.2) dt dt So far, the polarization is beautifully simple. However, we would love to be able to put polaritonic materials into our PML regions, and unfortunately in the PML region the electric eld has been split into two components, so we need P to gure out which of the two components gets the contribution from d dt . The obvious solution to this (well, maybe not exactly obvious, but it is the solution) is to split the polarization eld also into two components in the PML region, just as we split the electric and magnetic elds. The electric eld propogation equations in PML then become: dEr im dPr = c Hz Er dt r dt dEz dHr dPz z Ez =c dt dz dt dEzr 1 d(rH ) dPzr =c r Ezr dt r dr dt 11 (3.3) (3.4) (3.5)

12

CHAPTER 3. OF POLARITONS AND PLASMONS dErz dH dPrz = c z Erz dt dz dt dEr dHz dPr r Er = c dt dr dt dEz im dPz = c Hr Ez dt r dt (3.6) (3.7) (3.8)

Chapter 4

Hints for writing nite dierence time domain code


(Or Things I forgot many times, so I wrote down so maybe I wont make the same mistake again.) There is just one rule to remember when writing time domain code, and that is (as Lefteris has repeatedly told me) Always know when each equation is evaluated. The trick, of course, lies in knowing how to apply this rule, and remembering to actually apply it (and I think the latter is perhaps harder than the former). As an example, Ill convert a PML polariton equation into a nite dierence equation taken from equation 3.8 of chapter 3. im dPz dEz = c Hr Ez dt r dt If we consider the E timesteps to be at times n, n + 1 etc., then this equation needs to be evaluated at time n + 1 2 . This is no problem for most of the terms, but it means that the Ez term needs to be an average of its values at time n and n + 1. In short (taking t to be unity)...
n+1 n (Ez Ez ) = c

im n+ 1 n+1 n+1 n n Hr 2 (Ez + Ez ) (dPz dPz ) r

Simplifying a tad gives


n+1 n Ez Ez =

1 +
1 2

im n+ 1 n+1 n n Hr 2 Ez (dPz dPz ) r

Basically, that is all there is to it. You now have the equation to determine n+ 1 n+1 n+1 n n 2 Ez from Ez , im , dPz and dPz . r Hr

13

14CHAPTER 4. HINTS FOR WRITING FINITE DIFFERENCE TIME DOMAIN CODE

Chapter 5

Tutorial
5.1 A simple 2D system.

This example is intended to let you quickly get started using meep to run a simple calculation. As such, it will include within it the complete code of the example itself. Meep is a C++ library, so your control le is a small C++ program. At the beginning of your control le, you have to include the meep.h header and use the meep namespace... #include <meep.h> using namespace meep; Next we create a function to dene epsilon. This function accepts a vec argument, and returns a double, which is the value of epsilon. For this example, we use an index-guided waveguide with some air slits cut in it. You can choose whatever units you like in which to dene your structure. In this case we choose the width of the waveguide as our unit, which is also equal to 1 micron. const double half_cavity_width = 0.5*0.68, air_slit_width = 0.38, grating_periodicity = 0.48, half_waveguide_width = 1.0, num_air_slits = 15.0, high_dielectric = 12.0, low_dielectric = 11.5; const double pml_thickness = 1.0; const double x_center = 7.7 + pml_thickness; const double y_center = 10.5 + pml_thickness; double eps(const vec &rr) { // Displacement from center of cavity is r: const vec r = rr - vec(x_center, y_center); // First the air slits: double dx = fabs(r.x()) - half_cavity_width; if (dx < num_air_slits*grating_periodicity && dx > 0.0) { 15

16

CHAPTER 5. TUTORIAL

Figure 5.1: Ez

simple-out/ez-000200.00.eps

while (dx > grating_periodicity) dx -= grating_periodicity; if (dx < air_slit_width) return 1.0; } // Now check if the y value is within the waveguide: if (fabs(r.y()) < half_waveguide_width) return high_dielectric; // Otherwise we must be in the surrounding low dielectric: return low_dielectric; } The main function should always start by creating an initialize object. This object is responsible for setting up MPI if we are running on multiple processors, and cleaning up properly when it is deleted (which means we are done). int main(int argc, char *argv[]) { initialize mpi(argc, argv); The s structure denes the contents of the unit cell. It needs a volume, which includes the size of the grid and the resolution, as well as the epsilon function we dened earlier. Here we also choose to use PML absorbing boundary conditions in all directions, since we are interested in the high Q mode in the cavity. const double amicron = 10; // a micron is this many grid points. const volume vol = voltwo(2*x_center, 2*y_center, amicron); const symmetry S = mirror(Y, vol) + rotate2(Y, vol); structure s(vol, eps, pml(pml_thickness), S); To avoid clutter, well create a directory to hold the output. The function make_output_directory creates a directory based on the name of the example

5.2. A CONSIDERABLY MORE COMPLICATED 2D EXAMPLE.

17

program along with an extension. It also backs up the C++ source le if it can nd it. If the directory already exists, then it reuses it, unless the C++ control le has changed, in which case it creates a new one. const char *dirname = make_output_directory(__FILE__); s.set_output_directory(dirname); The structure only holds the epsilon. We will also need a elds object to hold our electric and magnetic elds. We add a point source oriented in the Ez direction, located in the center of our cavity. fields f(&s); const double wavelength = 1.72; const double freq = 1.0/wavelength; f.add_point_source(Hy, freq, 10.0, 0.0, 5.0, vec(x_center,y_center)); Im not interested in seeing the source itself, so Ill keep time stepping until the current time is greater than the last time at which the source is running. while (f.time() < f.last_source_time()) f.step(); Now well wait a bit (to let the low-Q modes die o) and then take a snapshot of the elds in encapsulated postscript format. while (f.time() < 200.0) f.step(); f.eps_slices(); And now were done, although you might wonder if weve done anything worthwhile, since all we got out of this was a picture... All that is left is (as a matter of principle) to delete the string containing the directory name of our output directory. delete[] dirname; }

5.2

A considerably more complicated 2D example.

This example demonstrates a lot more of what you can do using meep. The system is the same as in the previous example, but this time we will calculate the quality factor of the cavity. Again, the entire control le will be included here, but Ill skip over sections that have already been explained. #include <meep.h> using namespace meep; const double half_cavity_width = 0.5*0.68, air_slit_width = 0.38, grating_periodicity = 0.48,

18

CHAPTER 5. TUTORIAL

half_waveguide_width = 1.0, num_air_slits = 15.0, high_dielectric = 12.0, low_dielectric = 11.5; const double pml_thickness = 1.0; const double x_center = 7.7 + pml_thickness; const double y_center = 10.5 + pml_thickness; double eps(const vec &rr) { // Displacement from center of cavity is r: const vec r = rr - vec(x_center, y_center); // First the air slits: double dx = fabs(r.x()) - half_cavity_width; if (dx < num_air_slits*grating_periodicity && dx > 0.0) { while (dx > grating_periodicity) dx -= grating_periodicity; if (dx < air_slit_width) return 1.0; } // Now check if the y value is within the waveguide: if (fabs(r.y()) < half_waveguide_width) return high_dielectric; // Otherwise we must be in the surrounding low dielectric: return low_dielectric; } This time we use the deal_with_ctrl_c(); function. This is a handy utility function that is useful when running your meep code interactively. It traps the SIGINT signal, so when you hit cntl-C, rather than simply exiting, the global variable interrupt is incremented. If you really want to exit, just hit cntl-C again, and when interrupt reaches 2, the program will exit. int main(int argc, char *argv[]) { initialize mpi(argc, argv); deal_with_ctrl_c(); const double amicron = 10; // a micron is this many grid points. const volume vol = voltwo(2*x_center, 2*y_center, amicron); const symmetry S = mirror(Y, vol) + rotate2(Y, vol); structure s(vol, eps, pml(pml_thickness), S); const char *dirname = make_output_directory(__FILE__); s.set_output_directory(dirname); fields f(&s); const double wavelength = 1.72; const double freq = 1.0/wavelength; f.add_point_source(Hy, freq, 5.0, 0.0, 5.0, vec(x_center,y_center)); We add an additional check below && interrupt! so that when the user hits cntl-C we exit the loop. while (f.time() < f.last_source_time() && !interrupt) f.step(); f.eps_slices(); while (f.time() < 400.0 && !interrupt) f.step();

5.2. A CONSIDERABLY MORE COMPLICATED 2D EXAMPLE.

19

This time were going to run the simulation longer, so we would like to get occasional informative messages. To do this we dene a variable to hold the next time we want to print a message. double next_print_time = 500.0; To calculate the Q of our cavity, we use a monitor point p. We also store the value of Hy at our monitor point in a le named hy periodically. We create this le using create_output_file, which creates and opens a le for writing in the given output directory. This utility function works properly whether we are running in parallel or not. monitor_point *p = NULL; file *myout = create_output_file(dirname, "hy"); while (f.time() <= 2000.0 && !interrupt) { // Now well start taking data! f.step(); To get the monitor point data we use the get_new_point method of fields. This ends up creating a linked list containing the values of the eld at the monitor point as a function of time, which we will later use to run harminv and get the Q. p = f.get_new_point(vec(x_center,y_center), p); We use the get_component method to extract the (complex) elds from the monitor point so we can print them. We use the master_fprintf function because we only want to get one copy of the information even if were running in parallel. master_fprintf(myout, "%g\t%g\t%g\n", f.time(), real(p->get_component(Hy)), imag(p->get_component(Hy))); Every time we reach the next_print_time we print out a copy of the slices, along with a little message indicating the time and the total energy (which should be decaying at this point). The function master_printf is a utility function that works basically like printf, except that when running in parallel only one of the processors (the master) does the printing. You should use this function rather than something like if (my_rank()==0) printf(...), since the latter can cause problems if the arguments to printf require synchronization between the processes. if (f.time() >= next_print_time) { f.eps_slices(); master_printf("Energy is %g at time %g\n", f.total_energy(), f.time()); next_print_time += 500.0; } }

20

CHAPTER 5. TUTORIAL

Figure 5.2: Contents of freqs le 0.651297 7.25518e-07 -897700 -0.0913686 0.593691 0.660777 0.000187637 -3521.57 -2.17573e-05 0.000139436 0.660787 -0.00044706 1478.07 -0.000271147 0.0018975

Files which are opened with create_output_file need to be closed with everyone_close, which does the Right Thing when running in parallel. everyone_close(myout); Having collected all the monitor point data, we now want to run harminv1 on it to nd the Q of our resonant cavity. The harminv method gives us the complex amplitudes, the frequencies and the decay rates. The decay rate is given in the same units as the frequency, so you could choose to view it as the imaginary part of the frequency if you like. This harminv step is the real reason for using the ctrl-C trick, since if while running this example we get impatient and decide we have enough data we can just hit ctrl-C and get the results using what data we have. This means you can just set the code to run for an excessively long time without risking losing everything if you lose patience. In case youre wondering about the \begin{verbatim}, its there so I can easily include the output in this manual (see Figure 1). complex<double> *amp, *freqs; int num; file *myfreqs = create_output_file(dirname, "freqs"); master_fprintf(myfreqs, "\\begin{verbatim}\n"); master_printf("Harminving Hy...\n"); interrupt = 0; // Harminv even if we were interrupted. p->harminv(Hy, &amp, &freqs, &num, 0.8*freq, 1.2*freq, 5); for (int i=0;i<num;i++) { master_fprintf(myfreqs, "%g\t%g\t%g\t%g\t%g\n", real(freqs[i]), imag(freqs[i]), -real(freqs[i])/imag(freqs[i]), real(amp[i]), imag(amp[i])); } master_fprintf(myfreqs, "%cend{verbatim}\n", \\); everyone_close(myfreqs); delete[] dirname; }
1 If you dont know what harminv is, Im not going to explain it here, so you may as well ask me in person (or even better, ask Steven...

5.3. BABYS FIRST BANDSTRUCTURE

21

5.3

Babys First Bandstructure

In this example we calculate the lowest four TE modes of a simple hollow metallic waveguide of radius one. int main(int argc, char *argv[]) { initialize mpi(argc, argv); file *ban = everyone_open_write("bands"); structure s(volcyl(1.0, 0.0, rad), eps); for (int m=0;m<3;m++) { for (double k=0.0; k<= 1.01; k += 0.25) { master_printf("Working on k of %g and m = %d with a=%d...\n", k, m, rad); fields f(&s, m); f.use_bloch(k); There are a few tricks you should know before you decide to go about calculating a band structure. One of the biggest problems in calculating a band structure in a time domain code is that of exciting all the modes you are interested in. Meep makes this easy with a couple of elds methods, initialize_with_n_te, and initialize_with_n_tm. These initialize the eld with the n lowest TE and TM modes respectively. f.initialize_with_n_te(4); The band structure code itself begins with a call to prepare_for_bands, which allocates space to store the eld data, which is later used for the band structure calculation. Its third argument is the maximum frequency you are interested in. double fmax = 1.0, qmin = 200; f.prepare_for_bands(0, ttot, fmax, qmin); for (int t=0;t<ttot;t++) { The second band structure function is record_bands, which just copies the elds into the already allocated arrays for future use. f.record_bands(); f.step(); } Finally, the band structure is actually computed and output by the method output_bands. The key thing to know about output_bands is that its last argument should be something like twice the number of modes which have a frequency below your maximum. Rounding this number up slows the code down considerably, but can sometimes x problems where harminv (which is used internally) doesnt nd the modes correctly. Usually, however, when harminv fails it means you are misunderstanding something (for example, fmax may be less than the lowest frequency mode).

22 f.output_bands(ban, "band", 35); } } everyone_close(ban); }

CHAPTER 5. TUTORIAL

5.4

Computing the band structure of an omniguide

In this section we give as an example of a more complicated band structure, a computation of the band structure of an omniguide. The output of this program is shown in Figure 5.4. const int num_layers = 3; const double rcore = 3.0; double guided_eps(const vec &v) { double rr = v.r() - rcore; if (rr > num_layers + 0.3) return 1.0; // outside the entire waveguide if (rr < 0.0) return 1.0; // vacuum in the core while (rr > 1.0) rr -= 1.0; // calculate (r - rcore) % 1 if (rr < 0.3) return 21.16; // in the high dielectric return 1.6*1.6; // in the low dielectric } double vacuum_eps(const vec &v) { return 1.0; } For this band structure example, we use the grace object to create our plot. grace g("bands", dirname); g.set_range(0.0, 0.35, 0.0, 0.35); Since the m = 0 modes are pure TE or TM, it makes sense to calculate the two polarizations separately. Not only does this give us more interesting output, but it doesnt cost us any time, to speak of, and actually makes the band structure much easier to converge. However, for brevity, I wont include here in the manual computation of the TM modes, but will skip straight to the TE modes. for (int m=0;m<2 && !interrupt;m++) { g.new_set(); char m_string[30]; if (m) snprintf(m_string, 30, "m = %d", m); else snprintf(m_string, 30, "m = 0, TE"); g.set_legend(m_string); for (double k=0.0;k<0.351 && !interrupt;k+=0.05) {

5.4. COMPUTING THE BAND STRUCTURE OF AN OMNIGUIDE

23

Figure 5.3: Omniguide band structure.


0.4 m = 0, TM m = 0, TE m=1 0.3

0.2

0.1

0.1

0.2

0.3

0.4

In order to populate the modes that we are interested in, we rst populate the modes of an empty waveguide (whose modes are known), and then adiabatically transform from that waveguide into our omniguide structure. printf("Working on k of %g and %s with a=%d...\n", k, m_string, a); fields f(&vac, m); f.use_bloch(k); f.verbose(1); f.phase_in_material(&s, 1000); We initialize the elds with both TE and TM modes, and then phase in the epsilon as usual, and then do the actual phasing in of the structure. f.initialize_with_n_te(9); if (m) f.initialize_with_n_tm(9); while (f.is_phasing() && !interrupt) f.step(); Again, the band structure code is pretty normal, with the only real dierence being that in this case we really want to have specify a large Qmin , to help meep to distinguish between real modes and spurious noise. Note that we are using metallic boundary conditions, so all physical modes should have innite lifetime. f.prepare_for_bands(veccyl(4.801,0.0), ttot, .35, 300, 0.0); f.prepare_for_bands(veccyl(1.801,0.0), ttot, .35, 300, 0.0); f.prepare_for_bands(veccyl(2.801,0.0), ttot, .35, 300, 0.0); const double stoptime = f.time() + ttot; while (f.time() < stoptime && !interrupt) {

24

CHAPTER 5. TUTORIAL

Figure 5.4: Polariton band structure.


0.8

0.6

0.4

0.2

f.record_bands(); f.step(); } Finally, we just need to compute and output the bands. We are careful here to keep in mind that when m > 0, there are twice as many bands, since there are both TM and TE modes. f.grace_bands(&g, m?80:40); } The band is actually printed to disk only when the grace object is destroyed, which in this case happens just before the program exits.

5.5

Band structure of a polariton

Here we compute and plot the band structure of a polariton material. We look at a simple metallic waveguide lled with a polaritonic material. The material we look at has an epsilon of 13.4 and a longitudinal phonon frequency of 0.7 and a transverse phonon frequency of 0.4. double eps(const vec &) { return 13.4; } double one(const vec &) { return 1; } To create the polaritonic material, we add the polarizability to the material after we have created it.

5.6. ENERGY CONSERVATION IN CYLINDRICAL COORDINATES double freq = 0.4, gamma = 0.01, delta_eps = 27.63; s.add_polarizability(one, freq, gamma, delta_eps); for (k=0.0;k<4.01 && !interrupt;k+=.5) { master_printf("Working on k of %g and m = %d...\n", k, m); fields f(&s, m); f.use_bloch(k);

25

Now we excite the rst TE mode (we are only looking at m = 0 here), and remember to excite along with it the phonon with which it couples. f.initialize_with_nth_te(1); f.initialize_polarizations(); Finally, we compute the band structure as usual. f.prepare_for_bands(veccyl(0.501,0.0), ttot, .7+.15*k/3.0, 50, 1e-4); f.prepare_for_bands(veccyl(0.301,0.0), ttot, .7+.15*k/3.0, 50, 1e-4); while (f.time() < ttot && !interrupt) { f.record_bands(); f.step(); } f.grace_bands(&g, 16); The nal output of this routine (as calculated using the plot program) is shown in Figure 5.5.

5.6

Energy conservation in cylindrical coordinates

In this example, we compute the total energy over time for a polaritonic material in cylindrical coordinates. Eventually I gure I may extend this example to demonstrate energy/ux conservation using PML. That would denitely be more impressive. For our example polaritonic material, well use an (0) of 13.4. We will put the polaritons in just one quarter of our system to add a little extra excitement. double eps(const vec &) { return 13.4; } double one(const vec &p) { return (p.z() > 15.0)?1:0; } We use a long and skinny system so as to exaggerate any errors that may crop up at small r. structure s(volcyl(1.0,20.0, a), eps); We use several point sources, to cover a broad frequency range, just for the heck of it.

26

CHAPTER 5. TUTORIAL

Figure 5.5: Energy vs. Time.


30

25

20

15

10

100

200

300

400

500

600

f.add_point_source(Ep, 0.6 , 1.8, 0.0, 8.0, veccyl(0.5,2.0)); f.add_point_source(Ep, 0.4 , 1.8, 0.0, 8.0, veccyl(0.5,2.0)); f.add_point_source(Ep, 0.33, 1.8, 0.0, 8.0, veccyl(0.5,2.0)); We plot the total energy, the electromagnetic energy and the thermodynamic energy which is the energy that is either stored in the polarization, or has been converted into heat, or (if we had a saturating gain system) perhaps is stored in a population inversion. g.output_out_of_order(0, f.time(), f.total_energy()); g.output_out_of_order(1, f.time(), f.field_energy_in_box(f.v.surroundings())); g.output_out_of_order(2, f.time(), f.thermo_energy_in_box(f.v.surroundings()));

5.7

Energy conservation in one dimension

In this example, we compute the total energy over time for a polaritonic material in one dimension to verify that it is indeed conserved. This also demonstrates how to use a 1D system. For our example polaritonic material, well use an (0) of 13.4. We will put the polaritons in just one quarter of our system to add a little extra excitement. double eps(const vec &) { return 13.4; } double one(const vec &p) { return (p.z() > 15.0)?1:0; } We create a 1D system by making the volume with the volone function, and making sure any vecs we use are one dimensional. structure s(volone(20.0, a), eps);

5.7. ENERGY CONSERVATION IN ONE DIMENSION

27

Figure 5.6: Energy vs. Time.


2

1.5

0.5

100

200

300

400

500

600

The polarizability is added as usual... in this case we use a very sharp resonance, which means that our energy will only be very slowly absorbed. s.add_polarizability(one, 0.25, 0.0001, 3.0); fields f(&s); grace g("energy", dirname); We use several point sources, to cover a broad frequency range, just for the heck of it. f.add_point_source(Ex, 0.6 , 1.8, 0.0, 8.0, vec(2.0)); f.add_point_source(Ex, 0.4 , 1.8, 0.0, 8.0, vec(2.0)); f.add_point_source(Ex, 0.33, 1.8, 0.0, 8.0, vec(2.0)); We plot the total energy, the electromagnetic energy and the thermodynamic energy which is the energy that is either stored in the polarization, or has been converted into heat, or (if we had a saturating gain system) perhaps is stored in a population inversion. g.output_out_of_order(0, f.time(), f.total_energy() - ezero); g.output_out_of_order(1, f.time(), f.electric_energy_in_box(f.v.surroundings()) + f.magnetic_energy_in_box(f.v.surroundings())); g.output_out_of_order(2, f.time(), f.thermo_energy_in_box(f.v.surroundings()) - ezero);

28

CHAPTER 5. TUTORIAL

Figure 5.7: Epsilon of a polaritonic material.


2000 1 2 analytic 1 analytic 2

1500

1000

500

-500 0.3 0.35 0.4 0.45 0.5

5.8

Epsilon of a polaritonic material in one dimension

In this example, we compute epsilon as a function of frequency for a simple polaritonic material. This example is done in one dimension for speed purposes. One thing to be aware of when using polaritonic materials, is that generally you will be needing a rather higher grid resolution than you may be used to in order to properly model the material. Here I am using an a of 40. Altough in this calculation the polaritonic material will not be within the PML, it is all right to have polaritonic material within PML regions. s.add_polarizability(one, 0.4, 0.01, 27.63); We use a single rather high frequency (and very broad) point source, to cover a broad frequency range. f.add_point_source(Ex, 0.9, 0.8, 0.0, 8.0, vec(sourceloc)); We use a couple of monitor points to determine epsilon. monitor_point *left = NULL, *right = NULL, *middle = NULL; The monitor points are located one grid spacing from one another. The get_new_point method appends the elds at a given time to a monitor point linked list. left = f.get_new_point(vec(sourceloc+1.0/a), left ); middle = f.get_new_point(vec(sourceloc+2.0/a), middle); right = f.get_new_point(vec(sourceloc+3.0/a), right); When the time stepping is over, we take a fourier transform of the elds at the two monitor points.

5.9. DIELECTRIC FUNCTION OF A MATERIAL WITH LOSS AND GAIN29

Figure 5.8: Dielectric function of a material with loss and gain.


3 1 2 analytic 1 analytic 2

-1

-2 0.1

0.2

0.3

0.4

0.5

left->fourier_transform(Ex, &al, &freqs, &numl, 0.301, 0.5, 300); Finally we calculate epsilon from the second derivative of the eld using k 2 Hz ( ) = 2 Hz ( ) = 2 complex<double> *epsilon = new complex<double>[numl]; for (int i=0;i<numl;i++) { complex<double> ksqr = -(ar[i]+al[i]-2.0*am[i])*a*a/am[i]; epsilon[i] = ksqr/freqs[i]/freqs[i]/(2*pi*2*pi); } for (int i=0;i<numl;i++) g.output_point(real(freqs[i]), real(epsilon[i])); g.new_set(); g.set_legend("\\x\\e\\s2\\N"); for (int i=0;i<numl;i++) g.output_point(real(freqs[i]), imag(epsilon[i]));

5.9

Dielectric function of a material with loss and gain

In this section, we demonstrate a better way to calculate the dielectric function, and illustrate it by computing the dielectric function of a material with a normal lossy resonance as well as a gain line. Gain in the PML is a bad idea, so we restrict the polarizabilities to exist only in the middle of the system (which is surrounded by PML). s.add_polarizability(one_in_middle, 0.195, 0.03, 0.25*.25/.195); s.add_polarizability(one_in_middle, 0.25, 0.03,-0.25);

30

CHAPTER 5. TUTORIAL

For sources, we use a series of broad point sources covering the frequency range of interest. f.add_point_source(Ep, 0.3, 0.8, 0.0, 8.0, veccyl(rmax*0.5,sourceloc));

The calculation proceeds as usual, except that we now keep track of a set of monitor points that will allow us to take a laplacian of the Hz eld component. We choose m = 0, so we wont have to deal with the derivative. left middle top bottom right = = = = = f.get_new_point(veccyl(r_look , z_look - d), f.get_new_point(veccyl(r_look , z_look ), f.get_new_point(veccyl(r_look + d, z_look ), f.get_new_point(veccyl(r_look - d, z_look ), f.get_new_point(veccyl(r_look , z_look + d), left); middle); top); bottom); right);

We fourier transform Hz at each point: left->fourier_transform(Hz, &al, &freqs, &numl, minfreq, maxfreq, numfreqs); Finally, we calculate the laplacian of Hz ( ), which is equal to k 2 Hz ( ), from which we extract epsilon. for (int i=0;i<numl;i++) { complex<double> ksqr = -(ar[i]+al[i]-2.0*am[i] + at[i]*0.5*(1+(r_look+d)/r_look) + ab[i]*0.5*(1+(r_look-d)/r_look) - 2.0*am[i] - m*m*1.0*am[i]/r_look/r_look*a*a )*a*a/am[i]; epsilon[i] = ksqr/freqs[i]/freqs[i]/(2*pi*2*pi); } Ive left out the bulk of this example from the manual itself, since it is pretty much the same as the previous examples. Among other features, we use the grace functions to plot the result, which can be seen in Figure 5.9.

5.10

Nonlinear materials

FIXME: Add a nice discussion of nonlinear materials here... In this example, we will use a CW source and compute the amplitude of the eld at a given position and time as a function of the source amplitude. The result will be linear as long as the material remains in the linear regime. Once we have departed from the linear regime, we get more complicated behavior. Yes, this is a stupid example... The system is shown in Figure 5.10. It is a 2D metallic waveguide with vacuum of 2.25. In the center of the cell is a small region that is linear which contains the source, and the rest of the waveguide contains a nonlinear material. Both ends of the waveguide have PML absorbing boundary conditions.

5.10. NONLINEAR MATERIALS

31

Figure 5.9: Field vs. source amplitude with nonlinear material


nonlinear-out/ez-000400.00.eps

Figure 5.10: Field vs. source amplitude with nonlinear material


4

-1

-2

0.2

0.4

0.6

0.8

const double alpha_value = 0.07; double alpha(const vec &v) { if (fabs(v.x() - xmax/2.0) < .51) return 0.0; return alpha_value; } The set kerr method is used to set the kerr coecient. s.set_kerr(alpha); We use a CW source at a frequency of 0.4, which gives single-mode behavior when the amplitude is small. Also note that we use real elds, since complex elds are incorrect for nonlinear materials. continuous_src_time my_source(0.4, 0.8); for (double amp = 0.05; amp <= 1.01 && !interrupt; amp += 0.01) { fields f(&s, m); f.use_real_fields(); f.add_point_source(Ez, my_source, vec(xmax*0.5,ymax*0.5), amp); Time stepping, etc, is done as usual. We monitor the eld at one end of the cell, which gives Figure 5.10, which show the eld versus source amplitude.

32

CHAPTER 5. TUTORIAL

Appendix A

GNU General Public License


Version 2, June 1991
Copyright c 1989, 1991 Free Software Foundation, Inc. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

Preamble
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free softwareto make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundations software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. 33

34

APPENDIX A. GNU GENERAL PUBLIC LICENSE

For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) oer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each authors protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modied by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reect on the original authors reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in eect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyones free use or not licensed at all. The precise terms and conditions for copying, distribution and modication follow.

GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The Program, below, refers to any such program or work, and a work based on the Program means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modications and/or translated into another language. (Hereinafter, translation is included without limitation in the term modication.) Each licensee is addressed as you. Activities other than copying, distribution and modication are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Programs source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this

35 License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option oer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modications or work under the terms of Section 1 above, provided that you also meet all of these conditions: (a) You must cause the modied les to carry prominent notices stating that you changed the les and the date of any change. (b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. (c) If the modied program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modied work as a whole. If identiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.

36

APPENDIX A. GNU GENERAL PUBLIC LICENSE 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: (a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, (b) Accompany it with a written oer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, (c) Accompany it with the information you received as to the oer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an oer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface denition les, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by oering access to copy from a designated place, then oering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law

37 if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.

38

APPENDIX A. GNU GENERAL PUBLIC LICENSE 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may dier in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program species a version number of this License which applies to it and any later version, you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.

10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are dierent, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.

NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER

39 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

END OF TERMS AND CONDITIONS

S-ar putea să vă placă și