added check to length of input args for IndependantOperator (#2799)

Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
Jonathan Shimwell 2023-12-12 23:37:53 +00:00 committed by GitHub
parent 15a2199c0d
commit 552adc005c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View file

@ -130,6 +130,14 @@ class IndependentOperator(OpenMCOperator):
# 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)

View file

@ -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"
@ -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)