From c7175289eb0f801b38b7b684a5ddd4803261f66a Mon Sep 17 00:00:00 2001 From: Jack Fletcher <115663563+j-fletcher@users.noreply.github.com> Date: Thu, 11 Sep 2025 08:57:02 -0400 Subject: [PATCH] PowerLaw raises an error if sampling interval contains negative values (#3542) --- openmc/stats/univariate.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/openmc/stats/univariate.py b/openmc/stats/univariate.py index 28d5e87ef9..d6cf19f2b8 100644 --- a/openmc/stats/univariate.py +++ b/openmc/stats/univariate.py @@ -480,6 +480,9 @@ class PowerLaw(Univariate): """ def __init__(self, a: float = 0.0, b: float = 1.0, n: float = 0.): + if a >= b: + raise ValueError( + "Lower bound of sampling interval must be less than upper bound.") self.a = a self.b = b self.n = n @@ -494,6 +497,9 @@ class PowerLaw(Univariate): @a.setter def a(self, a): cv.check_type('interval lower bound', a, Real) + if a < 0: + raise ValueError( + "PowerLaw sampling is restricted to positive-valued intervals.") self._a = a @property @@ -503,6 +509,9 @@ class PowerLaw(Univariate): @b.setter def b(self, b): cv.check_type('interval upper bound', b, Real) + if b < 0: + raise ValueError( + "PowerLaw sampling is restricted to positive-valued intervals.") self._b = b @property