File: lossgain_epsilon.tex

package info (click to toggle)
meep 0.10-2.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,380 kB
  • ctags: 5,469
  • sloc: cpp: 50,653; sh: 8,380; haskell: 744; makefile: 367; perl: 10
file content (176 lines) | stat: -rw-r--r-- 5,928 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
\section{Dielectric function of a material with loss and gain}

\begin{comment}
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

#include <meep.hpp>
using namespace meep;

const double a = 10.0;
const int m = 0;
const double eps_value = 2.25;

const double pml_thickness = 1.0;
const double rmax  = 6.0/a;
const double zsize = 2*pml_thickness+10.0/a;
const double zmiddle = zsize/2.0;
const double sourceloc = zmiddle - 4.0/a;

const double r_look = 1.5/a, z_look = zmiddle, d = 1.0/a;

double eps(const vec &) { return eps_value; }
double one_in_middle(const vec &v) {
  const double midmax = r_look+2.0/a;
  const double midwid = 2.0/a;
  if (v.r() <= midmax && v.z() >= zmiddle-midwid && v.z() < zmiddle+midwid) {
    return 1;
  } else {
    return 0;
  }
}

int main(int argc, char **argv) {
  initialize mpi(argc, argv);
  deal_with_ctrl_c();
  const char *dirname = make_output_directory(__FILE__);
  master_printf("Using pml of %g thickness.\n", pml_thickness);
  master_printf("Using an rmax of %g\n", rmax);
  structure s(volcyl(rmax + pml_thickness, zsize, a), eps, pml(pml_thickness));
  s.set_output_directory(dirname);
\end{comment}

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).

\begin{figure}
\label{lossgain_epsilon}
\caption{Dielectric function of a material with loss and gain.}
\includegraphics[width=8.8cm,clip=true]{lossgain_epsilon-out/eps}
\end{figure}

\begin{verbatim}
  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);
\end{verbatim}

\begin{comment}
  fields f(&s, m);
  f.output_hdf5(Dielectric, f.total_volume());
\end{comment}

For sources, we use a series of broad point sources covering the frequency
range of interest.

\begin{verbatim}
  f.add_point_source(Ep, 0.3,  0.8, 0.0, 8.0, veccyl(rmax*0.5,sourceloc));
\end{verbatim}
\begin{comment}
  master_printf("Working with a=%g...\n", a);
  monitor_point *left = NULL, *right = NULL, *middle = NULL,
                *top = NULL, *bottom = NULL;
  double next_printtime = 10;
  while (f.time() < 130 && !interrupt) {
    if (f.time() >= next_printtime) {
      next_printtime += 10;
      master_printf("Working on time %g...  ", f.time());
      master_printf("energy is %g\n", f.field_energy());
    }
    f.step();
\end{comment}

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 $H_z$ field
component.  We choose $m=0$, so we won't have to deal with the $\phi$
derivative.

\begin{verbatim}
    left   = f.get_new_point(veccyl(r_look    , z_look - d), left);
    middle = f.get_new_point(veccyl(r_look    , z_look    ), middle);
    top    = f.get_new_point(veccyl(r_look + d, z_look    ), top);
    bottom = f.get_new_point(veccyl(r_look - d, z_look    ), bottom);
    right  = f.get_new_point(veccyl(r_look    , z_look + d), right);
\end{verbatim}
\begin{comment}
  }

  grace g("eps", dirname);
  complex<double> *al, *ar, *am, *at, *ab, *freqs;
  int numl, numr;
  master_printf("Working on left fourier transform...\n");
  double minfreq = 0.101, maxfreq = 0.5;
  int numfreqs = 300;
\end{comment}

We fourier transform $H_z$ at each point:

\begin{verbatim}
  left->fourier_transform(Hz, &al, &freqs, &numl, minfreq, maxfreq, numfreqs);
\end{verbatim}
\begin{comment}
  delete[] freqs;
  master_printf("Working on middle fourier transform...\n");
  middle->fourier_transform(Hz, &am, &freqs, &numr, minfreq, maxfreq, numfreqs);
  delete[] freqs;
  master_printf("Working on top fourier transform...\n");
  top->fourier_transform(Hz, &at, &freqs, &numr, minfreq, maxfreq, numfreqs);
  delete[] freqs;
  master_printf("Working on bottom fourier transform...\n");
  bottom->fourier_transform(Hz, &ab, &freqs, &numr, minfreq, maxfreq, numfreqs);
  delete[] freqs;
  master_printf("Working on right fourier transform...\n");
  right->fourier_transform(Hz, &ar, &freqs, &numr, minfreq, maxfreq, numfreqs);
  if (numl != numr)
    master_printf("Aaack you need both nums to be the same!\n");
  g.new_set();
  g.set_legend("\\x\\e\\s1\\N");
  complex<double> *epsilon = new complex<double>[numl];
\end{comment}

Finally, we calculate the laplacian of $H_z(\omega)$, which is equal to
$-k^2 H_z(\omega)$, from which we extract epsilon.

\begin{verbatim}
  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);
  }
\end{verbatim}

I've 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~\ref{lossgain_epsilon}.

\begin{comment}
  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]));
  }

  g.new_set();
  g.set_legend("analytic \\x\\e\\s1\\N");
  for (int i=0;i<numl;i++) {
    g.output_point(real(freqs[i]),
                   real(f.analytic_epsilon(real(freqs[i]),veccyl(r_look, z_look))));
  }
  g.new_set();
  g.set_legend("analytic \\x\\e\\s2\\N");
  for (int i=0;i<numl;i++) {
    g.output_point(real(freqs[i]),
                   imag(f.analytic_epsilon(real(freqs[i]),veccyl(r_look, z_look))));
  }
}
\end{comment}