pythonmeep

Setting source in Python-Meep for FDTD simulation


I'm trying to use Python-Meep package to conduct some FDTD simulations. First, I want to simulate a plane wave traveling through vacuum in 'z' direction. I have problems properly setting the source in three-dimensional case. In 2D case, I can make the source as a line which touches the borders of the computational matrix. In 3D it looks like it's impossible. Below are simple examples.

2D case: In 2D case, the source is a line from (x,y)=(0 , .1e-6) to (x,y)=(15e-6 , .1e-6) (from border to border). Thanks to this, the plane wave is traveling unperturbed to the opposite end of the matrix (where it is reflected).

import meep_mpi as meep

x, y, voxelsize = 15e-6, 15e-6, 50e-9
vol = meep.vol2d(x, y, 1/voxelsize)


class Model(meep.Callback):
def __init__(self):
    meep.Callback.__init__(self)

def double_vec(self, r):
    return 1

model = Model()
meep.set_EPS_Callback(model.__disown__())
struct = meep.structure(vol, meep.EPS)

f = meep.fields(struct)
f.add_volume_source(meep.Ex,
                meep.continuous_src_time(473.755e12/3e8),    # 632.8nm
                meep.volume(meep.vec(0e-6, .1e-6), meep.vec(15e-6, .1e-6)))

while f.time()/3e8 < 30e-15:
    f.step()

meep.del_EPS_Callback()

output = meep.prepareHDF5File("Ex1.h5")
f.output_hdf5(meep.Ex, vol.surroundings(), output)
del(output)

3D case: The source is a plane from (x,y,z)=(0 , 0 , .1e-6) to (x,y,z)=(15e-6 , 15e-6 , .1e-6). This should create a plane from border to border of the matrix. However, for unknown reason, the source does not touch the boundary (there is a small empty space) and whatever I do, I cannot force it to touch it. As a result, I cannot create a plane wave travelling in 'z' direction. Until now I tried: (a) explicitly giving no_pml argument (b) giving pml(0) argument, (c) changing sampling, (d) changing 'z' position of the source. With no luck. I will be grateful for any suggestions.

import meep_mpi as meep

x, y, z, voxelsize = 15e-6, 15e-6, 15e-6, 50e-9
vol = meep.vol3d(x, y, z, 1/voxelsize)


class Model(meep.Callback):
def __init__(self):
    meep.Callback.__init__(self)

def double_vec(self, r):
    return 1

model = Model()
meep.set_EPS_Callback(model.__disown__())
struct = meep.structure(vol, meep.EPS)

f = meep.fields(struct)
f.add_volume_source(meep.Ex,
                meep.continuous_src_time(473.755e12/3e8),    # 632.8nm
                meep.volume(meep.vec(0, 0, .1e-6), meep.vec(15e-6, 15e-6, .1e-6)))

while f.time()/3e8 < 30e-15:
f.step()

meep.del_EPS_Callback()

output = meep.prepareHDF5File("Ex1.h5")
f.output_hdf5(meep.Ex, vol.surroundings(), output)
del(output)

Solution

  • Screenshot of Ex1.vtk from ParaviewYour inability to send a homogeneous plane wave with electric field polarised along the X axis indeed manifests at the simulation volume boundaries perpendicular to the Y axis, where the field amplitude drops to zero. This trouble does not occur on the two boundaries perpendicular to X.

    This is however fully physical solution; by default, the boundaries behave as perfect electric/magnetic conductor; the electric field component parallel to PEC must be zero in its vicinity. (Good conductors screen the external electric field.)

    If you need an exact plane wave, you will have to append another command after the initialisation of field, to define the boundary as periodic:

    f.use_bloch(meep.X, 0) f.use_bloch(meep.Y, 0)

    Note that the second parameters doe not have to be zero, enabling the definition of arbitrary inclined wave sources.

    For a more advanced (and more convenient) example, see https://github.com/FilipDominec/python-meep-utils/blob/master/scatter.py