]> https://gitweb.dealii.org/ - dealii.git/commitdiff
allow the user to set the RNG seed in distort_random() - squashed previous commits 11003/head
authorDavid F. Castellanos <castellanos@gmx.com>
Tue, 6 Oct 2020 18:23:11 +0000 (20:23 +0200)
committerDaniel Arndt <arndtd@ornl.gov>
Wed, 7 Oct 2020 14:27:22 +0000 (10:27 -0400)
include/deal.II/grid/grid_tools.h
source/grid/grid_tools.cc
source/grid/grid_tools.inst.in

index f7a07d15acb3ba982c0dc812061fc549a035a0e7..d053321949436b4f9437b337a1f457de3ab56a4c 100644 (file)
@@ -45,6 +45,7 @@ DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
 #  include <boost/archive/binary_iarchive.hpp>
 #  include <boost/archive/binary_oarchive.hpp>
 #  include <boost/geometry/index/rtree.hpp>
+#  include <boost/random/mersenne_twister.hpp>
 #  include <boost/serialization/array.hpp>
 #  include <boost/serialization/vector.hpp>
 
@@ -628,12 +629,18 @@ namespace GridTools
    *
    * If @p keep_boundary is set to @p true (which is the default), then
    * boundary vertices are not moved.
+   *
+   * @p seed is used for the initialization of the random engine. Its
+   * default value initializes the engine with the same state as in
+   * previous versions of deal.II.
    */
   template <int dim, int spacedim>
   void
-  distort_random(const double                  factor,
-                 Triangulation<dim, spacedim> &triangulation,
-                 const bool                    keep_boundary = true);
+  distort_random(
+    const double                  factor,
+    Triangulation<dim, spacedim> &triangulation,
+    const bool                    keep_boundary = true,
+    const unsigned int            seed = boost::random::mt19937::default_seed);
 
   /**
    * Remove hanging nodes from a grid. If the @p isotropic parameter is set
index f0088f47556a38526af1e88443fd751101a97eb0..8d6c88822922af9a19f35fef2c633f60f8be9ca8 100644 (file)
@@ -1125,7 +1125,8 @@ namespace GridTools
   void
   distort_random(const double                  factor,
                  Triangulation<dim, spacedim> &triangulation,
-                 const bool                    keep_boundary)
+                 const bool                    keep_boundary,
+                 const unsigned int            seed)
   {
     // if spacedim>dim we need to make sure that we perturb
     // points but keep them on
@@ -1201,14 +1202,8 @@ namespace GridTools
             }
         }
 
-    // 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
-    // we could use std::mt19937 but doing so results in compiler-dependent
-    // output.
-    boost::random::mt19937                     rng;
+    // create a random number generator for the interval [-1,1]
+    boost::random::mt19937                     rng(seed);
     boost::random::uniform_real_distribution<> uniform_distribution(-1, 1);
 
     // If the triangulation is distributed, we need to
index 713d8c77bda1ee8c305c1321ab460ba45b64374f..d2e0e811cf15c408685ba93cb3dd658d0eaf2d97 100644 (file)
@@ -254,7 +254,8 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS)
       distort_random<deal_II_dimension>(
         const double,
         Triangulation<deal_II_dimension, deal_II_space_dimension> &,
-        const bool);
+        const bool,
+        const unsigned int);
 
       template void
       get_face_connectivity_of_cells(

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.