From 552adc005cd46d737ace131d020852519898eb56 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 12 Dec 2023 23:37:53 +0000 Subject: [PATCH] added check to length of input args for IndependantOperator (#2799) Co-authored-by: Paul Romano --- openmc/deplete/independent_operator.py | 8 ++++++++ .../test_deplete_independent_operator.py | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/openmc/deplete/independent_operator.py b/openmc/deplete/independent_operator.py index b45c8ad75..5469b28c7 100644 --- a/openmc/deplete/independent_operator.py +++ b/openmc/deplete/independent_operator.py @@ -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) diff --git a/tests/unit_tests/test_deplete_independent_operator.py b/tests/unit_tests/test_deplete_independent_operator.py index 813ac06de..9129cf064 100644 --- a/tests/unit_tests/test_deplete_independent_operator.py +++ b/tests/unit_tests/test_deplete_independent_operator.py @@ -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)