Пример #1
0
def bootstrapArmiTestEnv():
    """
    Perform ARMI config appropriate for running unit tests

    .. tip:: This can be imported and run from other ARMI applications
        for test support.
    """
    from armi.nucDirectory import nuclideBases

    cs = caseSettings.Settings()

    context.Mode.setMode(context.Mode.BATCH)
    settings.setMasterCs(cs)
    # Need to init burnChain.
    # see armi.cases.case.Case._initBurnChain
    with open(cs["burnChainFileName"]) as burnChainStream:
        nuclideBases.imposeBurnChain(burnChainStream)

    # turn on a non-interactive mpl backend to minimize errors related to
    # initializing Tcl in parallel tests
    matplotlib.use("agg")

    # set and create a test-specific FAST_PATH for parallel unit testing
    # Not all unit tests have operators, and operators are usually
    # responsible for making FAST_PATH, so we make it here.
    # It will be deleted by the atexit hook.
    context.activateLocalFastPath()
    if not os.path.exists(context.getFastPath()):
        os.makedirs(context.getFastPath())

    # some tests need to find the TEST_ROOT via an env variable when they're
    # filling in templates with ``$ARMITESTBASE`` in them or opening
    # input files use the variable in an `!include` tag. Thus
    # we provide it here.
    os.environ["ARMITESTBASE"] = TEST_ROOT
Пример #2
0
    def _initBurnChain(self):
        """
        Apply the burn chain setting to the nucDir.

        Notes
        -----
        This is admittedly an odd place for this but the burn chain info must be
        applied sometime after user-input has been loaded (for custom burn chains)
        but not long after (because nucDir is framework-level and expected to be
        up-to-date by lots of modules).
        """
        with open(self.cs["burnChainFileName"]) as burnChainStream:
            nuclideBases.imposeBurnChain(burnChainStream)
Пример #3
0
def pytest_sessionstart(session):
    import armi
    from armi import apps
    from armi.nucDirectory import nuclideBases

    print("Initializing generic ARMI Framework application")
    armi.configure(apps.App())
    cs = caseSettings.Settings()
    settings.setMasterCs(cs)
    # Need to init burnChain.
    # see armi.cases.case.Case._initBurnChain
    with open(cs["burnChainFileName"]) as burnChainStream:
        nuclideBases.imposeBurnChain(burnChainStream)
Пример #4
0
 def setUpClass(cls):
     cs = settings.Settings()
     # Need to init burnChain first.
     # see armi.cases.case.Case._initBurnChain
     with open(cs["burnChainFileName"]) as burnChainStream:
         nuclideBases.imposeBurnChain(burnChainStream)
     cs["xsKernel"] = "MC2v2"
     cls.bp = blueprints.Blueprints.load(cls.yamlString)
     cls.a = cls.bp.constructAssem("hex", cs, name="fuel a")
     cls.numUZrNuclides = 29  # Number of nuclides defined `nuclide flags`
     cls.numCustomNuclides = (
         28  # Number of nuclides defined in `nuclide flags` without Zr
     )
Пример #5
0
def plotAll(xlim, ylim):
    """Plot all nuclides and transformations."""
    # load the burn chain input that comes with ARMI
    with open(os.path.join(RES, "burn-chain.yaml")) as burnChainStream:
        nuclideBases.imposeBurnChain(burnChainStream)
    nbs = nuclideBases.instances
    fig, ax = plt.subplots(figsize=(15, 10))

    patches = []
    for nb in nbs:
        if not nb.trans and not nb.decays:
            # skip nuclides without any transmutations defined
            pass
        patch = plotNuc(nb, ax)
        patches.append(patch)
        # loop over all possible transmutations and decays and draw arrows
        for ti, trans in enumerate(nb.trans + nb.decays):
            product = nuclideBases.fromName(trans.productNuclides[0])
            if product.z == 0:
                # skip lumped fission products and DUMP nuclides
                continue
            # add index-based y-offset to minimize overlaps
            x, y, xp, yp = (
                nb.a - nb.z,
                nb.z + ti * 0.05,
                product.a - product.z,
                product.z + ti * 0.05,
            )
            if trans in nb.trans:
                color = "deeppink"
            else:
                color = "orangered"
            ax.annotate(
                "",
                (xp, yp),
                (x, y),
                arrowprops=dict(width=2 * trans.branch,
                                shrink=0.1,
                                alpha=0.4,
                                color=color),
            )
            # add reaction label towards the middle of the arrow
            xlabel = xp - (xp - x) * 0.5
            ylabel = yp - (yp - y) * 0.5
            # pretty up the labels a bit with some LaTeX and rotations
            rxnType = (trans.type.replace("nGamma", r"n,$\gamma$").replace(
                "nalph", r"n,$\alpha$").replace("ad", r"$\alpha$").replace(
                    "bmd", r"$\beta^-$").replace("bpd", r"$\beta^+$"))
            if xp != x:
                # rotate the nuclide type label to sit right on the arrow
                rotation = math.atan((yp - y) / (xp - x)) * 180 / math.pi
            else:
                rotation = 0
            ax.text(xlabel,
                    ylabel,
                    rxnType,
                    color="grey",
                    ha="center",
                    rotation=rotation)

    pc = PatchCollection(patches,
                         facecolor="mistyrose",
                         alpha=0.2,
                         edgecolor="black")
    ax.add_collection(pc)
    ax.set_xlim(xlim)
    ax.set_ylim(ylim)
    ax.set_aspect("equal")
    ax.set_xlabel("Neutrons (N)")
    ax.set_ylabel("Protons (Z)")
    ax.set_title("Transmutations and Decays (with branching)")
    plt.show()
Пример #6
0
 def setUpClass(cls):
     cs = settings.Settings()
     # Need to init burnChain first.
     # see armi.cases.case.Case._initBurnChain
     with open(cs["burnChainFileName"]) as burnChainStream:
         nuclideBases.imposeBurnChain(burnChainStream)
Пример #7
0
def applyDefaultBurnChain():
    """The framework has a default transmutation chain that many users will want to override."""
    with open(os.path.join(RES, "burn-chain.yaml")) as stream:
        nuclideBases.imposeBurnChain(stream)