mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Renamed Rational to Power Law
This commit is contained in:
parent
358f64c53a
commit
c0bcc3f1ca
8 changed files with 28 additions and 27 deletions
|
|
@ -638,7 +638,7 @@ variable and whose sub-elements/attributes are as follows:
|
|||
numbers :math:`a` and :math:`b` that define the interval :math:`[a,b]` over
|
||||
which random variates are sampled.
|
||||
|
||||
For a "rational" distribution, ``parameters`` should be given as three real
|
||||
For a "power law" 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)=c x^n`
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ Univariate Probability Distributions
|
|||
openmc.stats.Univariate
|
||||
openmc.stats.Discrete
|
||||
openmc.stats.Uniform
|
||||
openmc.stats.Rational
|
||||
openmc.stats.PowerLaw
|
||||
openmc.stats.Maxwell
|
||||
openmc.stats.Watt
|
||||
openmc.stats.Tabular
|
||||
|
|
|
|||
|
|
@ -81,15 +81,15 @@ private:
|
|||
};
|
||||
|
||||
//==============================================================================
|
||||
//! Rational distribution over the interval [a,b] with exponent n
|
||||
//! PowerLaw distribution over the interval [a,b] with exponent n : p(x)=c x^n
|
||||
//==============================================================================
|
||||
|
||||
class Rational : public Distribution {
|
||||
class PowerLaw : public Distribution {
|
||||
public:
|
||||
explicit Rational(pugi::xml_node node);
|
||||
Rational(double a, double b, double n)
|
||||
explicit PowerLaw(pugi::xml_node node);
|
||||
PowerLaw(double a, double b, double n)
|
||||
: offset_ {std::pow(a, n + 1)}, span_ {std::pow(b, n + 1) - offset_},
|
||||
ninv_ {1/(n+1)} {};
|
||||
ninv_ {1 / (n + 1)} {};
|
||||
|
||||
//! Sample a value from the distribution
|
||||
//! \param seed Pseudorandom number seed pointer
|
||||
|
|
@ -100,6 +100,7 @@ public:
|
|||
double b() const { return std::pow(offset_ + span_, ninv_); }
|
||||
double n() const { return 1 / ninv_ - 1; }
|
||||
private:
|
||||
//! Store processed values in object to allow for faster sampling
|
||||
double offset_; //!< a^(n+1)
|
||||
double span_; //!< b^(n+1) - a^(n+1)
|
||||
double ninv_; //!< 1/(n+1)
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ class Univariate(EqualityMixin, ABC):
|
|||
return Discrete.from_xml_element(elem)
|
||||
elif distribution == 'uniform':
|
||||
return Uniform.from_xml_element(elem)
|
||||
elif distribution == 'rational':
|
||||
return Rational.from_xml_element(elem)
|
||||
elif distribution == 'powerlaw':
|
||||
return PowerLaw.from_xml_element(elem)
|
||||
elif distribution == 'maxwell':
|
||||
return Maxwell.from_xml_element(elem)
|
||||
elif distribution == 'watt':
|
||||
|
|
@ -244,7 +244,7 @@ class Uniform(Univariate):
|
|||
params = get_text(elem, 'parameters').split()
|
||||
return cls(*map(float, params))
|
||||
|
||||
class Rational(Univariate):
|
||||
class PowerLaw(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`.
|
||||
|
|
@ -306,7 +306,7 @@ class Rational(Univariate):
|
|||
self._n = n
|
||||
|
||||
def to_xml_element(self, element_name):
|
||||
"""Return XML representation of the rational distribution
|
||||
"""Return XML representation of the power law distribution
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
|
@ -320,13 +320,13 @@ class Rational(Univariate):
|
|||
|
||||
"""
|
||||
element = ET.Element(element_name)
|
||||
element.set("type", "rational")
|
||||
element.set("type", "powerlaw")
|
||||
element.set("parameters", f'{self.a} {self.b} {self.n}')
|
||||
return element
|
||||
|
||||
@classmethod
|
||||
def from_xml_element(cls, elem):
|
||||
"""Generate rational distribution from an XML element
|
||||
"""Generate power law distribution from an XML element
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
|
@ -335,7 +335,7 @@ class Rational(Univariate):
|
|||
|
||||
Returns
|
||||
-------
|
||||
openmc.stats.Rational
|
||||
openmc.stats.PowerLaw
|
||||
Distribution generated from XML element
|
||||
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -86,14 +86,14 @@ double Uniform::sample(uint64_t* seed) const
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
// Rational implementation
|
||||
// PowerLaw implementation
|
||||
//==============================================================================
|
||||
|
||||
Rational::Rational(pugi::xml_node node)
|
||||
PowerLaw::PowerLaw(pugi::xml_node node)
|
||||
{
|
||||
auto params = get_node_array<double>(node, "parameters");
|
||||
if (params.size() != 3) {
|
||||
fatal_error("Rational distribution must have three "
|
||||
fatal_error("PowerLaw distribution must have three "
|
||||
"parameters specified.");
|
||||
}
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ Rational::Rational(pugi::xml_node node)
|
|||
ninv_ = 1 / (n + 1);
|
||||
}
|
||||
|
||||
double Rational::sample(uint64_t* seed) const
|
||||
double PowerLaw::sample(uint64_t* seed) const
|
||||
{
|
||||
return std::pow(offset_ + prn(seed) * span_, ninv_);
|
||||
}
|
||||
|
|
@ -373,8 +373,8 @@ UPtrDist distribution_from_xml(pugi::xml_node node)
|
|||
UPtrDist dist;
|
||||
if (type == "uniform") {
|
||||
dist = UPtrDist {new Uniform(node)};
|
||||
} else if (type == "rational") {
|
||||
dist = UPtrDist{new Rational(node)};
|
||||
} else if (type == "powerlaw") {
|
||||
dist = UPtrDist {new PowerLaw(node)};
|
||||
} else if (type == "maxwell") {
|
||||
dist = UPtrDist {new Maxwell(node)};
|
||||
} else if (type == "watt") {
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@
|
|||
</source>
|
||||
<source strength="0.1">
|
||||
<space origin="1.0 1.0 0.0" type="spherical">
|
||||
<r parameters="2.0 3.0 2.0" type="rational" />
|
||||
<r parameters="2.0 3.0 2.0" type="powerlaw" />
|
||||
<theta type="discrete">
|
||||
<parameters>0.7853981633974483 1.5707963267948966 2.356194490192345 0.3 0.4 0.3</parameters>
|
||||
</theta>
|
||||
|
|
@ -124,7 +124,7 @@
|
|||
</source>
|
||||
<source strength="0.1">
|
||||
<space origin="1.0 1.0 0.0" type="cylindrical">
|
||||
<r parameters="2.0 3.0 1.0" type="rational" />
|
||||
<r parameters="2.0 3.0 1.0" type="powerlaw" />
|
||||
<phi parameters="0.0 6.283185307179586" type="uniform" />
|
||||
<z interpolation="linear-linear" type="tabular">
|
||||
<parameters>-2.0 0.0 2.0 0.2 0.3 0.2</parameters>
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ class SourceTestHarness(PyAPITestHarness):
|
|||
y_dist = openmc.stats.Discrete([-4., -1., 3.], [0.2, 0.3, 0.5])
|
||||
z_dist = openmc.stats.Tabular([-2., 0., 2.], [0.2, 0.3, 0.2])
|
||||
r_dist = openmc.stats.Uniform(2., 3.)
|
||||
r_dist1 = openmc.stats.Rational(2., 3., 1.)
|
||||
r_dist2 = openmc.stats.Rational(2., 3., 2.)
|
||||
r_dist1 = openmc.stats.PowerLaw(2., 3., 1.)
|
||||
r_dist2 = openmc.stats.PowerLaw(2., 3., 2.)
|
||||
theta_dist = openmc.stats.Discrete([pi/4, pi/2, 3*pi/4],
|
||||
[0.3, 0.4, 0.3])
|
||||
phi_dist = openmc.stats.Uniform(0.0, 2*pi)
|
||||
|
|
|
|||
|
|
@ -42,12 +42,12 @@ def test_uniform():
|
|||
assert t.p == [1/(b-a), 1/(b-a)]
|
||||
assert t.interpolation == 'histogram'
|
||||
|
||||
def test_rational():
|
||||
def test_powerlaw():
|
||||
a, b, n = 10.0, 20.0, 2.0
|
||||
d = openmc.stats.Rational(a, b, n)
|
||||
d = openmc.stats.PowerLaw(a, b, n)
|
||||
elem = d.to_xml_element('distribution')
|
||||
|
||||
d = openmc.stats.Rational.from_xml_element(elem)
|
||||
d = openmc.stats.PowerLaw.from_xml_element(elem)
|
||||
assert d.a == a
|
||||
assert d.b == b
|
||||
assert d.n == n
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue