BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / OpenFOAM / primitives / random / cachedRandom / cachedRandom.H
blob64c078ecb17bae61397dd5ada8e42c953c07e419
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::cachedRandom
27 Description
28     Random number generator.
30     Pre-computes and caches samples on construction, so that when sample01()
31     is called, the function simply returns the next (pre-computed) sample. On
32     reaching the last sample, the sample sequence is repeated.
34     Constructed using a seed and sample count. If the supplied count is
35     negative, no caching is performed, and a new sample is generated on each
36     call to sample01().
38     Note: the copy constructor cannot be used if count = -1.
40 SourceFiles
41     cachedRandomI.H
42     cachedRandom.C
43     cachedRandomTemplates.C
45 \*---------------------------------------------------------------------------*/
47 #ifndef cachedRandom_H
48 #define cachedRandom_H
50 #include "scalarList.H"
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 namespace Foam
57 // Forward declaration of classes
58 class cachedRandom;
60 /*---------------------------------------------------------------------------*\
61                        Class cachedRandom Declaration
62 \*---------------------------------------------------------------------------*/
64 class cachedRandom
66 private:
68     // Private data
70         //- Initial random number seed
71         label seed_;
73         //- List of scalar samples
74         scalarList samples_;
76         //- Current sample marker
77         label sampleI_;
80     // Private Member Functions
82         //- Returns the current sample
83         scalar scalar01();
86 public:
89     // Constructors
91         //- Construct given seed and sample count
92         cachedRandom(const label seed, const label count);
94         //- Copy constructor with optional reset of sampleI
95         cachedRandom(const cachedRandom& cr, const bool reset = false);
98     // Destructor
99     ~cachedRandom();
102     // Member functions
104         // Access
106             //- Return const access to the initial random number seed
107             inline label seed() const;
109             //- Return const access to the list of samples
110             inline const scalarList& samples() const;
112             //- Return the current sample marker
113             inline label sampleI() const;
116         // Manipulation
118             //- Return non-const access to the sample marker
119             inline label& sampleI();
122         // Evaluation
124             //- Return a sample whose components lie in the range 0-1
125             template<class Type>
126             Type sample01();
128             //- Return a sample between start and end
129             template<class Type>
130             Type position(const Type& start, const Type& end);
132             //- Randomise value in the range 0-1
133             template<class Type>
134             void randomise01(Type& value);
137         // Operators
139             //- Assignment operator
140             void operator=(const cachedRandom& cr);
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 // Template specialisations
147 template<>
148 label cachedRandom::sample01<label>();
150 template<>
151 scalar cachedRandom::sample01<scalar>();
153 template<>
154 label cachedRandom::position<label>(const label& start, const label& end);
156 template<>
157 scalar cachedRandom::position<scalar>
159     const scalar& start,
160     const scalar& end
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 } // End namespace Foam
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 #include "cachedRandomI.H"
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 #ifdef NoRepository
174 #   include "cachedRandomTemplates.C"
175 #endif
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 #endif
181 // ************************************************************************* //