File: simplebands.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 (85 lines) | stat: -rw-r--r-- 2,621 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
\begin{comment}
/*
\end{comment}
\section{Baby's First Bandstructure}
\begin{comment}
*/
\end{comment}

\begin{comment}
#include <stdio.h>
#include <stdlib.h>
#include <meep.hpp>
using namespace meep;

double eps(const vec &) {
  return 1.0;
}
const int rad = 10;
const int ttot = 1500*rad;
\end{comment}

In this example we calculate the lowest four TE modes of a simple hollow
metallic waveguide of radius one.

\begin{verbatim}
int main(int argc, char *argv[]) {
  initialize mpi(argc, argv);
  FILE *ban = master_fopen("bands", "w");
  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);
\end{verbatim}

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 ``fields''
methods, \verb-initialize_with_n_te-, and \verb-initialize_with_n_tm-.
These initialize the field with the n lowest TE and TM modes respectively.

\begin{verbatim}
      f.initialize_with_n_te(4);
\end{verbatim}

The band structure code itself begins with a call to
\verb-prepare_for_bands-, which allocates space to store the field
data, which is later used for the band structure calculation.  Its third
argument is the maximum frequency you are interested in.

\begin{verbatim}
      double fmax = 1.0, qmin = 200;
      f.prepare_for_bands(0, ttot, fmax, qmin);
      for (int t=0;t<ttot;t++) {
\end{verbatim}

The second band structure function is \verb-record_bands-, which just
copies the fields into the already allocated arrays for future use.

\begin{verbatim}
        f.record_bands();
        f.step();
      }
\end{verbatim}

Finally, the band structure is actually computed and output by the method
\verb-output_bands-.  The key thing to know about
\verb-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
fix problems where harminv (which is used internally) doesn't find 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).

\begin{verbatim}
      f.output_bands(ban, "band", 35);
    }
  }
  master_fclose(ban);
}
\end{verbatim}