mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 13:45:36 -04:00
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:
parent
15a2199c0d
commit
552adc005c
2 changed files with 25 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue