NanoComp / meep

free finite-difference time-domain (FDTD) software for electromagnetic simulations
GNU General Public License v2.0
1.23k stars 625 forks source link

x parity constraints for eigenmodes #1109

Open stevengj opened 4 years ago

stevengj commented 4 years ago

This would be nice, as discussed in NanoComp/mpb#72. However, implementing it in MPB is rather subtle as discussed in NanoComp/mpb#74 because of the interaction with MPB's transverse basis.

Seems like it might be more straightforward to just do a cyclic rotation of the coordinates in Meep's src/mpb.cpp so that the x direction is always the propagation direction.

stevengj commented 4 years ago

i.e. if the waveguide is in the y direction, rotate the coordinates to (y,z,x), and if the waveguide is in the z direction, rotate them to (z,x,y)

stevengj commented 4 years ago

(The tricky part is just to make sure that we do this consistently. You have to transform all the inputs, lattice vectors etcetera, and also all of the outputs like fields and group velocity.)

stevengj commented 4 years ago

Examples of place that would need to be change:

Note that you have to cycle both the (x,y,z) coordinates and the field components (Ex,Ey,Ez). There will be some coordcycle which says to cycle the coordinates by 0, 1, or 2. Going from Meep to MPB you would cycle by +coordcycle and going from MPB to Meep you would cycle in the opposite direction (by -coordcycle)

stevengj commented 4 years ago

For example, d - X becomes (d - X + coordcycle) % 3.

stevengj commented 4 years ago

Note that the parity flags are defined here. In particular, you should think of parity as a bit field of flags: each bit of the integer is set by one of the *_PARITY flags.

We define our own bits for EVEN_X_PARITY = 16 (4th bit) and ODD_X_PARITY = 32 (the 5th bit). The caller can pass any combination of these. Your code will then have to shift these flags (e.g. if X shifts to Y then you have to shift the 4th and 5th bits to the 2nd and 3rd bits).

oskooi commented 4 years ago

Two questions related to implementation:

  1. How should the direction of the "waveguide" (which can only be one of the three coordinate directions x/y/z) be determined from the user data? One approach is to set it to the direction normal to eig_vol (assuming it is a line in 1d or a plane in 2d). However, the situation is more complicated if eig_vol has all of its dimensions with non-zero size (e.g., a photonic-crystal waveguide). Assume the user does not set direction=mp.NO_DIRECTION and specifies the waveguide direction using kpoint_func.
  2. Should coordcycle be a function (with a single input parameter eig_vol) or a global variable? How can the existing interface of meep_mpb_eps and fields::get_eigenmode (the two functions in src/mpb.cpp where coordcycle is to be used) be preserved?
stevengj commented 4 years ago
  1. see how it is already determining the k-point direction.
  2. coordcycle will have to be stored in the eigenmode_data