Parallel Finite Element - General geometry Ewald-like Method
Part of Continuum-particle Simulation Suite under MICCOM
random_generator.h
Go to the documentation of this file.
1 // Parallel Finite Element-General Geometry Ewald-like Method.
2 // Copyright (C) 2015-2016 Xujun Zhao, Jiyuan Li, Xikai Jiang
3 
4 // This code is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 
10 // This code is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 
15 
16 // You should have received a copy of the GNU General Public
17 // License along with this code; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20 
21 
22 #pragma once
23 
24 #include <stdio.h>
25 #include <random>
26 
27 #include "libmesh/reference_counted_object.h"
28 #include "libmesh/parallel_object.h"
29 
30 
31 /*
32  * This class provide a random number generator
33  * for stochastic modeling
34  */
35 
36 //using namespace libMesh;
37 
38 using libMesh::Real;
39 using libMesh::ParallelObject;
40 using libMesh::ReferenceCountedObject;
41 
42 
43 class RandomGenerator : public ReferenceCountedObject<RandomGenerator>//,
44  //public ParallelObject
45 {
46 public:
47  // Constructor
49 
50 
51  // Destructor
53 
54 
55  /*
56  * Generate a random vector with Gaussian(normal) distribution
57  * mean (μ) with a specific standard deviation (σ)
58  */
59  std::vector<Real> random_vector_normal(const std::size_t n,
60  const Real& mean_val,
61  const Real& dev_val);
62 
63 
64  /*
65  * Generate a random vector with uniform distribution
66  * in a range [a b]
67  */
68  std::vector<Real> random_vector_uniform(const std::size_t n,
69  const Real& a,
70  const Real& b);
71 
72 
73  /*
74  * reset the seed of the random generator.
75  * Thus it will generate a new group of random numbers.
76  */
77  void set_seed(std::size_t seed_val);
78 
79 
80  /*
81  * random generator
82  */
83  std::default_random_engine& generator() { return _generator; }
84 
85 private:
86  /*
87  * random engine should be put outside any function to
88  * avoid generating the same group of random values every time.
89  * std::default_random_engine generator(seed);
90  */
91  std::default_random_engine _generator;
92 
93 
94 }; // end of class
Definition: random_generator.h:43
RandomGenerator()
Definition: random_generator.C:31
std::vector< Real > random_vector_uniform(const std::size_t n, const Real &a, const Real &b)
Definition: random_generator.C:74
~RandomGenerator()
Definition: random_generator.C:38
std::vector< Real > random_vector_normal(const std::size_t n, const Real &mean_val, const Real &dev_val)
Definition: random_generator.C:46
std::default_random_engine & generator()
Definition: random_generator.h:83
void set_seed(std::size_t seed_val)
Definition: random_generator.C:101