Пример #1
0
    def export_to_xml(self, filename='mgxs.xml'):
        """Create an mgxs.xml file that can be used for a
        simulation.

        Parameters
        ----------
        filename : str, optional
            filename of file, default is mgxs.xml

        """

        # Reset xml element tree
        self._cross_sections_file.clear()

        self._create_groups_subelement()
        self._create_group_structure_subelement()
        self._create_inverse_velocities_subelement()
        self._create_xsdata_subelements()

        # Clean the indentation in the file to be user-readable
        sort_xml_elements(self._cross_sections_file)
        clean_xml_indentation(self._cross_sections_file)

        # Write the XML Tree to the xsdatas.xml file
        tree = ET.ElementTree(self._cross_sections_file)
        tree.write(filename, xml_declaration=True,
                   encoding='utf-8', method='xml')
Пример #2
0
    def export_to_xml(self):
        """Create a cmfd.xml file using the class data that can be used for an OpenMC
        simulation.

        """

        self._create_begin_subelement()
        self._create_dhat_reset_subelement()
        self._create_display_subelement()
        self._create_downscatter_subelement()
        self._create_feedback_subelement()
        self._create_gauss_seidel_tolerance_subelement()
        self._create_ktol_subelement()
        self._create_mesh_subelement()
        self._create_norm_subelement()
        self._create_power_monitor_subelement()
        self._create_run_adjoint_subelement()
        self._create_shift_subelement()
        self._create_spectral_subelement()
        self._create_stol_subelement()
        self._create_tally_reset_subelement()
        self._create_write_matrices_subelement()

        # Clean the indentation in the file to be user-readable
        clean_xml_indentation(self._cmfd_file)

        # Write the XML Tree to the cmfd.xml file
        tree = ET.ElementTree(self._cmfd_file)
        tree.write("cmfd.xml", xml_declaration=True,
                   encoding='utf-8', method="xml")
Пример #3
0
    def export_to_xml(self, path='cross_sections.xml'):
        """Export cross section data library to an XML file.

        Parameters
        ----------
        path : str
            Path to file to write. Defaults to 'cross_sections.xml'.

        """
        root = ET.Element('cross_sections')

        # Determine common directory for library paths
        common_dir = os.path.dirname(
            os.path.commonprefix([lib['path'] for lib in self.libraries]))
        if common_dir == '':
            common_dir = '.'

        directory = os.path.relpath(common_dir, os.path.dirname(path))
        if directory != '.':
            dir_element = ET.SubElement(root, "directory")
            dir_element.text = directory

        for library in self.libraries:
            lib_element = ET.SubElement(root, "library")
            lib_element.set('materials', ' '.join(library['materials']))
            lib_element.set('path', os.path.relpath(library['path'],
                                                    common_dir))
            lib_element.set('type', library['type'])

        # Clean the indentation to be user-readable
        clean_xml_indentation(root)

        # Write XML file
        tree = ET.ElementTree(root)
        tree.write(path, xml_declaration=True, encoding='utf-8', method='xml')
Пример #4
0
    def export_to_xml(self):
        """Create a cmfd.xml file using the class data that can be used for an OpenMC
        simulation.

        """

        self._create_begin_subelement()
        self._create_dhat_reset_subelement()
        self._create_display_subelement()
        self._create_downscatter_subelement()
        self._create_feedback_subelement()
        self._create_gauss_seidel_tolerance_subelement()
        self._create_ktol_subelement()
        self._create_mesh_subelement()
        self._create_norm_subelement()
        self._create_power_monitor_subelement()
        self._create_run_adjoint_subelement()
        self._create_shift_subelement()
        self._create_spectral_subelement()
        self._create_stol_subelement()
        self._create_tally_reset_subelement()
        self._create_write_matrices_subelement()

        # Clean the indentation in the file to be user-readable
        clean_xml_indentation(self._cmfd_file)

        # Write the XML Tree to the cmfd.xml file
        tree = ET.ElementTree(self._cmfd_file)
        tree.write("cmfd.xml",
                   xml_declaration=True,
                   encoding='utf-8',
                   method="xml")
