facebookresearch / fmmax

Fourier modal method with Jax
MIT License
97 stars 10 forks source link

Ensure no NaN in gradient with vector formulation and uniform permittivity #73

Closed mfschubert closed 9 months ago

mfschubert commented 9 months ago

Current vector field formulations can lead to NaN gradient when the permittivity is uniform. Here, we adjust how the special case of uniform permittivity is handled, which seems to resolve the issue.

A new test is added to test_grad.py file, which would have failed previously but now passes.

Tests for several examples are adjusted to run at higher resolution (i.e. higher N) so that they (hopefully) become less sensitive to small changes in the code. Results for reasonable N are essentially unchanged, as seen in uLED efficiency plot below. These can be compared to the figure in #70.

image

smartalecH commented 9 months ago

LGTM!