NanoComp / meep

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

mode decomposition at neighboring k points #885

Open acerjan opened 5 years ago

acerjan commented 5 years ago

I've been working with the mode decomposition function in Meep to extract the expansion coefficients, alpha_n (using the notation from meep's website), at different values of k for a structure which is periodic in 2D, and I have a few questions. In particular, I've noticed that the phase of alpha_n(k) will occasionally jump by exactly pi, and it would be nice to correct for this.

1) In principle, the eigenvectors that are returned by MPB could have an arbitrary phase attached to them, which would make comparing alpha_n(k) at neighboring k points useless without also evaluating the overlap between the two eigenvectors at these neighboring ks. In practice, MPB/MEEP seems to be using some convention to determine this potential phase, such that alpha_n(k) is fairly smooth. Is this convention documented somewhere? (is it MPB's fix-field-phase?)

1b) This also seems as though it would be a potential problem for the Mode Decomposition example "Phase Map of a Subwavelength Binary Grating," which calculates alpha_n as a function of the grating duty cycle, and thus must call MPB for each different structure, and yet the outputs are relatively smooth.

2) Given that I occasionally observe a jump in the phase of alpha_n(k) of exactly pi (when |alpha_n(k)| != 0), my guess is that this choice of phase convention is forcing some component of the eigenmode to be real, and I'm just observing a switch of this phase convention giving the MPB eigenmode a -1. To correct for this, I need to access the C++ functions get_eigenmode and get_mode_mode_overlap. Can you point me to what edits I would need to make in the source code to expose these functions in scheme? Or would python be much more convenient?

2b) Or would such edits to the source code be a larger undertaking than I'm realizing?

3) I'm aware that MEEP's sources at the neighboring k points will also be slightly different, and that this will impart a minor phase shift in alpha_n(k) from the MEEP portion of these overlap integrals. I think this effect is relatively small, but I also don't know how to calculate it.

stevengj commented 5 years ago

Yes, this is MPB's fix-field-phase. Basically, it chooses the phase to maximize the energy in the real part of the fields, but that still leaves the sign ambiguous, and we just pick the sign somewhat arbitrarily.

stevengj commented 5 years ago

In general, I would recommend doing this sort of thing with Python interface.

acerjan commented 5 years ago

From python, I'll have access to the two necessary functions as meep::fields::function ?

stevengj commented 5 years ago

In Python there is a documented function get_eigenmode that you can use to access the fields at any point. You can then get the eigenmodes for two neighboring k points, sample them at a grid of points, and compute any overlap integral you want to extract the relative phase, e.g. to detect a sign flip.