Esempio n. 1
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