alexysong / inkstone

Efficient electromagnetic solver based on rigorous coupled-wave analysis for 3D and 2D multi-layered structures with in-plane periodicity, such as gratings, photonic-crystal slabs, metasurfaces, surface-emitting lasers, nano-antennas, and more.
GNU Affero General Public License v3.0
45 stars 17 forks source link

Non-vacuum incidence medium #4

Closed phoebe-p closed 1 year ago

phoebe-p commented 1 year ago

Hi,

I have been working to integrate Inkstone into RayFlare, an open-source package developed in our group at UNSW for simulating solar cells. I previously developed an interface with S4, which I have benchmarked extensively against e.g. the Fresnel equations and the transfer matrix method (for planar layers). So far, integrating Inkstone has been relatively straightforward because many of the methods are the same as S4, and for 'normal' cases (incidence medium = air/vacuum, n = 1), I am getting the same results with S4 and Inkstone. However, I cannot obtain reasonable results (i.e. in agreement with the Fresnel equations/TMM/S4) when the incidence medium has n > 1 (still non-absorbing). I attach two plots, for the following two stacks:

STACK 1:

n = 1 (incidence medium)


n = 4.12 + 0.33 i (50 nm)


n = 4.13 + 0.03 i (transmission medium)

STACK 2:

n = 1.52 (incidence medium)


n = 4.12 + 0.33 i (50 nm)


n = 4.13 + 0.03 i (transmission medium)

image image

Calculated for 0 (normal) to 89.9 degree angle of incidence from the incidence medium (see note about incident polarisation below). The results for stack 1 are in excellent agreement at all angles (lines for TMM and Inkstone are on top of each other), while the results for stack 2 are not. I note that the result is correct at normal incidence, but not at other incidence angles, and I saw a comment in the code which implies perhaps this feature is simply not implemented yet: "todo: if incident not vacuum, then the incident wave shouldn't be Fourier order (which in general is not eigen)". Could you comment on whether there is currently a way to correct the result obtained for off-normal incidence, or if this is something that will be implemented in future?

Re: definition of incident polarisation, these seem to be conflicting between my definition in the TMM solver (which is the same as in S4) and that in Inkstone, but switching the s and p amplitudes gives the same results (for stack 1); these results are for Inkstone p-polarized incident light.

I have also attached the script which makes the plots, which requires the RayFlare package to work (pip install rayflare). inkstone_inc_issue.txt

alexysong commented 1 year ago

Thank you for using inkstone.

I think I know the reason behind this but need to confirm it. The example you attached requires solcore package for the material dispersion. Could you please attach it, or alternatively remove it? I think for this example we don't necessarily need dispersive material; you can use constant dielectric constants (which seems to be the case in your description but not in the code example.)

Polarization as explained in the front page: $s$ polarization is when $\vec{E}$ field of the incoming plane wave is in the $xy$ plane. $p$ polarization is orthogonal to it.

phoebe-p commented 1 year ago

Hi Alex, thanks for your very quick response! I have attached a new version of the file which doesn't use solcore or rayflare (since rayflare also requires solcore). I saved the TMM results calculated using rayflare as text files for comparison, also attached. Phoebe TMM_air.txt TMM.txt inkstone_inc_issue_2.txt

alexysong commented 1 year ago

This is fixed in 7ddf745f79349fbffadf27e58050380a53feada5, and in the newest release.

The reason it took a bit of time to fix is that Inkstone was in the middle of an update for stability in some extreme cases.

Figure_1 Figure_2 Figure_3

alexysong commented 1 year ago

A slightly longer explanation of is issue is as follows. This arises due to an awkward choice of setting the excitation due to a dilemma. Previously, the angles $\theta$ and $\phi$ were understood as if the incident was in the vacuum: if there was a vacuum before the infinite incident region; then in the actual solving there is no such vacuum before the infinite incident region. This awkward choice allows the incident region to be anything, including when patterned. See, in general, $s$ and $p$ are not even eigen in the incident region, and there is no canonical way of setting incident in these cases.

Bottom line, the original computation makes sense when you understand $\theta$ and $\phi$ as if they were in a vacuum. Now this is fixed; the $\theta$ and $\phi$ are in the incident region material, which makes intuitive sense.

phoebe-p commented 1 year ago

Many thanks for resolving this so promptly!

alexysong commented 1 year ago

Hi @phoebe-p,

[Edited] Sorry I am causing you confusions! Please see below.

In the code "inkstone_inc_issue_2.txt" you sent, you set the $p$ polarization. However, the TMM results matches the $s$ polarization incidence.

($s$ refers to when the incident $E$ field is parallel to the slab, perpendicular to the plane formed by the incident $k$ and the normal direction of the slab surface.)

The more confusing part: in the previous commit 7ddf745f79349fbffadf27e58050380a53feada5, Inkstone $p$ polarization results matches the TMM results. However, this should be incorrect; there was a bug which was fixed in the latest commit 620708845269a8035db505ca28022335bdeebcfe (v 0.3.12). Please upgrade to the newest.

Thanks,

phoebe-p commented 1 year ago

Yes, as I noted in my first post, I had to set the TMM polarisation to 's' and the Inkstone polarisation to 'p' to get the same result for incidence from air (and the TMM results match those of S4, with consistent definitions of the polarisation). So I think everything makes sense now, thanks!

alexysong commented 1 year ago

Great! Happy that this is resolved:)