From c9fee12e9d8ceb17d7e3499dba30b3b13e1e8656 Mon Sep 17 00:00:00 2001 From: "David F. Castellanos" Date: Tue, 6 Oct 2020 20:23:11 +0200 Subject: [PATCH] allow the user to set the RNG seed in distort_random() - squashed previous commits --- include/deal.II/grid/grid_tools.h | 13 ++++++++++--- source/grid/grid_tools.cc | 13 ++++--------- source/grid/grid_tools.inst.in | 3 ++- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/deal.II/grid/grid_tools.h b/include/deal.II/grid/grid_tools.h index f7a07d15ac..d053321949 100644 --- a/include/deal.II/grid/grid_tools.h +++ b/include/deal.II/grid/grid_tools.h @@ -45,6 +45,7 @@ DEAL_II_DISABLE_EXTRA_DIAGNOSTICS # include # include # include +# include # include # include @@ -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 void - distort_random(const double factor, - Triangulation &triangulation, - const bool keep_boundary = true); + distort_random( + const double factor, + Triangulation &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 diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index f0088f4755..8d6c888229 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -1125,7 +1125,8 @@ namespace GridTools void distort_random(const double factor, Triangulation &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 diff --git a/source/grid/grid_tools.inst.in b/source/grid/grid_tools.inst.in index 713d8c77bd..d2e0e811cf 100644 --- a/source/grid/grid_tools.inst.in +++ b/source/grid/grid_tools.inst.in @@ -254,7 +254,8 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS) distort_random( const double, Triangulation &, - const bool); + const bool, + const unsigned int); template void get_face_connectivity_of_cells( -- 2.39.5