Пример #5
0
    def export_to_xml(self, path='cross_sections.xml'):
        """Export cross section data library to an XML file.

        Parameters
        ----------
        path : str
            Path to file to write. Defaults to 'cross_sections.xml'.

        """
        root = ET.Element('cross_sections')

        # Determine common directory for library paths
        common_dir = os.path.dirname(os.path.commonprefix(
            [lib['path'] for lib in self.libraries]))
        if common_dir == '':
            common_dir = '.'

        directory = os.path.relpath(common_dir, os.path.dirname(path))
        if directory != '.':
            dir_element = ET.SubElement(root, "directory")
            dir_element.text = directory

        for library in self.libraries:
            lib_element = ET.SubElement(root, "library")
            lib_element.set('materials', ' '.join(library['materials']))
            lib_element.set('path', os.path.relpath(library['path'], common_dir))
            lib_element.set('type', library['type'])

        # Clean the indentation to be user-readable
        clean_xml_indentation(root)

        # Write XML file
        tree = ET.ElementTree(root)
        tree.write(path, xml_declaration=True, encoding='utf-8',
                   method='xml')
Пример #6
0
    def export_to_xml(self, path='settings.xml'):
        """Export simulation settings to an XML file.

        Parameters
        ----------
        path : str
            Path to file to write. Defaults to 'settings.xml'.

        """

        # Reset xml element tree
        root_element = ET.Element("settings")

        self._create_run_mode_subelement(root_element)
        self._create_particles_subelement(root_element)
        self._create_batches_subelement(root_element)
        self._create_inactive_subelement(root_element)
        self._create_generations_per_batch_subelement(root_element)
        self._create_keff_trigger_subelement(root_element)
        self._create_source_subelement(root_element)
        self._create_output_subelement(root_element)
        self._create_statepoint_subelement(root_element)
        self._create_sourcepoint_subelement(root_element)
        self._create_confidence_intervals(root_element)
        self._create_cross_sections_subelement(root_element)
        self._create_multipole_library_subelement(root_element)
        self._create_energy_mode_subelement(root_element)
        self._create_max_order_subelement(root_element)
        self._create_ptables_subelement(root_element)
        self._create_run_cmfd_subelement(root_element)
        self._create_seed_subelement(root_element)
        self._create_survival_biasing_subelement(root_element)
        self._create_cutoff_subelement(root_element)
        self._create_entropy_subelement(root_element)
        self._create_trigger_subelement(root_element)
        self._create_no_reduce_subelement(root_element)
        self._create_threads_subelement(root_element)
        self._create_verbosity_subelement(root_element)
        self._create_tabular_legendre_subelements(root_element)
        self._create_temperature_subelements(root_element)
        self._create_trace_subelement(root_element)
        self._create_track_subelement(root_element)
        self._create_ufs_subelement(root_element)
        self._create_dd_subelement(root_element)
        self._create_resonance_scattering_subelement(root_element)
        self._create_volume_calcs_subelement(root_element)
        self._create_create_fission_neutrons_subelement(root_element)

        # Clean the indentation in the file to be user-readable
        clean_xml_indentation(root_element)

        # Write the XML Tree to the settings.xml file
        tree = ET.ElementTree(root_element)
        tree.write(path, xml_declaration=True, encoding='utf-8', method="xml")
