Example #1
0
    def setUp(self):
        TestCase.setUp(self)

        self.geo = PenelopeGeometry('Test Geometry')

        surface1 = zplane(1e-10)
        surface2 = zplane(-1e-3)
        surface3 = cylinder(1e-2)
        surface4 = xplane(0.0)

        mat1 = PenelopeMaterial.pure(29)
        self.module1 = Module(self.geo, mat1)
        self.module1.add_surface(surface1, SIDEPOINTER_NEGATIVE)
        self.module1.add_surface(surface2, SIDEPOINTER_POSITIVE)
        self.module1.add_surface(surface3, SIDEPOINTER_NEGATIVE)
        self.module1.add_surface(surface4, SIDEPOINTER_POSITIVE)
        self.geo.modules.add(self.module1)

        mat2 = PenelopeMaterial.pure(30)
        self.module2 = Module(self.geo, mat2)
        self.module2.add_surface(surface1, SIDEPOINTER_NEGATIVE)
        self.module2.add_surface(surface2, SIDEPOINTER_POSITIVE)
        self.module2.add_surface(surface3, SIDEPOINTER_NEGATIVE)
        self.module2.add_module(self.module1)
        self.geo.modules.add(self.module2)

        self.geo.tilt_rad = radians(45)
    def setUp(self):
        TestCase.setUp(self)

        self.geo = PenelopeGeometry('Test Geometry')

        surface1 = zplane(1e-10)
        surface2 = zplane(-1e-3)
        surface3 = cylinder(1e-2)
        surface4 = xplane(0.0)

        mat1 = PenelopeMaterial.pure(29)
        self.module1 = Module(self.geo, mat1)
        self.module1.add_surface(surface1, SIDEPOINTER_NEGATIVE)
        self.module1.add_surface(surface2, SIDEPOINTER_POSITIVE)
        self.module1.add_surface(surface3, SIDEPOINTER_NEGATIVE)
        self.module1.add_surface(surface4, SIDEPOINTER_POSITIVE)
        self.geo.modules.add(self.module1)

        mat2 = PenelopeMaterial.pure(30)
        self.module2 = Module(self.geo, mat2)
        self.module2.add_surface(surface1, SIDEPOINTER_NEGATIVE)
        self.module2.add_surface(surface2, SIDEPOINTER_POSITIVE)
        self.module2.add_surface(surface3, SIDEPOINTER_NEGATIVE)
        self.module2.add_module(self.module1)
        self.geo.modules.add(self.module2)

        self.geo.tilt_rad = radians(45)
Example #3
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))
Example #4
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))
Example #5
0
    def setUp(self):
        TestCase.setUp(self)

        intforce = InteractionForcing(ELECTRON, HARD_BREMSSTRAHLUNG_EMISSION,
                                      -4)
        mat1 = PenelopeMaterial.pure(29,
                                     interaction_forcings=[intforce],
                                     maximum_step_length_m=1e4)
        mat1._index = 1

        mat2 = VACUUM
        mat2._index = 0

        surface1 = SurfaceImplicit()
        surface1._index = 0

        surface2 = SurfaceImplicit()
        surface2._index = 1

        self.module2 = Module(None, mat2)
        self.module2._index = 1

        self.module1 = Module(None, mat1, 'Test')
        self.module1.add_surface(surface1, -1)
        self.module1.add_surface(surface2, 1)
        self.module1.add_module(self.module2)
        self.module1.rotation.phi_rad = radians(180)
        self.module1.shift.z_m = -1e3
        self.module1._index = 0

        self.materials_lookup = {0: mat2, 1: mat1}
        self.surfaces_lookup = {0: surface1, 1: surface2}
        self.modules_lookup = {0: self.module1, 1: self.module2}
