Exemplo n.º 1
0
class TestPenelopeConverter(TestCase):

    def setUp(self):
        TestCase.setUp(self)

        self.converter = Converter((0.1, 0.2), 51.2, 53.4)

    def tearDown(self):
        TestCase.tearDown(self)

    def testskeleton(self):
        self.assertTrue(True)

    def test_convert_geometry_substrate(self):
        # Base options
        ops = Options(name="Test")
        mat = Material.pure(29, absorption_energy_eV={POSITRON: 63.4})
        ops.geometry = Substrate(mat)
        ops.limits.add(TimeLimit(100))

        # Convert
        self.converter._convert_geometry(ops)

        # Test
        self.assertEqual('Copper', str(ops.geometry.body.material))

        for material in ops.geometry.get_materials():
            self.assertAlmostEqual(0.1, material.elastic_scattering[0], 4)
            self.assertAlmostEqual(0.2, material.elastic_scattering[1], 4)
            self.assertAlmostEqual(51.2, material.cutoff_energy_inelastic_eV, 4)
            self.assertAlmostEqual(53.4, material.cutoff_energy_bremsstrahlung_eV, 4)
            self.assertAlmostEqual(63.4, material.absorption_energy_eV[POSITRON], 4)
            self.assertAlmostEqual(1e20, material.maximum_step_length_m, 4)
Exemplo n.º 2
0
class TestPenelopeExporter(TestCase):
    def setUp(self):
        TestCase.setUp(self)

        self.tmpdir = tempfile.mkdtemp()
        self.e = Exporter(get_settings().penepma.pendbase)
        self.c = Converter()

    def tearDown(self):
        TestCase.tearDown(self)

        shutil.rmtree(self.tmpdir)

    def testskeleton(self):
        self.assertTrue(True)

    @attr('slow')
    def testexport_substrate(self):
        # Create
        mat1 = PenelopeMaterial({79: 0.5, 47: 0.5}, 'mat')

        ops = Options()
        ops.geometry = Substrate(mat1)
        ops.limits.add(TimeLimit(100))

        self.c._convert_geometry(ops)
        self.e.export_geometry(ops.geometry, self.tmpdir)

        # Test
        geofilepath = os.path.join(self.tmpdir, 'substrate.geo')
        repfilepath = os.path.join(self.tmpdir, 'geometry.rep')
        nmat, nbody = pengeom.init(geofilepath, repfilepath)

        self.assertEqual(1, nmat)
        self.assertEqual(2, nbody)

        matfilepath = os.path.join(self.tmpdir, 'mat1.mat')
        self.assertTrue(os.path.exists(matfilepath))

    @attr('slow')
    def testexport_inclusion(self):
        # Create
        mat1 = PenelopeMaterial({79: 0.5, 47: 0.5}, 'mat')
        mat2 = PenelopeMaterial({29: 0.5, 30: 0.5}, 'mat')

        ops = Options()
        ops.geometry = Inclusion(mat1, mat2, 0.01)
        ops.limits.add(TimeLimit(100))

        self.c._convert_geometry(ops)
        self.e.export_geometry(ops.geometry, self.tmpdir)

        # Test
        geofilepath = os.path.join(self.tmpdir, 'inclusion.geo')
        repfilepath = os.path.join(self.tmpdir, 'geometry.rep')
        nmat, nbody = pengeom.init(geofilepath, repfilepath)

        self.assertEqual(2, nmat)
        self.assertEqual(3, nbody)

        matfilepath = os.path.join(self.tmpdir, 'mat1.mat')
        self.assertTrue(os.path.exists(matfilepath))

        matfilepath = os.path.join(self.tmpdir, 'mat2.mat')
        self.assertTrue(os.path.exists(matfilepath))

    @attr('slow')
    def testexport_horizontal_layers(self):
        # Create
        mat1 = PenelopeMaterial({79: 0.5, 47: 0.5}, 'mat1')
        mat2 = PenelopeMaterial({29: 0.5, 30: 0.5}, 'mat2')
        mat3 = PenelopeMaterial({13: 0.5, 14: 0.5}, 'mat3')

        ops = Options()
        ops.beam.energy_eV = 1234
        ops.beam.diameter_m = 25e-9
        ops.beam.origin_m = (100e-9, 0, 1)

        ops.geometry = HorizontalLayers(mat1)
        ops.geometry.add_layer(mat2, 52e-9)
        ops.geometry.add_layer(mat3, 25e-9)

        ops.limits.add(TimeLimit(100))

        self.c._convert_geometry(ops)
        self.e.export_geometry(ops.geometry, self.tmpdir)

        # Test
        geofilepath = os.path.join(self.tmpdir, 'horizontallayers.geo')
        repfilepath = os.path.join(self.tmpdir, 'geometry.rep')
        nmat, nbody = pengeom.init(geofilepath, repfilepath)

        self.assertEqual(3, nmat)
        self.assertEqual(6, nbody)

        matfilepath = os.path.join(self.tmpdir, 'mat1.mat')
        self.assertTrue(os.path.exists(matfilepath))

        matfilepath = os.path.join(self.tmpdir, 'mat2.mat')
        self.assertTrue(os.path.exists(matfilepath))

        matfilepath = os.path.join(self.tmpdir, 'mat3.mat')
        self.assertTrue(os.path.exists(matfilepath))

    @attr('slow')
    def testexport_vertical_layers(self):
        # Create
        mat1 = PenelopeMaterial({79: 0.5, 47: 0.5}, 'mat1')
        mat2 = PenelopeMaterial({29: 0.5, 30: 0.5}, 'mat2')
        mat3 = PenelopeMaterial({13: 0.5, 14: 0.5}, 'mat3')

        ops = Options()
        ops.beam.energy_eV = 1234
        ops.beam.diameter_m = 25e-9
        ops.beam.origin_m = (100e-9, 0, 1)

        ops.geometry = VerticalLayers(mat1, mat2)
        ops.geometry.add_layer(mat3, 5e-3)

        ops.limits.add(TimeLimit(100))

        self.c._convert_geometry(ops)
        self.e.export_geometry(ops.geometry, self.tmpdir)

        # Test
        geofilepath = os.path.join(self.tmpdir, 'verticallayers.geo')
        repfilepath = os.path.join(self.tmpdir, 'geometry.rep')
        nmat, nbody = pengeom.init(geofilepath, repfilepath)

        self.assertEqual(3, nmat)
        self.assertEqual(4, nbody)

        matfilepath = os.path.join(self.tmpdir, 'mat1.mat')
        self.assertTrue(os.path.exists(matfilepath))

        matfilepath = os.path.join(self.tmpdir, 'mat2.mat')
        self.assertTrue(os.path.exists(matfilepath))

        matfilepath = os.path.join(self.tmpdir, 'mat3.mat')
        self.assertTrue(os.path.exists(matfilepath))

    @attr('slow')
    def testexport_sphere(self):
        # Create
        mat1 = PenelopeMaterial({79: 0.5, 47: 0.5}, 'mat')

        ops = Options()
        ops.geometry = Sphere(mat1, 0.01)
        ops.limits.add(TimeLimit(100))

        self.c._convert_geometry(ops)
        self.e.export_geometry(ops.geometry, self.tmpdir)

        # Test
        geofilepath = os.path.join(self.tmpdir, 'sphere.geo')
        repfilepath = os.path.join(self.tmpdir, 'geometry.rep')
        nmat, nbody = pengeom.init(geofilepath, repfilepath)

        self.assertEqual(1, nmat)
        self.assertEqual(2, nbody)

        matfilepath = os.path.join(self.tmpdir, 'mat1.mat')
        self.assertTrue(os.path.exists(matfilepath))
