def test_minicore(materials, pins, pinArray): PINS_PRIMARY = 8 PINS_NEIGHBOR = 5 primary = hydep.CartesianLattice(3, 3, pitch=1.26, array=pinArray) neighbor = hydep.CartesianLattice(3, 3, pitch=1.26) neighbor.array = [ [pins["fuel"], pins["guide"], pins["fuel"]], [pins["guide"], pins["fuel"], pins["guide"]], [pins["fuel"], pins["guide"], pins["fuel"]], ] stack = hydep.LatticeStack(2, heights=(0, 180, 360), items=[primary, neighbor]) minicore = hydep.CartesianLattice(2, 1, pitch=3 * 1.26, array=[[stack, stack]], name="minicore") assert minicore.size == 2 assert minicore.shape == (1, 2) assert minicore[0, 0] is minicore[0, 1] is stack assert minicore[0, 0][0] is primary assert minicore[0, 0][1] is neighbor found = list(minicore.findMaterials()) assert len(found) == len(materials) assert len(set(id(m) for m in found)) == len(materials) for m in found: assert m is materials[m.name] burnable = minicore.countBurnableMaterials() assert len(burnable) == 1 _hid, (mat, count) = burnable.popitem() assert mat is materials["fuel"] assert count == 2 * (PINS_PRIMARY + PINS_NEIGHBOR) assert minicore.differentiateBurnableMaterials() is minicore assert minicore[0, 0] is stack assert minicore[0, 0][0] is primary assert minicore[0, 0][1] is neighbor assert minicore[0, 1] is not stack # Count new materials newburnable = minicore.countBurnableMaterials() assert len(newburnable) == count for _mat, count in newburnable.values(): assert count == 1
def test_latticeStack(materials, pins, pinArray): xylattice = hydep.CartesianLattice(3, 3, pitch=1.26, array=pinArray) assert xylattice.id == len(pins) + 1 stack = hydep.LatticeStack(1, heights=(0, 1), items=[xylattice]) assert stack.id == xylattice.id + 1 hwidth = xylattice.nx * xylattice.pitch * 0.5 assert len(stack) == 1 assert stack.items[0] is stack[0] is xylattice for ix, item in enumerate(stack): assert ix == 0, "Over iterated" assert item is xylattice numpy.testing.assert_equal(stack.heights, (0, 1)) found = list(stack.findMaterials()) assert len(found) == len(set(m.name for m in found)) assert len(found) == len(materials) burnable = stack.countBurnableMaterials() assert len(burnable) == 1 _hid, (mat, count) = burnable.popitem() assert mat is materials["fuel"] assert count == 8 bounds = stack.boundaries() assert bounds.x == bounds.y == (-hwidth, hwidth) assert bounds.z == (0, 1)
def depletionModel(): # Roughly one-fourth volume of fuel in PWR VOLUME = math.pi * 0.49**2 * 360 * 264 / 4 fuel1 = hydep.BurnableMaterial("partially burned PWR fuel", adens=2.6858e-2, temperature=900, volume=VOLUME) ISO_THRESH = 1e-10 CONC_FILE = pathlib.Path(__file__).parent / "partial_burned.dat" with CONC_FILE.open("r") as stream: for line in stream: za, adens = line.split() adens = float(adens) if adens < ISO_THRESH: continue z, a = divmod(int(za), 1000) fuel1[(z, a, 0)] = adens water = hydep.Material("water", mdens=0.7, H1=2, O16=1) clad = hydep.Material("clad", mdens=6.6, Zr96=1) fuel2 = fuel1.copy() fuel3 = fuel1.copy() fuel4 = hydep.BurnableMaterial( "other fuel", adens=fuel1.adens, temperature=fuel1.temperature, volume=VOLUME, O16=4.643355421e-4, U234=4.742255584e-9, U235=7.403701961e-4, U236=1.090905903e-5, U238=2.550365361e-2, ) pin1 = hydep.Pin([0.39, 0.42], [fuel1, clad], outer=water) pin2 = hydep.Pin([0.39, 0.42], [fuel2, clad], outer=water) pin3 = hydep.Pin([0.39, 0.42], [fuel3, clad], outer=water) pin4 = hydep.Pin([0.39, 0.42], [fuel4, clad], outer=water) PITCH = 1.2 cart = hydep.CartesianLattice(nx=2, ny=2, pitch=1.2, array=[[pin1, pin2], [pin3, pin4]], outer=water) assembly = hydep.LatticeStack(1, [0, 360], [cart]) assembly.bounds = ((-PITCH, PITCH), (-PITCH, PITCH), (0, 360)) # TODO Retrieve boundaries from model if given model = hydep.Model(assembly) model.bounds = assembly.bounds yield model
def toy2x2lattice(): """A simple 2x2 model with 4 UO2 fuel pins""" fuel = hydep.BurnableMaterial("fuel", mdens=10.4, U235=8e-4, U238=2e-2, O16=4e-4) clad = hydep.Material("clad", mdens=6, Zr91=4e-2) water = hydep.Material("water", mdens=1, H1=5e-2, O16=2e-2) pin = hydep.Pin([0.42, 0.45], [fuel, clad], outer=water) return hydep.CartesianLattice(2, 2, 1.23, [[pin, pin], [pin, pin]])
def test_diffBuLattice(materials, pins, pinArray): lattice = hydep.CartesianLattice(3, 3, pitch=1.26, array=pinArray, name="cloned lattice") assert len(list(lattice.findMaterials())) == len(materials) assert len(list(lattice.findBurnableMaterials())) == 1 # Nine total pins in pin array # One is guide tube -> 8 fuel pins # All are originally the same fuel pin -> one will not be cloned NEW_PINS = 7 memo = set() assert lattice.differentiateBurnableMaterials(memo) is lattice assert id(lattice) in memo foundguide = False for ix, p in enumerate(lattice.flat): if p is pins["guide"]: foundguide = True continue if ix == 0: assert p is pins["fuel"] else: assert p is not pins["fuel"] assert foundguide assert len(list(lattice.findMaterials())) == len(materials) + NEW_PINS assert len(list(lattice.findBurnableMaterials())) == 1 + NEW_PINS # Repeat again to ensure that a new array is created newlat = lattice.differentiateBurnableMaterials(memo) assert newlat is not lattice assert newlat.shape == lattice.shape assert newlat.pitch == lattice.pitch assert newlat.name == lattice.name assert newlat.id != lattice.id foundguide = False for p in newlat.flat: if p is pins["guide"]: foundguide = True else: assert p is not pins["fuel"] assert foundguide
def simpleSfvProblem(endfChain): PIN_RAD = 0.39 PIN_HEIGHT = 10 PITCH = 1.2 volume = math.pi * PIN_RAD**2 * PIN_HEIGHT fuel1 = hydep.BurnableMaterial("partial burned PWR fuel", adens=2.6856e-2, temperature=900, volume=volume) fuel1[80160] = 4.643e-04 fuel1[922340] = 4.742e-9 fuel1[922350] = 7.404e-4 fuel1[922360] = 1.091e-5 fuel1[922380] = 2.550e-5 fuel1[942390] = 2.569e-05 fuel1[942400] = 1.099e-06 fuel1[942410] = 1.225e-07 fuel1[942420] = 1.866e-09 fuel2 = fuel1.copy() fuel3 = fuel1.copy() fuel4 = hydep.BurnableMaterial( "other fuel", adens=fuel1.adens, temperature=fuel1.temperature, volume=volume, O16=4.6433e-4, U234=4.742e-9, U235=7.403e-4, U236=1.091e-5, U238=2.55e-2, ) water = hydep.Material("water", mdens=0.7, H1=2, O16=1) clad = hydep.Material("clad", mdens=6.6, Zr96=1) pin1 = hydep.Pin([PIN_RAD, 0.42], [fuel1, clad], outer=water) pin2 = hydep.Pin([PIN_RAD, 0.42], [fuel2, clad], outer=water) pin3 = hydep.Pin([PIN_RAD, 0.42], [fuel3, clad], outer=water) pin4 = hydep.Pin([PIN_RAD, 0.42], [fuel4, clad], outer=water) cart = hydep.CartesianLattice(nx=2, ny=2, pitch=1.2, array=[[pin1, pin2], [pin3, pin4]], outer=water) assembly = hydep.LatticeStack(2, [0, PIN_HEIGHT, 2 * PIN_HEIGHT], [cart, cart]) assembly.bounds = ((-PITCH, PITCH), (-PITCH, PITCH), (0, 2 * PIN_HEIGHT)) model = hydep.Model(assembly) model.bounds = assembly.bounds model.root.differentiateBurnableMaterials() problem = Mock() problem.model = model problem.dep.burnable = tuple(model.root.findBurnableMaterials()) problem.dep.chain = endfChain settings = hydep.settings.Settings(fittingOrder=1, numFittingPoints=2) settings.sfv.densityCutoff = 0.0 settings.sfv.modes = len(problem.dep.burnable) - 2 problem.settings = settings yield problem
def test_cartesianLattice(materials, pins, pinArray): lat = hydep.CartesianLattice(3, 3, pitch=1.26) assert lat.id == len(pins) + 1 hwidth = 1.5 * lat.pitch # Act on "empty" lattice assert len(lat) == 3 for _item in lat: raise RuntimeError("Iteration on empty array should not be supported") with pytest.raises(AttributeError, match="Array not set"): lat[0, 1] with pytest.raises(AttributeError, match="Array not set"): list(lat.findMaterials()) with pytest.raises(AttributeError, match="Array not set"): lat.countBurnableMaterials() lat[0, 1] = pins["guide"] assert lat[0, 1] is pins["guide"] assert lat[0, 0] is None # default numpy empty object lat.array = pinArray assert lat.nx == 3 assert lat.ny == 3 assert lat.array.shape == lat.shape == (3, 3) assert lat.pitch == 1.26 assert lat.array.size == lat.size == 9 assert lat.array.dtype == object bounds = lat.boundaries() assert bounds.x == bounds.y == (-hwidth, hwidth) assert bounds.z == (-numpy.inf, numpy.inf) assert lat[0, 0] is pins["fuel"] assert lat[1, 1] is pins["guide"] for rx, row in enumerate(lat): assert row.size == 3 for cx, cpin in enumerate(row): assert cpin is pinArray[rx][cx] mats = list(lat.findMaterials()) assert len(mats) == len(materials) for mat in mats: assert mat is materials[mat.name] burnable = list(lat.findBurnableMaterials()) assert len(burnable) == 1 assert burnable[0] is materials["fuel"] burnCount = lat.countBurnableMaterials() assert len(burnCount) == 1 _hid, (mat, count) = burnCount.popitem() assert mat is materials["fuel"] assert count == 8 lat[1, 1] = pins["segmented"] assert lat[1, 1] is pins["segmented"] burnCount = lat.countBurnableMaterials() assert len(burnCount) == 1 _hid, (mat, count) = burnCount.popitem() assert mat is materials["fuel"] assert count == 10 for l, a in zip(lat.flat, lat.array.flat): assert l is a lat.center = (-1, 1) assert lat.center == (-1, 1) with pytest.raises(TypeError, match="X|x"): lat.center = ("1", 1) assert lat.center == (-1, 1) with pytest.raises(TypeError, match="Y|y"): lat.center = (1, "1.2") assert lat.center == (-1, 1) lat.center = (4.5, -100.0) with pytest.raises(TypeError, match="Center"): lat.center = (0.0, 0.0, 0.0) assert lat.center == (4.5, -100)