Пример #7
0
    def export_to_xml(self, path='settings.xml'):
        """Export simulation settings to an XML file.

        Parameters
        ----------
        path : str
            Path to file to write. Defaults to 'settings.xml'.

        """

        # Reset xml element tree
        root_element = ET.Element("settings")

        self._create_run_mode_subelement(root_element)
        self._create_particles_subelement(root_element)
        self._create_batches_subelement(root_element)
        self._create_inactive_subelement(root_element)
        self._create_generations_per_batch_subelement(root_element)
        self._create_keff_trigger_subelement(root_element)
        self._create_source_subelement(root_element)
        self._create_output_subelement(root_element)
        self._create_statepoint_subelement(root_element)
        self._create_sourcepoint_subelement(root_element)
        self._create_confidence_intervals(root_element)
        self._create_cross_sections_subelement(root_element)
        self._create_multipole_library_subelement(root_element)
        self._create_energy_mode_subelement(root_element)
        self._create_max_order_subelement(root_element)
        self._create_ptables_subelement(root_element)
        self._create_run_cmfd_subelement(root_element)
        self._create_seed_subelement(root_element)
        self._create_survival_biasing_subelement(root_element)
        self._create_cutoff_subelement(root_element)
        self._create_entropy_subelement(root_element)
        self._create_trigger_subelement(root_element)
        self._create_no_reduce_subelement(root_element)
        self._create_threads_subelement(root_element)
        self._create_verbosity_subelement(root_element)
        self._create_tabular_legendre_subelements(root_element)
        self._create_temperature_subelements(root_element)
        self._create_trace_subelement(root_element)
        self._create_track_subelement(root_element)
        self._create_ufs_subelement(root_element)
        self._create_dd_subelement(root_element)
        self._create_resonance_scattering_subelement(root_element)
        self._create_volume_calcs_subelement(root_element)
        self._create_create_fission_neutrons_subelement(root_element)

        # Clean the indentation in the file to be user-readable
        clean_xml_indentation(root_element)

        # Write the XML Tree to the settings.xml file
        tree = ET.ElementTree(root_element)
        tree.write(path, xml_declaration=True, encoding='utf-8', method="xml")
Пример #8
0
    def export_to_xml(self):
        """Create a settings.xml file that can be used for a simulation.

        """

        # Reset xml element tree
        self._settings_file.clear()
        self._source_subelement = None
        self._trigger_subelement = None
        self._run_mode_subelement = None
        self._source_element = None

        self._create_run_mode_subelement()
        self._create_source_subelement()
        self._create_output_subelement()
        self._create_statepoint_subelement()
        self._create_sourcepoint_subelement()
        self._create_confidence_intervals()
        self._create_cross_sections_subelement()
        self._create_multipole_library_subelement()
        self._create_energy_grid_subelement()
        self._create_energy_mode_subelement()
        self._create_max_order_subelement()
        self._create_ptables_subelement()
        self._create_run_cmfd_subelement()
        self._create_seed_subelement()
        self._create_survival_biasing_subelement()
        self._create_cutoff_subelement()
        self._create_entropy_subelement()
        self._create_trigger_subelement()
        self._create_no_reduce_subelement()
        self._create_threads_subelement()
        self._create_verbosity_subelement()
        self._create_trace_subelement()
        self._create_track_subelement()
        self._create_ufs_subelement()
        self._create_dd_subelement()
        self._create_use_multipole_subelement()
        self._create_resonance_scattering_element()

        # Clean the indentation in the file to be user-readable
        clean_xml_indentation(self._settings_file)

        # Write the XML Tree to the settings.xml file
        tree = ET.ElementTree(self._settings_file)
        tree.write("settings.xml",
                   xml_declaration=True,
                   encoding='utf-8',
                   method="xml")
Пример #9
0
    def export_to_xml(self):
        """Create a settings.xml file that can be used for a simulation.

        """

        # Reset xml element tree
        self._settings_file.clear()
        self._source_subelement = None
        self._trigger_subelement = None
        self._run_mode_subelement = None
        self._source_element = None

        self._create_run_mode_subelement()
        self._create_source_subelement()
        self._create_output_subelement()
        self._create_statepoint_subelement()
        self._create_sourcepoint_subelement()
        self._create_confidence_intervals()
        self._create_cross_sections_subelement()
        self._create_multipole_library_subelement()
        self._create_energy_grid_subelement()
        self._create_energy_mode_subelement()
        self._create_max_order_subelement()
        self._create_ptables_subelement()
        self._create_run_cmfd_subelement()
        self._create_seed_subelement()
        self._create_survival_biasing_subelement()
        self._create_cutoff_subelement()
        self._create_entropy_subelement()
        self._create_trigger_subelement()
        self._create_no_reduce_subelement()
        self._create_threads_subelement()
        self._create_verbosity_subelement()
        self._create_trace_subelement()
        self._create_track_subelement()
        self._create_ufs_subelement()
        self._create_dd_subelement()
        self._create_use_multipole_subelement()
        self._create_resonance_scattering_element()

        # Clean the indentation in the file to be user-readable
        clean_xml_indentation(self._settings_file)

        # Write the XML Tree to the settings.xml file
        tree = ET.ElementTree(self._settings_file)
        tree.write("settings.xml", xml_declaration=True,
                   encoding='utf-8', method="xml")