class TestPenelopeExporter(TestCase):
    def setUp(self):
        TestCase.setUp(self)

        self.tmpdir = tempfile.mkdtemp()
        self.e = Exporter(get_settings().penepma.pendbase)
        self.c = Converter()

    def tearDown(self):
        TestCase.tearDown(self)

        shutil.rmtree(self.tmpdir)

    def testskeleton(self):
        self.assertTrue(True)

    @attr("slow")
    def testexport_substrate(self):
        # Create
        mat1 = PenelopeMaterial({79: 0.5, 47: 0.5}, "mat")

        ops = Options()
        ops.geometry = Substrate(mat1)
        ops.limits.add(TimeLimit(100))

        self.c._convert_geometry(ops)
        self.e.export_geometry(ops.geometry, self.tmpdir)

        # Test
        geofilepath = os.path.join(self.tmpdir, "substrate.geo")
        repfilepath = os.path.join(self.tmpdir, "geometry.rep")
        nmat, nbody = pengeom.init(geofilepath, repfilepath)

        self.assertEqual(1, nmat)
        self.assertEqual(2, nbody)

        matfilepath = os.path.join(self.tmpdir, "mat1.mat")
        self.assertTrue(os.path.exists(matfilepath))

    @attr("slow")
    def testexport_inclusion(self):
        # Create
        mat1 = PenelopeMaterial({79: 0.5, 47: 0.5}, "mat")
        mat2 = PenelopeMaterial({29: 0.5, 30: 0.5}, "mat")

        ops = Options()
        ops.geometry = Inclusion(mat1, mat2, 0.01)
        ops.limits.add(TimeLimit(100))

        self.c._convert_geometry(ops)
        self.e.export_geometry(ops.geometry, self.tmpdir)

        # Test
        geofilepath = os.path.join(self.tmpdir, "inclusion.geo")
        repfilepath = os.path.join(self.tmpdir, "geometry.rep")
        nmat, nbody = pengeom.init(geofilepath, repfilepath)

        self.assertEqual(2, nmat)
        self.assertEqual(3, nbody)

        matfilepath = os.path.join(self.tmpdir, "mat1.mat")
        self.assertTrue(os.path.exists(matfilepath))

        matfilepath = os.path.join(self.tmpdir, "mat2.mat")
        self.assertTrue(os.path.exists(matfilepath))

    @attr("slow")
    def testexport_horizontal_layers(self):
        # Create
        mat1 = PenelopeMaterial({79: 0.5, 47: 0.5}, "mat1")
        mat2 = PenelopeMaterial({29: 0.5, 30: 0.5}, "mat2")
        mat3 = PenelopeMaterial({13: 0.5, 14: 0.5}, "mat3")

        ops = Options()
        ops.beam.energy_eV = 1234
        ops.beam.diameter_m = 25e-9
        ops.beam.origin_m = (100e-9, 0, 1)

        ops.geometry = HorizontalLayers(mat1)
        ops.geometry.add_layer(mat2, 52e-9)
        ops.geometry.add_layer(mat3, 25e-9)

        ops.limits.add(TimeLimit(100))

        self.c._convert_geometry(ops)
        self.e.export_geometry(ops.geometry, self.tmpdir)

        # Test
        geofilepath = os.path.join(self.tmpdir, "horizontallayers.geo")
        repfilepath = os.path.join(self.tmpdir, "geometry.rep")
        nmat, nbody = pengeom.init(geofilepath, repfilepath)

        self.assertEqual(3, nmat)
        self.assertEqual(6, nbody)

        matfilepath = os.path.join(self.tmpdir, "mat1.mat")
        self.assertTrue(os.path.exists(matfilepath))

        matfilepath = os.path.join(self.tmpdir, "mat2.mat")
        self.assertTrue(os.path.exists(matfilepath))

        matfilepath = os.path.join(self.tmpdir, "mat3.mat")
        self.assertTrue(os.path.exists(matfilepath))

    @attr("slow")
    def testexport_vertical_layers(self):
        # Create
        mat1 = PenelopeMaterial({79: 0.5, 47: 0.5}, "mat1")
        mat2 = PenelopeMaterial({29: 0.5, 30: 0.5}, "mat2")
        mat3 = PenelopeMaterial({13: 0.5, 14: 0.5}, "mat3")

        ops = Options()
        ops.beam.energy_eV = 1234
        ops.beam.diameter_m = 25e-9
        ops.beam.origin_m = (100e-9, 0, 1)

        ops.geometry = VerticalLayers(mat1, mat2)
        ops.geometry.add_layer(mat3, 5e-3)

        ops.limits.add(TimeLimit(100))

        self.c._convert_geometry(ops)
        self.e.export_geometry(ops.geometry, self.tmpdir)

        # Test
        geofilepath = os.path.join(self.tmpdir, "verticallayers.geo")
        repfilepath = os.path.join(self.tmpdir, "geometry.rep")
        nmat, nbody = pengeom.init(geofilepath, repfilepath)

        self.assertEqual(3, nmat)
        self.assertEqual(4, nbody)

        matfilepath = os.path.join(self.tmpdir, "mat1.mat")
        self.assertTrue(os.path.exists(matfilepath))

        matfilepath = os.path.join(self.tmpdir, "mat2.mat")
        self.assertTrue(os.path.exists(matfilepath))

        matfilepath = os.path.join(self.tmpdir, "mat3.mat")
        self.assertTrue(os.path.exists(matfilepath))

    @attr("slow")
    def testexport_sphere(self):
        # Create
        mat1 = PenelopeMaterial({79: 0.5, 47: 0.5}, "mat")

        ops = Options()
        ops.geometry = Sphere(mat1, 0.01)
        ops.limits.add(TimeLimit(100))

        self.c._convert_geometry(ops)
        self.e.export_geometry(ops.geometry, self.tmpdir)

        # Test
        geofilepath = os.path.join(self.tmpdir, "sphere.geo")
        repfilepath = os.path.join(self.tmpdir, "geometry.rep")
        nmat, nbody = pengeom.init(geofilepath, repfilepath)

        self.assertEqual(1, nmat)
        self.assertEqual(2, nbody)

        matfilepath = os.path.join(self.tmpdir, "mat1.mat")
        self.assertTrue(os.path.exists(matfilepath))