Creating different structures in MEEP FDTD

code.pyMEEP allows to create structures out of primitive objects viz sphere,cylinder cone, block and ellipsoid.  It is impossible to create hexagon shape with the direct use of primitive shapes. But if we cut a block with non-orthogonal planes we will get a triangle 1 . Now since we can make triangular shapes, how can we get other shapes? A very nice post to create arbitrary shapes is written by Mr. Bala1. As a beginner, I couldn't understand certain things in his post. In this post, I am going to explain how to create polygon in MEEP 2D out of primitive objects. I am using the method described in that post1 .  I have also written a python script, in which you just feed in the coordinates and it will return you a meep code describing the structure. As an example, I'll make a hexagon shape in MEEP.

Delaunay Triangulation

In simple words, Delaunay triangulation is triangulation of set of points(that make the polygon).

With the help of Delaunay triangulation, we can deconstruct a polygon into a set of triangles.
Once we construct these triangles, we would get our structure 🙂
Step 1: Finding the triangles

Use delaunay triangulation to convert your polygon into set of triangles.

Triangulation of the points


Step 2: Once you have found the triangles insert the properties of all the triangles in your meep code and execute to get your desired structure. 

Hexagonal structure, generated in MEEP
Hexagonal structure, generated in MEEP

Python Script:

I have written the following python script for convenience. Write down the points of your polygonal structure. It will return you MEEP code of the desired structure in a separate file name "coordinates". Install triangle package 3,4 before you run the code. Enjoy 🙂
You can also download the script , .

import triangle
import triangle.plot
import numpy as np
import matplotlib.pyplot as plt
#define the points of the polygon
A = dict(vertices=np.array(((-5,4), (-11,0), (-5,-4), (5,4),(11,0),(5,-4))))
B = triangle.triangulate(A)
#plot the figure, A, B)
a=B['vertices'] #vertices
b=B['triangles'] # getting the indices of vertices
n=len(b) #no. of triangles
#declaring the constants
e=12 #epsilon
z=-5.0 #point in another plane
f = open('coordinates', 'w') #file to write meep code
f.write("(set! geometry (list \n") #first line in meep to create geometrical objects
for i in range(0, n):
   print "vertices of %d th triangle" %(i+1)   
   for j in range(0,3):
     print "x coordinate is" + str(a[b[i][j]][0])+ " y coordinate is " + str (a[b[i][j]][1])
   #defining the centers    
   #direction vectors
   #magnitude of direction vectors
   f.write("(make block (center " +str(xc) +" " +str(yc) +" " +str((-z/2)) +") (material ( make        dielectric (epsilon " + str(e)+ " ))) (size  (sqrt "+str(s1)+") (sqrt "+str(s2)+ ") (sqrt  "+str(s3)+")  ) (e1 " +str(e1x)+" "+ str(e1y)+" " +str(-z)+ " ) (e2" +str(e2x)+" "+ str(e2y)+" "    +str(-z)+ ") (e3 "+str(e3x)+" "+ str(e3y)+" " +str(-z)+ ") ) \n")     
f.write(" ))")



2 thoughts on “Creating different structures in MEEP FDTD

  1. When someone writes an post he/she retains the plan of a user in his/her brain that how a user can be aware of it.
    So that's why this post is amazing. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *