def test_photon_good_coords_leaks(self): VectorTuple = polycap.VectorTuple start_coords = (0.0585, 0. , 0.) start_direction = (0.001, 0, 1.0) start_electric_vector = (0.5, 0.5, 0.) photon = polycap.Photon(TestPolycapPhoton.description, start_coords, start_direction, start_electric_vector) weights = photon.launch(40.0, leak_calc=True) extleaks = list(photon.extleak_data) self.assertEqual(len(extleaks), 2) extleaks = list(photon.extleak_data) # do it twice to test caching self.assertEqual(len(extleaks), 2) intleaks = list(photon.intleak_data) self.assertEqual(len(intleaks), 3) intleaks = list(photon.intleak_data) # do it twice to test caching self.assertEqual(len(intleaks), 3) self.assertAlmostEqual(extleaks[0].coords.x, 0.067419, delta=1e-6) self.assertAlmostEqual(extleaks[0].coords.y, 0., delta=1e-6) self.assertAlmostEqual(extleaks[0].coords.z, 8.918919, delta=1e-6) self.assertAlmostEqual(extleaks[0].direction.x, 0.001, delta=1e-6) self.assertAlmostEqual(extleaks[0].direction.y, 0., delta=1e-6) self.assertAlmostEqual(extleaks[0].direction.z, 1., delta=1e-6) self.assertAlmostEqual(extleaks[0].weight[0], 0.042922, delta=1e-6) self.assertAlmostEqual(extleaks[1].coords.x, 0.058851, delta=1e-6) self.assertAlmostEqual(extleaks[1].coords.y, 0., delta=1e-6) self.assertAlmostEqual(extleaks[1].coords.z, 9., delta=1e-6) self.assertAlmostEqual(extleaks[1].direction.x, 0.000146, delta=1e-6) self.assertAlmostEqual(extleaks[1].direction.y, 0., delta=1e-6) self.assertAlmostEqual(extleaks[1].direction.z, 1., delta=1e-6) self.assertAlmostEqual(extleaks[1].weight[0], 0.001793, delta=1e-6) self.assertAlmostEqual(intleaks[0].coords.x, 0.048777, delta=1e-6) self.assertAlmostEqual(intleaks[0].coords.y, 0., delta=1e-6) self.assertAlmostEqual(intleaks[0].coords.z, 9., delta=1e-6) self.assertAlmostEqual(intleaks[0].direction.x, -0.001078, delta=1e-6) self.assertAlmostEqual(intleaks[0].direction.y, 0., delta=1e-6) self.assertAlmostEqual(intleaks[0].direction.z, 0.999999, delta=1e-6) self.assertAlmostEqual(intleaks[0].weight[0], 0.000143, delta=1e-6) self.assertAlmostEqual(intleaks[1].coords.x, 0.053113, delta=1e-6) self.assertAlmostEqual(intleaks[1].coords.y, 0., delta=1e-6) self.assertAlmostEqual(intleaks[1].coords.z, 9., delta=1e-6) self.assertAlmostEqual(intleaks[1].direction.x, -0.000511, delta=1e-6) self.assertAlmostEqual(intleaks[1].direction.y, 0., delta=1e-6) self.assertAlmostEqual(intleaks[1].direction.z, 1., delta=1e-6) self.assertAlmostEqual(intleaks[1].weight[0], 0.000352, delta=1e-6) self.assertAlmostEqual(intleaks[2].coords.x, 0.027487, delta=1e-6) self.assertAlmostEqual(intleaks[2].coords.y, 0., delta=1e-6) self.assertAlmostEqual(intleaks[2].coords.z, 9., delta=1e-6) self.assertAlmostEqual(intleaks[2].direction.x, -0.006149, delta=1e-6) self.assertAlmostEqual(intleaks[2].direction.y, 0., delta=1e-6) self.assertAlmostEqual(intleaks[2].direction.z, 0.999981, delta=1e-6) self.assertAlmostEqual(intleaks[2].weight[0], 0.000142, delta=1e-6) self.assertIsInstance(weights, np.ndarray) self.assertIsInstance(photon.get_exit_coords, VectorTuple) self.assertIsInstance(photon.get_exit_direction, VectorTuple) self.assertIsInstance(photon.get_exit_electric_vector, VectorTuple) del photon
def test_photon_good_coords(self): VectorTuple = polycap.VectorTuple start_coords = (0., 0. , 0.) start_direction = (0, 0, 1.0) start_electric_vector = (0.5, 0.5, 0.) photon = polycap.Photon(TestPolycapPhoton.description, start_coords, start_direction, start_electric_vector) weights = photon.launch(10.0, leak_calc=False) self.assertIsInstance(weights, np.ndarray) self.assertIsInstance(photon.get_exit_coords, VectorTuple) self.assertIsInstance(photon.get_exit_direction, VectorTuple) self.assertIsInstance(photon.get_exit_electric_vector, VectorTuple) self.assertIsInstance(photon.exit_coords, VectorTuple) self.assertIsInstance(photon.exit_direction, VectorTuple) self.assertIsInstance(photon.exit_electric_vector, VectorTuple) self.assertIsInstance(photon.start_coords, VectorTuple) self.assertIsInstance(photon.start_direction, VectorTuple) self.assertIsInstance(photon.start_electric_vector, VectorTuple) self.assertEqual(photon.i_refl, 0.) self.assertEqual(photon.d_travel, 0.)
def test_photon_bad_input(self): start_coords = (0., 0. , 0.) start_direction = ( 0.005, -0.005, 0.1) start_electric_vector = (0.5, 0.5, 0.) with self.assertRaises(ValueError): photon = polycap.Photon(None, start_coords, start_direction, start_electric_vector)
def test_photon_bad_coords(self): start_coords = (0.15104418, 0.087000430 , 0.) start_direction = ( 0., 0., 1.) start_electric_vector = (0.5, 0.5, 0.) photon = polycap.Photon(TestPolycapPhoton.description, start_coords, start_direction, start_electric_vector) self.assertIsNone(photon.launch(10.0))
# Define optic profile shape profile = polycap.Profile(polycap.Profile.ELLIPSOIDAL, optic_length, rad_ext_upstream, rad_ext_downstream, rad_int_upstream, rad_int_downstream, focal_dist_upstream, focal_dist_downstream) #Define optic description description = polycap.Description(profile, surface_rough, n_capillaries, composition, density) # Launches a single photon with given start coordinates, direction and electric vector start_coords = (0., 0., 0.) start_direction = (0, 0, 1.0) start_electric_vector = (0.5, 0.5, 0.) photon = polycap.Photon(description, start_coords, start_direction, start_electric_vector) weights = photon.launch(np.linspace(1, 25.0, 250)) # Calculate transmission efficiency curve of given optic source = polycap.Source(description, source_dist, source_rad_x, source_rad_y, source_div_x, source_div_y, source_shift_x, source_shift_y, source_polar, np.linspace(1, 25.0, 250)) efficiencies = source.get_transmission_efficiencies(n_threads, n_photons) # Use matplotlib to plot the data fig = plt.figure() ax = fig.add_subplot(111) ax.plot(*efficiencies.data, color='r') plt.draw() plt.show()