Commit 8c67b2a8 authored by Patrick Shriwise's avatar Patrick Shriwise
Browse files

Supporting Materials specified in the MOOSE input files

parent b908eaf4
Loading
Loading
Loading
Loading
+40 −7
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ from numbers import Integral
import os
from pathlib import Path
import subprocess
import re
import warnings

from . import checkvalue as cv
@@ -109,6 +110,7 @@ class PyGriffin:
        if not color:
            cmd += ['--color', 'off']

        # execute griffin run
        if logfile is not None:
            with open(logfile, 'w') as OUT:
                p = subprocess.Popen(cmd,
@@ -125,30 +127,61 @@ class PyGriffin:

    def report_materials(self):

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

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

        isoxml_set = set(isoxml_materials)
        exodus_set = set(exodus_materials)
        mesh_set = set(mesh_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")
        if not isoxml_set.issuperset(mesh_set):
            invalid_mats = [m for m in mesh_materials if m not in isoxml_set]
            print("WARNING: 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_set)
        unused_mats = list(isoxml_set - mesh_set)

        return invalid_mats, unused_mats

    def get_material_assignments(self):
        if str(self.mesh).endswith('.e'):
            return self.get_exodus_materials()
        elif str(self.mesh).endswith('.i'):
            return self.get_moose_materials()
        else:
            return ["No materials found"]

    def get_moose_materials(self):
        # open the mesh and options files
        lines = []
        with open(self.input, 'r') as input:
            lines += input.readlines()
        with open(self.mesh, 'r') as mesh:
            lines += mesh.readlines()

        mat_lines = []
        accumulate_lines = False
        for line in lines:
            if 'Materials' in line:
                accumulate_lines = True

            if accumulate_lines:
                mat_lines += [line]

            if accumulate_lines and line.rstrip('\n') == '[]':
                print("Breaking")
                break

        return mat_lines

    def get_exodus_materials(self):
        # generate the exodus file that would be used in the Griffin run
        self.mesh = self.generate_mesh()
+5 −2
Original line number Diff line number Diff line
@@ -39,14 +39,15 @@ if __name__ == '__main__':
    with open('isoxml.i', 'w') as xs_inp_file:
        xs_inp_file.write(xs_inp_content)

    if str(griffin_block.report_materials.value) == '"true"':
        pyg.report_materials()

    print("Generating Griffin mesh...")
    sys.stdout.flush()
    pyg.mesh = pyg.generate_mesh(logfile=args.logfile)
    print("Done")
    sys.stdout.flush()

    if str(griffin_block.report_materials.value) == '"true"':
        pyg.report_materials()

    if griffin_block.simulate is None or str(son_obj.griffin.simulate.value) == '"true"':
        print("Running PyGriffin...")
@@ -54,3 +55,5 @@ if __name__ == '__main__':
        pyg.run(other_args=['-i', 'isoxml.i'], logfile=args.logfile)
        print("Done")
        sys.stdout.flush()
    else:
        print("Griffin simulation disabled.")
 No newline at end of file