histogram.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) 2016 OpenFOAM Foundation
9  Copyright (C) 2017-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::functionObjects::histogram
29 
30 Group
31  grpFieldFunctionObjects
32 
33 Description
34  Computes the volume-weighted histogram of an input \c volScalarField.
35 
36  Operands:
37  \table
38  Operand | Type | Location
39  input | volScalarField | $FOAM_CASE/<time>/<inpField>
40  output file | dat | $FOAM_CASE/postProcessing/<FO>/<time>/<file>
41  output field | - | -
42  \endtable
43 
44  The set written contains two columns, the first the volume averaged values,
45  the second the raw bin count.
46 
47 Usage
48  Minimal example by using \c system/controlDict.functions:
49  \verbatim
50  histogram1
51  {
52  // Mandatory entries (unmodifiable)
53  type histogram;
54  libs (fieldFunctionObjects);
55 
56  // Mandatory (inherited) entries (runtime modifiable)
57  field p;
58  nBins 100;
59  setFormat gnuplot;
60 
61  // Optional entries (runtime modifiable)
62  max 5;
63  min -5;
64 
65  // Optional (inherited) entries
66  ...
67  }
68  \endverbatim
69 
70  where the entries mean:
71  \table
72  Property | Description | Type | Req'd | Dflt
73  type | Type name: histogram | word | yes | -
74  libs | Library name: fieldFunctionObjects | word | yes | -
75  field | Name of operand field | word | yes | -
76  nBins | Number of histogram bins | label | yes | -
77  setFormat | Output format | word | yes | -
78  max | Maximum value sampled | scalar | no | fieldMax
79  min | minimum value sampled | scalar | no | 0.0
80  \endtable
81 
82  The inherited entries are elaborated in:
83  - \link functionObject.H \endlink
84  - \link writeFile.H \endlink
85 
86  Usage by the \c postProcess utility is not available.
87 
88 Note
89  If \c max is not provided it will use the field's min and max as the bin
90  extremes. If \c max is provided but not \c min it will use 0.
91 
92 See also
93  - Foam::functionObject
94  - Foam::functionObjects::fvMeshFunctionObject
95  - Foam::functionObjects::writeFile
96  - ExtendedCodeGuide::functionObjects::field::histogram
97 
98 SourceFiles
99  histogram.C
100 
101 \*---------------------------------------------------------------------------*/
102 
103 #ifndef functionObjects_histogram_H
104 #define functionObjects_histogram_H
105 
106 #include "fvMeshFunctionObject.H"
107 #include "writeFile.H"
108 #include "writer.H"
109 
110 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
111 
112 namespace Foam
113 {
114 namespace functionObjects
115 {
116 
117 /*---------------------------------------------------------------------------*\
118  Class histogram Declaration
119 \*---------------------------------------------------------------------------*/
120 
121 class histogram
122 :
123  public fvMeshFunctionObject,
124  public writeFile
125 {
126  // Private Data
127 
128  //- Number of bins
129  label nBins_;
130 
131  //- Name of field
132  word fieldName_;
133 
134  //- Maximum value
135  scalar max_;
136 
137  //- Minimum value
138  scalar min_;
139 
140  //- Output formatter to write
141  autoPtr<writer<scalar>> formatterPtr_;
142 
143 
144  // Private Member Functions
145 
146  void writeGraph
147  (
148  const coordSet& coords,
149  const word& valueName,
150  const scalarField& normalizedValues,
151  const scalarField& absoluteValues
152  ) const;
153 
154 
155 public:
156 
157  //- Runtime type information
158  TypeName("histogram");
159 
160 
161  // Constructors
162 
163  //- Construct from Time and dictionary
164  histogram
165  (
166  const word& name,
167  const Time& runTime,
168  const dictionary& dict
169  );
170 
171  //- No copy construct
172  histogram(const histogram&) = delete;
173 
174  //- No copy assignment
175  void operator=(const histogram&) = delete;
176 
177 
178  // Destructor
179  virtual ~histogram() = default;
180 
181 
182  // Member Functions
183 
184  //- Read the histogram data
185  virtual bool read(const dictionary&);
186 
187  //- Execute (effectively no-op)
188  virtual bool execute();
189 
190  //- Calculate the histogram and write
191  // postProcess overrides the usual writeControl behaviour and
192  // forces writing always (used in post-processing mode)
193  virtual bool write();
194 };
195 
196 
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 
199 } // End namespace functionObjects
200 } // End namespace Foam
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 #endif
205 
206 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
writeFile.H
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
fvMeshFunctionObject.H
Foam::functionObjects::histogram::write
virtual bool write()
Calculate the histogram and write.
Definition: histogram.C:132
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::histogram::execute
virtual bool execute()
Execute (effectively no-op)
Definition: histogram.C:126
Foam::functionObjects::histogram::TypeName
TypeName("histogram")
Runtime type information.
Foam::Field< scalar >
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:123
Foam::coordSet
Holds list of sampling positions.
Definition: coordSet.H:53
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::histogram::read
virtual bool read(const dictionary &)
Read the histogram data.
Definition: histogram.C:100
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::functionObjects::histogram
Computes the volume-weighted histogram of an input volScalarField.
Definition: histogram.H:184
Foam::functionObjects::histogram::operator=
void operator=(const histogram &)=delete
No copy assignment.
Foam::functionObjects::histogram::histogram
histogram(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: histogram.C:83
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:119
writer.H
Foam::functionObjects::histogram::~histogram
virtual ~histogram()=default