]> https://gitweb.dealii.org/ - dealii.git/commitdiff
mu_parser functions modified to use std random number generators
authorReza Rastak <rastak@stanford.edu>
Mon, 30 Dec 2019 20:48:58 +0000 (12:48 -0800)
committerReza Rastak <rastak@stanford.edu>
Mon, 30 Dec 2019 20:48:58 +0000 (12:48 -0800)
doc/news/changes/minor/20191230RezaRastak [new file with mode: 0644]
source/base/function_parser.cc
source/base/mu_parser_internal.cc
source/base/tensor_function_parser.cc
tests/base/function_parser_09.with_muparser=true.output
tests/base/function_parser_10.with_muparser=true.output

diff --git a/doc/news/changes/minor/20191230RezaRastak b/doc/news/changes/minor/20191230RezaRastak
new file mode 100644 (file)
index 0000000..a902da5
--- /dev/null
@@ -0,0 +1,4 @@
+Improved: mu_parser functions now use random number generation facilities
+provided by the standard library.
+<br>
+(Reza Rastak, 2019/20/30)
index 0a20249014b0d85decac83273e4c48c6bf71dff7..26bd537890dfc56c15348c575ebcd3e420c0bc75 100644 (file)
@@ -22,8 +22,6 @@
 
 #include <deal.II/lac/vector.h>
 
-#include <boost/random.hpp>
-
 #include <cmath>
 #include <map>
 
index 9c4b964f239a9a6eb3d317b07ee0fd8b45d3aeed..74b9890d6ee5c196f0c962da336e0129d88cfdeb 100644 (file)
 #include <deal.II/base/mu_parser_internal.h>
 #include <deal.II/base/thread_management.h>
 
-#include <boost/random.hpp>
-
 #include <cmath>
 #include <ctime>
 #include <map>
 #include <mutex>
+#include <random>
 #include <vector>
 
 
@@ -121,20 +120,17 @@ namespace internal
     double
     mu_rand_seed(double seed)
     {
-      static Threads::Mutex       rand_mutex;
+      static std::mutex           rand_mutex;
       std::lock_guard<std::mutex> lock(rand_mutex);
 
-      static boost::random::uniform_real_distribution<> uniform_distribution(0,
-                                                                             1);
+      std::uniform_real_distribution<> uniform_distribution(0., 1.);
 
-      // for each seed an unique random number generator is created,
+      // for each seed a unique random number generator is created,
       // which is initialized with the seed itself
-      // we could use std::mt19937 but doing so results in compiler-dependent
-      // output.
-      static std::map<double, boost::random::mt19937> rng_map;
+      static std::map<double, std::mt19937> rng_map;
 
       if (rng_map.find(seed) == rng_map.end())
-        rng_map[seed] = boost::random::mt19937(static_cast<unsigned int>(seed));
+        rng_map[seed] = std::mt19937(static_cast<unsigned int>(seed));
 
       return uniform_distribution(rng_map[seed]);
     }
@@ -143,12 +139,11 @@ namespace internal
     double
     mu_rand()
     {
-      static Threads::Mutex                             rand_mutex;
-      std::lock_guard<std::mutex>                       lock(rand_mutex);
-      static boost::random::uniform_real_distribution<> uniform_distribution(0,
-                                                                             1);
-      static boost::random::mt19937                     rng(
-                            static_cast<unsigned long>(std::time(nullptr)));
+      static std::mutex                rand_mutex;
+      std::lock_guard<std::mutex>      lock(rand_mutex);
+      std::uniform_real_distribution<> uniform_distribution(0., 1.);
+      const unsigned int  seed = static_cast<unsigned long>(std::time(nullptr));
+      static std::mt19937 rng(seed);
       return uniform_distribution(rng);
     }
 
index eb4cb8c13c2831cc479e380d1cd983aaa383a3f8..f77927125d3fd411509b86e891b9b7548ff1f1e4 100644 (file)
@@ -22,8 +22,6 @@
 #include <deal.II/base/thread_management.h>
 #include <deal.II/base/utilities.h>
 
-#include <boost/random.hpp>
-
 #include <cmath>
 #include <map>
 
index 59f845a4298fb947637bfece03189566d4a86d0e..03a86172f4202fb25a3fcb382bf5484272b96c51 100644 (file)
@@ -1,3 +1,3 @@
 
 DEAL::OK
-DEAL::0.771321
+DEAL::0.298761
index 59f845a4298fb947637bfece03189566d4a86d0e..03a86172f4202fb25a3fcb382bf5484272b96c51 100644 (file)
@@ -1,3 +1,3 @@
 
 DEAL::OK
-DEAL::0.771321
+DEAL::0.298761

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.