Example #6
0
    def parse(self, element):
        mat = _MaterialXMLHandler.parse(self, element)

        elastic_scattering = (float(element.get('c1')),
                              float(element.get('c2')))
        cutoff_energy_inelastic_eV = float(element.get('wcc'))
        cutoff_energy_bremsstrahlung_eV = float(element.get('wcr'))

        interaction_forcings = []
        for subelement in element.findall('interactionForcing'):
            particle = _PARTICLES_LOOKUP[subelement.get('particle')]
            collision = _COLLISIONS_LOOKUP[subelement.get('collision')]
            forcer = float(subelement.get('forcer'))
            weight = (float(subelement.get('wlow')),
                      float(subelement.get('whigh')))
            interaction_forcings.append(
                InteractionForcing(particle, collision, forcer, weight))

        maximum_step_length_m = float(element.get('dsmax'))

        return PenelopeMaterial(mat.composition, mat.name, mat.density_kg_m3,
                                mat.absorption_energy_eV, elastic_scattering,
                                cutoff_energy_inelastic_eV,
                                cutoff_energy_bremsstrahlung_eV,
                                interaction_forcings, maximum_step_length_m)
    def setUp(self):
        TestCase.setUp(self)

        intforce = InteractionForcing(ELECTRON, HARD_BREMSSTRAHLUNG_EMISSION, -4)
        mat1 = PenelopeMaterial.pure(29, interaction_forcings=[intforce],
                             maximum_step_length_m=1e4)
        mat1._index = 1

        mat2 = VACUUM
        mat2._index = 0

        surface1 = SurfaceImplicit()
        surface1._index = 0

        surface2 = SurfaceImplicit()
        surface2._index = 1

        self.module2 = Module(None, mat2)
        self.module2._index = 1

        self.module1 = Module(None, mat1, 'Test')
        self.module1.add_surface(surface1, -1)
        self.module1.add_surface(surface2, 1)
        self.module1.add_module(self.module2)
        self.module1.rotation.phi_rad = radians(180)
        self.module1.shift.z_m = -1e3
        self.module1._index = 0

        self.materials_lookup = {0: mat2, 1: mat1}
        self.surfaces_lookup = {0: surface1, 1: surface2}
        self.modules_lookup = {0: self.module1, 1: self.module2}
    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)
Example #9
0
    def setUp(self):
        TestCase.setUp(self)

        if1 = InteractionForcing(ELECTRON, HARD_BREMSSTRAHLUNG_EMISSION,
                                 - 4, (0.1, 1.0))
        self.m = PenelopeMaterial({'Cu': 1.0}, 'Pure Cu', density_kg_m3=8960.0,
                                  elastic_scattering=(0.1, 0.2),
                                  cutoff_energy_inelastic_eV=51.2,
                                  cutoff_energy_bremsstrahlung_eV=53.4,
                                  interaction_forcings=[if1],
                                  maximum_step_length_m=123.456)
Example #10
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)
    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)
Example #12
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)
Example #13
0
    def _convert_geometry(self, options):
        # Replace material with PENLOPE material
        for old_material in options.geometry.get_materials():
            new_material = \
                PenelopeMaterial.from_material(old_material,
                                               self._elastic_scattering,
                                               self._cutoff_energy_inelastic_eV,
                                               self._cutoff_energy_bremsstrahlung_eV,
                                               self._interaction_forcings,
                                               self._maximum_step_length_m)
            replace_material(options, old_material, new_material)

        if not _Converter._convert_geometry(self, options):
            return False

        return True
Example #14
0
    def _createMaterial(self, parameters, varied):
        mat = _MaterialDialog._createMaterial(self, parameters, varied)

        c1 = parameters['c1']
        c2 = parameters['c2']
        wcc = parameters['wcc']
        wcr = parameters['wcr']
        dsmax = parameters['dsmax']
        forcings = parameters['forcings']

        return PenelopeMaterial(mat.composition, mat.name, mat.density_kg_m3,
                                mat.absorption_energy_eV,
                                elastic_scattering=(c1, c2),
                                cutoff_energy_inelastic_eV=wcc,
                                cutoff_energy_bremsstrahlung_eV=wcr,
                                interaction_forcings=forcings,
                                maximum_step_length_m=dsmax)
    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)
