Skip to content

Commit 358f64c

Browse files
Apply suggestions from code review
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
1 parent 3028193 commit 358f64c

4 files changed

Lines changed: 21 additions & 16 deletions

File tree

‎docs/source/io_formats/settings.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ variable and whose sub-elements/attributes are as follows:
641641
For a "rational" distribution, ``parameters`` should be given as three real
642642
numbers :math:`a` and :math:`b` that define the interval :math:`[a,b]` over
643643
which random variates are sampled and :math:`n` that defines the exponent of
644-
the probability distribution :math:`p(x)=x^n`
644+
the probability distribution :math:`p(x)=c x^n`
645645

646646
For a "discrete" or "tabular" distribution, ``parameters`` provides the
647647
:math:`(x,p)` pairs defining the discrete/tabular distribution. All :math:`x`

‎include/openmc/distribution.h‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,22 @@ class Uniform : public Distribution {
8787
class Rational : public Distribution {
8888
public:
8989
explicit Rational(pugi::xml_node node);
90-
Rational(double a, double b, double n) : offset_{std::pow(a, n+1)}, span_{std::pow(b, n+1) - offset_}, ninv_{1/(n+1)} {};
90+
Rational(double a, double b, double n)
91+
: offset_ {std::pow(a, n + 1)}, span_ {std::pow(b, n + 1) - offset_},
92+
ninv_ {1/(n+1)} {};
9193

9294
//! Sample a value from the distribution
9395
//! \param seed Pseudorandom number seed pointer
9496
//! \return Sampled value
9597
double sample(uint64_t* seed) const;
9698

9799
double a() const { return std::pow(offset_, ninv_); }
98-
double b() const { return std::pow(offset_+span_, ninv_); }
99-
double n() const { return 1/ninv_-1; }
100+
double b() const { return std::pow(offset_ + span_, ninv_); }
101+
double n() const { return 1 / ninv_ - 1; }
100102
private:
101-
double offset_; //!< Lower bound of distribution
102-
double span_; //!< Upper bound of distribution
103-
double ninv_; //!< inverse Exponent of distribution
103+
double offset_; //!< a^(n+1)
104+
double span_; //!< b^(n+1) - a^(n+1)
105+
double ninv_; //!< 1/(n+1)
104106
};
105107

106108
//==============================================================================

‎openmc/stats/univariate.py‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ def from_xml_element(cls, elem):
246246

247247
class Rational(Univariate):
248248
"""Distribution with power law probability over a finite interval [a,b]
249+
250+
The power law distribution has density function :math:`p(x) dx = c x^n dx`.
249251
250252
Parameters
251253
----------
@@ -254,7 +256,8 @@ class Rational(Univariate):
254256
b : float, optional
255257
Upper bound of the sampling interval. Defaults to unity.
256258
n : float, optional
257-
power law exponent. Defaults to zero, which is eqivalent to an uniform distribution
259+
Power law exponent. Defaults to zero, which is equivalent to a uniform
260+
distribution.
258261
259262
Attributes
260263
----------
@@ -289,17 +292,17 @@ def n(self):
289292

290293
@a.setter
291294
def a(self, a):
292-
cv.check_type('Uniform a', a, Real)
295+
cv.check_type('interval lower bound', a, Real)
293296
self._a = a
294297

295298
@b.setter
296299
def b(self, b):
297-
cv.check_type('Uniform b', b, Real)
300+
cv.check_type('interval upper bound', b, Real)
298301
self._b = b
299302

300303
@n.setter
301304
def n(self, n):
302-
cv.check_type('Uniform n', n, Real)
305+
cv.check_type('power law exponent', n, Real)
303306
self._n = n
304307

305308
def to_xml_element(self, element_name):
@@ -313,12 +316,12 @@ def to_xml_element(self, element_name):
313316
Returns
314317
-------
315318
element : xml.etree.ElementTree.Element
316-
XML element containing uniform distribution data
319+
XML element containing distribution data
317320
318321
"""
319322
element = ET.Element(element_name)
320323
element.set("type", "rational")
321-
element.set("parameters", '{} {} {}'.format(self.a, self.b, self.n))
324+
element.set("parameters", f'{self.a} {self.b} {self.n}')
322325
return element
323326

324327
@classmethod
@@ -333,7 +336,7 @@ def from_xml_element(cls, elem):
333336
Returns
334337
-------
335338
openmc.stats.Rational
336-
Uniform distribution generated from XML element
339+
Distribution generated from XML element
337340
338341
"""
339342
params = get_text(elem, 'parameters').split()

‎src/distribution.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ Rational::Rational(pugi::xml_node node)
101101
const double b = params.at(1);
102102
const double n = params.at(2);
103103

104-
offset_ = std::pow(a, n+1);
104+
offset_ = std::pow(a, n + 1);
105105
span_ = std::pow(b, n + 1) - offset_;
106-
ninv_ = 1/(n+1);
106+
ninv_ = 1 / (n + 1);
107107
}
108108

109109
double Rational::sample(uint64_t* seed) const

0 commit comments

Comments
 (0)