lbolla / EMpy

Electromagnetic Python
MIT License
194 stars 82 forks source link

What type of mesh are the Ex and Ey modes defined on ?? #12

Closed DavidRimel closed 7 years ago

DavidRimel commented 7 years ago

i was wondering if EMpy solves modes on a yee grid?

if so is there a way to get the X and Y components of that yee grid?

I noticed a function in the Class FDMode called get_fields_for_FDTD so is this the function i would need to get the mode on the yee grid?

I ask this because i wish to use these calculated mode profiles to initialize the boundary of a yee mesh to perform FDTD and was wondering what would be a good way of doing this?

lbolla commented 7 years ago

No, it's not a Yee grid, iirc. Looking at the code (e.g. https://github.com/lbolla/EMpy/blob/master/EMpy/modesolvers/FD.py#L1041) you can tell that Ex is defined on the same points as Hy and Ey <-> Hx. get_fields_for_FDTD is then used to interpolate those fields to the points of a Yee grid. By the way, using the mode solver to calculate the initial conditions of an FDTD solver was my use-case, as well.

DavidRimel commented 7 years ago

Ok

does this use finite difference for finite element also where are the basis vectors located ?

lbolla commented 7 years ago

@DavidRimel I think your best bet is to look at the papers which are the basis for the implementation:

Fallahkhair, "Vector Finite Difference Modesolver for Anisotropic Dielectric Waveguides", JLT 2007 http://www.photonics.umd.edu/pubs/journal-articles/JA-D/anisotropic-modesolver.pdf

And: http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=12734&objectType=FILE

DanHickstein commented 7 years ago

The link to the paper has actually changed: http://www.photonics.umd.edu/wp-content/uploads/pubs/ja-20/Fallahkhair_JLT_26_1423_2008.pdf

I made PR https://github.com/lbolla/EMpy/pull/13 to update it.

A side-note about the grids: One thing that confused me for a while is that the permittivity grid and the H-field grid are offset by half-a-pixel. This is shown in Fig 1 of the manuscript, where you can see that the dots (which define the H-grid) occur at the borders, where (in this case) e1, e2, e3, and e4 meet (where e=epsilon). This caused me to incorrectly set up my eps grids for a while, but I think that I finally have it figured out.

image

The issue is that Fig. 1 doesn't actually tell you which way the grids are offset. For the code, I believe that the convention is that xc and yc define the permittivity (eps) grid, while x and y define the grid on which H is solved. xc, yc = x + dx/2, y+dy/2. So, the permittivity is displaced in the "positive-x and positive-y" directions from the H-grid.

lbolla commented 7 years ago

Brilliant! Thanks a lot for clarifying further.

DavidRimel commented 7 years ago

Ok I think I figured it out!

So this mode solver is using finite differencing

Hx, and Hy values are defined at all nodal point on the grid, while Hy and eps values are defined in the center of each cell.

similarly, Ex and Ey values are defined at all nodal points on the grid where Ez values are defined in the center of each cell.

Thank you @lbolla and @DanHickstein !!

DanHickstein commented 7 years ago

Hey @DavidRimel, How did you conclude that Ez is defined on a different grid from Ex and Ey? Is there some part of the code you can link to?

I have not looked into this in-depth, but I noticed this line in the corresponding Matlab code, which leads me to believe that Hx, Hy, Hz are all defined on the "corners" while Ex, Ey, EZ are all defined at the "centers":

% Hz - calculated longitudinal magnetic field.  This output will 
%   have the same dimensions as Hx and Hy.
% Ex, Ey, Ez - calculated electric field.  These field components 
%   are computed at the center of each element instead of on the
%   edges or vertices.
DavidRimel commented 7 years ago

Yes you are right Hx,y,z are defined on the nodes or "corners" and Ex,y,z are defined on the faces or "centers".

Thank you @DanHickstein

DavidRimel commented 7 years ago

also note that eps is defined on the centers or faces also this makes sense because Ex,y,z are also defined there so one can simply multiply them together to get D.

DanHickstein commented 7 years ago

Yup. The only catch here is that the E-fields that you get from, for example, solver.modes[0].Ex are not defined on the x and y arrays that you provided when you call EMpy.modesolvers.FD.VFDModeSolver(wl, x y, epsfunc, boundary).solve(neigs, tol), but instead on a grid defined by x[1:] + 0.5dx and y[1:] + 0.5dx.

Right?