12#ifndef DUMUX_COMMON_RANDOM_HH
13#define DUMUX_COMMON_RANDOM_HH
28template<
class Scalar =
double>
33 Parameters(Scalar
a, Scalar
b)
36 Scalar
a()
const {
return a_; }
37 Scalar
b()
const {
return b_; }
65 {
return { offset_, offset_+size_ }; }
67 Scalar
a()
const {
return offset_; }
68 Scalar
b()
const {
return offset_ + size_; }
70 template<
class Generator,
71 typename std::enable_if_t<std::is_same_v<typename Generator::result_type, std::uint_fast32_t>,
int> = 0>
73 {
return offset_ + size_*(0x1.0p-32 * gen()); }
87template<
class Scalar =
double>
92 Parameters(Scalar
m, Scalar
s)
95 Scalar
m()
const {
return m_; }
96 Scalar
s()
const {
return s_; }
124 {
return { mean_, stddev_ }; }
126 Scalar
m()
const {
return mean_; }
127 Scalar
s()
const {
return stddev_; }
129 template<
class Generator>
139 const auto [u1, u2] = generateUniformPair_(gen);
141 using std::sqrt;
using std::log;
142 using std::cos;
using std::sin;
143 constexpr Scalar twoPi = 2.0 * M_PI;
145 const Scalar magnitude = stddev_ * sqrt(-2.0 * log(u1));
146 const Scalar z0 = magnitude * cos(twoPi * u2) + mean_;
147 const Scalar z1 = magnitude * sin(twoPi * u2) + mean_;
154 template<
class Generator,
155 typename std::enable_if_t<std::is_same_v<typename Generator::result_type, std::uint_fast32_t>,
int> = 0>
156 auto generateUniformPair_(Generator& gen)
160 constexpr Scalar eps = std::numeric_limits<Scalar>::epsilon();
161 Scalar u1 = 0.0, u2 = 0.0;
163 u1 = 0x1.0p-32 * gen();
164 u2 = 0x1.0p-32 * gen();
166 return std::make_pair(u1, u2);
171 bool isCached_ =
false;
172 Scalar cachedValue_ = {};
181template<
class Scalar =
double>
190 : normal_(mean, stddev)
202 { normal_.param(p); }
205 {
return normal_.param(); }
207 Scalar
m()
const {
return normal_.m(); }
208 Scalar
s()
const {
return normal_.s(); }
210 template<
class Generator>
214 return exp(normal_(gen));
A simple log-normal distribution.
Definition: random.hh:183
Scalar operator()(Generator &gen)
Definition: random.hh:211
Scalar m() const
Definition: random.hh:207
SimpleLogNormalDistribution()
Definition: random.hh:197
Parameters param_type
Definition: random.hh:186
Parameters param() const
Definition: random.hh:204
SimpleLogNormalDistribution(const Parameters &p)
Definition: random.hh:193
SimpleLogNormalDistribution(Scalar mean, Scalar stddev=1.0)
Definition: random.hh:189
void param(const Parameters &p)
Definition: random.hh:201
Scalar s() const
Definition: random.hh:208
Scalar result_type
Definition: random.hh:187
A simple normal distribution based on a biased uniform number generator and the Box-Mueller transform...
Definition: random.hh:89
Scalar operator()(Generator &gen)
Definition: random.hh:130
Parameters param_type
Definition: random.hh:101
void param(const Parameters &p)
Definition: random.hh:117
SimpleNormalDistribution(const Parameters &p)
Definition: random.hh:109
SimpleNormalDistribution(Scalar mean, Scalar stddev=1.0)
Definition: random.hh:104
Scalar result_type
Definition: random.hh:102
Parameters param() const
Definition: random.hh:123
Scalar m() const
Definition: random.hh:126
SimpleNormalDistribution()
Definition: random.hh:113
Scalar s() const
Definition: random.hh:127