コード例 #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)
コード例 #2
0
    def export_geometry(self, geometry, outputdir):
        """
        Exports geometry to a *geo* file and all materials to *mat* files.

        :arg geometry: :geometry object

        :arg outputdir: full path to a directory where the files will be saved.
            Note that any conflicting files will be overwritten without warnings.

        :return: a :class:`tuple` and a list of :class:`tuple`.
            The class:`tuple` contains 2 items: the :class:`PenelopeGeometry`
            object used to create the *geo* file and the full path of this
            *geo* file.
            Each :class:`tuple` in the list contains 2 items: the
            :class:`PenelopeMaterial` object and its associated *mat* filepath.
            The order of the materials is the same as they appear in the
            geometry file.
            In other words, the first material has an index of 1 in the
            geometry file.
        """
        # Save geometry
        title = geometry.__class__.__name__.lower()
        pengeom = PenelopeGeometry(title)
        pengeom.tilt_rad = geometry.tilt_rad
        pengeom.rotation_rad = geometry.rotation_rad

        self._export_geometry(geometry, pengeom)

        lines = pengeom.to_geo()
        geofilepath = os.path.join(outputdir, title + ".geo")
        with open(geofilepath, 'w') as f:
            for line in lines:
                f.write(line + '\n')

        # Save materials
        matinfos = []
        for material in pengeom.get_materials():
            if material is VACUUM: continue
            index = material._index

            filepath = os.path.join(outputdir, 'mat%i.mat' % index)

            penmaterial.create(material.name, dict(material.composition),
                               material.density_kg_m3, filepath,
                               self._pendbase_dir)

            matinfos.append((material, filepath))

        return (pengeom, geofilepath), matinfos