Example #16
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)
Example #17
0
    def _generateName(self, parameters, varied):
        name = parameters.pop('name')
        if name is None:
            name = PenelopeMaterial.generate_name(parameters['composition'])

        parts = [name]
        for key in varied:
            if key == 'composition':
                continue
            elif key == 'forcings':
                forcing = parameters[key][0]
                forcer = forcing.forcer
                wlow = forcing.weight[0]
                whigh = forcing.weight[1]
                parts.append('forcings={0:n}_{1:n}_{2:n}'.format(forcer, wlow, whigh))
            else:
                parts.append('{0:s}={1:n}'.format(key, parameters[key]))
        return '+'.join(parts)
Example #18
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))
Example #19
0
    def testpure(self):
        m = PenelopeMaterial.pure(29)

        self.assertEqual('Copper', str(m))

        self.assertTrue(29 in m.composition)
        self.assertAlmostEqual(1.0, m.composition[29], 4)

        self.assertAlmostEqual(8.96, m.density_kg_m3 / 1000.0, 4)

        self.assertAlmostEqual(50, m.absorption_energy_eV[ELECTRON], 4)
        self.assertAlmostEqual(50, m.absorption_energy_eV[PHOTON], 4)
        self.assertAlmostEqual(50, m.absorption_energy_eV[POSITRON], 4)

        self.assertAlmostEqual(0.0, m.elastic_scattering[0], 4)
        self.assertAlmostEqual(0.0, m.elastic_scattering[1], 4)

        self.assertAlmostEqual(50.0, m.cutoff_energy_inelastic_eV, 4)
        self.assertAlmostEqual(50.0, m.cutoff_energy_bremsstrahlung_eV, 4)

        self.assertEqual(0, len(m.interaction_forcings))

        self.assertAlmostEqual(1e20, m.maximum_step_length_m, 4)
Example #20
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        self.h = PenelopeMaterialXMLHandler()

        if1 = InteractionForcing(ELECTRON, HARD_BREMSSTRAHLUNG_EMISSION, -4,
                                 (0.1, 1.0))
        self.obj = PenelopeMaterial({'Cu': 1.0},
                                    'Pure Cu',
                                    density_kg_m3=8960.0,
                                    elastic_scattering=(0.1, 0.2),
                                    cutoff_energy_inelastic_eV=51.2,
                                    cutoff_energy_bremsstrahlung_eV=53.4,
                                    interaction_forcings=[if1],
                                    maximum_step_length_m=123.456)

        etree.register_namespace('mc', 'http://pymontecarlo.sf.net')
        etree.register_namespace('mc-pen',
                                 'http://pymontecarlo.sf.net/penelope')
        source = BytesIO(
            b'<mc-pen:material xmlns:mc-pen="http://pymontecarlo.sf.net/penelope" c1="0.1" c2="0.2" density="8960.0" dsmax="123.456" name="Pure Cu" wcc="51.2" wcr="53.4"><composition><element weightFraction="1.0" z="29" /></composition><interactionForcing collision="hard bremsstrahlung emission" forcer="-4" particle="electron" whigh="1.0" wlow="0.1" /></mc-pen:material>'
        )
        self.element = etree.parse(source).getroot()
Example #21
0
def __run():
    import sys
    from PySide.QtGui import QApplication

    material = \
        PenelopeMaterial({5: 0.5, 6: 0.5}, absorption_energy_eV={ELECTRON: 60.0},
                         elastic_scattering=(0.05, 0.1),
                         cutoff_energy_inelastic_eV=60.0,
                         cutoff_energy_bremsstrahlung_eV=70.0,
                         maximum_step_length_m=0.4,
                         interaction_forcings=[InteractionForcing(ELECTRON, DELTA, -2.0, (0.05, 0.6))])

    app = QApplication(sys.argv)

    dialog = PenelopeMaterialDialog(None)
    dialog.setValue(material)
    if dialog.exec_():
        values = dialog.values()
        print(len(values))
        for value in values:
            print(repr(value))

    app.exec_()