From: Wolfgang Bangerth Date: Thu, 13 Nov 2014 17:14:14 +0000 (-0600) Subject: Use a different random number generator. X-Git-Tag: v8.2.0-rc1~64^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5addc4f8307132b07321142aa6d213c3007940b;p=dealii.git Use a different random number generator. For historical reason, GridTools::distort_random() is not deterministic in that if you call it twice on the same mesh, it will produce different results. This is because we call rand() which carries around internal state. On the other hand, for the newly implemented parallel algorithm, we can ensure that this isn't the case by creating our own random number generator that we start from the same seed every time. --- diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index 3a7d574306..981b1ad5b5 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -35,6 +35,9 @@ #include #include +#include +#include + #include #include #include @@ -720,6 +723,14 @@ namespace GridTools if (parallel::distributed::Triangulation< dim, spacedim > *distributed_triangulation = dynamic_cast*> (&triangulation)) { + // create a random number generator for the interval [-1,1]. we use + // this to make sure the distribution we get is repeatable, i.e., + // if you call the function twice on the same mesh, then you will + // get the same mesh. this would not be the case if you used + // the rand() function, which carries around some internal state + boost::random::mt19937 rng; + boost::random::uniform_real_distribution<> uniform_distribution(-1,1); + const std::vector locally_owned_vertices = get_locally_owned_vertices(triangulation); std::vector vertex_moved (triangulation.n_vertices(), false); @@ -744,7 +755,7 @@ namespace GridTools // first compute a random shift vector Point shift_vector; for (unsigned int d=0; d