Bala's Website Bala's Website
Arbitrary 2d shapes in MEEP

In MEEP (1.1.1), dielectric structures are often created by constructive geometry (adding and subtracting primitive shapes). The primitive shapes that are allowed are blocks, cylinders, ellipsoids and cones. To create a complex shape, one has to decompose the geometry into these primitive shapes. Over the weekend, I was wondering if it was possible to somehow create any complex shape in 2d without figuring out the exact positions and operations with the available primitive shapes. Here I report how I solve this problem.

The first thing I figured out was to create a 2d triangle with known vertices using a certain primitive shape. One can cut a cone to create a triangle, but that would limit me to isosceles triangle. My very smart colleague (Mengqian Lu) suggested me to cut a block/brick object with non-orthogonal axes such that you get a triangle. In meep, block object requires, 1) the lengths of the block edges along each of its three axes, 2) the directions of the axes of the block and 3)center. A triangle with known (x1,y1,0), (x2,y2,0) and (x3,y3,0) can be represented with a block (with possible non-orthogonality) element by modifications as shown in the figure. I pick a random point “E” which is not in the plane of my triangle and assume it as origin of the block. Then the vectors corresponding to axes of block are given by EA, EB, EC vectors, sizes are given by |EA|,|EB|,|EC| and the center of the block is OE+0.5*(EA+EB+EC).

Triangle in meep using block primitive object

To test this, I wrote a octave code which produces a meep code that that can be executed to create a triangle with vertices of (-10,0,0), (10,0,0) and (0,10,0). The result of compiling the meep code and exporting the dielectric distribution is shown below. The length of the simulation domain is 20 units in both x and y directions.

Triangle shape implemented in meep using block primitive object

With this information of incorporating a single triangle in meep, I can now obtain complex 2d shapes in meep. I start by writing a file that contains information regarding points that make up my structure and do a constrained delaunay triangulation. One can use matlab (versions >2009) to do such constrained delaunay triangulation. However, many of us (poor graduate students :( ) do not have access to matlab. I figured out that constrained delaunay triangulation can be done by using Triangle package, which is free. After I compile this code, I see two executables 1) Triangle and 2) Showme in my source folder. Triangle does the triangulation and showme does the visualization before and after triangulation.

First, I write a “.poly” file, to mention my structure. ”.poly” file contains information of the points that make up the structure, one has to also mention segments (the border of the polygon) and any holes (if present). More information can be found here. Once a poly file is written, it can visualized using showme executable . If everything is ok, then do a constrained delaunay triangulation using Triangle executable (beware of concavities). I again visualize the structure after triangulation using showme executable to check whether triangulation has happened correctly or not. Once triangulated, I use the method above to convert each triangle to a corresponding meep block element (with suitable centers, sizes and axes) and stitch all of them together (once again use a octave code to do that automatically).

Using the poly file for shape “A” obtained from here I create a dielectric structure in MEEP with each triangle representing a random dielectric constant. Below is the final result. This method can also be extended to a group of arbitrary shapes in one simulation each with different dielectric functions.

Screenshot of showme executable showing the triangulation of 'A' shape

'A' shaped dielectric structure in MEEP

arrow5 Responses

  1. 64 mos, 4 wks ago


    I found this method quite interesting and useful and I would like to implement it, but I can’t understand when you say “non-orthogonal axes”. You mean non-orthogonal to the principal axes of MEEP or non orthogonal to each other (i.e. a “warped” block, which I never heard of in meep) ?
    The point is that, in my first interpretation, since you speak of blocks with “possible” nonorthogonality, the opposite case (i.e. orthogonality) implies square or rectangular cross-sections, which would make no sense in this context.
    Please shed some light on this as I’m really keen on implementing the method.

    Thank you in advance and kindest regards,


  2. 64 mos, 1 wk ago

    hi Bala Krishna Juluri , I try non-orthogonal axes in my meep codes, but I dont take my wanted result. before one year, to create a triangle in my meep, I cut a block with non-orthogonal axes with air for get a triangle. unfortunately, I try for A shape , but I write given data with respect to you poly file, I don’t obtain, A shape is defined different blocks in different size and coordinates…..Does not this state directly to poly data ??? , How to be written poly data in meep codes ??? I do not know I missing something there…..

    Thanks in advance,

  3. Felipe BM
    2 mos, 1 wk ago

    Thank you for the nice post!

    Could you please share the Octave code?

    Thanks again!

  4. Felipe BM
    2 mos, 1 wk ago

    Now I think I’ve figured it out thanks to your complete explanation.

    Maybe is something like this?

    function out = MEEPtriangle(p1,p2,p3);
    % Create a triangle in MEEP with vertices in p1, p2, p3
    % as explained in

    O = [0 0 0]; % for now axes origin is a constant

    OA = [p1 0] - O;
    OB = [p2 0] - O;
    OC = [p3 0] - O;

    % Origin of the triangle
    E =  [0 0 -5];% for now coords' origin is a constant
    OE = E - O;

    % block edges and center
    EA = OA - OE;
    EB = OB - OE;
    EC = OC - OE;
    CC = OE+0.5*(EA+EB+EC); % center

    fprintf(['(make block (center %6.4f %6.4f %6.4f)\n\t\t'...
            '(size %6.4f %6.4f %6.4f)\n\t\t'...
            '(e1 %6.4f %6.4f %6.4f)\n\t\t'...
            '(e2 %6.4f %6.4f %6.4f)\n\t\t'...
            '(e3 %6.4f %6.4f %6.4f)\n\t\t'...
            '(material (make dielectric (epsilon 12))))'],...% for now epsilon is constant
  5. Bala Krishna Juluri
    5 days, 8 hrs ago

    Thumbs up!

Leave A Comment