Beispiel #1
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)
Beispiel #2
0
    def _create_extra_module(self):
        extra = Module(VACUUM,
                       description='Extra module for rotation and tilt')

        ## Find all unlinked modules
        all_modules = set(self.get_modules())
        linked_modules = set(
            chain(*map(methodcaller('get_modules'), all_modules)))
        unlinked_modules = all_modules - linked_modules
        for module in unlinked_modules:
            extra.add_module(module)

        ## Change of Euler angles convention from ZXZ to ZYZ
        extra.rotation.omega_deg = (self.rotation_deg - 90.0) % 360.0
        extra.rotation.theta_deg = self.tilt_deg
        extra.rotation.phi_deg = 90.0

        return extra
Beispiel #3
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
Beispiel #4
0
class TestModule(unittest.TestCase):

    LINES1 = [
        'MODULE  (   1) Test', 'MATERIAL(   1)',
        'SURFACE (   1), SIDE POINTER=(-1)',
        'SURFACE (   2), SIDE POINTER=( 1)', 'MODULE  (   2)',
        '1111111111111111111111111111111111111111111111111111111111111111',
        '  OMEGA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '  THETA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '    PHI=(+1.800000000000000E+02,   0) DEG          (DEFAULT=0.0)',
        'X-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Y-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Z-SHIFT=(-1.000000000000000E+05,   0)              (DEFAULT=0.0)',
        '0000000000000000000000000000000000000000000000000000000000000000'
    ]
    LINES2 = [
        'MODULE  (   2) ', 'MATERIAL(   0)',
        '1111111111111111111111111111111111111111111111111111111111111111',
        '  OMEGA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '  THETA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '    PHI=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        'X-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Y-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Z-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        '0000000000000000000000000000000000000000000000000000000000000000'
    ]

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

        self.mat1 = Material('copper', {29: 1.0}, 8.9)

        self.surface1 = SurfaceImplicit()
        self.surface2 = SurfaceImplicit()

        self.module2 = Module(VACUUM)

        self.module1 = Module(self.mat1, 'Test')
        self.module1.add_surface(self.surface1, -1)
        self.module1.add_surface(self.surface2, 1)
        self.module1.add_module(self.module2)
        self.module1.rotation.phi_deg = 180
        self.module1.shift.z_cm = -1e5

    def _test_module1(self, module1):
        self.assertEqual('copper', module1.material.name)
        self.assertEqual('Test', module1.description)
        self.assertAlmostEqual(180, module1.rotation.phi_deg, 4)
        self.assertAlmostEqual(-1e5, module1.shift.z_cm, 4)
        self.assertEqual(2, len(module1.get_surfaces()))
        self.assertEqual(1, len(module1.get_modules()))

    def _test_module2(self, module2):
        self.assertEqual(str(VACUUM), str(module2.material))
        self.assertEqual(0, len(module2.get_surfaces()))
        self.assertEqual(0, len(module2.get_modules()))

    def testskeleton(self):
        self._test_module1(self.module1)
        self._test_module2(self.module2)

    def test_write_read(self):
        material_lookup = {0: VACUUM, 1: self.mat1}
        surface_lookup = {1: self.surface1, 2: self.surface2}
        module_lookup = {2: self.module2}
        index_lookup = {
            VACUUM: 0,
            self.mat1: 1,
            self.surface1: 1,
            self.surface2: 2,
            self.module1: 1,
            self.module2: 2
        }

        # Module 1
        fileobj = io.StringIO()

        try:
            self.module1._write(fileobj, index_lookup)

            lines = fileobj.getvalue().splitlines()
            self.assertListEqual(self.LINES1, lines)

            fileobj.seek(0)
            module = Module()
            module._read(fileobj, material_lookup, surface_lookup,
                         module_lookup)
            self._test_module1(module)
        finally:
            fileobj.close()

        # Module 2
        fileobj = io.StringIO()

        try:
            self.module2._write(fileobj, index_lookup)

            lines = fileobj.getvalue().splitlines()
            self.assertListEqual(self.LINES2, lines)

            fileobj.seek(0)
            module = Module()
            module._read(fileobj, material_lookup, surface_lookup,
                         module_lookup)
            self._test_module2(module)
        finally:
            fileobj.close()
