New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix to deal with unphysical results in incoherent calculations for incident n > 1 #237
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #237 +/- ##
===========================================
+ Coverage 46.07% 46.11% +0.04%
===========================================
Files 85 85
Lines 9133 9140 +7
===========================================
+ Hits 4208 4215 +7
Misses 4925 4925
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does maintain the condition, but is there any check that R + A + T == 1 when doing these manipulations?
About the underlying origin, is it just numerical accuracy issues or physical reason?
In any case, the changes look good to me.
Ok, so contrary to what I said last week, there actually is a check that R+A+T = 1 (in calculate_rat in transfer_matrix.py). I found another issue in the calculation of incoherent profiles (this was due to a misunderstanding on my part; assuming Beer-Lambert absorption in incoherent layers is actually not quite correct, but there is no way to calculate the profile correctly without knowing the coherence length. I have kept the assumption of a Beer-Lambert-like absorption profile in these incoherent layers but now correctly scaled, and have added a note about this in the docstring of the relevant functions). Finally, not related to these changes (the scheduled tests are also failing), the newest version of setuptools seems to break the installation. I don't know if this is related to #238? I have fixed it for now by specifying the previous version (setuptools==65.6.1) in the workflow files but that probably shouldn't be the long-term solution. |
Co-authored-by: Diego Alonso Álvarez <6095790+dalonsoa@users.noreply.github.com>
Co-authored-by: Diego Alonso Álvarez <6095790+dalonsoa@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great that you picked these issues! They are tricky, but have a large impact into the problem. I assume Rayflare have this sorted out by default, right?
In very specific circumstances (multi-layer incoherent/partially coherent stacks, at non-normal incidence, when the incident medium has n > 1) the inc_tmm function sometimes returns unphysical results. This happens when using the Fresnel equations with incidence/outgoing angles equal to or extremely close to pi/2. This situation only happens if you have total internal reflection and light could not reach that layer in any case, but there seems to be some numerical error because extremely large (>> 1) values for the transmission probabilities T and R are produced in these cases.