简体   繁体   English

在Python-Meep中设置源以进行FDTD仿真

[英]Setting source in Python-Meep for FDTD simulation

I'm trying to use Python-Meep package to conduct some FDTD simulations. 我正在尝试使用Python-Meep包进行一些FDTD仿真。 First, I want to simulate a plane wave traveling through vacuum in 'z' direction. 首先,我要模拟一个平面波,该平面波在'z'方向通过真空传播。 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. 在2D情况下,我可以将源制作为一条接触计算矩阵边界的线。 In 3D it looks like it's impossible. 在3D中,这似乎是不可能的。 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). 2D情况:在2D情况下,源是从(x,y)=(0,.1e-6)到(x,y)=(15e-6,.1e-6)的线(从边界到边界) 。 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). 3D情况:源是从(x,y,z)=(0,0,.1e-6)到(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. 结果,我无法创建沿“ z”方向传播的平面波。 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. 到目前为止,我尝试过:(a)明确给出no_pml参数;(b)给出pml(0)参数;(c)更改采样;(d)更改源的“ z”位置。 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)

Paraview的Ex1.vtk的屏幕截图 Your 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. 实际上,您无法发送具有沿X轴极化的电场的均匀平面波,这确实体现在垂直于Y轴的模拟体积边界处,其中场振幅降至零。 This trouble does not occur on the two boundaries perpendicular to X. 在垂直于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. 与PEC平行的电场分量在其附近必须为零。 (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) 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 有关更高级(更方便)的示例,请参见https://github.com/FilipDominec/python-meep-utils/blob/master/scatter.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM