Exemplo n.º 1
0
def test_beam_tracing(qtbot):
    n = 1.5
    lamb = 860e-9
    w = 80e-3
    f = 100e-3
    waist = 20e-6
    k = 2*np.pi/lamb
    roc, center_thickness = paraxial.design_thick_spherical_transform_lens(n, w, f)
    lens_surfaces = rt1.make_spherical_lens_surfaces(roc, -roc, center_thickness, ri.FixedIndex(n))
    z_fp = center_thickness/2 + w
    beam = asbt1.Beam(asbp.PlaneProfile.make_gaussian(lamb, 1, waist, 160e-6, 64, z_waist=-z_fp))
    surface1 = rt1.Surface(rt1.PlanarProfile(), otk.h4t.make_translation(0, 0, z_fp))
    surfaces = lens_surfaces + (surface1,)
    beam_segments = asbt1.trace_surfaces(beam, surfaces, ['transmitted', 'transmitted', None])

    origin = beam.to_global(v4hb.stack_xyzw([0, -waist, waist, 0, 0], [0, 0, 0, -waist, waist], -z_fp, 1))
    vector_local = v4hb.normalize(v4hb.stack_xyzw([0, 2/waist, -2/waist, 0, 0], [0, 0, 0, 2/waist, -2/waist], k, 0))
    vector = beam.to_global(vector_local)
    line = otk.rt1._lines.Line(origin, vector)
    polarization = v4hb.normalize(v4hb.cross(vector, [1,0,0,0]))
    ray_segments = otk.rt1._raytrace.Ray(line, polarization, 1, 0, lamb, 1).trace_surfaces(surfaces, ['transmitted', 'transmitted', 'incident'])

    # TODO resurrect
    # segments = [asbp.BeamRaySegment.combine(bs, rs) for bs, rs in zip(beam_segments, ray_segments)]
    #
    # widget = asbp.MultiProfileWidget.plot_segments(segments)
    # qtbot.addWidget(widget)
    # for n in range(len(widget.entries)):
    #     widget.set_index(n)
Exemplo n.º 2
0
def test_conic_surface():
    # Prove that with a conic surface we can focus parallel rays perfectly.
    n1 = 1
    n2 = 1.5
    f = 1
    roc = f * (n2 - n1) / n2
    x0s = [-0.2, -0.1, 0, 0.1, 0.2]
    # There is a formula for this:
    # https://www.iap.uni - jena.de/iapmedia/de/Lecture/Advanced + Lens + Design1393542000/ALD13_Advanced + Lens + Design + 7 + _ + Aspheres + and +freeforms.pdf
    # but I obtained it numerically (in demo_conic_surface.py).
    kappa = 0.55555
    f = roc * n2 / (n2 - n1)
    interface = rt1.FresnelInterface(ri.FixedIndex(n1), ri.FixedIndex(n2))
    conic_surface = rt1.Surface(rt1.ConicProfile(roc, kappa),
                                interface=interface)
    origin = v4hb.stack_xyzw(x0s, 0, -1, 1)
    vector = v4hb.stack_xyzw(0, 0, 1, 0)
    detector_surface = rt1.Surface(rt1.PlanarProfile(),
                                   matrix=h4t.make_translation(0, 0, f))
    surfaces = conic_surface, detector_surface
    line = rt1.Line(origin, vector)
    pol = v4hb.cross(line.vector, [0, 1, 0, 0])
    ray = rt1.Ray(line, pol, 1, 0, 860e-9, n1)
    segments = ray.trace_surfaces(surfaces, ['transmitted', 'incident'])[0]
    assert len(segments) == 3
    xy = segments[-1].ray.line.origin[..., :2]
    # The focusing is close (f number 2.5) but not quite perfect due to errors in the intersection solver.
    assert np.allclose(xy, 0, atol=2e-6)
Exemplo n.º 3
0
def test_reflect_Surface():
    s = rt1.Surface(rt1.PlanarProfile(), interface=rt1.Mirror())
    s.rotate_y(np.pi / 4)
    line = rt1.Line((0, 0, -1, 1), (0, 0, 1, 0))
    pol = v4hb.cross(line.vector, [0, 1, 0, 0])
    ray = rt1._raytrace.Ray(line, pol, 0, 860e-9, 1)
    segments = ray.trace_surfaces([s], ['reflected'])[0]
    assert len(segments) == 2
    assert np.allclose(segments[-1].ray.line.vector, (-1, 0, 0, 0))
