Esempio n. 1
0
 def setUpClass(cls):
     cls.isotxsAA = isotxs.readBinary(ISOTXS_AA)
     cls.gamisoAA = gamiso.readBinary(GAMISO_AA)
     cls.pmatrxAA = pmatrx.readBinary(PMATRX_AA)
     cls.xsLib = xsLibraries.IsotxsLibrary()
     cls.xsLibGenerationErrorStack = None
     try:
         cls.xsLib.merge(copy.deepcopy(cls.isotxsAA))
         cls.xsLib.merge(copy.deepcopy(cls.gamisoAA))
         cls.xsLib.merge(copy.deepcopy(cls.pmatrxAA))
     except:
         cls.xsLibGenerationErrorStack = traceback.format_exc()
Esempio n. 2
0
def mergeXSLibrariesInWorkingDirectory(lib,
                                       xsLibrarySuffix="",
                                       mergeGammaLibs=False):
    """
    Merge neutron (ISOTXS) and gamma (GAMISO/PMATRX) library data into the provided library.

    Parameters
    ----------
    lib : obj
        ISOTXS library object

    xsLibrarySuffix : str, optional
        XS library suffix used to determine which ISOTXS files are merged together,
        typically something like `-doppler`. If empty string, will merge everything
        without suffix (indicated by a `-`).

    mergeGammaLibs : bool, optional
        If True, the GAMISO and PMATRX files that correspond to the ISOTXS library will be merged. Note: if these
        files do not exist this will fail.
    """
    # pylint: disable=import-outside-toplevel) ; avoid cyclic import with isotxs bringing this in for data structure
    from armi.nuclearDataIO.cccc import isotxs
    from armi.nuclearDataIO.cccc import gamiso
    from armi.nuclearDataIO.cccc import pmatrx
    from armi import nuclearDataIO

    xsLibFiles = getISOTXSLibrariesToMerge(
        xsLibrarySuffix, [iso for iso in glob.glob(_ISOTXS_EXT + "*")])
    librariesToMerge = []
    neutronVelocities = {
    }  # Dictionary of neutron velocities from each ISOTXS file
    for xsLibFilePath in sorted(xsLibFiles):
        try:
            xsID = re.search("ISO([A-Z0-9]{2})", xsLibFilePath).group(
                1)  # get XS ID from the cross section library name
        except AttributeError:
            # if glob has matched something that is not actually an ISOXX file,
            # the .group() call will fail
            runLog.debug(
                f"Ignoring file {xsLibFilePath} in the merging of ISOXX files")
            continue

        xsFileTypes = "ISOTXS" if not mergeGammaLibs else "ISOTXS, GAMISO, and PMATRX"
        runLog.info("Retrieving {} data for XS ID {}{}".format(
            xsFileTypes, xsID, xsLibrarySuffix))
        if xsLibFilePath in lib.isotxsMetadata.fileNames:
            runLog.extra(
                "Skipping merge of {} because data already exists in the library"
                .format(xsLibFilePath))
            continue
        neutronLibrary = isotxs.readBinary(xsLibFilePath)
        neutronVelocities[xsID] = neutronLibrary.neutronVelocity
        librariesToMerge.append(neutronLibrary)
        if mergeGammaLibs:
            dummyNuclides = [
                nuc for nuc in neutronLibrary.nuclides
                if isinstance(nuc._base, nuclideBases.DummyNuclideBase)
            ]

            gamisoLibraryPath = nuclearDataIO.getExpectedGAMISOFileName(
                suffix=xsLibrarySuffix, xsID=xsID)
            pmatrxLibraryPath = nuclearDataIO.getExpectedPMATRXFileName(
                suffix=xsLibrarySuffix, xsID=xsID)

            # Check if the gamiso and pmatrx data paths exist with the xs library suffix so that
            # these are merged in. If they don't both exist then that is OK and we can just
            # revert back to expecting the files just based on the XS ID.
            if not (os.path.exists(gamisoLibraryPath)
                    and os.path.exists(pmatrxLibraryPath)):
                runLog.warning(f"One of GAMISO or PMATRX data exist for "
                               f"XS ID {xsID} with suffix {xsLibrarySuffix}. "
                               f"Attempting to find GAMISO/PMATRX data with "
                               f"only XS ID {xsID} instead.")
                gamisoLibraryPath = nuclearDataIO.getExpectedGAMISOFileName(
                    xsID=xsID)
                pmatrxLibraryPath = nuclearDataIO.getExpectedPMATRXFileName(
                    xsID=xsID)

            # GAMISO data
            gammaLibrary = gamiso.readBinary(gamisoLibraryPath)
            addedDummyData = gamiso.addDummyNuclidesToLibrary(
                gammaLibrary,
                dummyNuclides)  # Add DUMMY nuclide data not produced by MC2-3
            if addedDummyData:
                gamisoDummyPath = os.path.abspath(
                    os.path.join(os.getcwd(), gamisoLibraryPath))
                gamiso.writeBinary(gammaLibrary, gamisoDummyPath)
                gammaLibraryDummyData = gamiso.readBinary(gamisoDummyPath)
                librariesToMerge.append(gammaLibraryDummyData)
            else:
                librariesToMerge.append(gammaLibrary)

            # PMATRX data
            pmatrxLibrary = pmatrx.readBinary(pmatrxLibraryPath)
            addedDummyData = pmatrx.addDummyNuclidesToLibrary(
                pmatrxLibrary,
                dummyNuclides)  # Add DUMMY nuclide data not produced by MC2-3
            if addedDummyData:
                pmatrxDummyPath = os.path.abspath(
                    os.path.join(os.getcwd(), pmatrxLibraryPath))
                pmatrx.writeBinary(pmatrxLibrary, pmatrxDummyPath)
                pmatrxLibraryDummyData = pmatrx.readBinary(pmatrxDummyPath)
                librariesToMerge.append(pmatrxLibraryDummyData)
            else:
                librariesToMerge.append(pmatrxLibrary)
    for library in librariesToMerge:
        lib.merge(library)

    return neutronVelocities
Esempio n. 3
0
 def setUpClass(cls):
     # load a library that is in the ARMI tree. This should
     # be a small library with LFPs, Actinides, structure, and coolant
     cls.lib = pmatrx.readBinary(test_xsLibraries.PMATRX_AA)
Esempio n. 4
0
 def setUp(self):
     self.fname = self._testMethodName + "temp-aa.pmatrx.ascii"
     lib = pmatrx.readBinary(test_xsLibraries.PMATRX_AA)
     pmatrx.writeAscii(lib, self.fname)
     self.lib = pmatrx.readAscii(self.fname)
Esempio n. 5
0
 def setUpClass(cls):
     cls.origLib = pmatrx.readBinary(test_xsLibraries.PMATRX_AA)
Esempio n. 6
0
 def setUp(self):
     self.fname = self._testMethodName + "temp-aa.pmatrx"
     pmatrx.writeBinary(self.origLib, self.fname)
     self.lib = pmatrx.readBinary(self.fname)