Skip to content

Polarizing components v2 - #25

Merged
StackEnjoyer merged 33 commits into
masterfrom
PolarizingComponents
Aug 26, 2025
Merged

StackEnjoyer merged 33 commits into
masterfrom
PolarizingComponents

Conversation

@StackEnjoyer

@StackEnjoyer StackEnjoyer commented Aug 22, 2025 •

Copy link
Copy Markdown
Owner

This branch is a revisit of the polarization ray tracing calculus introduced in:

Yun, Garam, Karlton Crabtree, and Russell A. Chipman. "Three-dimensional polarization ray-tracing calculus I: definition and diattenuation." Applied optics 50.18 (2011): 2855-2865.

This method looks great on paper, but there are some issues in practice, especially for Jones matrices that are tied to the orientation of their geometry, e.g. thin film filters. For the classic s-p-basis defined values, the tracing scheme works great. However, multiple unsuccessful attempts where made in order to resolve #19 using the Yun scheme.

The implementation of _calculate_global_E0 in this PR for the GlobalJonesBasis fully avoids the Yun scheme and simply projects the 3x3 polarization matrix into the transverse plane of the incoming ray. This seems to work fine i.e. there are no sudden jumps or discontinuities in the transmitted field values when rotating the PolarizationFilter around its axes. Also, the field vector orthogonality to the ray direction of propagation is maintained. It violates P*in_dir = out_dir in many cases, but I am not sure if this is required in global coordinates.

The suggested solution for #19 is as follows in order to move on with our lives (this will surely not bite us in the ass at some later point :D)

  • use the LocalJonesBasis for all interactions that are defined in the s-p-basis and use the Yun tracing algorithm, e.g. all current test cases for reflection and refraction are maintained
  • use the GlobalJonesBasis and the method described above for all thin-film polarizing element representations that due not change the ray direction

I am so sick and tired of polarization its unreal...

ToDos

  • extensive testcases for the correctness of the PolarizationFilter
  • add cutoff field strength to filter where weak rays are blocked

Additional changes and additions

  • the Utils.jl file has been broken down into multiple, smaller files and moved into its own folder
  • lin. algebra utils: isorthognal3d and isparallel3d
  • polarization state utils: islinear, iscircular and iselliptical

Additional fixes

This branch also contains bug fixes for

@StackEnjoyer
StackEnjoyer requested a review from TacHawkes August 22, 2025 15:23
@StackEnjoyer StackEnjoyer self-assigned this Aug 22, 2025
@TacHawkes

Copy link
Copy Markdown
Collaborator

I had a first look at it. It would be great, if you could provide your test script for playing around with it.

I did not have a too deep in-depth look at the physics. As already mentioned, I would have chosen the approach of giving elements an explicit axis (i.e. fast/slow axis) instead of an implicit axis by introducing the convention of s/p orientation having some relationship with a local/global xyz coordinate system. This should work but it is implicit and does not feel as physical as the explicit axis. The advantage of course is that you do not have to introduce an axis field for every polarizing component but you will have to document this properly to not confuse the BMO users.

Changes I have done so far:

  • Removed some sloppy coding which introduced type instability/dynamic dispatch
  • Generalized the code a bit so it can seamlessly work with static arrays or mutable default arrays. It should now work either way and if static vectors/arrays are used for in_dir, out_dir and normal, then the whole code should be virtually free of allocations
  • Mesh still used a Matrix for orientation instead of SArray. I have changed this, as we have done this everywhere else in BMO
  • islinear should be faster if it is not linear and also not allocate

I think one general issue remains: We only have polarization as of the Jones formalism. Which is fine! However, we should know and state the limitations of this approach. It is quite simple on the one hand, but not able to correctly model complex/arbitrary polarizing components in 3D.
If we want to be very generic, we might need to use 4×4-Berreman methods in the future...

@StackEnjoyer

Copy link
Copy Markdown
Owner Author

The test script I am using is the one provided in #19. The projection method is loosely inspired by this paper. The explicit axis approach is inherently embedded into the current implementation of the algorithm, since the local Jones matrix is coupled to the global orientation of the element, thereby encoding the slow-/fast-axis. I.e. for the filter, the fast and slow axis orientation is determined by the diagonal entries in a XY/XZ/YZ coordinate system. This approach was inspired by your initial proposal in #19 and the mentioned paper.

I agree that the Jones formalism is a rough implementation for the moment, but I think it should be sufficient for the foresable future. The Berreman method looks very promising but is way above my head right now.

@codecov

codecov Bot commented Aug 26, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.20365% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.46%. Comparing base (10d939e) to head (15e0ec5).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/Utils/MiscUtils.jl 32.07% 36 Missing ⚠️
ext/BeamletOpticsMakieExt.jl 0.00% 12 Missing ⚠️
src/PolarizedRays.jl 77.55% 11 Missing ⚠️
src/Utils/OpticUtils.jl 86.66% 10 Missing ⚠️
ext/RenderPresets.jl 0.00% 3 Missing ⚠️
src/OpticalComponents/Polarizers/JonesCalculus.jl 90.00% 1 Missing ⚠️
...OpticalComponents/Polarizers/PolarizationFilter.jl 93.33% 1 Missing ⚠️
src/Utils/LinearAlgebraUtils.jl 98.21% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #25      +/-   ##
==========================================
+ Coverage   69.82%   71.46%   +1.64%     
==========================================
  Files          52       57       +5     
  Lines        2674     2793     +119     
==========================================
+ Hits         1867     1996     +129     
+ Misses        807      797      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@StackEnjoyer
StackEnjoyer marked this pull request as ready for review August 26, 2025 15:26
@StackEnjoyer
StackEnjoyer merged commit 99636a3 into master Aug 26, 2025
@StackEnjoyer
StackEnjoyer deleted the PolarizingComponents branch August 26, 2025 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Polarized ray tracing - global orientation

2 participants