Beispiel #1
0
    def test_eval_child_ray(self):
        ray_in = Ray(origin=(-1.0, -2.0, -3.0),
                     direction=(1.0, 2.0, 3.0),
                     E_vector=(1.0, -2.0, 0.0),
                     E1_amp=(1.0 + 1.0j),
                     E2_amp=(2.0 + 0.0j),
                     refractive_index=1.5)

        mat = FullDielectricMaterial(n_inside=1.0,
                                     n_outside=1.5,
                                     reflection_threshold=-0.01,
                                     transmission_threshold=-0.01)

        out = RayCollection(8)
        ray_idx = 123
        point = (0.0, 0.0, 0.0)
        normal = (0.0, 0.0, -1.0)
        tangent = (0.0, -1.0, 0.0)

        mat.eval_child_ray(ray_in, ray_idx, point, normal, tangent, out)

        self.assertEqual(len(out), 2)

        aspect_in = dotprod(norm(ray_in.direction), norm(normal))
        P_in = (P(ray_in.E1_amp) +
                P(ray_in.E2_amp)) * (ray_in.refractive_index.real)

        print("D_in:", norm((1.0, 2.0, 3.0)), "P_in:", P_in * aspect_in)
        for item in out:
            E1 = item.E1_amp
            E2 = item.E2_amp
            aspect_out = dotprod(norm(item.direction), norm(normal))
            print((P(E1) + P(E2)) * (item.refractive_index.real) * aspect_out,
                  item.refractive_index)
Beispiel #2
0
    def test_brewster_angle(self):
        n_out = 1.2
        n_in = 2.0

        theta_B = numpy.arctan2(n_in, n_out)
        print("Brewsters angle:", theta_B * 180 / numpy.pi)

        y = numpy.sin(theta_B)
        z = numpy.cos(theta_B)

        #angle inside dielectric (for transmitted ray)
        theta_inside = numpy.arcsin(n_out * numpy.sin(theta_B) / n_in)
        trans_direction = norm(
            (0.0, numpy.sin(theta_inside), numpy.cos(theta_inside)))

        ###input ray is directed into object
        ray_in = Ray(origin=(0.0, -y, -z),
                     direction=(0.0, y, z),
                     E_vector=(0.0, 1.0, 0.0),
                     E1_amp=(1.0 + 1.0j),
                     E2_amp=(0.0 + 0.0j),
                     refractive_index=n_out)

        mat = FullDielectricMaterial(n_inside=n_in,
                                     n_outside=n_out,
                                     reflection_threshold=-0.01,
                                     transmission_threshold=-0.01)

        out = RayCollection(8)
        ray_idx = 123
        point = (0.0, 0.0, 0.0)
        normal = (0.0, 0.0, -1.0)
        tangent = (0.0, -1.0, 0.0)

        P_in = ray_power(ray_in)

        mat.eval_child_ray(ray_in, ray_idx, point, normal, tangent, out)

        self.assertEqual(len(out), 2)

        refl_pow = ray_power(out[0])
        trans_pow = ray_power(out[1])

        self.assertAlmostEqual(0.0, refl_pow)
        self.assertAlmostEqual(refl_pow, out[0].power)

        self.assertAlmostEqual(P_in, trans_pow)

        ###check relfected ray direction
        self.assertAlmostEqual(
            abs(
                dotprod(norm(subvv(ray_in.direction, out[0].direction)),
                        normal)), 1)

        ###check transmitted ray direction
        self.assertAlmostEqual(abs(dotprod(out[1].direction, trans_direction)),
                               1)
 def test_norm(self):
     a = [1.1, 2.2, 3.3]
     b = ctracer.norm(a)
     print("B", b)
     self.assertAlmostEqual(1.0, sum(x**2 for x in b))
     self.assertAlmostEqual(0.0, ctracer.mag(ctracer.cross(a, b)))
Beispiel #4
0
    def test_snells_law(self):
        n_out = 1.2
        n_in = 2.0

        d_out = NondispersiveCurve(n_out)
        d_in = NondispersiveCurve(n_in)
        d_coating = NondispersiveCurve(1.4)

        theta_B = numpy.arctan2(n_in, n_out)
        print("Brewsters angle:", theta_B * 180 / numpy.pi)

        y = numpy.sin(theta_B)
        z = numpy.cos(theta_B)

        #angle inside dielectric (for transmitted ray)
        theta_inside = numpy.arcsin(n_out * numpy.sin(theta_B) / n_in)
        trans_direction = norm(
            (0.0, numpy.sin(theta_inside), numpy.cos(theta_inside)))

        ###input ray is directed into object
        ray_in = Ray(origin=(0.0, -y, -z),
                     direction=(0.0, y, z),
                     E_vector=(0.0, 1.0, 0.0),
                     E1_amp=(1.0 + 1.0j),
                     E2_amp=(0.0 + 0.0j),
                     refractive_index=n_out)
        print(ray_in.wavelength_idx)

        mat = CoatedDispersiveMaterial(dispersion_inside=d_in,
                                       dispersion_outside=d_out,
                                       coating_thickness=0.1,
                                       dispersion_coating=d_coating,
                                       reflection_threshold=0.01,
                                       transmission_threshold=0.01)
        wavelens = numpy.array([0.78], 'd')
        mat.wavelengths = wavelens

        out = RayCollection(8)
        ray_idx = 123
        point = (0.0, 0.0, 0.0)
        normal = (0.0, 0.0, -1.0)
        tangent = (0.0, -1.0, 0.0)

        P_in = ray_power(ray_in)

        mat.eval_child_ray(ray_in, ray_idx, point, normal, tangent, out)

        self.assertEqual(len(out), 2)

        refl_pow = ray_power(out[0])
        trans_pow = ray_power(out[1])

        #self.assertAlmostEquals(0.0, refl_pow)
        #self.assertAlmostEquals(refl_pow, out[0].power)

        #self.assertAlmostEquals(P_in, trans_pow)

        ###check relfected ray direction
        self.assertAlmostEqual(
            abs(
                dotprod(norm(subvv(ray_in.direction, out[0].direction)),
                        normal)), 1)

        ###check transmitted ray direction
        self.assertAlmostEqual(abs(dotprod(out[1].direction, trans_direction)),
                               1)
Beispiel #5
0
    def test_brewster_angle(self):
        n_out = 1.2
        n_in = 2.0

        theta_B = numpy.arctan2(n_in, n_out)
        print("Brewsters angle:", theta_B * 180 / numpy.pi)

        y = numpy.sin(theta_B)
        z = numpy.cos(theta_B)

        #angle inside dielectric (for transmitted ray)
        theta_inside = numpy.arcsin(n_out * numpy.sin(theta_B) / n_in)
        print("Internal angle:", theta_inside * 180 / numpy.pi)
        trans_direction = norm(
            (0.0, numpy.sin(theta_inside), numpy.cos(theta_inside)))

        ###input ray is directed into object
        ray_in = Ray(origin=(0.0, -y, -z),
                     direction=(0.0, y, z),
                     E_vector=(0.0, 1.0, 0.0),
                     E1_amp=(1.0 + 1.0j),
                     E2_amp=(0.0 + 0.0j),
                     refractive_index=n_out)

        mat = SingleLayerCoatedMaterial(thickness=0.1,
                                        n_coating=1.5,
                                        n_inside=n_in,
                                        n_outside=n_out,
                                        reflection_threshold=-0.01,
                                        transmission_threshold=-0.01)
        mat.wavelengths = numpy.array([0.78])

        out = RayCollection(8)
        ray_idx = 123
        point = (0.0, 0.0, 0.0)
        normal = (0.0, 0.0, -1.0)
        tangent = (0.0, -1.0, 0.0)

        P_in = ray_power(ray_in)

        mat.eval_child_ray(ray_in, ray_idx, point, normal, tangent, out)

        self.assertEqual(len(out), 2)

        refl_pow = ray_power(out[0])
        trans_pow = ray_power(out[1])

        #self.assertAlmostEquals(0.0, refl_pow)
        #self.assertAlmostEquals(refl_pow, out[0].power)

        #self.assertAlmostEquals(P_in, trans_pow)

        ###check relfected ray direction
        self.assertAlmostEqual(
            abs(
                dotprod(norm(subvv(ray_in.direction, out[0].direction)),
                        normal)), 1)

        dir_out = out[1].direction
        theta_trans = 180 * numpy.arctan2(dir_out[2], dir_out[1]) / numpy.pi
        print("Transmitted angle:", theta_trans)
        ###check transmitted ray direction
        self.assertAlmostEqual(abs(dotprod(out[1].direction, trans_direction)),
                               1)