binned.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2015-2016 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  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  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::distributionModels::binned
28 
29 Description
30  A binned distribution model where the random sample is taken from a
31  discrete set of bins
32 
33 SourceFiles
34  binned.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef distributionModels_binned_H
39 #define distributionModels_binned_H
40 
41 #include "distributionModel.H"
42 #include "Field.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward declaration of classes
50 class Istream;
51 class Ostream;
52 
53 namespace distributionModels
54 {
55  class binned;
56 }
57 
58 // Forward declaration of friend functions and operators
59 Istream& operator>>(Istream&, distributionModels::binned&);
60 Ostream& operator<<(Ostream&, const distributionModels::binned&);
61 
62 namespace distributionModels
63 {
64 
65 /*---------------------------------------------------------------------------*\
66  Class binned Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class binned
70 :
71  public distributionModel
72 {
73  // Private data
74 
75  typedef VectorSpace<Vector<scalar>, scalar, 2> pair;
76 
77  // List of (bin probability)
78  List<pair> xy_;
79 
80  //- Distribution mean value
81  scalar meanValue_;
82 
83 
84  // Private member functions
85 
86  //- Initialise the distribution parameters
87  void initialise();
88 
89 
90 public:
91 
92  //- Runtime type information
93  TypeName("binned");
94 
95  static const char* header;
96 
97 
98  // Constructors
99 
100  //- Construct from dictionary
101  binned(const dictionary& dict, Random& rndGen);
102 
103  //- Construct from components
104  binned
105  (
106  const UList<scalar>& sampleData,
107  const scalar binWidth,
108  Random& rndGen
109  );
110 
111  //- Construct copy
112  binned(const binned& p);
113 
114  //- Construct and return a clone
115  virtual autoPtr<distributionModel> clone() const
116  {
117  return autoPtr<distributionModel>(new binned(*this));
118  }
119 
120 
121  //- Destructor
122  virtual ~binned();
123 
124 
125  // Member Functions
126 
127  //- Sample the distributionModel
128  virtual scalar sample() const;
129 
130  //- Return the minimum value
131  virtual scalar minValue() const;
132 
133  //- Return the maximum value
134  virtual scalar maxValue() const;
135 
136  //- Return the mean value
137  virtual scalar meanValue() const;
138 
139  //- Write data to stream
140  virtual void writeData(Ostream& os) const;
141 
142  //- Read data from stream
143  virtual void readData(Istream& os);
144 
145  //- Write data in dictionary format
146  virtual dictionary writeDict(const word& dictName) const;
147 
148  //- Read data from dictionary
149  virtual void readDict(const dictionary& dict);
150 };
151 
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 } // End namespace distributionModels
156 } // End namespace Foam
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 #endif
161 
162 // ************************************************************************* //
Foam::Random
Random number generator.
Definition: Random.H:59
Foam::distributionModels::binned::readDict
virtual void readDict(const dictionary &dict)
Read data from dictionary.
Definition: binned.C:249
Foam::distributionModels::binned::maxValue
virtual scalar maxValue() const
Return the maximum value.
Definition: binned.C:210
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::distributionModels::binned::writeData
virtual void writeData(Ostream &os) const
Write data to stream.
Definition: binned.C:229
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::distributionModels::binned::TypeName
TypeName("binned")
Runtime type information.
Foam::distributionModels::binned::readData
virtual void readData(Istream &os)
Read data from stream.
Definition: binned.C:222
dictName
const word dictName("blockMeshDict")
Foam::distributionModels::binned
A binned distribution model where the random sample is taken from a discrete set of bins.
Definition: binned.H:68
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::distributionModel
A library of runtime-selectable distribution models.
Definition: distributionModel.H:70
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::distributionModels::binned::meanValue
virtual scalar meanValue() const
Return the mean value.
Definition: binned.C:216
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::distributionModels::binned::sample
virtual scalar sample() const
Sample the distributionModel.
Definition: binned.C:188
Foam::distributionModels::binned::minValue
virtual scalar minValue() const
Return the minimum value.
Definition: binned.C:204
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Field.H
Foam::distributionModels::binned::~binned
virtual ~binned()
Destructor.
Definition: binned.C:182
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::distributionModels::binned::header
static const char * header
Definition: binned.H:94
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::distributionModels::binned::binned
binned(const dictionary &dict, Random &rndGen)
Construct from dictionary.
Definition: binned.C:84
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::distributionModels::binned::clone
virtual autoPtr< distributionModel > clone() const
Construct and return a clone.
Definition: binned.H:114
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::distributionModels::binned::writeDict
virtual dictionary writeDict(const word &dictName) const
Write data in dictionary format.
Definition: binned.C:237
rndGen
Random rndGen
Definition: createFields.H:23
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
distributionModel.H