Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / random / seed.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2015,2016,2017,2018,2019, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35
36 /*! \file
37  * \brief Random seed and domain utilities
38  *
39  * This file contains utilities to create true random seeds from the system,
40  * and logic to keep track of different random domains for random engines such
41  * as ThreeFry that can take a second seed value.
42  *
43  * \author Erik Lindahl <erik.lindahl@gmail.com>
44  * \inpublicapi
45  * \ingroup module_random
46  */
47
48 #ifndef GMX_RANDOM_SEED_H
49 #define GMX_RANDOM_SEED_H
50
51 #include <random>
52
53 #include "gromacs/utility/basedefinitions.h"
54
55 namespace gmx
56 {
57
58 /*! \brief Return 64 random bits from the random device, suitable as seed.
59  *
60  *  If the internal random device output is smaller than 64 bits, this routine
61  *  will use multiple calls internally until we have 64 bits of random data.
62  *
63  *  \return 64-bit unsigned integer with random bits.
64  */
65 uint64_t makeRandomSeed();
66
67 /*! \brief Random device
68  *
69  *  For now this is identical to the standard library, but since we use
70  *  the GROMACS random module for all other random engines and distributions
71  *  it is convenient to have this too in the same module.
72  */
73 typedef std::random_device RandomDevice;
74
75 /*! \brief Enumerated values for fixed part of random seed (domain)
76  *
77  *  Random numbers are used in many places in GROMACS, and to avoid identical
78  *  streams the random seeds should be different. Instead of keeping track of
79  *  several different user-provided seeds, it is better to use the fact that
80  *  generators like ThreeFry take two 64-bit keys, and combine a general
81  *  user-provided 64-bit random seed with a second constant value from this list
82  *  to make each stream guaranteed unique.
83  *
84  *  \note There is no reason to go overboard with adding options; we only
85  *        need to guarantee different streams for cases that might be present
86  *        simultaneously in a single simulation. As an example, two different
87  *        integrators (or thermostats) can reuse the same domain.
88  *  \note When you do add options, leave some space between the values so
89  *        you can group new options with old ones without changing old values.
90  */
91 enum class RandomDomain
92 {
93     Other                 = 0x00000000, //!< Generic - stream uniqueness is not important
94     MaxwellVelocities     = 0x00001000, //!< Veolcity assignment from Maxwell distribution
95     TestParticleInsertion = 0x00002000, //!< Test particle insertion
96     UpdateCoordinates     = 0x00003000, //!< Particle integrators
97     UpdateConstraints     = 0x00004000, //!< Second integrator step for constraints
98     Thermostat            = 0x00005000, //!< Stochastic temperature coupling
99     Barostat              = 0x00006000, //!< Stochastic pressure coupling
100     ReplicaExchange       = 0x00007000, //!< Replica exchange metropolis moves
101     ExpandedEnsemble      = 0x00008000, //!< Expanded ensemble lambda moves
102     AwhBiasing            = 0x00009000  //!< AWH biasing reference value moves
103 };
104
105 } // namespace gmx
106
107 #endif // GMX_RANDOM_SEED_H