OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Uniform.h
Go to the documentation of this file.
1//
2// Class Uniform
3// This class creates uniformly distributed samples.
4//
5// Copyright (c) 2018, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// Implemented as part of the PhD thesis
9// "Precise Simulations of Multibunches in High Intensity Cyclotrons"
10//
11// This file is part of OPAL.
12//
13// OPAL is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// You should have received a copy of the GNU General Public License
19// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20//
21#ifndef OPAL_UNIFORM_H
22#define OPAL_UNIFORM_H
23
25#include "Sample/RNGStream.h"
26
27#include <type_traits>
28
29template <typename T>
30class Uniform : public SamplingMethod
31{
32
33public:
34 typedef typename std::conditional<
35 std::is_integral<T>::value,
36 std::uniform_int_distribution<T>,
37 std::uniform_real_distribution<T>
39
40 Uniform(T lower, T upper)
41 : dist_m(lower, upper)
42 , RNGInstance_m(RNGStream::getInstance())
43 , seed_m(RNGStream::getGlobalSeed())
44 {}
45
46 Uniform(T lower, T upper, std::size_t seed)
47 : dist_m(lower, upper)
48 , RNGInstance_m(nullptr)
49 , seed_m(seed)
50 {}
51
53 if ( RNGInstance_m )
55 }
56
57 void create(boost::shared_ptr<SampleIndividual>& ind, size_t i) {
58 ind->genes[i] = RNGInstance_m->getNext(dist_m);
59 }
60
61 void allocate(const CmdArguments_t& /*args*/, const Comm::Bundle_t& comm) {
62 if ( !RNGInstance_m )
64 }
65
68 }
69
70private:
72
74
75 std::size_t seed_m;
76};
77
78#endif
boost::shared_ptr< CmdArguments > CmdArguments_t
Definition: CmdArguments.h:176
int seed
The current random seed.
Definition: Options.cpp:37
boost::function< boost::tuple< double, bool >(arguments_t)> type
Definition: function.hpp:21
static RNGStream * getInstance()
Definition: RNGStream.cpp:26
static void deleteInstance(RNGStream *&generator)
Definition: RNGStream.cpp:38
DISTR::result_type getNext(DISTR &RNGDist)
Definition: RNGStream.h:37
std::size_t seed_m
Definition: Uniform.h:75
T getNext()
Definition: Uniform.h:66
RNGStream * RNGInstance_m
Definition: Uniform.h:73
Uniform(T lower, T upper)
Definition: Uniform.h:40
std::conditional< std::is_integral< T >::value, std::uniform_int_distribution< T >, std::uniform_real_distribution< T > >::type dist_t
Definition: Uniform.h:38
void create(boost::shared_ptr< SampleIndividual > &ind, size_t i)
Definition: Uniform.h:57
~Uniform()
Definition: Uniform.h:52
dist_t dist_m
Definition: Uniform.h:71
void allocate(const CmdArguments_t &, const Comm::Bundle_t &comm)
Definition: Uniform.h:61
Uniform(T lower, T upper, std::size_t seed)
Definition: Uniform.h:46
bundles all communicators for a specific role/pid
Definition: types.h:32
int island_id
Definition: types.h:33