tidy3d
tidy3d copied to clipboard
Homogeneous medium validators with custom medium
We have a validator that is meant to validate that a diffraction monitor is in a homogeneous medium. However, what it actually does is compute the list of mediums that the plane intersects, and make sure that there's only one element in that list. This does not work for custom medium, which is a single medium which may nevertheless still be inhomogeneous physically. This same issue applies to the validator for plane wave/gaussian beam sources, as well as, in some sense, to the [TFSF validator](def _validate_tfsf_structure_intersections) about structure intersections. I am not sure what's a good way to fix this:
- Error if custom medium found
- Just warn for the user to make sure that it's homogeneous
- Actually sample the permittivity and check if it is homogeneous
I think the warning approach might make the most sense to me, in the sense that it's the least restrictive and also fastest. Maybe we just exclude any custom media from the list and warn?
In fact looking at the solver, TFSF where the source surface crosses a custom medium would straight up not work, or the results may be wrong, even if the custom medium is uniform on those surfaces. We should just validate that out.
For plane wave, diffraction monitor, we could just warn if in custom medium.
What about checking if custom medium is uniform, if not, warn that it should be uniform on the plane?
In fact looking at the solver, TFSF where the source surface crosses a custom medium would straight up not work, or the results may be wrong, even if the custom medium is uniform on those surfaces.
@momchil-flex could you explain a bit more why it doesn't work even for a uniform custom medium?
What about checking if custom medium is uniform, if not, warn that it should be uniform on the plane?
If we actually do the check, we should error if it's not uniform, not warn. But I wonder if the check may be expensive for e.g. a large plane, e.g. a large-area metalens?
In fact looking at the solver, TFSF where the source surface crosses a custom medium would straight up not work, or the results may be wrong, even if the custom medium is uniform on those surfaces.
@momchil-flex could you explain a bit more why it doesn't work even for a uniform custom medium?
Actually I don't remember anymore what I saw when I first commented this. Perhaps I was thinking that the custom medium is ignored in the auxiliary simulation - but now that I look again, I can't really tell. Maybe best to try...
What about checking if custom medium is uniform, if not, warn that it should be uniform on the plane?
If we actually do the check, we should error if it's not uniform, not warn. But I wonder if the check may be expensive for e.g. a large plane, e.g. a large-area metalens?
I mean we only check if the entire custom medium is uniform, but not the intersecting plane. This should be cheap as we don't compute the intersection? And if it's nonuniform, it's still possible that the medium is uniform on the plane, so we just warn.
Is there a cheap way to check this? I guess something like np.amin(arr) == np.amax(arr)? But would this be slow for a large array?
Is there a cheap way to check this? I guess something like
np.amin(arr) == np.amax(arr)? But would this be slow for a large array?
It will take at least O(N), N being the number of array size. Will this be too slow?
That's true, I forgot amin/amax is not sorting but just O(N). I think this is fine then.