Пример #10
0
    def export_to_xml(self):
        """Create a plots.xml file that can be used by OpenMC.

        """

        # Reset xml element tree
        self._plots_file.clear()

        self._create_plot_subelements()

        # Clean the indentation in the file to be user-readable
        clean_xml_indentation(self._plots_file)

        # Write the XML Tree to the plots.xml file
        tree = ET.ElementTree(self._plots_file)
        tree.write("plots.xml", xml_declaration=True,
                   encoding='utf-8', method="xml")
Пример #11
0
    def export_to_xml(self):
        """Create a materials.xml file that can be used for a simulation.

        """

        # Reset xml element tree
        self._materials_file.clear()

        self._create_material_subelements()

        # Clean the indentation in the file to be user-readable
        sort_xml_elements(self._materials_file)
        clean_xml_indentation(self._materials_file)

        # Write the XML Tree to the materials.xml file
        tree = ET.ElementTree(self._materials_file)
        tree.write("materials.xml", xml_declaration=True,
                   encoding='utf-8', method="xml")
Пример #12
0
    def export_to_xml(self):
        """Create a plots.xml file that can be used by OpenMC.

        """

        # Reset xml element tree
        self._plots_file.clear()

        self._create_plot_subelements()

        # Clean the indentation in the file to be user-readable
        clean_xml_indentation(self._plots_file)

        # Write the XML Tree to the plots.xml file
        tree = ET.ElementTree(self._plots_file)
        tree.write("plots.xml",
                   xml_declaration=True,
                   encoding='utf-8',
                   method="xml")
Пример #13
0
    def xml_write(self, filename):
        """Writes a depletion chain XML file.

        Parameters
        ----------
        filename : str
            The path to the depletion chain XML file.

        """

        root_elem = ET.Element('depletion')
        for nuclide in self.nuclides:
            root_elem.append(nuclide.xml_write())

        tree = ET.ElementTree(root_elem)
        if _have_lxml:
            tree.write(filename, encoding='utf-8', pretty_print=True)
        else:
            clean_xml_indentation(root_elem, spaces_per_level=2)
            tree.write(filename, encoding='utf-8')
Пример #14
0
    def export_to_xml(self, path='geometry.xml'):
        """Export geometry to an XML file.

        Parameters
        ----------
        path : str
            Path to file to write. Defaults to 'geometry.xml'.

        """
        # Create XML representation
        root_element = ET.Element("geometry")
        self.root_universe.create_xml_subelement(root_element)

        # Clean the indentation in the file to be user-readable
        sort_xml_elements(root_element)
        clean_xml_indentation(root_element)

        # Write the XML Tree to the geometry.xml file
        tree = ET.ElementTree(root_element)
        tree.write(path, xml_declaration=True, encoding='utf-8', method="xml")
Пример #15
0
    def export_to_xml(self, path='plots.xml'):
        """Export plot specifications to an XML file.

        Parameters
        ----------
        path : str
            Path to file to write. Defaults to 'plots.xml'.

        """
        # Reset xml element tree
        self._plots_file.clear()

        self._create_plot_subelements()

        # Clean the indentation in the file to be user-readable
        clean_xml_indentation(self._plots_file)

        # Write the XML Tree to the plots.xml file
        tree = ET.ElementTree(self._plots_file)
        tree.write(path, xml_declaration=True, encoding='utf-8', method="xml")
Пример #16
0
    def export_to_xml(self, path='materials.xml'):
        """Export material collection to an XML file.

        Parameters
        ----------
        path : str
            Path to file to write. Defaults to 'materials.xml'.

        """

        root_element = ET.Element("materials")
        self._create_cross_sections_subelement(root_element)
        self._create_multipole_library_subelement(root_element)
        self._create_material_subelements(root_element)

        # Clean the indentation in the file to be user-readable
        clean_xml_indentation(root_element)

        # Write the XML Tree to the materials.xml file
        tree = ET.ElementTree(root_element)
        tree.write(path, xml_declaration=True, encoding='utf-8')
