Commit ae9f7563 authored by Kilian Weishaupt's avatar Kilian Weishaupt
Browse files

Merge branch 'feature/test-use-library-independent-distribution' into 'master'

[example][1ptracer] Use library-independent portable random distribution

See merge request !2484
parents 92bc8ea8 f2c46647
...@@ -118,7 +118,6 @@ public: ...@@ -118,7 +118,6 @@ public:
explicit SimpleNormalDistribution(Scalar mean, Scalar stddev = 1.0) explicit SimpleNormalDistribution(Scalar mean, Scalar stddev = 1.0)
: mean_(mean) : mean_(mean)
, stddev_(stddev) , stddev_(stddev)
, isCached_(false)
{} {}
explicit SimpleNormalDistribution(const Parameters& p) explicit SimpleNormalDistribution(const Parameters& p)
...@@ -183,8 +182,8 @@ private: ...@@ -183,8 +182,8 @@ private:
Scalar mean_; Scalar mean_;
Scalar stddev_; Scalar stddev_;
bool isCached_; bool isCached_ = false;
Scalar cachedValue_; Scalar cachedValue_ = {};
}; };
/*! /*!
......
...@@ -32,7 +32,13 @@ ...@@ -32,7 +32,13 @@
// In this example, we use a randomly generated and element-wise distributed // In this example, we use a randomly generated and element-wise distributed
// permeability field. For this, we use the random number generation facilities // permeability field. For this, we use the random number generation facilities
// provided by the C++ standard library. // provided by the C++ standard library.
// Dumux additionally implements some simpler but
// standard-library-implementation-independent random distributions
// that are accurate enough for our purposes
// but allow to generate reproducible and portable random fields (when using a constant seed)
// for testing purposes.
#include <random> #include <random>
#include <dumux/common/random.hh>
// We include the spatial parameters class for single-phase models discretized // We include the spatial parameters class for single-phase models discretized
// by finite volume schemes, from which the spatial parameters defined for this // by finite volume schemes, from which the spatial parameters defined for this
...@@ -88,15 +94,19 @@ public: ...@@ -88,15 +94,19 @@ public:
// Furthermore, the position of the lens, which is defined by the position of the lower left and the upper right corners, are obtained from the input file. // Furthermore, the position of the lens, which is defined by the position of the lower left and the upper right corners, are obtained from the input file.
lensLowerLeft_ = getParam<GlobalPosition>("SpatialParams.LensLowerLeft"); lensLowerLeft_ = getParam<GlobalPosition>("SpatialParams.LensLowerLeft");
lensUpperRight_ =getParam<GlobalPosition>("SpatialParams.LensUpperRight"); lensUpperRight_ = getParam<GlobalPosition>("SpatialParams.LensUpperRight");
// We generate random fields for the permeability using lognormal distributions, // We generate random fields for the permeability using lognormal distributions,
// with `permeability_` as mean value and 10 % of it as standard deviation. // with `permeability_` as mean value and 10 % of it as standard deviation.
// A separate distribution is used for the lens using `permeabilityLens_`. // A separate distribution is used for the lens using `permeabilityLens_`.
// A permeability value is created for each element of the grid and is stored in the vector `K_`. // A permeability value is created for each element of the grid and is stored in the vector `K_`.
// For a "truly" random field (different every time we execute) the seed `0` for the
// Mersenne-Twister pseudo-random-number generator should be replaced
// by `std::random_device{}()`. For unbiased high-quality distributions (usually not needed)
// replace `Dumux::SimpleLogNormalDistribution` by `std::lognormal_distribution`.
std::mt19937 rand(0); std::mt19937 rand(0);
std::lognormal_distribution<Scalar> K(std::log(permeability_), std::log(permeability_)*0.1); Dumux::SimpleLogNormalDistribution<Scalar> K(std::log(permeability_), std::log(permeability_)*0.1);
std::lognormal_distribution<Scalar> KLens(std::log(permeabilityLens_), std::log(permeabilityLens_)*0.1); Dumux::SimpleLogNormalDistribution<Scalar> KLens(std::log(permeabilityLens_), std::log(permeabilityLens_)*0.1);
// loop over all elements and compute a permeability value // loop over all elements and compute a permeability value
for (const auto& element : elements(gridGeometry->gridView())) for (const auto& element : elements(gridGeometry->gridView()))
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment