Skip to content

Commit

Permalink
Merge 66e52a6 into 190c0ca
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjarrett authored Oct 20, 2021
2 parents 190c0ca + 66e52a6 commit 1b96570
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 117 deletions.
116 changes: 0 additions & 116 deletions armi/reactor/converters/geometryConverters.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,122 +125,6 @@ def __init__(self, cs=None, quiet=False):
self.convReactor = None


class BlockNumberModifier(GeometryChanger):
"""
Change the fueled region to have a certain number of blocks with uniform height.
Notes
-----
Makes some assumptions about how control and fuel blocks are laid out.
"""

def __init__(self, cs):
GeometryChanger.__init__(self, cs)
self.numToAdd = None

def convert(self, r=None):
"""
Changes the fueled region to have a certain number of blocks with uniform height
Makes some assumptions about how control and fuel blocks
are laid out.
"""
refAssem = r.core.refAssem
fuelI = refAssem.getBlocks().index(refAssem.getFirstBlock(Flags.FUEL))
# store this b/c the ref assem length will change.
origRefBlocks = len(refAssem)

for a in r.core.getAssemblies(includeBolAssems=True):
if len(a) == origRefBlocks:
# modify the number of blocks. Otherwise, it might be a shield
# and snapping should accomplish its goal
if a.hasFlags(Flags.FUEL):
self.setNumberOfBlocks(a)
else:
# non-fuel. Control?
self.setNumberOfBlocks(a, blockFlags=a[fuelI].p.flags)
else:
# radial shields, etc. go here.
pass

# update inert assemblies to snap to the proper block sizes.
axMesh = refAssem.getAxialMesh()
for a in r.core.getAssemblies(includeBolAssems=True):
a.makeAxialSnapList(refAssem)
a.setBlockMesh(axMesh)
r.core.updateAxialMesh()
# update bookkeeping.
r.core.regenAssemblyLists()

def setNumberOfBlocks(self, assem, blockFlags=Flags.FUEL):
r"""
Change the region to have a certain number of blocks with uniform height
Useful for parameter studies varying the block resolution.
Parameters
----------
assem : Assembly
The assembly to modify
blockFlags : Flags, optional
Type of block to change. Default: Flags.FUEL. Allows control
assemblies, etc. to be modified just like fuel assemblies.
Notes
-----
This also snaps the non-fuel blocks to the fuel mesh after calling this function
on all assemblies. You will need to manually do this to all inert assems
in the reactor.
This renames blocks according to their axial position. Rerun history tracker
if you're tracking history.
"""
fuelHeight = assem.getTotalHeight(blockFlags)
blockHeight = fuelHeight / self.numToAdd
fuelBlocks = set(assem.getBlocks(blockFlags))
newBlockStack = []
numFuelBlocksAdded = 0
# make a tracker flag that tells us if we're below or above fuel.
# This model requires that there are no inert blocks interspersed in the fuel.
fuelEncountered = False
# add lower blocks, and as much fuel as possible.
for bi, b in enumerate(assem.getBlocks()):
if b not in fuelBlocks:
if fuelEncountered:
# we're above fuel and assem[bi] is the first above-fuel block.
break
else:
# add lower inert blocks as they are
newBlockStack.append(b)
else:
# fuel block.
fuelEncountered = True
if numFuelBlocksAdded < self.numToAdd:
numFuelBlocksAdded += 1
newBlockStack.append(b)
b.setHeight(blockHeight)
b.completeInitialLoading()

# potentially add extra fuel blocks to fill up the assembly.
# this will happen if we increased the number of fuel blocks
# by a lot.
for _extraBlock in range(self.numToAdd - numFuelBlocksAdded):
newB = newBlockStack[-1].duplicate() # copy the last fuel block.
newBlockStack.append(newB)

# add in the upper inert blocks, starting with the bi-th
for b in assem.getBlocks()[bi:]:
newBlockStack.append(b)

# apply the new blocks to this assembly.
assem.removeAll()
for b in newBlockStack:
assem.add(b)
assem.reestablishBlockOrder()


class FuelAssemNumModifier(GeometryChanger):
"""
Modify the number of fuel assemblies in the reactor.
Expand Down
38 changes: 37 additions & 1 deletion armi/reactor/converters/tests/test_geometryConverters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import os
import unittest

from numpy.testing import assert_allclose

from armi import runLog
from armi import settings
from armi.reactor import blocks
Expand All @@ -27,6 +29,7 @@
from armi.reactor.converters import geometryConverters
from armi.reactor.tests.test_reactors import loadTestReactor
from armi.reactor.flags import Flags
from armi.utils import directoryChangers


THIS_DIR = os.path.dirname(__file__)
Expand Down Expand Up @@ -149,7 +152,7 @@ def testConvert(self):
"axialConversionType": "Axial Coordinates",
"uniformThetaMesh": True,
"thetaBins": 1,
"axialMesh": [50, 100, 150, 175],
"axialMesh": [25, 50, 75, 100, 150, 175],
"thetaMesh": [2 * math.pi],
}

Expand All @@ -163,6 +166,39 @@ def testConvert(self):
self._checkBlockComponents(newR)
self._checkNuclidesMatch(expectedNuclideList, newR)
self._checkNuclideMasses(expectedMassDict, newR)
self._checkBlockAtMeshPoint(geomConv)
self._checkReactorMeshCoordinates(geomConv)
figs = geomConv.plotConvertedReactor()
with directoryChangers.TemporaryDirectoryChanger():
geomConv.plotConvertedReactor("fname")

def _checkBlockAtMeshPoint(self, geomConv):
b = geomConv._getBlockAtMeshPoint(0.0, 2.0 * math.pi, 0.0, 12.0, 50.0, 75.0)
self.assertTrue(b.hasFlags(Flags.FUEL))

def _checkReactorMeshCoordinates(self, geomConv):
thetaMesh, radialMesh, axialMesh = geomConv._getReactorMeshCoordinates()
expectedThetaMesh = [math.pi * 2.0]
expectedAxialMesh = [25.0, 50.0, 75.0, 100.0, 150.0, 175.0]
expectedRadialMesh = [
8.794379,
23.26774,
35.177517,
38.33381,
51.279602,
53.494121,
63.417171,
66.975997,
68.686298,
83.893031,
96.738172,
99.107621,
114.32693,
129.549296,
]
assert_allclose(expectedThetaMesh, thetaMesh)
assert_allclose(expectedRadialMesh, radialMesh)
assert_allclose(expectedAxialMesh, axialMesh)

def _getExpectedData(self):
"""Retrieve the mass of all nuclides in the reactor prior to converting."""
Expand Down

0 comments on commit 1b96570

Please sign in to comment.