Commit c9dfc0e2 authored by Patrick Shriwise's avatar Patrick Shriwise
Browse files

Adding isoxml and exodus material readers

parent a6530b84
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -6,18 +6,12 @@ def parse_isoxml(isoxml_file):
    tree = ET.parse(isoxml_file)
    root = tree.getroot()

    out_str = ""
    # find all "Isotope" elements
    isotopes = list(root.iter('Isotope'))
    out_str += f'Found {len(isotopes)} isotopes in the ISOXML:\n'
    for isotope in isotopes:
        out_str += f"\t{isotope.attrib['Name']}\n"

    return out_str
    return [f'{isotope.attrib["Name"]}' for isotope in isotopes]

if __name__ == '__main__':
    print(f'Parsing XML file {sys.argv[1]}...')
    print(parse_isoxml(sys.argv[1]))


    isoxml_materials = parse_isoxml(sys.argv[1])
    print(f'Found {len(isoxml_materials)} isotopes in the ISOXML:')
    print(''.join(f'\t{m}\n' for m in isoxml_materials))
+49 −0
Original line number Diff line number Diff line
@@ -7,6 +7,10 @@ import warnings

from . import checkvalue as cv
from .config import PyGriffinConfig
from .exodus_reader import parse_exodus
from .isoxml_reader import parse_isoxml
from .util import run_in_tmpdir


class PyGriffin:
    """
@@ -112,6 +116,51 @@ class PyGriffin:
        p.wait()
        return p.returncode

    def report_materials(self):

        exodus_materials = self.get_exodus_materials()
        print("Materials applied in the Griffin mesh:")
        print(''.join(f'\t{m}\n' for m in exodus_materials))

        isoxml_materials = parse_isoxml(self.process_xs())
        print("Materials available in the ISOXML library:")
        print(''.join(f'\t{m}\n' for m in isoxml_materials))

        isoxml_set = set(isoxml_materials)
        exodus_set = set(exodus_materials)

        # determine materials used in the mesh that are not
        # not present in the ISOXML file
        if not isoxml_set.issuperset(exodus_set):
            invalid_mats = [m for m in exodus_materials if m not in isoxml_set]
            print("ERROR: Some materials applied in the mesh are not present in the ISOXML")
        else:
            invalid_mats = []

        # determine which materials in the ISOXML are unused
        unused_mats = list(isoxml_set - exodus_materials)

        return invalid_mats, unused_mats

    def get_exodus_materials(self):
        with run_in_tmpdir():
            # generate the exodus file that would be used in the Griffin run
            mesh_file = self.generate_mesh()

            # call ncdump and capture output
            ncdump_out = subprocess.check_output(['ncdump', mesh_file]).decode()
            ncdump_out = ncdump_out.split('\n')

            materials = []
            for line in output:
                if 'isotope' in line:
                    isotope = line.split(" ")[-1]
                    isotope = isotope[:isotope.find('\\')]
                    isotope = isotope.replace('"', '')
                    materials.append(isotope)

        return materials

    def process_xs(self, overwrite=False, particle='neutron', cwd=None):
        """
        Runs ISOXML on the current set of cross sections