diff --git a/openmc/deplete/results_list.py b/openmc/deplete/results_list.py index 390724fc89..02e55f8f88 100644 --- a/openmc/deplete/results_list.py +++ b/openmc/deplete/results_list.py @@ -243,6 +243,9 @@ class ResultsList(list): will be at most one past the point in time requested, but only according to tolerances requested. + Passing ``atol=math.inf`` and ``rtol=math.inf`` will return + the closest index to the requested point. + Parameters ---------- time : float @@ -251,10 +254,9 @@ class ResultsList(list): Units on ``time``. Default: days atol : float, optional Absolute tolerance (in ``time_units``) if ``time`` is not - found. A value of ``None`` is converted to infinity. + found. rtol : float, optional - Relative tolerance if ``time`` is not found. A value of - ``None`` is converted to infinity. + Relative tolerance if ``time`` is not found. Returns ------- @@ -262,14 +264,8 @@ class ResultsList(list): """ check_type("time", time, numbers.Real) - if atol is not None: - check_type("atol", atol, numbers.Real) - else: - atol = math.inf - if rtol is not None: - check_type("rtol", rtol, numbers.Real) - else: - rtol = math.inf + check_type("atol", atol, numbers.Real) + check_type("rtol", rtol, numbers.Real) times = self.get_times(time_units) diff --git a/tests/unit_tests/test_deplete_resultslist.py b/tests/unit_tests/test_deplete_resultslist.py index c96108cfd2..392d5d0d5c 100644 --- a/tests/unit_tests/test_deplete_resultslist.py +++ b/tests/unit_tests/test_deplete_resultslist.py @@ -1,6 +1,7 @@ """Tests the ResultsList class""" from pathlib import Path +from math import inf import numpy as np import pytest @@ -110,12 +111,12 @@ def test_get_steps(unit): target = value + mult * offset # Compare using absolute and relative tolerances actual = results.get_step_where( - target, time_units=unit, atol=offset * 2, rtol=None) + target, time_units=unit, atol=offset * 2, rtol=inf) assert actual == expected, ( target, times[actual], times[expected], offset) actual = results.get_step_where( - target, time_units=unit, atol=None, rtol=offset / value) + target, time_units=unit, atol=inf, rtol=offset / value) assert actual == expected, ( target, times[actual], times[expected], offset) # Check that the lower index is returned for the exact mid-point @@ -126,5 +127,5 @@ def test_get_steps(unit): # Shoot way over with no tolerance -> just give closest value actual = results.get_step_where( - times[-1] * 100, time_units=unit, atol=None, rtol=None) + times[-1] * 100, time_units=unit, atol=inf, rtol=inf) assert actual == times.size - 1