def test_eval_child(self): m = cmaterials.PECMaterial() in_ray = ctracer.Ray(origin=(-1, 0, -1), direction=(1, 0, 1)) out_rays = ctracer.RayCollection(1) m.eval_child_ray(in_ray, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0), out_rays) out_ray = out_rays[0] self.assertEqual(out_ray.direction, (1, 0, -1))
def make_ray(): rnd = random.random r = ctracer.Ray(origin=(rnd(), rnd(), rnd()), direction=(rnd(), rnd(), rnd()), E1_amp=(rnd() + 1j * rnd()), E2_amp=(rnd() + 1j * rnd()), refractive_index=(rnd() + 1j * rnd())) return r
def test_iteration(self): ray = ctracer.Ray(origin=(-1, 0, -1), direction=(1, 0, 1)) rc = ctracer.RayCollection(10) for i in range(6): rc.add_ray(ray) self.assertEqual(rc.n_rays, 6) rays = [r for r in rc] self.assertEqual(len(rays), 6)
def test_linear(self): in_ray = ctracer.Ray(origin=(-1, 0, -1), direction=(1, 0, 1), E_vector=(1., 2., 3.), E1_amp=(1.0 + 2.0j) / numpy.sqrt(2), E2_amp=(2.0 + 4.0j) / numpy.sqrt(2)) self.assertAlmostEqual(in_ray.ellipticity, 0.0)
def test_termination(self): a = (1, 2, 3) b = (4, 5, 6) c = 2.3 ray = ctracer.Ray(origin=a, direction=b) ray.length = c result = tuple(A + c * B for A, B in zip(a, b)) shift = sum((a - b)**2 for a, b in zip(result, ray.termination)) self.assertAlmostEqual(shift, 0.0)
def test_ellipticity_LHS(self): phase = (1.23 + 3.45j) in_ray = ctracer.Ray(origin=(-1, 0, -1), direction=(1, 0, 1), E_vector=(1., 2., 3.), E1_amp=phase * (2.0 + 0.0j) / numpy.sqrt(2), E2_amp=phase * (0.0 - 2.0j) / numpy.sqrt(2)) self.assertEqual(in_ray.ellipticity, -1.0)
def test_face_set_intersection(self): o = AnOwner(diameter=5.5, offset=6.6) c = cfaces.CircularFace(owner=o) c.idx = 7 fl = ctracer.FaceList() fl.faces = [c] r = ctracer.Ray(origin=(-1, 0, -1), direction=(1, 0, 1), length=10) idx = fl.intersect(r, 20) self.assertEqual(r.end_face_idx, 7) self.assertEqual(r.length, sqrt(2.0))
def test_iteration2(self): ray = ctracer.Ray(origin=(-1, 0, -1), direction=(1, 0, 1)) rc = ctracer.RayCollection(10) for i in range(6): rc.add_ray(ray) self.assertEqual(rc.n_rays, 6) itr = iter(rc) self.assertEqual(type(itr), ctracer.RayCollectionIterator) for i in range(6): r1 = next(itr) self.assertEqual(r1.origin, ray.origin) self.assertEqual(r1.direction, ray.direction)
def test_trace_segment(self): from raytrace import cfaces o = AnOwner(diameter=5.5, offset=6.6) c = cfaces.CircularFace(owner=o) rays = ctracer.RayCollection(10) in_ray = ctracer.Ray(origin=(-1, 0, -1), direction=(1, 0, 1)) rays.add_ray(in_ray) self.assertEqual(rays.n_rays, 1) face_set = ctracer.FaceList() face_set.faces = [c] all_faces = [c] out_rays = ctracer.trace_segment(rays, [face_set], all_faces) self.assertEqual(out_rays.n_rays, 1) out_ray = out_rays[0] self.assertEqual(out_ray.direction, (1, 0, -1))