Skip to content

Commit

Permalink
added check to length of input args for IndependantOperator (#2799)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Romano <[email protected]>
  • Loading branch information
shimwell and paulromano authored Dec 12, 2023
1 parent 15a2199 commit 552adc0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions openmc/deplete/independent_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ def __init__(self,
# Validate micro-xs parameters
check_type('materials', materials, openmc.Materials)
check_type('micros', micros, Iterable, MicroXS)
check_type('fluxes', fluxes, Iterable, float)

if not (len(fluxes) == len(micros) == len(materials)):
msg = (f'The length of fluxes ({len(fluxes)}) should be equal to '
f'the length of micros ({len(micros)}) and the length of '
f'materials ({len(materials)}).')
raise ValueError(msg)

if keff is not None:
check_type('keff', keff, tuple, float)
keff = ufloat(*keff)
Expand Down
18 changes: 17 additions & 1 deletion tests/unit_tests/test_deplete_independent_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

from pathlib import Path

from openmc.deplete import IndependentOperator, MicroXS
import pytest

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

CHAIN_PATH = Path(__file__).parents[1] / "chain_simple.xml"
ONE_GROUP_XS = Path(__file__).parents[1] / "micro_xs_simple.csv"
Expand Down Expand Up @@ -36,3 +38,17 @@ def test_operator_init():
fluxes = [1.0]
micros = [micro_xs]
IndependentOperator(materials, fluxes, micros, CHAIN_PATH)


def test_error_handling():
micro_xs = MicroXS.from_csv(ONE_GROUP_XS)
fuel = Material(name="oxygen")
fuel.add_element("O", 2)
fuel.set_density("g/cc", 1)
fuel.depletable = True
fuel.volume = 1
materials = Materials([fuel])
fluxes = [1.0, 2.0]
micros = [micro_xs]
with pytest.raises(ValueError, match=r"The length of fluxes \(2\)"):
IndependentOperator(materials, fluxes, micros, CHAIN_PATH)

0 comments on commit 552adc0

Please sign in to comment.