mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Avoid divide-by-zero in from_multigroup_flux when flux is zero (#3624)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
parent
5c2bfe771e
commit
e5348d3f62
2 changed files with 21 additions and 4 deletions
|
|
@ -356,13 +356,17 @@ class MicroXS:
|
|||
reactions = chain.reactions
|
||||
mts = [REACTION_MT[name] for name in reactions]
|
||||
|
||||
# Normalize multigroup flux
|
||||
multigroup_flux = np.array(multigroup_flux)
|
||||
multigroup_flux /= multigroup_flux.sum()
|
||||
|
||||
# Create 3D array for microscopic cross sections
|
||||
microxs_arr = np.zeros((len(nuclides), len(mts), 1))
|
||||
|
||||
# If flux is zero, safely return zero cross sections
|
||||
multigroup_flux = np.array(multigroup_flux)
|
||||
if (flux_sum := multigroup_flux.sum()) == 0.0:
|
||||
return cls(microxs_arr, nuclides, reactions)
|
||||
|
||||
# Normalize multigroup flux
|
||||
multigroup_flux /= flux_sum
|
||||
|
||||
# Compute microscopic cross sections within a temporary session
|
||||
with openmc.lib.TemporarySession(**init_kwargs):
|
||||
# For each nuclide and reaction, compute the flux-averaged xs
|
||||
|
|
|
|||
|
|
@ -111,3 +111,16 @@ def test_multigroup_flux_same():
|
|||
energies=energies, multigroup_flux=flux, chain_file=chain_file)
|
||||
|
||||
assert microxs_4g.data == pytest.approx(microxs_2g.data)
|
||||
|
||||
|
||||
def test_microxs_zero_flux():
|
||||
chain_file = Path(__file__).parents[1] / 'chain_simple.xml'
|
||||
|
||||
# Generate micro XS based on zero flux
|
||||
energies = [0., 6.25e-1, 5.53e3, 8.21e5, 2.e7]
|
||||
flux = [0.0, 0.0, 0.0, 0.0]
|
||||
microxs = MicroXS.from_multigroup_flux(
|
||||
energies=energies, multigroup_flux=flux, chain_file=chain_file)
|
||||
|
||||
# All microscopic cross sections should be zero
|
||||
assert np.all(microxs.data == 0.0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue