Пример #1
0
 def test_mergeMccV2FilesRemovesTheFileWideChi(self):
     isoaa = isotxs.readBinary(ISOAA_PATH)
     self.assertAlmostEqual(1.0, sum(isoaa.isotxsMetadata["chi"]), 5)
     self.assertAlmostEqual(1, isoaa.isotxsMetadata["fileWideChiFlag"])
     someIsotxs = xsLibraries.IsotxsLibrary()
     # semi-copy...
     someIsotxs.merge(isoaa)
     self.assertAlmostEqual(1.0, sum(someIsotxs.isotxsMetadata["chi"]), 5)
     self.assertEqual(1, someIsotxs.isotxsMetadata["fileWideChiFlag"])
     # OK, now I need to delete all the nuclides, so we can merge again.
     for key in someIsotxs.nuclideLabels:
         del someIsotxs[key]
     someIsotxs.merge(isotxs.readBinary(ISOAA_PATH))
     self.assertEqual(None, someIsotxs.isotxsMetadata["chi"])
Пример #2
0
    def test_plotBlockFlux(self):
        try:
            xslib = isotxs.readBinary(ISOAA_PATH)
            self.r.core.lib = xslib

            blockList = self.r.core.getBlocks()
            for _, b in enumerate(blockList):
                b.p.mgFlux = range(33)

            plotting.plotBlockFlux(self.r.core,
                                   fName="flux.png",
                                   bList=blockList)
            self.assertTrue(os.path.exists("flux.png"))
            plotting.plotBlockFlux(self.r.core,
                                   fName="peak.png",
                                   bList=blockList,
                                   peak=True)
            self.assertTrue(os.path.exists("peak.png"))
            plotting.plotBlockFlux(
                self.r.core,
                fName="bList2.png",
                bList=blockList,
                bList2=blockList,
            )
            self.assertTrue(os.path.exists("bList2.png"))
            # can't test adjoint at the moment, testBlock doesn't like to .getMgFlux(adjoint=True)
        finally:
            os.remove("flux.txt")  # secondarily created during the call.
            os.remove("flux.png")  # created during the call.
            os.remove("peak.txt")  # csecondarily reated during the call.
            os.remove("peak.png")  # created during the call.
            os.remove("bList2.txt")  # secondarily created during the call.
            os.remove("bList2.png")  # created during the call.
Пример #3
0
    def test_mapper(self):
        # Switch to MC2v2 setting to make sure the isotopic/elemental expansions are compatible
        # with actually doing some math using the ISOAA test microscopic library
        _o, r = test_reactors.loadTestReactor(customSettings={"xsKernel": "MC2v2"})
        applyDummyFlux(r)
        r.core.lib = isotxs.readBinary(ISOAA_PATH)
        mapper = globalFluxInterface.GlobalFluxResultMapper()
        mapper.r = r
        mapper._renormalizeNeutronFluxByBlock(100)
        self.assertAlmostEqual(r.core.calcTotalParam("power", generationNum=2), 100)

        mapper._updateDerivedParams()
        self.assertGreater(r.core.p.maxPD, 0.0)
        self.assertGreater(r.core.p.maxFlux, 0.0)

        mapper.updateDpaRate()
        block = r.core.getFirstBlock()
        self.assertGreater(block.p.detailedDpaRate, 0)
        self.assertEqual(block.p.detailedDpa, 0)

        # Test DoseResultsMapper. Pass in full list of blocks to apply() in order
        # to exercise blockList option (does not change behavior, since this is what
        # apply() does anyway)
        opts = globalFluxInterface.GlobalFluxOptions("test")
        dosemapper = globalFluxInterface.DoseResultsMapper(1000, opts)
        dosemapper.apply(r, blockList=r.core.getBlocks())
        self.assertGreater(block.p.detailedDpa, 0)

        mapper.clearFlux()
        self.assertEqual(len(block.p.mgFlux), 0)
Пример #4
0
 def setUp(self):
     self.o, self.r = test_reactors.loadTestReactor(
         TEST_ROOT, customSettings={"xsKernel": "MC2v2"}
     )
     self.r.core.lib = isotxs.readBinary(ISOAA_PATH)
     self.r.core.p.keff = 1.0
     self.converter = uniformMesh.NeutronicsUniformMeshConverter()
