Test-BinSum.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Application
25  Test-BinSum
26 
27 Description
28  Test BinSum container
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "List.H"
33 #include "BinSum.H"
34 #include "IOstreams.H"
35 #include "Random.H"
36 #include "scalarField.H"
37 
38 using namespace Foam;
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 int main(int argc, char *argv[])
43 {
44  Random rndGen(0);
45 
46  scalarField samples(10000000);
47  forAll(samples, i)
48  {
49  samples[i] = rndGen.scalar01();
50  }
51 
52  const scalar min = 0;
53  const scalar max = 1;
54  const scalar delta = 0.1;
55 
58 
59  forAll(samples, i)
60  {
61  count.add(samples[i], 1);
62  sum.add(samples[i], samples[i]);
63  }
64 
65  Info<< "sum : " << sum << endl;
66  Info<< "count : " << count << endl;
67  Info<< "average: " << sum/count << endl;
68 
69  Info<< "End\n" << endl;
70 
71  return 0;
72 }
73 
74 
75 // ************************************************************************* //
Foam::Random
Simple random number generator.
Definition: Random.H:49
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
List.H
BinSum.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
scalarField.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
samples
scalarField samples(nIntervals, 0)
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Info
messageStream Info
delta
scalar delta
Definition: LISASMDCalcMethod2.H:8
Foam::BinSum
Sums into bins.
Definition: BinSum.H:55
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::cachedRandom::scalar01
scalar scalar01()
Returns the current sample.
Definition: cachedRandom.C:32
Random.H
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
main
int main(int argc, char *argv[])
Definition: Test-BinSum.C:39
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:333
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
rndGen
cachedRandom rndGen(label(0), -1)
Foam::BinSum::add
void add(const IndexType &indexVal, const typename List::const_reference val, const CombineOp &cop=plusEqOp< typename List::value_type >())
Definition: BinSum.C:76