Пример #17
0
    def export_to_xml(self):
        """Create a geometry.xml file that can be used for a simulation.

        """

        # Clear OpenMC written IDs used to optimize XML generation
        openmc.universe.WRITTEN_IDS = {}

        # Create XML representation
        geometry_file = ET.Element("geometry")
        self.root_universe.create_xml_subelement(geometry_file)

        # Clean the indentation in the file to be user-readable
        sort_xml_elements(geometry_file)
        clean_xml_indentation(geometry_file)

        # Write the XML Tree to the geometry.xml file
        tree = ET.ElementTree(geometry_file)
        tree.write("geometry.xml",
                   xml_declaration=True,
                   encoding='utf-8',
                   method="xml")
Пример #18
0
    def export_to_xml(self, path='geometry.xml'):
        """Export geometry to an XML file.

        Parameters
        ----------
        path : str
            Path to file to write. Defaults to 'geometry.xml'.

        """
        # Create XML representation
        root_element = ET.Element("geometry")
        self.root_universe.create_xml_subelement(root_element)

        # Sort the elements in the file
        root_element[:] = sorted(root_element, key=lambda x: (
            x.tag, int(x.get('id'))))

        # Clean the indentation in the file to be user-readable
        clean_xml_indentation(root_element)

        # Write the XML Tree to the geometry.xml file
        tree = ET.ElementTree(root_element)
        tree.write(path, xml_declaration=True, encoding='utf-8')
Пример #19
0
    def generate_materials_xml(self):
        """ Creates materials.xml from self.number.

        Due to uncertainty with how MPI interacts with OpenMC API, this
        constructs the XML manually.  The long term goal is to do this
        either through PHDF5 or direct memory writing.
        """

        xml_strings = []

        for mat in self.number.mat_to_ind:
            root = ET.Element("material")
            root.set("id", mat)

            density = ET.SubElement(root, "density")
            density.set("units", "sum")

            temperature = ET.SubElement(root, "temperature")
            mat_id = self.number.mat_to_ind[mat]
            temperature.text = str(self.materials[mat_id].temperature)

            for nuc in self.number.nuc_to_ind:
                if nuc in self.participating_nuclides:
                    val = 1.0e-24 * self.number.get_atom_density(mat, nuc)

                    # If nuclide is zero, do not add to the problem.
                    if val > 0.0:
                        if self.settings.round_number:
                            val_magnitude = np.floor(np.log10(val))
                            val_scaled = val / 10**val_magnitude
                            val_round = round(val_scaled, 8)

                            val = val_round * 10**val_magnitude

                        nuc_element = ET.SubElement(root, "nuclide")
                        nuc_element.set("ao", str(val))
                        nuc_element.set("name", nuc)
                    else:
                        # Only output warnings if values are significantly
                        # negative.  CRAM does not guarantee positive values.
                        if val < -1.0e-21:
                            print("WARNING: nuclide ", nuc, " in material ",
                                  mat, " is negative (density = ", val,
                                  " at/barn-cm)")
                        self.number[mat, nuc] = 0.0

            for sab in self.materials[mat_id].sab:
                sab_el = ET.SubElement(root, "sab")
                sab_el.set("name", sab)

            if _have_lxml:
                fragment = ET.tostring(root,
                                       encoding="unicode",
                                       pretty_print="true")
                xml_strings.append(fragment)
            else:
                clean_xml_indentation(root, spaces_per_level=2)
                fragment = ET.tostring(root,
                                       encoding="unicode",
                                       pretty_print="true")
                xml_strings.append(fragment)

        xml_string = "".join(xml_strings)

        # Append beginning, end text.
        if self.rank == 0:
            xml_string = "<?xml version='1.0' encoding='utf-8'?>\n<materials>\n" + xml_string
        if self.rank == self.size:
            xml_string += "\n</materials>"

        xml_bytes = np.fromstring(xml_string, dtype=np.uint8)

        # Use MPI-IO to write to disk.
        # First, communicate to all nodes the length of their string.
        str_len = np.zeros(self.size, np.int32)

        str_my_len = np.zeros(1, np.int32)
        str_my_len[0] = len(xml_string)
        self.comm.Allgather([str_my_len, MPI.INT], [str_len, MPI.INT])

        # Compute index start.
        start_ind = np.sum(str_len[0:self.rank])

        # Open/create file
        handle = MPI.File.Open(self.comm, "materials.xml",
                               MPI.MODE_WRONLY | MPI.MODE_CREATE)

        handle.Seek(start_ind, MPI.SEEK_SET)
        handle.Write(xml_bytes)
        handle.Close()

        self.comm.barrier()
Пример #20
0
    def generate_tallies_xml(self, filename_string, default_group_struc=False):
        """Generate tallies.xml with hybrid tallies by using the energy group structure
       as a filter together with the material filter of an original tallies.xml.

        Parameters
        ----------
        filename_string : string
            string with the path to a tallies.xml file that contains
            the reaction rate tally of a given geometry. This method will
            expand on this by adding the extra flux tally method and by 
            reducing the number of scores in the original reaction-rate tally
            from 7 to 2.
        SHEM361_only : bool
            In case the user wants to use only the SHEM361 library.

    """
        #reads a tallies.xml file with a reaction rate tally and uses the
        #material filter to build a new tallies.xml with hybrid tallies using
        #the energy filter.

        tree = ET.parse(filename_string)
        root = tree.getroot()
        mat_filter = root[0][0].text
        energy_filter = self.gen_energy_struc(default_group_struc)

        new_data = ET.Element('tallies')

        #attributes for hybrid tally.
        attrib_mat = {'id': '1', 'type': 'material'}
        attrib_energy = {'id': '2', 'type': 'energy'}
        empty_attrib = {}

        filter_mat = ET.SubElement(new_data, 'filter', attrib_mat)
        filter_ene = ET.SubElement(new_data, 'filter', attrib_energy)
        ET.SubElement(filter_mat, 'bins', empty_attrib)
        ET.SubElement(filter_ene, 'bins', empty_attrib)

        new_data[0][0].text = mat_filter
        new_data[1][0].text = ' '.join(str(i) for i in energy_filter)

        #writing '<tally>' object
        for key, value in enumerate(self.tallies_dict.items()):
            tally_id = value[1]['id']
            tally_name = value[1]['name']
            attrib_tallies = {'id': tally_id, 'name': tally_name}
            tally_level = ET.SubElement(new_data, 'tally', attrib_tallies)

            ET.SubElement(tally_level, 'filters', empty_attrib)

            if (value[1]['nuclides'] != ''):
                ET.SubElement(tally_level, 'nuclides', empty_attrib)
            ET.SubElement(tally_level, 'scores', empty_attrib)
            #last_index could be either a 1 or a 2, depending on
            #whether we are doing a reaction rate tally (i.e, last_index=1) or
            #a flux tally (i.e., last_index = 2)
            last_index = 1
            filter_list = value[1]['filter']
            score_list = value[1]['scores']
            #offset by '2' indicates we are writing the tally objects below
            #the material and energy filters
            new_data[key + 2][0].text = ' '.join(i for i in filter_list)

            if (value[1]['nuclides'] != ''):
                nuclide_list = value[1]['nuclides']
                new_data[key + 2][1].text = ' '.join(nuc
                                                     for nuc in nuclide_list)
                last_index = 2
            new_data[key + 2][last_index].text = ' '.join(i
                                                          for i in score_list)

        if (old is True):
            clean_xml_indentation(new_data)
        else:
            clean_indentation(new_data)
        #renaming original 'tallies.xml' to 'tallies-original.xml'
        #to distinguish it from  the new hybrid 'tally.xml' file.
        tree = ET.ElementTree(new_data)
        #os.rename(filename_string,'tallies-original.xml')
        tree.write('./tallies-hybrid-tally.xml',
                   xml_declaration=True,
                   encoding='utf-8',
                   method="xml")