Exemplo n.º 1
0
 def _perturbTemps(self, block, cName, tCold, tHot):
     "Give the component different ref and hot temperatures than in test_Blocks."
     c = block.getComponent(Flags.fromString(cName))
     c.refTemp, c.refHot = tCold, tHot
     c.applyHotHeightDensityReduction()
     c.setTemperature(tHot)
     return block
Exemplo n.º 2
0
 def _perturbTemps(self, block, cName, tCold, tHot):
     "Give the component different ref and hot temperatures than in test_Blocks."
     c = block.getComponent(Flags.fromString(cName))
     c.refTemp, c.refHot = tCold, tHot
     c.applyMaterialMassFracsToNumberDensities()
     c.setTemperature(tHot)
     return block
Exemplo n.º 3
0
    def __init__(self, allNuclidesInProblem, validBlockTypes=None):
        list.__init__(self)
        self.allNuclidesInProblem = allNuclidesInProblem
        self.weightingParam = None

        # allowed to be independent of fuel component temperatures b/c Doppler
        self.avgNucTemperatures = {}
        self._validRepresentativeBlockTypes = None
        if validBlockTypes:
            self._validRepresentativeBlockTypes = []
            for t in validBlockTypes:
                self._validRepresentativeBlockTypes.append(Flags.fromString(t))
Exemplo n.º 4
0
def _setComponentFlags(component, flags, blueprint):
    """Update component flags based on user input in blueprint"""
    # the component __init__ calls setType(), which gives us our initial guess at
    # what the flags should be.
    if flags is not None:
        # override the flags from __init__ with the ones from the blueprint
        component.p.flags = Flags.fromString(flags)
    else:
        # potentially add the DEPLETABLE flag. Don't do this if we set flags
        # explicitly. WARNING: If you add flags explicitly, it will
        # turn off depletion so be sure to add depletable to your list of flags
        # if you expect depletion
        if any(nuc in blueprint.activeNuclides
               for nuc in component.getNuclides()):
            component.p.flags |= Flags.DEPLETABLE
Exemplo n.º 5
0
    def construct(self, blueprint, matMods):
        """Construct a component"""
        runLog.debug("Constructing component {}".format(self.name))
        kwargs = self._conformKwargs(blueprint, matMods)
        component = components.factory(self.shape.strip().lower(), [], kwargs)

        # the component __init__ calls setType(), which gives us our initial guess at
        # what the flags should be.
        if self.flags is not None:
            # override the flags from __init__ with the ones from the blueprint
            component.p.flags = Flags.fromString(self.flags)
        else:
            # potentially add the DEPLETABLE flag. Don't do this if we set flags
            # explicitly
            _insertDepletableNuclideKeys(component, blueprint)
        return component
Exemplo n.º 6
0
    def _constructAssembly(self, cs, blueprint):
        """Construct the current assembly."""
        blocks = []
        for axialIndex, bDesign in enumerate(self.blocks):
            b = self._createBlock(cs, blueprint, bDesign, axialIndex)
            blocks.append(b)

        assemblyClass = self.getAssemClass(blocks)
        a = assemblyClass(self.name)
        flags = None
        if self.flags is not None:
            flags = Flags.fromString(self.flags)
            a.p.flags = flags

        # set a basic grid with the right number of blocks with bounds to be adjusted.
        a.spatialGrid = grids.axialUnitGrid(len(blocks))
        a.spatialGrid.armiObject = a

        # TODO: Remove mesh points from blueprints entirely. Submeshing should be
        # handled by specific physics interfaces
        radMeshPoints = self.radialMeshPoints or 1
        a.p.RadMesh = radMeshPoints
        aziMeshPoints = self.azimuthalMeshPoints or 1
        a.p.AziMesh = aziMeshPoints

        # loop a second time because we needed all the blocks before choosing the
        # assembly class.
        for axialIndex, block in enumerate(blocks):
            b.p.assemNum = a.p.assemNum
            b.name = b.makeName(a.p.assemNum, axialIndex)
            a.add(block)

        # Assign values for the parameters if they are defined on the blueprints
        for paramDef in a.p.paramDefs.inCategory(
            parameters.Category.assignInBlueprints
        ):
            val = getattr(self, paramDef.name)
            if val is not None:
                a.p[paramDef.name] = val

        return a
Exemplo n.º 7
0
    def schema(val) -> List[Flags]:
        """
        Return a list of :py:class:`Flags <armi.reactor.flags.Flags`.
        
        Raises
        ------
        TypeError
            When ``val`` is not a list.
        ValueError
            When ``val`` is not an instance of str or Flags.
        """
        if not isinstance(val, list):
            raise TypeError(f"Expected `{val}` to be a list.")

        flagVals = []
        for v in val:
            if isinstance(v, str):
                flagVals.append(Flags.fromString(v))
            elif isinstance(v, Flags):
                flagVals.append(v)
            else:
                raise ValueError(f"Invalid flag input `{v}` in `{self}`")
        return flagVals
Exemplo n.º 8
0
    def construct(self, blueprint, matMods):
        """Construct a component"""
        runLog.debug("Constructing component {}".format(self.name))
        kwargs = self._conformKwargs(blueprint, matMods)
        component = components.factory(self.shape.strip().lower(), [], kwargs)

        # the component __init__ calls setType(), which gives us our initial guess at
        # what the flags should be.
        if self.flags is not None:
            # override the flags from __init__ with the ones from the blueprint
            component.p.flags = Flags.fromString(self.flags)
        else:
            # potentially add the DEPLETABLE flag. Don't do this if we set flags
            # explicitly. WARNING: If you add flags explicitly, it will
            # turn off depletion so be sure to add depletable to your list of flags
            # if you expect depletion
            if any(nuc in blueprint.activeNuclides for nuc in component.getNuclides()):
                component.p.flags |= Flags.DEPLETABLE

        if component.hasFlags(Flags.DEPLETABLE):
            # depletable components, whether auto-derived or explicitly flagged need expanded nucs
            _insertDepletableNuclideKeys(component, blueprint)
        return component
Exemplo n.º 9
0
    def construct(self, cs, blueprint, axialIndex, axialMeshPoints, height,
                  xsType, materialInput):
        """
        Construct an ARMI ``Block`` to be placed in an ``Assembly``.

        Parameters
        ----------
        cs : CaseSettings
            CaseSettings object for the appropriate simulation.

        blueprint : Blueprints
            Blueprints object containing various detailed information, such as nuclides to model

        axialIndex : int
            The Axial index this block exists within the parent assembly

        axialMeshPoints : int
            number of mesh points for use in the neutronics kernel

        height : float
            initial height of the block

        xsType : str
            String representing the xsType of this block.

        materialInput : dict
            dict containing material modification names and values
        """
        runLog.debug("Constructing block {}".format(self.name))
        components = collections.OrderedDict()
        # build grid before components so you can load
        # the components into the grid.
        gridDesign = self._getGridDesign(blueprint)
        if gridDesign:
            spatialGrid = gridDesign.construct()
        else:
            spatialGrid = None
        for componentDesign in self:
            c = componentDesign.construct(blueprint, materialInput)
            components[c.name] = c
            if spatialGrid:
                componentLocators = gridDesign.getMultiLocator(
                    spatialGrid, componentDesign.latticeIDs)
                if componentLocators:
                    # this component is defined in the block grid
                    # We can infer the multiplicity from the grid.
                    # Otherwise it's a component that is in a block
                    # with grids but that's not in the grid itself.
                    c.spatialLocator = componentLocators
                    mult = c.getDimension("mult")
                    if mult and mult != 1.0 and mult != len(c.spatialLocator):
                        raise ValueError(
                            f"Conflicting ``mult`` input ({mult}) and number of "
                            f"lattice positions ({len(c.spatialLocator)}) for {c}. "
                            "Recommend leaving off ``mult`` input when using grids."
                        )
                    elif not mult or mult == 1.0:
                        # learn mult from grid definition
                        c.setDimension("mult", len(c.spatialLocator))

        for c in components.values():
            c._resolveLinkedDims(components)

        boundingComp = sorted(components.values())[-1]
        # give a temporary name (will be updated by b.makeName as real blocks populate systems)
        b = self._getBlockClass(boundingComp)(
            name=f"block-bol-{axialIndex:03d}")

        for paramDef in b.p.paramDefs.inCategory(
                parameters.Category.assignInBlueprints):
            val = getattr(self, paramDef.name)
            if val is not None:
                b.p[paramDef.name] = val

        flags = None
        if self.flags is not None:
            flags = Flags.fromString(self.flags)

        b.setType(self.name, flags)
        for c in components.values():
            b.add(c)
        b.p.nPins = b.getNumPins()
        b.p.axMesh = _setBlueprintNumberOfAxialMeshes(
            axialMeshPoints, cs["axialMeshRefinementFactor"])
        b.p.height = height
        b.p.heightBOL = height  # for fuel performance
        b.p.xsType = xsType
        b.setBuLimitInfo(cs)
        b = self._mergeComponents(b)
        b.verifyBlockDims()
        b.spatialGrid = spatialGrid

        return b
Exemplo n.º 10
0
def _plotBlocksInAssembly(
    axis,
    assem,
    isLastAssem,
    yBlockHeights,
    yBlockAxMesh,
    xAssemLoc,
    xAssemEndLoc,
    showBlockAxMesh,
):
    # Set dictionary of pre-defined block types and colors for the plot
    lightsage = "xkcd:light sage"
    blockTypeColorMap = collections.OrderedDict({
        "fuel": "tomato",
        "shield": "cadetblue",
        "reflector": "darkcyan",
        "aclp": "lightslategrey",
        "plenum": "white",
        "duct": "plum",
        "control": lightsage,
        "handling socket": "lightgrey",
        "grid plate": "lightgrey",
        "inlet nozzle": "lightgrey",
    })

    # Initialize block positions
    blockWidth = 5.0
    yBlockLoc = 0
    xBlockLoc = xAssemLoc
    xTextLoc = xBlockLoc + blockWidth / 20.0
    for b in assem:
        blockHeight = b.getHeight()
        blockXsId = b.p.xsType
        yBlockCenterLoc = yBlockLoc + blockHeight / 2.5

        # Get the basic text label for the block
        try:
            blockType = [
                bType for bType in blockTypeColorMap.keys()
                if b.hasFlags(Flags.fromString(bType))
            ][0]
            color = blockTypeColorMap[blockType]
        except IndexError:
            blockType = b.getType()
            color = "grey"

        # Get the detailed text label for the block
        dLabel = ""
        if b.hasFlags(Flags.FUEL):
            dLabel = " {:0.2f}%".format(b.getFissileMassEnrich() * 100)
        elif b.hasFlags(Flags.CONTROL):
            blockType = "ctrl"
            dLabel = " {:0.2f}%".format(b.getBoronMassEnrich() * 100)
        dLabel += " ({})".format(blockXsId)

        # Set up block rectangle
        blockPatch = matplotlib.patches.Rectangle(
            (xBlockLoc, yBlockLoc),
            blockWidth,
            blockHeight,
            facecolor=color,
            alpha=0.7,
            edgecolor="k",
            lw=1.0,
            ls="solid",
        )
        axis.add_patch(blockPatch)
        axis.text(
            xTextLoc,
            yBlockCenterLoc,
            blockType.upper() + dLabel,
            ha="left",
            fontsize=10,
        )
        yBlockLoc += blockHeight
        yBlockHeights.append(yBlockLoc)

        # Add location, block heights, and axial mesh points to ordered set
        yBlockAxMesh.add((yBlockCenterLoc, blockHeight, b.p.axMesh))

    # Add the block heights, block number of axial mesh points on the far right of the plot.
    if isLastAssem and showBlockAxMesh:
        xEndLoc = 0.5 + xAssemEndLoc
        for bCenter, bHeight, axMeshPoints in yBlockAxMesh:
            axis.text(
                xEndLoc,
                bCenter,
                "{} cm ({})".format(bHeight, axMeshPoints),
                fontsize=10,
                ha="left",
            )

    return xBlockLoc, yBlockHeights, yBlockAxMesh
Exemplo n.º 11
0
    def construct(self, cs, blueprint, axialIndex, axialMeshPoints, height,
                  xsType, materialInput):
        """
        Construct an ARMI ``Block`` to be placed in an ``Assembly``.

        Parameters
        ----------
        cs : CaseSettings
            CaseSettings object for the appropriate simulation.

        blueprint : Blueprints
            Blueprints object containing various detailed information, such as nuclides to model

        axialIndex : int
            The Axial index this block exists within the parent assembly

        axialMeshPoints : int
            number of mesh points for use in the neutronics kernel

        height : float
            initial height of the block

        xsType : str
            String representing the xsType of this block.

        materialInput : dict
            Double-layered dict.
            Top layer groups the by-block material modifications under the `byBlock` key
            and the by-component material modifications under the component's name.
            The inner dict under each key contains material modification names and values.
        """
        runLog.debug("Constructing block {}".format(self.name))
        components = collections.OrderedDict()
        # build grid before components so you can load
        # the components into the grid.
        gridDesign = self._getGridDesign(blueprint)
        if gridDesign:
            spatialGrid = gridDesign.construct()
        else:
            spatialGrid = None

        self._checkByComponentMaterialInput(materialInput)

        for componentDesign in self:
            filteredMaterialInput = self._filterMaterialInput(
                materialInput, componentDesign)
            c = componentDesign.construct(blueprint, filteredMaterialInput)
            if cs["inputHeightsConsideredHot"]:
                if "group" in c.name:
                    for component in c:
                        component.applyHotHeightDensityReduction()
                        componentBlueprint.insertDepletableNuclideKeys(
                            component, blueprint)
                else:
                    c.applyHotHeightDensityReduction()
                    componentBlueprint.insertDepletableNuclideKeys(
                        c, blueprint)
            components[c.name] = c
            if spatialGrid:
                componentLocators = gridDesign.getMultiLocator(
                    spatialGrid, componentDesign.latticeIDs)
                if componentLocators:
                    # this component is defined in the block grid
                    # We can infer the multiplicity from the grid.
                    # Otherwise it's a component that is in a block
                    # with grids but that's not in the grid itself.
                    c.spatialLocator = componentLocators
                    mult = c.getDimension("mult")
                    if mult and mult != 1.0 and mult != len(c.spatialLocator):
                        raise ValueError(
                            f"Conflicting ``mult`` input ({mult}) and number of "
                            f"lattice positions ({len(c.spatialLocator)}) for {c}. "
                            "Recommend leaving off ``mult`` input when using grids."
                        )
                    elif not mult or mult == 1.0:
                        # learn mult from grid definition
                        c.setDimension("mult", len(c.spatialLocator))

        # Resolve linked dims after all components in the block are created
        for c in components.values():
            c.resolveLinkedDims(components)

        boundingComp = sorted(components.values())[-1]
        # give a temporary name (will be updated by b.makeName as real blocks populate systems)
        b = self._getBlockClass(boundingComp)(
            name=f"block-bol-{axialIndex:03d}")

        for paramDef in b.p.paramDefs.inCategory(
                parameters.Category.assignInBlueprints):
            val = getattr(self, paramDef.name)
            if val is not None:
                b.p[paramDef.name] = val

        flags = None
        if self.flags is not None:
            flags = Flags.fromString(self.flags)

        b.setType(self.name, flags)
        for c in components.values():
            b.add(c)
        b.p.nPins = b.getNumPins()
        b.p.axMesh = _setBlueprintNumberOfAxialMeshes(
            axialMeshPoints, cs["axialMeshRefinementFactor"])
        b.p.height = height
        b.p.heightBOL = height  # for fuel performance
        b.p.xsType = xsType
        b.setBuLimitInfo(cs)
        b = self._mergeComponents(b)
        b.verifyBlockDims()
        b.spatialGrid = spatialGrid

        if b.spatialGrid is None and cs[globalSettings.CONF_BLOCK_AUTO_GRID]:
            try:
                b.autoCreateSpatialGrids()
            except (ValueError, NotImplementedError) as e:
                runLog.warning(str(e), single=True)
        return b