Пример #5
0
 def testMakeTable(self):
     obj = loadTestBlock()
     obj.p.mgFlux = range(33)
     core = obj.getAncestorWithFlags(Flags.CORE)
     core.lib = isotxs.readBinary(ISOAA_PATH)
     table = cst.makeReactionRateTable(obj)
     self.assertEqual(len(table), len(obj.getNuclides()))
Пример #6
0
 def setUpClass(cls):
     # random seed to support random mesh in unit tests below
     random.seed(987324987234)
     cls.o, cls.r = test_reactors.loadTestReactor(
         TEST_ROOT, customSettings={"xsKernel": "MC2v2"})
     cls.r.core.lib = isotxs.readBinary(ISOAA_PATH)
     # make the mesh a little non-uniform
     a = cls.r.core[4]
     a[2].setHeight(a[2].getHeight() * 1.05)
Пример #7
0
 def setUpClass(cls):
     random.seed(987324987234)  # so it's always the same
     cls.o, cls.r = test_reactors.loadTestReactor(
         TEST_ROOT, customSettings={"xsKernel": "MC2v2"}
     )
     cls.r.core.lib = isotxs.readBinary(ISOAA_PATH)
     # make the mesh a little non-uniform
     a = cls.r.core[4]
     a[2].setHeight(a[2].getHeight() * 1.05)
Пример #8
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()
Пример #9
0
    def test_makeTable(self):
        obj = loadTestBlock()
        obj.p.mgFlux = range(33)
        core = obj.getAncestorWithFlags(Flags.CORE)
        core.lib = isotxs.readBinary(ISOAA_PATH)
        table = crossSectionTable.makeReactionRateTable(obj)

        self.assertEqual(len(obj.getNuclides()), len(table))
        self.assertEqual(obj.getName(), "B0001-000")

        self.assertEqual(table.getName(), "B0001-000")
        self.assertTrue(table.hasValues())

        xSecTable = table.getXsecTable()
        self.assertEqual(len(xSecTable), 11)
        self.assertIn("xsecs", xSecTable[0])
        self.assertIn("mcnpId", xSecTable[-1])
Пример #10
0
 def test_compareDifferentComponentsOfAnXSLibrary(self):
     self.assertTrue(xsLibraries.compare(self.isotxsAA, self.isotxsAA))
     self.assertTrue(xsLibraries.compare(self.pmatrxAA, self.pmatrxAA))
     aa = isotxs.readBinary(ISOTXS_AA)
     del aa[aa.nuclideLabels[0]]
     self.assertFalse(xsLibraries.compare(aa, self.isotxsAA))
Пример #11
0
In this example, several cross sections are plotted from
an existing binary cross section library file in :py:mod:`ISOTXS <armi.nuclearDataIO.isotxs>` format.

"""
import matplotlib.pyplot as plt

from armi.physics.neutronics import energyGroups
from armi.tests import ISOAA_PATH
from armi.nuclearDataIO.cccc import isotxs
from armi import configure

configure(permissive=True)

gs = energyGroups.getGroupStructure("ANL33")
lib = isotxs.readBinary(ISOAA_PATH)

fe56 = lib.getNuclide("FE", "AA")
u235 = lib.getNuclide("U235", "AA")
u238 = lib.getNuclide("U238", "AA")
b10 = lib.getNuclide("B10", "AA")

plt.step(gs, fe56.micros.nGamma, label=r"Fe (n, $\gamma$)")
plt.step(gs, u235.micros.fission, label="U-235 (n, fission)")
plt.step(gs, u238.micros.nGamma, label=r"U-238 (n, $\gamma$)")
plt.step(gs, b10.micros.nalph, label=r"B-10 (n, $\alpha$)")

plt.xscale("log")
plt.yscale("log")
plt.xlabel("Neutron Energy, eV")
plt.ylabel("Cross Section, barns")
Пример #12
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
Пример #13
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 = isotxs.readBinary(ISOAA_PATH)
Пример #14
0
def ISOTXS(fName="ISOTXS"):
    # load a library that is in the ARMI tree. This should
    # be a small library with LFPs, Actinides, structure, and coolant
    from armi.nuclearDataIO.cccc import isotxs

    return isotxs.readBinary(fName)