Monday, April 13, 2015

Tutorial - Making a dielectric function with MPB

Tutorial
Tutorial - Making a dielectric function using Matlab
Tutorial - Making a dielectric function using MPB
Tutorial - Visualizing dielectric functions
Tutorial - Placing and configuring the dipoles
Tutorial - Selecting the time steps
Tutorial - Reading the results

What is MPB?
MPB stand for the MIT Photonic Bands Package, an excellent software package for the calculation of photonic bands developed by Steven G. Johnson. The latest version, 1.5, was released in April 2014 by the Joannopoulos Ab Initio Physics group. Certainly, their own thorough manual and tutorial on the MIT Photonic-Bands webpage is the best guide for understanding how to use their software. However, since in this case we will be using their software simply for the generation of a dielectric function (in a different manner than typically used by MPB users), it makes sense to cover the basics here. This tutorial is adapted from another similar tutorial I wrote for using MPB, which is included as an appendix.

You should have installed MPB by following the installation instructions on their webpage, or by simply searching for MPB in the Linux software repository. You may want to consider installing the parallelized version of the software mpb-mpi along with the serial version to take advantage of your computer's multiple cores.

The most straightforward way to run MPB is in connection with a control file, which we will call example.ctl for this tutorial. In that case, MPB is executed from the terminal by entering "mpb example.ctl" from the directory containing the control file. For example, if you keep your control files in a folder called "ctl" inside another folder called "mpb" in your home directory:

user@photonics-machine:~/mpb/ctl/mpb example.ctl

Or, if executing over 10 processors with MPI:

user@photonics-machine:~/mpb/ctl/mpirun -np 10 mpb-mpi example.ctl

The best way to understand how to use a control file to generate a dielectric function is to look at an example, and go over each part line by line.



;Example ctl file for FPS tutorial
;a silica micro-lens on a GaAs substrate
;let the optical radius of curvature equal 1

Everything following a semicolon is ignored by the program, so that notes such as these can be made in the file. It is important to pick a feature of your structure and use it as an internal unit or reference. In case of crystalline structures the most natural thing would be the lattice constant, here we use the radius of the sphere.

(set! geometry-lattice (make lattice
(basis-size 8 8 4)
(basis1 1 0 0)
(basis2 0 1 0)
(basis3 0 0 1)
))

First, regarding the (set! ...). These ctl files are written in Scheme syntax. A function or command is called in parenthesis, followed by what is passed on to that function. Here, the function set! is called and passed the parameter to be set, geometry-lattice, followed by what parameter geometry-lattice should be set to (make lattice …). (set! ...) is used whenever an important system parameter should be specified.

(set! geometry-lattice (make lattice
(basis-size 8 8 4)
(basis1 1 0 0)
(basis2 0 1 0)
(basis3 0 0 1)
))

Normally, MPB is used to define crystal structures so the lattice type is typically very important. Here, we want to essentially make a supercell and fill it with the structure we need so the main requirements are that the basis is the right size and the space is Cartesian. The radius of the sphere, r, was defined to be 1, and as an example the size of the basis (which is the size of the calculation domain) was chosen to be 8x8x4. In the end, we want a rectangular calculation domain so basis vectors pointing in the Cartesian directions are chosen.

(define-param r 1); the radius of curvature
(define-param thickness 2); the thickness of the substrate
(define-param n1 1.45); the refractive index of the microlens, silica
(define-param n2 3.54); the refractive index of GaAs

It is smart to define the parameters that are used, and then use their names later in the control file. By doing this if something is changed, like the refractive index of the structure, it only needs to be changed in one place. Also, it is more clear later in the file if named parameters are used rather than numbers.

(define silica (make dielectric (epsilon (* n1 n1)))); silica
(define GaAs (make dielectric (epsilon (* n2 n2)))); GaAs

Here, we use (define... ) because we are not really defining a parameter, and not setting an important system-made parameter, but making a material type. See the use of (make... ) which has shown up before. We can (make lattice (...) (...)) or (make dialectric (...) (...)), or make geometric objects (see the MPB manual for all the things you can make). It is very intuitive.

Note the use of math in Scheme. It is always inside parenthesis: the operator followed by the operands. (- 3 1) = 2, (* 3 1) = 3, (/ 1 (* 2 (sqrt 2))) = 1/[2*sqrt(2)]

;If you don't have a cubic box, you should scale the resolution
;so that each dimension is discretized into equal sized pieces
(set-param! resolution (vector3 256 256 128))

We want the distance between each grid point to correspond to the same physical distance in all directions. Since the z-scale of the box is half the size of the x and y dimensions, the z grid resolution should be half. Note the use of the (vector3 ...) data-type.

;The geometry is written so that what ever is
;subsequent in the list writes over what was before
(set! geometry (list
(make block (center 0 0 0) (size 8 8 4) (material air))
(make sphere (center 0 0 0) (radius r) (material silica))
(make block (center 0 0 -0.25) (size 8 8 thickness) (material GaAs))
))

The geometry inside the calculation domain is written by making sequentially a list of geometric objects. Whatever is written second is written on top of what was earlier in the list. What is wanted is a hemispherical silica lens on top of a GaAs substrate.

First, we fill the domain with air. Second, we write a sphere with the desired radius right at the center of the domain. Finally, we write the substrate which has a thickness equal to half the domain and centered one fourth of the domain down. It is important to remember:
  1. When it comes to locating the center of an object, the units are "percent of the size of the whole domain." For example, the point (0, 0, 0.6) would lay just outside the domain because z spans from -50% to +50%.
  2. When it comes to the size of objects, the units are whatever you defined (up to the size of the lattice). For example, if (basis-size 4 4 4), then a block could have the dimensions (size 2 2 2) and fit easily.
  3. If anything spills over the edge of the domain, it is written through onto the other side. For example, the point (0, 0, 0.6) would be written at (0, 0, 0.1)... which, if (basis-size 4 4 4) in units of r, corresponds (0, 0, 0.4r).
(run)

This final command tells MPB that we are done passing instructions on to it, and it should do it's job.

user@photonics-machine:~/mpb/ctl/mpb example.ctl

Executing the program with the ctl file above results in a file called "epsilon.h5" being placed in the same folder as the ctl file. This file, epsilon.h5, can be read by FPS. It is helpful to look at the file directly using HDF5 viewer, or converting it to vtk format for viewing with software such as Mayavi2. To convert, use the h5tovtk tool that comes with MPB.

user@photonics-machine:~/mpb/ctl/h5tovtk epsilon.h5



See an example here of visualizing a dielectric function.

No comments:

Post a Comment