def setUp(self):
        super().setUp()

        self.testdatadir = os.path.join(os.path.dirname(__file__), '..',
                                        'testdata', 'pengeom')

        self.geo = Geometry('Test Geometry')

        surface1 = zplane(1e-8)
        surface2 = zplane(-1e-1)
        surface3 = cylinder(1.0)
        surface4 = xplane(0.0)

        self.mat1 = Material('copper', {29: 1.0}, 8.9)
        self.module1 = Module(self.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.add_module(self.module1)

        self.mat2 = Material('zinc', {30: 1.0}, 7.14)
        self.module2 = Module(self.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.add_module(self.module2)

        self.geo.tilt_deg = 45
def create_example1_disc():
    # Create materials
    material_cu = Material('Cu', {29: 1.0}, 8.9)

    # Create geometry
    module = Module(material_cu, 'Solid cylinder')
    module.add_surface(zplane(0.0), SIDEPOINTER_POSITIVE)
    module.add_surface(zplane(0.005), SIDEPOINTER_NEGATIVE)
    module.add_surface(cylinder(1.0), SIDEPOINTER_NEGATIVE)

    geometry = Geometry('A solid cylinder.')
    geometry.add_module(module)

    # Create input
    input = PenmainInput()

    input.TITLE.set('Point source and a homogeneous cylinder.')
    input.SKPAR.set(1)
    input.SENERG.set(40e3)
    input.SPOSIT.set(0.0, 0.0, -0.0001)
    input.SCONE.set(0.0, 0.0, 5.0)

    input.materials.add(1, material_cu.filename, 1e3, 1e3, 1e3, 0.05, 0.05,
                        1e3, 1e3)

    input.GEOMFN.set('disc.geo')
    input.PARINP.add(1, 0.005)
    input.PARINP.add(2, 0.01)
    input.DSMAX.add(1, 1e-4)

    input.IFORCE.add(1, 1, 4, 2000, 0.1, 2.0)
    input.IFORCE.add(1, 1, 5, 200, 0.1, 2.0)
    input.IBRSPL.add(1, 2)
    input.IXRSPL.add(1, 2)

    input.NBE.set(0, 0, 100)
    input.NBANGL.set(45, 18)

    detector = input.impact_detectors.add(0.0, 0.0, 100, 0, 2)
    detector.IDBODY.add(1)

    detector = input.energy_deposition_detectors.add(0, 0, 100)
    detector.EDBODY.add(1)

    input.GRIDZ.set(0, 0.005, 100)
    input.GRIDR.set(0.01, 50)

    input.RESUME.set('dump.dat')
    input.DUMPTO.set('dump.dat')
    input.DUMPP.set(60)

    input.NSIMSH.set(2e9)
    input.TIME.set(600)

    return input
Exemple #3
0
    def _export_sample_inclusion(self, sample, options, erracc, geometry,
                                 dsmaxs):
        self._validate_sample_inclusion(sample, options, erracc)

        # Surface
        inclusion_diameter_m = apply_lazy(sample.inclusion_diameter_m, sample,
                                          options)

        surface_cylinder = cylinder(100.0)  # 100 cm radius
        surface_top = zplane(0.0)  # z = 0
        surface_bottom = zplane(-100.0)  # z = -100 cm
        surface_sphere = sphere(inclusion_diameter_m / 2.0 * 100.0)

        # Inclusion module
        inclusion_material = apply_lazy(sample.inclusion_material, sample,
                                        options)
        penmaterial = self._export_material(inclusion_material,
                                            options,
                                            erracc,
                                            index=1)

        module_inclusion = Module(penmaterial, "Inclusion")
        module_inclusion.add_surface(surface_top, SidePointer.NEGATIVE)
        module_inclusion.add_surface(surface_sphere, SidePointer.NEGATIVE)

        dsmaxs[module_inclusion] = inclusion_diameter_m

        # Substrate module
        substrate_material = apply_lazy(sample.substrate_material, sample,
                                        options)
        penmaterial = self._export_material(substrate_material,
                                            options,
                                            erracc,
                                            index=2)

        module_substrate = Module(penmaterial, "Substrate")
        module_substrate.add_surface(surface_cylinder, SidePointer.NEGATIVE)
        module_substrate.add_surface(surface_top, SidePointer.NEGATIVE)
        module_substrate.add_surface(surface_bottom, SidePointer.POSITIVE)
        module_substrate.add_module(module_inclusion)

        # Geometry
        geometry.title = "Inclusion"
        geometry.add_module(module_substrate)
        geometry.add_module(module_inclusion)
        geometry.tilt_rad = apply_lazy(sample.tilt_rad, sample, options)
        geometry.rotation_rad = apply_lazy(sample.azimuth_rad, sample, options)
Exemple #4
0
    def _export_sample_substrate(self, sample, options, erracc, geometry,
                                 dsmaxs):
        self._validate_sample_substrate(sample, options, erracc)

        # Geometry
        surface_cylinder = cylinder(100)  # 100 cm radius
        surface_top = zplane(0.0)  # z = 0
        surface_bottom = zplane(-100)  # z = -100 cm

        material = apply_lazy(sample.material, sample, options)
        penmaterial = self._export_material(material, options, erracc, index=1)

        module = Module(penmaterial, "Substrate")
        module.add_surface(surface_cylinder, SidePointer.NEGATIVE)
        module.add_surface(surface_top, SidePointer.NEGATIVE)
        module.add_surface(surface_bottom, SidePointer.POSITIVE)

        geometry.title = "Substrate"
        geometry.add_module(module)
        geometry.tilt_rad = apply_lazy(sample.tilt_rad, sample, options)
        geometry.rotation_rad = apply_lazy(sample.azimuth_rad, sample, options)
Exemple #5
0
def create_epma2():
    # Create geometry
    surface_top = zplane(0.0)
    surface_bottom = zplane(-0.1)
    surface_cylinder = cylinder(1.0)
    surface_divider = xplane(0.0)

    module_right = Module(MATERIAL_CU, 'Right half of the sample')
    module_right.add_surface(surface_top, SIDEPOINTER_NEGATIVE)
    module_right.add_surface(surface_bottom, SIDEPOINTER_POSITIVE)
    module_right.add_surface(surface_cylinder, SIDEPOINTER_NEGATIVE)
    module_right.add_surface(surface_divider, SIDEPOINTER_POSITIVE)

    module_left = Module(MATERIAL_FE, 'Left half of the sample')
    module_left.add_surface(surface_top, SIDEPOINTER_NEGATIVE)
    module_left.add_surface(surface_bottom, SIDEPOINTER_POSITIVE)
    module_left.add_surface(surface_cylinder, SIDEPOINTER_NEGATIVE)
    module_left.add_module(module_right)

    geometry = Geometry('Cylindrical homogeneous foil')
    geometry.add_module(module_right)
    geometry.add_module(module_left)

    index_lookup = geometry.indexify()
    index_lookup[MATERIAL_CU] = 1
    index_lookup[MATERIAL_FE] = 2

    # Create input
    input = PenepmaInput()

    input.TITLE.set('A CU-Fe couple')
    input.SENERG.set(15e3)
    input.SPOSIT.set(2e-5, 0.0, 1.0)
    input.SDIREC.set(180, 0.0)
    input.SAPERT.set(0.0)

    input.materials.add(index_lookup[MATERIAL_FE], MATERIAL_FE.filename, 1e3,
                        1e3, 1e3, 0.2, 0.2, 1e3, 1e3)  # Note inversion
    input.materials.add(index_lookup[MATERIAL_CU], MATERIAL_CU.filename, 1e3,
                        1e3, 1e3, 0.2, 0.2, 1e3, 1e3)

    input.GEOMFN.set('epma2.geo')
    input.DSMAX.add(index_lookup[module_right], 1e-4)
    input.DSMAX.add(index_lookup[module_left], 1e-4)

    input.IFORCE.add(index_lookup[module_right], 1, 4, -5, 0.9, 1.0)
    input.IFORCE.add(index_lookup[module_right], 1, 5, -250, 0.9, 1.0)
    input.IFORCE.add(index_lookup[module_right], 2, 2, 10, 1e-3, 1.0)
    input.IFORCE.add(index_lookup[module_right], 2, 3, 10, 1e-3, 1.0)
    input.IFORCE.add(index_lookup[module_left], 1, 4, -5, 0.9, 1.0)
    input.IFORCE.add(index_lookup[module_left], 1, 5, -7, 0.9, 1.0)
    input.IFORCE.add(index_lookup[module_left], 2, 2, 10, 1e-3, 1.0)
    input.IFORCE.add(index_lookup[module_left], 2, 3, 10, 1e-3, 1.0)

    input.IBRSPL.add(index_lookup[module_right], 2)
    input.IBRSPL.add(index_lookup[module_left], 2)

    input.IXRSPL.add(index_lookup[module_right], 2)
    input.IXRSPL.add(index_lookup[module_left], 2)

    input.NBE.set(0, 0, 300)
    input.NBANGL.set(45, 30)

    input.photon_detectors.add(0, 90, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(5, 15, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(15, 25, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(25, 35, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(35, 45, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(45, 55, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(55, 65, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(65, 75, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(75, 85, 0, 360, 0, 0.0, 0.0, 1000)

    input.GRIDX.set(-1e-5, 5e-5, 60)
    input.GRIDY.set(-3e-5, 3e-5, 60)
    input.GRIDZ.set(-6e-5, 0.0, 60)
    input.XRLINE.add(26010300)
    input.XRLINE.add(29010300)

    input.RESUME.set('dump2.dat')
    input.DUMPTO.set('dump2.dat')
    input.DUMPP.set(60)

    input.RSEED.set(-10, 1)
    input.REFLIN.set(26010300, 1, 1.5e-3)
    input.NSIMSH.set(2e9)
    input.TIME.set(2e9)

    return input
Exemple #6
0
def create_epma1():
    # Create geometry
    module = Module(MATERIAL_CU, 'Sample')
    module.add_surface(zplane(0.0), SIDEPOINTER_NEGATIVE)
    module.add_surface(zplane(-0.1), SIDEPOINTER_POSITIVE)
    module.add_surface(cylinder(1.0), SIDEPOINTER_NEGATIVE)

    geometry = Geometry('Cylindrical homogeneous foil')
    geometry.add_module(module)

    index_lookup = geometry.indexify()

    # Create input
    input = PenepmaInput()

    input.TITLE.set('A Cu slab')
    input.SENERG.set(15e3)
    input.SPOSIT.set(0.0, 0.0, 1.0)
    input.SDIREC.set(180, 0.0)
    input.SAPERT.set(0.0)

    input.materials.add(index_lookup[MATERIAL_CU], MATERIAL_CU.filename, 1e3,
                        1e3, 1e3, 0.2, 0.2, 1e3, 1e3)

    input.GEOMFN.set('epma1.geo')
    input.DSMAX.add(index_lookup[module], 1e-4)

    input.IFORCE.add(index_lookup[module], 1, 4, -5, 0.9, 1.0)
    input.IFORCE.add(index_lookup[module], 1, 5, -250, 0.9, 1.0)
    input.IFORCE.add(index_lookup[module], 2, 2, 10, 1e-3, 1.0)
    input.IFORCE.add(index_lookup[module], 2, 3, 10, 1e-3, 1.0)
    input.IBRSPL.add(index_lookup[module], 2)
    input.IXRSPL.add(index_lookup[module], 2)

    input.NBE.set(0, 0, 300)
    input.NBANGL.set(45, 30)

    input.photon_detectors.add(0, 90, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(5, 15, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(15, 25, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(25, 35, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(35, 45, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(45, 55, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(55, 65, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(65, 75, 0, 360, 0, 0.0, 0.0, 1000)
    input.photon_detectors.add(75, 85, 0, 360, 0, 0.0, 0.0, 1000)

    input.GRIDX.set(-4e-5, 4e-5, 60)
    input.GRIDY.set(-4e-5, 4e-5, 60)
    input.GRIDZ.set(-6e-5, 0.0, 60)
    input.XRLINE.set(29010300)

    input.RESUME.set('dump1.dat')
    input.DUMPTO.set('dump1.dat')
    input.DUMPP.set(60)

    input.RSEED.set(-10, 1)
    input.REFLIN.set(29010300, 1, 1.25e-3)
    input.NSIMSH.set(2e9)
    input.TIME.set(2e9)

    return input
Exemple #7
0
    def _export_sample_verticallayers(self, sample, options, erracc, geometry,
                                      dsmaxs):
        self._validate_sample_verticallayers(sample, options, erracc)

        layers = apply_lazy(sample.layers, sample, options)
        xpositions_m = sample.layers_xpositions_m

        # Surfaces
        surface_cylinder = cylinder(100)  # 100 cm radius

        surface_top = zplane(0.0)  # z = 0

        depth_m = apply_lazy(sample.depth_m, sample, options)
        if math.isfinite(depth_m):
            surface_bottom = zplane(-depth_m * 100.0)
        else:
            surface_bottom = zplane(-100.0)  # z = -100 cm

        surface_layers = []
        if layers:
            for layer, (xmin_m, _xmax_m) in zip(layers, xpositions_m):
                surface = xplane(xmin_m * 100.0)
                surface_layers.append(surface)

            _xmin_m, xmax_m = xpositions_m[-1]
            surface = xplane(xmax_m * 100.0)
            surface_layers.append(surface)

        else:
            surface = xplane(0.0)
            surface_layers.append(surface)

        # Modules
        index = 1

        ## Left substrate
        left_material = apply_lazy(sample.left_material, sample, options)
        penmaterial = self._export_material(left_material, options, erracc,
                                            index)

        module = Module(penmaterial, "Left substrate")
        module.add_surface(surface_cylinder, SidePointer.NEGATIVE)
        module.add_surface(surface_top, SidePointer.NEGATIVE)
        module.add_surface(surface_bottom, SidePointer.POSITIVE)
        module.add_surface(surface_layers[0], SidePointer.NEGATIVE)

        if math.isfinite(depth_m):
            dsmaxs[module] = depth_m

        geometry.add_module(module)
        index += 1

        ## Layers
        for layer, (surface_left,
                    surface_right) in zip(layers, _pairwise(surface_layers)):
            material = apply_lazy(layer.material, layer, options)
            penmaterial = self._export_material(material, options, erracc,
                                                index)

            module = Module(penmaterial, "Layer {}".format(index - 1))
            module.add_surface(surface_cylinder, SidePointer.NEGATIVE)
            module.add_surface(surface_top, SidePointer.NEGATIVE)
            module.add_surface(surface_bottom, SidePointer.POSITIVE)
            module.add_surface(surface_left, SidePointer.POSITIVE)
            module.add_surface(surface_right, SidePointer.NEGATIVE)

            thickness_m = apply_lazy(layer.thickness_m, layer, options)
            dsmaxs[module] = min(thickness_m, depth_m)

            geometry.add_module(module)
            index += 1

        ## Right substrate
        right_material = apply_lazy(sample.right_material, sample, options)
        penmaterial = self._export_material(right_material, options, erracc,
                                            index)

        module = Module(penmaterial, "Right substrate")
        module.add_surface(surface_cylinder, SidePointer.NEGATIVE)
        module.add_surface(surface_top, SidePointer.NEGATIVE)
        module.add_surface(surface_bottom, SidePointer.POSITIVE)
        module.add_surface(surface_layers[-1], SidePointer.POSITIVE)

        if math.isfinite(depth_m):
            dsmaxs[module] = depth_m

        geometry.title = "Vertical layers"
        geometry.add_module(module)
        geometry.tilt_rad = apply_lazy(sample.tilt_rad, sample, options)
        geometry.rotation_rad = apply_lazy(sample.azimuth_rad, sample, options)
Exemple #8
0
    def _export_sample_horizontallayers(self, sample, options, erracc,
                                        geometry, dsmaxs):
        self._validate_sample_horizontallayers(sample, options, erracc)

        layers = apply_lazy(sample.layers, sample, options)
        zpositions_m = sample.layers_zpositions_m

        # Surfaces
        surface_cylinder = cylinder(100)  # 100 cm radius

        surface_layers = [zplane(0.0)]
        for layer, (zmin_m, _zmax_m) in zip(layers, zpositions_m):
            surface = zplane(zmin_m * 100.0)
            surface_layers.append(surface)

        # Modules
        index = 0
        tmpgrouping = []
        for layer, (surface_top,
                    surface_bottom) in zip(layers, _pairwise(surface_layers)):
            material = apply_lazy(layer.material, layer, options)
            penmaterial = self._export_material(material, options, erracc,
                                                index)

            module = Module(penmaterial, "Layer {}".format(index))
            module.add_surface(surface_cylinder, SidePointer.NEGATIVE)
            module.add_surface(surface_top, SidePointer.NEGATIVE)
            module.add_surface(surface_bottom, SidePointer.POSITIVE)

            thickness_m = apply_lazy(layer.thickness_m, layer, options)
            dsmaxs[module] = thickness_m

            geometry.add_module(module)
            tmpgrouping.append((module, surface_bottom))

            index += 1

        if sample.has_substrate():
            surface_top = surface_layers[-1]
            surface_bottom = zplane(surface_top.shift.z_cm -
                                    100)  # 100 cm below last layer

            substrate_material = apply_lazy(sample.substrate_material, sample,
                                            options)
            penmaterial = self._export_material(substrate_material, options,
                                                erracc, index)

            module = Module(penmaterial, "Substrate")
            module.add_surface(surface_cylinder, SidePointer.NEGATIVE)
            module.add_surface(surface_top, SidePointer.NEGATIVE)
            module.add_surface(surface_bottom, SidePointer.POSITIVE)

            geometry.add_module(module)
            tmpgrouping.append((module, surface_bottom))

        # Grouping
        # G0: s0, s2, m0, m1
        # G1: s0, s3, m2, g0
        # G2: s0, s4, m3, g1
        # etc.

        if len(tmpgrouping) <= 2:  # no grouping required if only 2 modules
            return

        module, surface_bottom = tmpgrouping[1]

        group = Module(PENELOPE_VACUUM, "grouping")
        group.add_surface(surface_cylinder, SidePointer.NEGATIVE)
        group.add_surface(surface_layers[0],
                          SidePointer.NEGATIVE)  # top z = 0.0
        group.add_surface(surface_bottom, SidePointer.POSITIVE)
        group.add_module(tmpgrouping[0][0])  # m0
        group.add_module(module)  # m1

        geometry.add_module(group)

        for module, surface_bottom in tmpgrouping[2:]:
            oldgroup = group

            group = Module(PENELOPE_VACUUM, "grouping")
            group.add_surface(surface_cylinder, SidePointer.NEGATIVE)
            group.add_surface(surface_layers[0],
                              SidePointer.NEGATIVE)  # top z = 0.0
            group.add_surface(surface_bottom, SidePointer.POSITIVE)
            group.add_module(module)
            group.add_module(oldgroup)

            geometry.add_module(group)

        geometry.title = "Horizontal layers"
        geometry.tilt_rad = apply_lazy(sample.tilt_rad, sample, options)
        geometry.rotation_rad = apply_lazy(sample.azimuth_rad, sample, options)