Ejemplo n.º 1
0
 def test_getPMATRXFileName(self):
     self.assertEqual(nuclearDataIO.getExpectedPMATRXFileName(cycle=0),
                      "cycle0.PMATRX")
     self.assertEqual(nuclearDataIO.getExpectedPMATRXFileName(cycle=1),
                      "cycle1.PMATRX")
     self.assertEqual(nuclearDataIO.getExpectedPMATRXFileName(cycle=23),
                      "cycle23.PMATRX")
     self.assertEqual(nuclearDataIO.getExpectedPMATRXFileName(xsID="AA"),
                      "AA.PMATRX")
     self.assertEqual(
         nuclearDataIO.getExpectedPMATRXFileName(xsID="AA", suffix="test"),
         "AA-test.PMATRX",
     )
     self.assertEqual(nuclearDataIO.getExpectedPMATRXFileName(), "PMATRX")
     with self.assertRaises(ValueError):
         # Error when over specified
         nuclearDataIO.getExpectedPMATRXFileName(cycle=10, xsID="AA")
Ejemplo n.º 2
0
 def _renameExistingLibrariesForCycle(self, cycle):
     """Copy the existing neutron and/or gamma libraries into cycle-dependent files."""
     shutil.copy(neutronics.ISOTXS, nuclearDataIO.getExpectedISOTXSFileName(cycle))
     if self.includeGammaXS:
         shutil.copy(
             neutronics.GAMISO,
             nuclearDataIO.getExpectedGAMISOFileName(
                 cycle=cycle, suffix=self._getSuffix(cycle)
             ),
         )
         shutil.copy(
             neutronics.PMATRX,
             nuclearDataIO.getExpectedPMATRXFileName(
                 cycle=cycle, suffix=self._getSuffix(cycle)
             ),
         )
Ejemplo n.º 3
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.
    """
    from armi import nuclearDataIO
    from armi.nuclearDataIO import isotxs
    from armi.nuclearDataIO import gamiso
    from armi.nuclearDataIO import pmatrx

    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):
        xsID = re.search("ISO([A-Z0-9]{2})", xsLibFilePath).group(
            1)  # get XS ID from the cross section library name
        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)
            ]
            # GAMISO data
            gamisoLibraryPath = nuclearDataIO.getExpectedGAMISOFileName(
                xsID=xsID)
            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
            pmatrxLibraryPath = nuclearDataIO.getExpectedPMATRXFileName(
                xsID=xsID)
            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
Ejemplo n.º 4
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