tidy3d
tidy3d copied to clipboard
Flux monitor issues
Currently, the flux monitor does the computation server-side and interpolates to the Yee field center closest to the position of the flux plane along the normal direction. This is probably fine, but we should either fix it or comment on it in the documentation.
I'm also slightly worried that a server-side and user-side flux computation (https://github.com/flexcompute/tidy3d-core/blob/c7abda6364583cd681dcac64b78153cce9e4ce44/tests/test_monitors.py#L120-L141) agree to only within 1e-3 in relative error. I'm not sure if this is due to the interpolating or what, and if it requires further investigation.
Another issue is with the fact that depending on the discretization, the numerical size of the integration plane does not match the size of the plane as defined by the user. The fields at the edges need to be weighted accordingly.
The user-side and server-side fluxes now match very well.
I made some changes to the backend and brought mode sources, mode monitors, and flux monitors to a level that I finally find satisfactory in terms of consistency of the results. A bit of explanation about this: assume you have a mode source that injects a mode perfectly. Even then, because you have to interpolate the E and H fields to the same locations to compute the flux, the value you obtain will slightly differ depending on where exactly within the same Yee cell you put the plane position along the normal direction. Note that this is purely an artifact of the discretization. There is no physical reason that the flux would vary depending on where you place the monitor, or the source.
Thus, I have now made the choice to normalize the flux to unity when recorded at the closest Yee grid center, which is how the solver records flux on the fly anyway. This also affects how mode sources currents and mode monitor coefficients are normalized. A fix has been applied to to take this into account, such that the exact position of the plane they are defined on will now affect the phase of the injected fields and of the mode coefficients, as expected, but will not affect their magnitude. I think now a user would have to work very hard to get the small numerical artifacts due to discretization that I was observing before. This also nicely sets the stage up for the S-matrix computation, since the S-matrix elements should now be very very weakly varying on where exactly you place the sources and monitors.
The one thing remaining to be done in this issue is to think about how to make the plane size in flux computations consistent, such that for example the flux through a closed box is computed correctly independent of resolution, rather than under-counting or over-counting some of the flux at the edges depending on how the positions of the monitors overlap.