mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 13:15:39 -04:00
Apply suggestions from code review
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
parent
3028193f58
commit
358f64c53a
4 changed files with 21 additions and 16 deletions
|
|
@ -641,7 +641,7 @@ variable and whose sub-elements/attributes are as follows:
|
|||
For a "rational" distribution, ``parameters`` should be given as three real
|
||||
numbers :math:`a` and :math:`b` that define the interval :math:`[a,b]` over
|
||||
which random variates are sampled and :math:`n` that defines the exponent of
|
||||
the probability distribution :math:`p(x)=x^n`
|
||||
the probability distribution :math:`p(x)=c x^n`
|
||||
|
||||
For a "discrete" or "tabular" distribution, ``parameters`` provides the
|
||||
:math:`(x,p)` pairs defining the discrete/tabular distribution. All :math:`x`
|
||||
|
|
|
|||
|
|
@ -87,7 +87,9 @@ private:
|
|||
class Rational : public Distribution {
|
||||
public:
|
||||
explicit Rational(pugi::xml_node node);
|
||||
Rational(double a, double b, double n) : offset_{std::pow(a, n+1)}, span_{std::pow(b, n+1) - offset_}, ninv_{1/(n+1)} {};
|
||||
Rational(double a, double b, double n)
|
||||
: offset_ {std::pow(a, n + 1)}, span_ {std::pow(b, n + 1) - offset_},
|
||||
ninv_ {1/(n+1)} {};
|
||||
|
||||
//! Sample a value from the distribution
|
||||
//! \param seed Pseudorandom number seed pointer
|
||||
|
|
@ -95,12 +97,12 @@ public:
|
|||
double sample(uint64_t* seed) const;
|
||||
|
||||
double a() const { return std::pow(offset_, ninv_); }
|
||||
double b() const { return std::pow(offset_+span_, ninv_); }
|
||||
double n() const { return 1/ninv_-1; }
|
||||
double b() const { return std::pow(offset_ + span_, ninv_); }
|
||||
double n() const { return 1 / ninv_ - 1; }
|
||||
private:
|
||||
double offset_; //!< Lower bound of distribution
|
||||
double span_; //!< Upper bound of distribution
|
||||
double ninv_; //!< inverse Exponent of distribution
|
||||
double offset_; //!< a^(n+1)
|
||||
double span_; //!< b^(n+1) - a^(n+1)
|
||||
double ninv_; //!< 1/(n+1)
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -246,6 +246,8 @@ class Uniform(Univariate):
|
|||
|
||||
class Rational(Univariate):
|
||||
"""Distribution with power law probability over a finite interval [a,b]
|
||||
|
||||
The power law distribution has density function :math:`p(x) dx = c x^n dx`.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
|
@ -254,7 +256,8 @@ class Rational(Univariate):
|
|||
b : float, optional
|
||||
Upper bound of the sampling interval. Defaults to unity.
|
||||
n : float, optional
|
||||
power law exponent. Defaults to zero, which is eqivalent to an uniform distribution
|
||||
Power law exponent. Defaults to zero, which is equivalent to a uniform
|
||||
distribution.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
|
@ -289,17 +292,17 @@ class Rational(Univariate):
|
|||
|
||||
@a.setter
|
||||
def a(self, a):
|
||||
cv.check_type('Uniform a', a, Real)
|
||||
cv.check_type('interval lower bound', a, Real)
|
||||
self._a = a
|
||||
|
||||
@b.setter
|
||||
def b(self, b):
|
||||
cv.check_type('Uniform b', b, Real)
|
||||
cv.check_type('interval upper bound', b, Real)
|
||||
self._b = b
|
||||
|
||||
@n.setter
|
||||
def n(self, n):
|
||||
cv.check_type('Uniform n', n, Real)
|
||||
cv.check_type('power law exponent', n, Real)
|
||||
self._n = n
|
||||
|
||||
def to_xml_element(self, element_name):
|
||||
|
|
@ -313,12 +316,12 @@ class Rational(Univariate):
|
|||
Returns
|
||||
-------
|
||||
element : xml.etree.ElementTree.Element
|
||||
XML element containing uniform distribution data
|
||||
XML element containing distribution data
|
||||
|
||||
"""
|
||||
element = ET.Element(element_name)
|
||||
element.set("type", "rational")
|
||||
element.set("parameters", '{} {} {}'.format(self.a, self.b, self.n))
|
||||
element.set("parameters", f'{self.a} {self.b} {self.n}')
|
||||
return element
|
||||
|
||||
@classmethod
|
||||
|
|
@ -333,7 +336,7 @@ class Rational(Univariate):
|
|||
Returns
|
||||
-------
|
||||
openmc.stats.Rational
|
||||
Uniform distribution generated from XML element
|
||||
Distribution generated from XML element
|
||||
|
||||
"""
|
||||
params = get_text(elem, 'parameters').split()
|
||||
|
|
|
|||
|
|
@ -101,9 +101,9 @@ Rational::Rational(pugi::xml_node node)
|
|||
const double b = params.at(1);
|
||||
const double n = params.at(2);
|
||||
|
||||
offset_ = std::pow(a, n+1);
|
||||
offset_ = std::pow(a, n + 1);
|
||||
span_ = std::pow(b, n + 1) - offset_;
|
||||
ninv_ = 1/(n+1);
|
||||
ninv_ = 1 / (n + 1);
|
||||
}
|
||||
|
||||
double Rational::sample(uint64_t* seed) const
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue