Skip to content
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

Incorrect ccd.hit_list optical path upon reflection #61

Open
ederag opened this issue Aug 28, 2019 · 0 comments
Open

Incorrect ccd.hit_list optical path upon reflection #61

ederag opened this issue Aug 28, 2019 · 0 comments
Assignees

Comments

@ederag
Copy link
Contributor

ederag commented Aug 28, 2019

Here is a minimal working example.
With the lens in the path, the optical path returned by ccd.get_optical_path_data() is wrong.
Removing the lens it works.

from pyoptools.all import *

opengl = True
if opengl:
    from pyoptools.gui.ipynbplotutils import Plot3D
    # slight tilt to see the CCD
    plot3d_rot=[(0, pi/2, 0), (-pi/2, -1e-2, 0)]
else:
    plot3d_rot=[(0,-pi/2,0)]


norot = (0, 0, 0)

mirror = RoundMirror(radius=10, thickness=1, reflectivity=1)
ccd = CCD(size=(20, 20))
lens = SphericalLens(radius=10, thickness=5, curvature_s1=1./100, curvature_s2=0)

base = System(complist=[(ccd, (0, 0, -20), norot),
                        # comment out next line => optical path increases from ~50 to 80 !
                        (lens, (0, 0, 10), norot), 
                         ])

system = System(complist=[(mirror, (0, 0, 30), norot),
                          (base, (0, 0, 0), norot),
                         ])
                          
ray = Ray(pos=(0,0,0), dir=(1, 0, 10))
source = [ray]
system.reset()
system.ray_add(source)
system.propagate()
pos, hit_ray = ccd.hit_list[0]
print(hit_ray.optical_path())
Plot3D(system, center=(0,0,0), size=(80, 30), rot=plot3d_rot, scale=10)

image

80 = 30 + 30 + 20 is approximately the expected value.

With the lens in place, the hit_ray ancestor has its origin on the mirror (wrong).

def find_ancestor(ray):
    """"Return the ray source ray.
    
    The first ray in the given ray ancestry.
    """
    
    while ray.parent:
        ray = ray.parent
    return ray

print(find_ancestor(hit_ray))

# output:
Ray(pos=array([  3.,   0.,  30.]),direc=array([ 0.09950372,  0.        , -0.99503719]),intensity=1.0,wavelength=0.58929,n=1.0,label='',orig_surf=['C0', 'S1'], order=0)

The weird thing is, the source ray ray has the correct optical_path in it !

def get_descendance(ray):
    """"Return cumulative z position and optical path until each interface.
    
    Discard the last one (infinite).
    """
    deltas = []
    z = []
    while True:
        z.append(ray.pos[2])
        deltas.append(ray.optical_path_parent())
        if ray.childs:
            assert(len(ray.childs) == 1)
            last_hit = ray
            ray = ray.childs[0]
        else:
            break
    return deltas, z, last_hit

_, _, hitting_ray = get_descendance(ray)
print(hitting_ray.optical_path())

But the CCD hit_ray is found nowhere in the ray parts.

pyoptools is remarkable, it feels really physical.
(define, assemble subsystems, then propagate rays through the whole system)
Without reflection the optical path calculation works fine.

Looks related to this commented line,
but then where is hit_list updated ?

# Add the information to the hitlist
# self._hit_list.append((PI, ri))

Any pointer would be appreciated.

@ramezquitao ramezquitao self-assigned this Oct 22, 2019
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

No branches or pull requests

2 participants