Remove gmx custom fixed int (e.g. gmx_int64_t) types
[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, 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
66 makeRandomSeed();
67
68 /*! \brief Random device
69  *
70  *  For now this is identical to the standard library, but since we use
71  *  the GROMACS random module for all other random engines and distributions
72  *  it is convenient to have this too in the same module.
73  */
74 typedef std::random_device RandomDevice;
75
76 /*! \brief Enumerated values for fixed part of random seed (domain)
77  *
78  *  Random numbers are used in many places in GROMACS, and to avoid identical
79  *  streams the random seeds should be different. Instead of keeping track of
80  *  several different user-provided seeds, it is better to use the fact that
81  *  generators like ThreeFry take two 64-bit keys, and combine a general
82  *  user-provided 64-bit random seed with a second constant value from this list
83  *  to make each stream guaranteed unique.
84  *
85  *  \note There is no reason to go overboard with adding options; we only
86  *        need to guarantee different streams for cases that might be present
87  *        simultaneously in a single simulation. As an example, two different
88  *        integrators (or thermostats) can reuse the same domain.
89  *  \note When you do add options, leave some space between the values so
90  *        you can group new options with old ones without changing old values.
91  */
92 enum class RandomDomain
93 {
94     Other                    = 0x00000000,   //!< Generic - stream uniqueness is not important
95     MaxwellVelocities        = 0x00001000,   //!< Veolcity assignment from Maxwell distribution
96     TestParticleInsertion    = 0x00002000,   //!< Test particle insertion
97     UpdateCoordinates        = 0x00003000,   //!< Particle integrators
98     UpdateConstraints        = 0x00004000,   //!< Second integrator step for constraints
99     Thermostat               = 0x00005000,   //!< Stochastic temperature coupling
100     Barostat                 = 0x00006000,   //!< Stochastic pressure coupling
101     ReplicaExchange          = 0x00007000,   //!< Replica exchange metropolis moves
102     ExpandedEnsemble         = 0x00008000,   //!< Expanded ensemble lambda moves
103     AwhBiasing               = 0x00009000    //!< AWH biasing reference value moves
104 };
105
106 }      // namespace gmx
107
108 #endif // GMX_RANDOM_SEED_H