def testexport_multilayers1(self):
        # Create options
        mat1 = Material({79: 0.5, 47: 0.5}, "Mat1", absorption_energy_eV={ELECTRON: 123.0})
        mat2 = Material({29: 0.5, 30: 0.5}, "Mat2", absorption_energy_eV={ELECTRON: 89.0})
        mat3 = Material({13: 0.5, 14: 0.5}, "Mat3", absorption_energy_eV={ELECTRON: 89.0})

        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, 25e-9)
        ops.geometry.add_layer(mat3, 55e-9)

        ops.limits.add(ShowersLimit(5678))

        # Export to CAS
        casfile = self.e.export_cas(ops)

        # Test
        simdata = casfile.getOptionSimulationData()
        simops = simdata.getSimulationOptions()
        regionops = simdata.getRegionOptions()

        self.assertAlmostEqual(1.234, simops.getIncidentEnergy_keV(0), 4)
        self.assertAlmostEqual(34.93392125, simops.Beam_Diameter, 4)  # FWHM
        self.assertAlmostEqual(100.0, simops._positionStart_nm, 4)

        self.assertEqual(3, regionops.getNumberRegions())

        region = regionops.getRegion(0)
        elements = list(map(attrgetter("Z"), region.getElements()))
        self.assertAlmostEqual(mat2.density_kg_m3 / 1000.0, region.Rho, 4)
        self.assertEqual("Mat2", region.Name)
        self.assertEqual(2, len(elements))
        self.assertTrue(29 in elements)
        self.assertTrue(30 in elements)

        region = regionops.getRegion(1)
        elements = list(map(attrgetter("Z"), region.getElements()))
        self.assertAlmostEqual(mat3.density_kg_m3 / 1000.0, region.Rho, 4)
        self.assertEqual("Mat3", region.Name)
        self.assertEqual(2, len(elements))
        self.assertTrue(13 in elements)
        self.assertTrue(14 in elements)

        region = regionops.getRegion(2)
        elements = list(map(attrgetter("Z"), region.getElements()))
        self.assertAlmostEqual(mat1.density_kg_m3 / 1000.0, region.Rho, 4)
        self.assertEqual("Mat1", region.Name)
        self.assertEqual(2, len(elements))
        self.assertTrue(79 in elements)
        self.assertTrue(47 in elements)

        self.assertAlmostEqual(0.089, simops.Eminimum, 3)

        self.assertEqual(5678, simops.getNumberElectrons())

        self.assertFalse(simops.FEmissionRX)
Ejemplo n.º 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))
Ejemplo n.º 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))
    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))
    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))
Ejemplo n.º 6
0
    def _run(self, element):
        self._update_status(0.1, "Check version")
        if self.is_cancelled():
            return
        version = self._read_version(element)
        if version != VERSION:
            raise ValueError("Incompatible version: %s != %s" % (version, VERSION))

        self._update_status(0.13, "Reading name")
        if self.is_cancelled():
            return
        name = self._read_name(element)
        options = Options(name)

        self._update_status(0.16, "Reading UUID")
        if self.is_cancelled():
            return
        options._uuid = self._read_uuid(element)

        self._update_status(0.2, "Reading programs")
        if self.is_cancelled():
            return
        options.programs.update(self._read_programs(element))

        self._update_status(0.3, "Reading beams")
        if self.is_cancelled():
            return
        options.beam = self._read_beams(element)

        self._update_status(0.4, "Reading geometries")
        if self.is_cancelled():
            return
        options.geometry = self._read_geometries(element)

        self._update_status(0.6, "Reading detectors")
        if self.is_cancelled():
            return
        options.detectors.update(self._read_detectors(element))

        self._update_status(0.8, "Reading limits")
        if self.is_cancelled():
            return
        options.limits.update(self._read_limits(element))

        self._update_status(0.9, "Reading models")
        if self.is_cancelled():
            return
        options.models.update(self._read_models(element))

        return options
Ejemplo n.º 7
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)
Ejemplo n.º 8
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))
    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))