Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions openmc/deplete/independent_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class IndependentOperator(OpenMCOperator):

Parameters
----------
materials : openmc.Materials
materials : iterable of openmc.Material
Materials to deplete.
fluxes : list of numpy.ndarray
Flux in each group in [n-cm/src] for each domain
Expand Down Expand Up @@ -127,8 +127,9 @@ def __init__(self,
reduce_chain_level=None,
fission_yield_opts=None):
# Validate micro-xs parameters
check_type('materials', materials, openmc.Materials)
check_type('materials', materials, Iterable, openmc.Material)
check_type('micros', micros, Iterable, MicroXS)
materials = openmc.Materials(materials)

if not (len(fluxes) == len(micros) == len(materials)):
msg = (f'The length of fluxes ({len(fluxes)}) should be equal to '
Expand Down
10 changes: 6 additions & 4 deletions openmc/deplete/microxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ class MicroXS:
"""
def __init__(self, data: np.ndarray, nuclides: list[str], reactions: list[str]):
# Validate inputs
if len(data.shape) != 3:
raise ValueError('Data array must be 3D.')
if data.shape[:2] != (len(nuclides), len(reactions)):
raise ValueError(
f'Nuclides list of length {len(nuclides)} and '
Expand Down Expand Up @@ -291,11 +293,11 @@ def from_multigroup_flux(
mts = [REACTION_MT[name] for name in reactions]

# Normalize multigroup flux
multigroup_flux = np.asarray(multigroup_flux)
multigroup_flux = np.array(multigroup_flux)
multigroup_flux /= multigroup_flux.sum()

# Create 2D array for microscopic cross sections
microxs_arr = np.zeros((len(nuclides), len(mts)))
# Create 3D array for microscopic cross sections
microxs_arr = np.zeros((len(nuclides), len(mts), 1))

# Create a material with all nuclides
mat_all_nucs = openmc.Material()
Expand Down Expand Up @@ -327,7 +329,7 @@ def from_multigroup_flux(
xs = lib_nuc.collapse_rate(
mt, temperature, energies, multigroup_flux
)
microxs_arr[nuc_index, mt_index] = xs
microxs_arr[nuc_index, mt_index, 0] = xs

return cls(microxs_arr, nuclides, reactions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the changes above look good, but would this also do the trick?

Suggested change
return cls(microxs_arr, nuclides, reactions)
# ensure microxs_arr has the correct number of dimensions for a one-group cross section
microxs_arr = np.expand_dims(microxs_arr, -1)
return cls(microxs_arr, nuclides, reactions)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work if we keep microxs_arr as 2D, but it is a lot less obvious to someone reading the code in my opinion, so I'd prefer the current version (explicit is better than implicit).


Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_deplete_decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_deplete_decay_products(run_in_tmpdir):
""")

# Create MicroXS object with no cross sections
micro_xs = openmc.deplete.MicroXS(np.empty((0, 0)), [], [])
micro_xs = openmc.deplete.MicroXS(np.empty((0, 0, 0)), [], [])

# Create depletion operator with no reactions
op = openmc.deplete.IndependentOperator.from_nuclides(
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_deplete_decay_step_fissionable(run_in_tmpdir):
"""

# Set up a pure decay operator
micro_xs = openmc.deplete.MicroXS(np.empty((0, 0)), [], [])
micro_xs = openmc.deplete.MicroXS(np.empty((0, 0, 0)), [], [])
mat = openmc.Material()
mat.name = 'I do not decay.'
mat.add_nuclide('U238', 1.0, 'ao')
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/test_deplete_independent_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from openmc import Material, Materials
from openmc import Material
from openmc.deplete import IndependentOperator, MicroXS

CHAIN_PATH = Path(__file__).parents[1] / "chain_simple.xml"
Expand Down Expand Up @@ -34,7 +34,7 @@ def test_operator_init():
fuel.set_density("g/cc", 10.4)
fuel.depletable = True
fuel.volume = 1
materials = Materials([fuel])
materials = [fuel]
fluxes = [1.0]
micros = [micro_xs]
IndependentOperator(materials, fluxes, micros, CHAIN_PATH)
Expand All @@ -47,7 +47,7 @@ def test_error_handling():
fuel.set_density("g/cc", 1)
fuel.depletable = True
fuel.volume = 1
materials = Materials([fuel])
materials = [fuel]
fluxes = [1.0, 2.0]
micros = [micro_xs]
with pytest.raises(ValueError, match=r"The length of fluxes \(2\)"):
Expand Down
8 changes: 5 additions & 3 deletions tests/unit_tests/test_deplete_microxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def test_from_array():
data.shape = (12, 2, 1)

MicroXS(data, nuclides, reactions)
with pytest.raises(ValueError, match=r'Nuclides list of length \d* and '
r'reactions array of length \d* do not '
r'match dimensions of data array of shape \(\d*\, \d*\)'):
with pytest.raises(ValueError, match='Data array must be 3D'):
MicroXS(data[:, 0], nuclides, reactions)


Expand Down Expand Up @@ -96,9 +94,13 @@ def test_multigroup_flux_same():
energies = [0., 6.25e-1, 5.53e3, 8.21e5, 2.e7]
flux_per_ev = [0.3, 0.3, 1.0, 1.0]
flux = flux_per_ev * np.diff(energies)
flux_sum = flux.sum()
microxs_4g = MicroXS.from_multigroup_flux(
energies=energies, multigroup_flux=flux, chain_file=chain_file)

# from_multigroup_flux should not modify the flux
assert flux.sum() == flux_sum

# Generate micro XS based on 2-group flux, where the boundaries line up with
# the 4 group flux and have the same flux per eV across the full energy
# range
Expand Down