Beispiel #5
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)
class TestGeometry(unittest.TestCase):

    LINES = [
        'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
        '       Test Geometry',
        '0000000000000000000000000000000000000000000000000000000000000000',
        'SURFACE (   1) Plane Z=0.00 m', 'INDICES=( 0, 0, 0, 1, 0)',
        'X-SCALE=(+1.000000000000000E+00,   0)              (DEFAULT=1.0)',
        'Y-SCALE=(+1.000000000000000E+00,   0)              (DEFAULT=1.0)',
        'Z-SCALE=(+1.000000000000000E+00,   0)              (DEFAULT=1.0)',
        '  OMEGA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '  THETA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '    PHI=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        'X-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Y-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Z-SHIFT=(+1.000000000000000E-08,   0)              (DEFAULT=0.0)',
        '0000000000000000000000000000000000000000000000000000000000000000',
        'SURFACE (   2) Cylinder of radius 0.01 m along z-axis',
        'INDICES=( 1, 1, 0, 0,-1)',
        'X-SCALE=(+1.000000000000000E-02,   0)              (DEFAULT=1.0)',
        'Y-SCALE=(+1.000000000000000E-02,   0)              (DEFAULT=1.0)',
        'Z-SCALE=(+1.000000000000000E+00,   0)              (DEFAULT=1.0)',
        '  OMEGA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '  THETA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '    PHI=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        'X-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Y-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Z-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        '0000000000000000000000000000000000000000000000000000000000000000',
        'SURFACE (   3) Plane Z=-0.00 m', 'INDICES=( 0, 0, 0, 1, 0)',
        'X-SCALE=(+1.000000000000000E+00,   0)              (DEFAULT=1.0)',
        'Y-SCALE=(+1.000000000000000E+00,   0)              (DEFAULT=1.0)',
        'Z-SCALE=(+1.000000000000000E+00,   0)              (DEFAULT=1.0)',
        '  OMEGA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '  THETA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '    PHI=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        'X-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Y-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Z-SHIFT=(-1.000000000000000E-01,   0)              (DEFAULT=0.0)',
        '0000000000000000000000000000000000000000000000000000000000000000',
        'SURFACE (   4) Plane X=0.00 m', 'INDICES=( 0, 0, 0, 1, 0)',
        'X-SCALE=(+1.000000000000000E+00,   0)              (DEFAULT=1.0)',
        'Y-SCALE=(+1.000000000000000E+00,   0)              (DEFAULT=1.0)',
        'Z-SCALE=(+1.000000000000000E+00,   0)              (DEFAULT=1.0)',
        '  OMEGA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '  THETA=(+9.000000000000000E+01,   0) DEG          (DEFAULT=0.0)',
        '    PHI=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        'X-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Y-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Z-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        '0000000000000000000000000000000000000000000000000000000000000000',
        'MODULE  (   1) ', 'MATERIAL(   1)',
        'SURFACE (   1), SIDE POINTER=(-1)',
        'SURFACE (   2), SIDE POINTER=(-1)',
        'SURFACE (   3), SIDE POINTER=( 1)',
        'SURFACE (   4), SIDE POINTER=( 1)',
        '1111111111111111111111111111111111111111111111111111111111111111',
        '  OMEGA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '  THETA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '    PHI=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        'X-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Y-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Z-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        '0000000000000000000000000000000000000000000000000000000000000000',
        'MODULE  (   2) ', 'MATERIAL(   2)',
        'SURFACE (   1), SIDE POINTER=(-1)',
        'SURFACE (   2), SIDE POINTER=(-1)',
        'SURFACE (   3), SIDE POINTER=( 1)', 'MODULE  (   1)',
        '1111111111111111111111111111111111111111111111111111111111111111',
        '  OMEGA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '  THETA=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        '    PHI=(+0.000000000000000E+00,   0) DEG          (DEFAULT=0.0)',
        'X-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Y-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Z-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        '0000000000000000000000000000000000000000000000000000000000000000',
        'MODULE  (   3) Extra module for rotation and tilt', 'MATERIAL(   0)',
        'MODULE  (   2)',
        '1111111111111111111111111111111111111111111111111111111111111111',
        '  OMEGA=(+2.700000000000000E+02,   0) DEG          (DEFAULT=0.0)',
        '  THETA=(+4.500000000000000E+01,   0) DEG          (DEFAULT=0.0)',
        '    PHI=(+9.000000000000000E+01,   0) DEG          (DEFAULT=0.0)',
        'X-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Y-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        'Z-SHIFT=(+0.000000000000000E+00,   0)              (DEFAULT=0.0)',
        '0000000000000000000000000000000000000000000000000000000000000000',
        'END      0000000000000000000000000000000000000000000000000000000'
    ]

    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 _test_geometry(self, geometry):
        self.assertEqual('Test Geometry', geometry.title)
        self.assertEqual(3, len(geometry.get_modules()))
        self.assertEqual(4, len(geometry.get_surfaces()))
        self.assertEqual(3, len(geometry.get_materials()))

    def testskeleton(self):
        self.assertEqual('Test Geometry', self.geo.title)
        self.assertEqual(2, len(self.geo.get_modules()))
        self.assertEqual(4, len(self.geo.get_surfaces()))
        self.assertEqual(2, len(self.geo.get_materials()))
        self.assertAlmostEqual(45, self.geo.tilt_deg, 4)
        self.assertAlmostEqual(0.0, self.geo.rotation_deg, 4)

    def testindexify(self):
        index_lookup = self.geo.indexify()

        # 4 surfaces, 2 materials, 2 modules, 1 extra module
        self.assertEqual(4 + 2 + 2 + 1, len(index_lookup))

        index_lookup2 = self.geo.indexify()
        self.assertDictEqual(index_lookup, index_lookup2)

    def testwriteread(self):
        material_lookup = {0: VACUUM, 1: self.mat1, 2: self.mat2}
        fileobj = io.StringIO()

        try:
            self.geo.write(fileobj)

            fileobj.seek(0)
            lines = fileobj.getvalue().splitlines()
            self.assertListEqual(self.LINES[:3], lines[:3])
            self.assertEqual(self.LINES[14], lines[14])
            self.assertEqual(self.LINES[26], lines[26])
            self.assertEqual(self.LINES[38], lines[38])
            self.assertEqual(self.LINES[50], lines[50])
            self.assertEqual(self.LINES[51], lines[51])
            self.assertListEqual(self.LINES[57:65], lines[57:65])
            self.assertEqual(self.LINES[65], lines[65])
            self.assertListEqual(self.LINES[71:], lines[71:])

            fileobj.seek(0)
            geometry = Geometry()
            geometry.read(fileobj, material_lookup)

            self._test_geometry(geometry)

            index_lookup = geometry.indexify()
            self.assertEqual(4 + 3 + 3, len(index_lookup))
        finally:
            fileobj.close()

    def test_epma1_read(self):
        material_lookup = {1: self.mat1}

        filepath = os.path.join(self.testdatadir, 'epma1.geo')
        geometry = Geometry()
        with open(filepath, 'r') as fp:
            geometry.read(fp, material_lookup)

        self.assertEqual('Cylindrical homogeneous foil', geometry.title)
        self.assertEqual(3, len(geometry.get_surfaces()))
        self.assertEqual(1, len(geometry.get_modules()))
        self.assertEqual(1, len(geometry.get_materials()))

    def test_epma2_read(self):
        material_lookup = {1: self.mat1, 2: self.mat2}

        filepath = os.path.join(self.testdatadir, 'epma2.geo')
        geometry = Geometry()
        with open(filepath, 'r') as fp:
            geometry.read(fp, material_lookup)

        self.assertEqual('Cylindrical foil with a material couple',
                         geometry.title)
        self.assertEqual(4, len(geometry.get_surfaces()))
        self.assertEqual(2, len(geometry.get_modules()))
        self.assertEqual(2, len(geometry.get_materials()))