Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Add aspheric surface with odd and even terms (#291) #300

Merged
merged 28 commits into from
Nov 11, 2021

Conversation

mattderstine
Copy link
Contributor

@mattderstine mattderstine commented Oct 17, 2021

Adds support for odd polynomical aspheric terms.
Changes the calculation of the aspheric terms for point() and partials() to minimize the number of multiplications
Updates zernikesurface to call asphericsurface internally.
Adds separate methods for even, odd and oddeven calculations of point() and partials() for aspheric surfaces. AsphericSurface is modified to pick the appropriate methods.
New functions are created to directly allocate even, odd and oddeven aspheric surfaces.
Tests are added to check the new methods
Minor changes to other functions to directly call aphericsurface when no zernike terms are possible
Fixes #291

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

ran tests on package. added tests to cover for new functions and methods

Test Configuration(s):

Checklist:

I need help at this point to fix the failing allocations tests.

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings (but fail allocation tests)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

@ghost
Copy link

ghost commented Oct 17, 2021

CLA assistant check
All CLA requirements met.

@friggog friggog changed the title Issue291 Add aspheric surface with odd and even terms (#291) Oct 18, 2021
Copy link
Collaborator

@friggog friggog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mattderstine this is fantastic! I think we can simplify ApshericSurface.jl significantly, but this is looking great overall :)

src/Geometry/Primitives/Zernike.jl Outdated Show resolved Hide resolved
src/Geometry/Primitives/Zernike.jl Outdated Show resolved Hide resolved
src/Geometry/Primitives/AsphericSurface.jl Outdated Show resolved Hide resolved
src/Geometry/Primitives/Zernike.jl Outdated Show resolved Hide resolved
src/Geometry/Primitives/AsphericSurface.jl Outdated Show resolved Hide resolved
test/testsets/Comparison.jl Show resolved Hide resolved
@friggog
Copy link
Collaborator

friggog commented Oct 18, 2021

Also need an update to https://github.com/microsoft/OpticSim.jl/blob/main/docs/src/primitives.md for the new surface type(s)

@BrianGun
Copy link
Contributor

BrianGun commented Oct 18, 2021

@mattderstine Thank you for spending the time to write this PR. Very nice upgrade to aspherics. We sincerely appreciate the hard work required to understand OpticSim and write this code.

Allocation tests are failing, which probably has to do with your use of an abstract type rather than a concrete type, as noted by @friggog.

We are fanatical about controlling allocations, even though it is a pain, because any allocations that happen in the innermost ray tracing loop kill multithreaded performance, to the point where single threaded is faster than multithreaded on a 64 core machine.

Both @friggog and I have experience coaxing the compiler to avoid allocations. It can be tricky. If you run into problems ping us and we'll be happy to help out.

Copy link
Contributor

@BrianGun BrianGun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments inline in the source code for changes.

@mattderstine
Copy link
Contributor Author

I have another issue that doesn't make sense to me. I modified julia.jl (new line 27) to include AsphericSurface.jl as Zernike.jl is included. It gives a strange error. I don't understand this code well so I have no clue what to do to fix it. This error only arose after I fixed all the unbound args issues.

Any pointers would be appreciated.

Copy link
Collaborator

@friggog friggog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly formatting stuff, but a couple of fixes for the AsphericSurface as well

src/Geometry/Primitives/AsphericSurface.jl Outdated Show resolved Hide resolved
src/Geometry/Primitives/Zernike.jl Outdated Show resolved Hide resolved
src/Geometry/Primitives/Zernike.jl Outdated Show resolved Hide resolved
src/Geometry/Primitives/AsphericSurface.jl Outdated Show resolved Hide resolved
src/Geometry/Primitives/AsphericSurface.jl Outdated Show resolved Hide resolved
src/Geometry/Primitives/AsphericSurface.jl Outdated Show resolved Hide resolved
src/Geometry/Primitives/AsphericSurface.jl Outdated Show resolved Hide resolved
@friggog
Copy link
Collaborator

friggog commented Oct 30, 2021

Also to flag I think we still need some docs and allocation test updates, don't want to forget these before merging - happy to help as these may be bit more difficult to find

@friggog friggog added the enhancement New feature or request label Oct 30, 2021
@friggog
Copy link
Collaborator

friggog commented Oct 31, 2021

Sorry got my syntax wrong, L185-187 should be:

partial_prod_step(z::AsphericSurface{T,3,Q,EVEN}, r::T, r2::T) where {T<:Real,Q} = r, r2, 2:2:2Q
partial_prod_step(z::AsphericSurface{T,3,Q,ODD}, r::T, r2::T) where {T<:Real,Q} = one(T), r2, 1:2:(2Q-1)
partial_prod_step(z::AsphericSurface{T,3,Q,ODDEVEN}, r::T, r2::T) where {T<:Real,Q} = one(T), r, 1:1:Q

@codecov-commenter
Copy link

codecov-commenter commented Nov 9, 2021

Codecov Report

Merging #300 (b2bdaa1) into main (1661d8b) will increase coverage by 0.19%.
The diff coverage is 61.02%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #300      +/-   ##
==========================================
+ Coverage   54.56%   54.76%   +0.19%     
==========================================
  Files          78       79       +1     
  Lines        7079     7194     +115     
==========================================
+ Hits         3863     3940      +77     
- Misses       3216     3254      +38     
Impacted Files Coverage Δ
src/Geometry/Geometry.jl 0.00% <ø> (ø)
src/Optical/Lenses.jl 36.52% <0.00%> (ø)
src/Geometry/Primitives/AsphericSurface.jl 58.89% <58.89%> (ø)
src/Geometry/Primitives/Zernike.jl 76.86% <76.66%> (+4.35%) ⬆️
src/Vis/Visualization.jl 9.42% <0.00%> (+0.15%) ⬆️
src/Geometry/CSG/CSG.jl 83.52% <0.00%> (+0.31%) ⬆️
src/RepeatingStructures/HexagonalLattice.jl 47.14% <0.00%> (+0.66%) ⬆️
src/Geometry/AccelSurface.jl 97.27% <0.00%> (+0.68%) ⬆️
src/Geometry/Surface.jl 69.69% <0.00%> (+1.51%) ⬆️
src/RepeatingStructures/Lattice.jl 76.92% <0.00%> (+5.49%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1661d8b...b2bdaa1. Read the comment docs.

@mattderstine mattderstine requested a review from friggog November 10, 2021 18:28
Copy link
Collaborator

@friggog friggog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few tiny changes left - just to get the docs building 🙂 Awesome work so far - super close now!

src/Geometry/Primitives/AsphericSurface.jl Outdated Show resolved Hide resolved
test/testsets/JuliaLang.jl Outdated Show resolved Hide resolved
src/Geometry/Primitives/AsphericSurface.jl Outdated Show resolved Hide resolved
src/Geometry/Primitives/AsphericSurface.jl Outdated Show resolved Hide resolved
@mattderstine
Copy link
Contributor Author

@friggog Could you explain the failure in the Documentation test? I know nothing about the documentation system so I can't begin to figure out how to address the issue.

@friggog
Copy link
Collaborator

friggog commented Nov 11, 2021

@friggog Could you explain the failure in the Documentation test? I know nothing about the documentation system so I can't begin to figure out how to address the issue.

Sorry missed this before, you added AsphericSurface somewhere in the docs where it wasn't needed - I just made a commit which should fix it. I'll take a look at the docs once they build to check it's fine, but otherwise I think this all looks good!

Awesome work and thanks for sticking with it through the reviews, hopefully you can continue to make great contributions like this to OpticSim.jl 🙂

Copy link
Collaborator

@friggog friggog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrianGun I'll leave this for you to have a final look and complete - all looks ok to me

@mattderstine thanks again for the contribution!

@BrianGun
Copy link
Contributor

@mattderstine looks great! Thank you for your contribution to OpticSim.

@BrianGun BrianGun merged commit d4e4c12 into microsoft:main Nov 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for odd aspheric terms
4 participants