Exemplo n.º 4
0
def test_rt_pgl(qtbot):
    surface = rt1.Surface(rt1.PlanarProfile())
    line = rt1.Line((0, 0, -1, 1), (0, 0, 1, 0))
    segments = otk.rt1._raytrace.Ray(line, [1, 0, 0, 0], 0, 860e-9,
                                     1).trace_surfaces((surface, ),
                                                       ['incident'])

    widget = rtpgl.plot_surfaces((surface, ))
    qtbot.addWidget(widget)

    item = rtpgl.ParentItem()
    item.add_surface(surface)
    rtpgl.SegmentsItem(segments, item)
    widget = pgl.GLViewWidget()
    widget.addItem(item)
    qtbot.addWidget(widget)
Exemplo n.º 5
0
    def propagate(self):
        lamb = self.wavelength_widget.value() * 1e-9
        waist0 = self.source_diameter_widget.value() / 2 * 1e-3
        num_points = self.num_points
        rs_waist = np.asarray((self.source_x_widget.value() * 1e-3,
                               self.source_y_widget.value() * 1e-3))
        source_z = self.source_z_widget.value() * 1e-3
        roc1 = self.roc1_widget.value() * 1e-3
        roc2 = self.roc2_widget.value() * 1e-3
        d = self.thickness_widget.value() * 1e-3
        n = ri.FixedIndex(self.n_widget.value())
        # These are calculated by lens update.
        f = self.f
        w1 = self.w1
        w2 = self.w2

        r0_centers = rs_waist
        q0_centers = (0, 0)
        k = 2 * np.pi / lamb
        r0_support = waist0 * self.waist0_factor  # *#(np.pi*num_points)**0.5*waist0
        x0, y0 = asbp.calc_xy(r0_support, num_points, r0_centers)

        # Create input beam and prepare for propagation to first surface.
        Er0 = asbp.calc_gaussian(k, x0, y0, waist0, r0s=rs_waist)

        profile0 = asbp.PlaneProfile(
            lamb, 1, source_z, r0_support, Er0,
            asbp.calc_gradxyE(r0_support, Er0, q0_centers), r0_centers,
            q0_centers)
        b0 = asbt1.Beam(profile0)
        s1 = rt1.Surface(rt1.SphericalProfile(roc1),
                         otk.h4t.make_translation(0, 0, w1),
                         interface=rt1.PerfectRefractor(ri.air, n))
        s2 = rt1.Surface(rt1.SphericalProfile(-roc2),
                         otk.h4t.make_translation(0, 0, w1 + d),
                         interface=rt1.PerfectRefractor(n, ri.air))
        s3 = rt1.Surface(rt1.PlanarProfile(),
                         otk.h4t.make_translation(0, 0, w1 + d + w2))

        segments = asbt1.trace_surfaces(
            b0, (s1, s2, s3), ('transmitted', 'transmitted', None))[0]
        b1_incident = segments[0].beams[1]
        b1_refracted = segments[1].beams[0]
        b1_plane = segments[1].planarized_beam
        b2_incident = segments[1].beams[1]
        b2_refracted = segments[2].beams[0]
        b2_plane = segments[2].planarized_beam
        b3 = segments[2].beams[1]
        # b1_incident = b0.propagate(s1, self.kz_mode)
        # b1_refracted = b1_incident.refract(s1, self.kz_mode)
        # b1_plane = b1_refracted.planarize(kz_mode=self.kz_mode, invert_kwargs=self.invert_kwargs)
        # b2_incident = b1_plane.propagate(s2, self.kz_mode)
        # b2_refracted = b2_incident.refract(s2, self.kz_mode)
        # b2_plane = b2_refracted.planarize(kz_mode=self.kz_mode, invert_kwargs=self.invert_kwargs)
        # b3 = b2_plane.propagate(s3, kz_mode=self.kz_mode)

        self.b0 = b0
        self.b1_incident = b1_incident
        self.b1_refracted = b1_refracted
        self.b1_plane = b1_plane
        self.b2_incident = b2_incident
        self.b2_plane = b2_plane
        self.b3 = b3
        waist3 = f * lamb / (np.pi * waist0)
        self.b3_scale = waist3 / waist0

        self.update_plots()