OpenLB 1.7
Loading...
Searching...
No Matches
random.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Nicolas Hafen, Mathias J. Krause
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef RANDOM_H
25#define RANDOM_H
26
27
28namespace olb {
29
30namespace util {
31
32/* The present class is supposed to represent a random scalar generator that can
33 * be fed from stored values also. This is supposed to enable a semi-random approach,
34 * which will enable reproducible results with random-like values. This is primarily
35 * intendet to be used in the random particle seeding.
36 * When passing useStored=true, 'generateScalar' will use stored values provided in
37 * the constructor or by a specified file.
38 */
39template<typename T,bool useStored=false>
41private:
42 std::vector<T> _storedSequence;
43 std::size_t _count = 0;
44
45public:
47 Randomizer();
48
50 Randomizer(std::vector<T> sequence);
51
54 Randomizer(std::string filePathSequence, bool enforceStored=false );
55
57 template<typename O=T>
58 O generate();
59
61 T generateScalarNormal(T avg, T stdDev );
62 T generateScalarNormal(T avg, T stdDev, T cutoff );
63
65 void writeSequence( std::size_t numOfValues,
66 std::string filePathSequence = "./randomSequence.dat",
67 int precision = 5 );
68
69private:
70
72 T generateScalarRandom();
73
75 T generateScalarStored();
76
78 T generateScalar();
79};
80
81
82} //namespace util
83
84} //namespace olb
85
86#endif
void writeSequence(std::size_t numOfValues, std::string filePathSequence="./randomSequence.dat", int precision=5)
Write sequence to file for later retrieval.
Definition random.hh:125
T generateScalarNormal(T avg, T stdDev)
Generate scalar leading to normal distribution based on the Box-Muller approach.
Definition random.hh:105
O generate()
Generate scalar or vector filled with scalars.
Definition random.hh:90
Randomizer()
Constructor for (useStored=false)
Definition random.hh:35
Top level namespace for all of OpenLB.