NanoComp / meep

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

Enhancement: Monitors along arbitrary directions. #2444

Open Andeloth opened 1 year ago

Andeloth commented 1 year ago

Currently there is no way in meep to place monitors (or EigenmodeSources, see https://meep.readthedocs.io/en/latest/Python_Tutorials/Eigenmode_Source/, though the source part is not that important), since FluxRegions don't have a Vector3Type argument for direction, just an int for the Cartesian axis to use as the direction (See https://github.com/NanoComp/meep/blob/c376694f8b094d9aa50499ee4667d4388f98f6dd/python/simulation.py#L499.)

It would be good to implement monitors in arbitrary directions for cases where the flux should be computed normal to a direction which is not a Cartesian axis direction. Technically one could use a DFT Monitor in the same dimensionality as the simulation (1 more than would be needed for a flux plane/line) and calculate the flux at arbitrary angles along a "diagonal" of the region, but that is quite annoying. If I'm wrong and there is a way to calculate flux along a non-Cartesian direction with the current flux monitor implementation then please correct me, I'd like to know.

That being said, I expect this would have relatively rare use cases, but I wanted to post this while I was thinking of it. I'm mostly leaving this here for future reference so that eventually if I get to it I will remember to work on this.

smartalecH commented 1 year ago

or EigenmodeSources

With an Eigenmode source, you just specify a k-vector pointing in the direction you want (as described in that tutorial you linked). You can do the same with a Gaussian beam source etc. In fact, you can do the same with any source using the Principle of Equivalence.

It would be good to implement monitors in arbitrary directions

Just place monitors in all orthogonal directions (x,y,z) and the relative powers will describe the final vector. This is how commercial codes tend to do it under the hood (from what I've seen). They "draw" a diagonal monitor in their GUI, but they "trace" a projection of it along the yee grid using orthogonal monitors and do a quick post-processing step (e.g. a simple inner product).

Andeloth commented 1 year ago

I see, that makes sense. Is that included somewhere in the documentation? If not, this issue could be converted to a documentation issue and it would be nice to post this info somewhere on readthedocs.

smartalecH commented 1 year ago

It's not documented AFAIK.

It might be nice to add a wrapper function that places the projected monitors for you (the user could just supply two opposite corner locations of the plane, and the routine does the rest under the hood).

stevengj commented 1 year ago

See the tutorial on eigenmode sources for oblique waveguides; mode monitors should be essentially the same.