コード例 #1
0
    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))
コード例 #2
0
    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))
コード例 #3
0
    def test_append_photon_detectors_maxchannels(self):
        ops = Options()
        ops.limits.add(TimeLimit(100))
        ops.detectors['spectrum'] = \
            PhotonSpectrumDetector((radians(35), radians(45)), (0, radians(360.0)),
                                   50000, (0, 1000))

        opss = self.c.convert(ops)

        self.e.export(opss[0], self.tmpdir)
コード例 #4
0
    def testconvert_nolimit(self):
        # Base options
        ops = Options(name="Test")
        ops.detectors['trajectories'] = TrajectoryDetector(100)
        ops.limits.add(TimeLimit(1))

        # Convert
        opss = self.converter.convert(ops)

        # Test
        self.assertEqual(0, len(opss))
コード例 #5
0
    def test_append_photon_detectors_maxlimit(self):
        ops = Options()
        ops.limits.add(TimeLimit(100))

        for i in range(MAX_PHOTON_DETECTORS + 1):
            ops.detectors['det%i' % i] = \
                PhotonSpectrumDetector((radians(i), radians(45)), (0, radians(360.0)),
                                       500, (0, 1000))

        opss = self.c.convert(ops)
        self.assertRaises(ExporterException, self.e.export, opss[0],
                          self.tmpdir)
コード例 #6
0
    def testinteraction_forcing(self):
        ops = Options()
        ops.beam.energy_eV = 30e3
        intfor = InteractionForcing(ELECTRON, HARD_ELASTIC, -40)
        ops.geometry.material = PenelopeMaterial.pure(
            29, interaction_forcings=[intfor])
        ops.detectors['det1'] = TimeDetector()
        ops.limits.add(TimeLimit(100))

        opss = self.c.convert(ops)

        self.e.export(opss[0], self.tmpdir)
コード例 #7
0
    def test_photon_depth_detector(self):
        # Create
        ops = Options(name='test1')
        ops.beam.energy_eV = 30e3
        ops.geometry.body.material = PenelopeMaterial.pure(29)
        ops.detectors['prz'] = \
            PhotonDepthDetector((radians(0), radians(90)), (0, radians(360.0)),
                                500, [Transition(29, siegbahn='Ka1')])
        ops.limits.add(TimeLimit(100))

        # Export
        opss = self.c.convert(ops)
        self.e.export(opss[0], self.tmpdir)
コード例 #8
0
    def testexport(self):
        # Create
        ops = Options(name='test1')
        ops.beam.energy_eV = 30e3
        ops.geometry.body.material = PenelopeMaterial.pure(29)
        ops.detectors['x-ray'] = \
            PhotonIntensityDetector((radians(35), radians(45)), (0, radians(360.0)))
        ops.detectors['spectrum'] = \
            PhotonSpectrumDetector((radians(35), radians(45)), (0, radians(360.0)), 500, (0, 1000))
        ops.detectors['prz'] = \
            PhotonDepthDetector((radians(0), radians(90)), (0, radians(360.0)), 500)
        ops.limits.add(TimeLimit(100))
        ops.limits.add(
            UncertaintyLimit(Transition(29, siegbahn='Ka1'), 'x-ray', 0.05))

        # Export
        opss = self.c.convert(ops)
        self.e.export(opss[0], self.tmpdir)
コード例 #9
0
    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)
コード例 #10
0
    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))
コード例 #11
0
    def testconvert_pencilbeam(self):
        # Base options
        ops = Options(name="Test")
        ops.beam = PencilBeam(1234)
        ops.detectors['det1'] = TimeDetector()
        ops.limits.add(TimeLimit(100))

        # Convert
        with warnings.catch_warnings(record=True) as ws:
            opss = self.converter.convert(ops)

        # 7 warning:
        # PencilBeam -> GaussianBeam
        # Set default models (6)
        self.assertEqual(1, len(opss))
        self.assertEqual(7, len(ws))

        # Test
        self.assertAlmostEqual(1234, opss[0].beam.energy_eV, 4)
        self.assertAlmostEqual(0.0, opss[0].beam.diameter_m, 4)

        self.assertEqual(6, len(opss[0].models))