mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 13:45:36 -04:00
Require atol / rtol to be real in ResultsList.get_step_where
Previous implementation converted a value of None to infinity.
This commit is contained in:
parent
3905e7a8a0
commit
eb5121b14a
2 changed files with 11 additions and 14 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue