Skip to content
Snippets Groups Projects
Commit 77ee618b authored by Timo Koch's avatar Timo Koch
Browse files

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

parent 340c157f
No related branches found
No related tags found
1 merge request!2484[example][1ptracer] Use library-independent portable random distribution
......@@ -32,7 +32,13 @@
// In this example, we use a randomly generated and element-wise distributed
// permeability field. For this, we use the random number generation facilities
// 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 <dumux/common/random.hh>
// We include the spatial parameters class for single-phase models discretized
// by finite volume schemes, from which the spatial parameters defined for this
......@@ -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.
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,
// with `permeability_` as mean value and 10 % of it as standard deviation.
// 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_`.
// 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::lognormal_distribution<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> K(std::log(permeability_), std::log(permeability_)*0.1);
Dumux::SimpleLogNormalDistribution<Scalar> KLens(std::log(permeabilityLens_), std::log(permeabilityLens_)*0.1);
// loop over all elements and compute a permeability value
for (const auto& element : elements(gridGeometry->gridView()))
......
This diff is collapsed.
source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment