volFieldValue.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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2016-2019 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::fieldValues::volFieldValue
29 
30 Group
31  grpFieldFunctionObjects
32 
33 Description
34  Provides a 'volRegion' specialization of the fieldValue function object.
35 
36  Given a list of user-specified fields and a 'volRegion', a number of
37  operations can be performed, such as sums, averages and integrations.
38 
39 Usage
40  Example of function object specification:
41  \verbatim
42  volFieldValue1
43  {
44  type volFieldValue;
45  libs ("libfieldFunctionObjects.so");
46 
47  log true;
48  writeControl writeTime;
49  writeFields true;
50 
51  regionType cellZone;
52  name c0;
53  operation volAverage;
54 
55  weightField alpha1;
56 
57  fields
58  (
59  p
60  U
61  );
62  }
63  \endverbatim
64 
65  Where the entries comprise:
66  \table
67  Property | Description | Required | Default value
68  type | Type name: volFieldValue | yes |
69  log | Write data to standard output | no | no
70  writeFields | Write the region field values | yes |
71  regionType | volRegion type: see below | yes |
72  name | Name of volRegion if required | no |
73  operation | Operation to perform | yes |
74  weightField | Name of field to apply weighting | no |
75  fields | List of fields to operate on | yes |
76  \endtable
77 
78  Where \c regionType is defined by
79  \plaintable
80  cellZone | requires a 'name' entry to specify the cellZone
81  all | all cells
82  \endplaintable
83 
84  The \c operation is one of:
85  \plaintable
86  none | No operation
87  min | Minimum
88  max | Maximum
89  sum | Sum
90  sumMag | Sum of component magnitudes
91  average | Ensemble average
92  volAverage | Volume weighted average
93  volIntegrate | Volume integral
94  CoV | Coefficient of variation: standard deviation/mean
95  weightedSum | Weighted sum
96  weightedAverage | Weighted average
97  weightedVolAverage | Weighted volume average
98  weightedVolIntegrate | Weighted volume integral
99  \endplaintable
100 
101 See also
102  Foam::functionObjects::fieldValues::fieldValue
103  Foam::functionObjects::volRegion
104  Foam::functionObject
105 
106 SourceFiles
107  volFieldValue.C
108 
109 \*---------------------------------------------------------------------------*/
110 
111 #ifndef functionObjects_volFieldValue_H
112 #define functionObjects_volFieldValue_H
113 
114 #include "fieldValue.H"
115 #include "volRegion.H"
116 
117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
118 
119 namespace Foam
120 {
121 namespace functionObjects
122 {
123 namespace fieldValues
124 {
125 
126 /*---------------------------------------------------------------------------*\
127  Class volFieldValue Declaration
128 \*---------------------------------------------------------------------------*/
129 
130 class volFieldValue
131 :
132  public fieldValue,
133  public volRegion
134 {
135 
136 public:
137 
138  // Public data types
139 
140  //- Bitmask values for operation variants
141  enum operationVariant
142  {
143  typeBase = 0,
144  typeWeighted = 0x200,
145  };
146 
147  //- Operation type enumeration
148  enum operationType
149  {
150  // Normal operations
151 
152  opNone = 0,
153  opMin,
154  opMax,
155  opSum,
156  opSumMag,
157  opAverage,
158  opVolAverage,
160  opCoV,
161 
162  // Weighted variants
163 
166 
169 
172 
175  };
176 
177  //- Operation type names
178  static const Enum<operationType> operationTypeNames_;
179 
180 
181 protected:
182 
183  // Protected data
184 
185  //- Operation to apply to values
187 
188  //- Weight field name - only used for weighted modes
189  word weightFieldName_;
190 
191 
192  // Protected Member Functions
193 
194  //- True if the operation needs the cell-volume
195  bool usesVol() const;
196 
197  //- True if the operation variant uses a weight-field
198  bool usesWeight() const;
199 
200  //- True if operation variant uses a weight-field that is available.
201  // Checks for availability on any processor.
202  inline bool canWeight(const scalarField& weightField) const;
203 
204  //- Initialise, e.g. cell addressing
205  void initialise(const dictionary& dict);
206 
207  //- Return true if the field name is valid
208  template<class Type>
209  bool validField(const word& fieldName) const;
210 
211  //- Insert field values into values list
212  template<class Type>
213  tmp<Field<Type>> getFieldValues
214  (
215  const word& fieldName,
216  const bool mustGet = false
217  ) const;
218 
219  //- Apply the 'operation' to the values
220  template<class Type>
221  Type processValues
222  (
223  const Field<Type>& values,
224  const scalarField& V,
225  const scalarField& weightField
226  ) const;
227 
228  //- Helper function to output field values
230  (
231  const scalarField& V,
232  const scalarField& weightField
233  );
234 
235  //- Templated helper function to output field values
236  template<class Type>
237  bool writeValues
238  (
239  const word& fieldName,
240  const scalarField& V,
241  const scalarField& weightField
242  );
243 
244  //- Filter a field according to cellIds
245  template<class Type>
247 
248 
249  //- Output file header information
250  virtual void writeFileHeader(Ostream& os) const;
251 
252 public:
253 
254  //- Run-time type information
255  TypeName("volFieldValue");
256 
257 
258  // Constructors
259 
260  //- Construct from name, Time and dictionary
262  (
263  const word& name,
264  const Time& runTime,
265  const dictionary& dict
266  );
267 
268  //- Construct from name, objectRegistry and dictionary
270  (
271  const word& name,
273  const dictionary& dict
274  );
275 
276 
277  //- Destructor
278  virtual ~volFieldValue() = default;
279 
280 
281  // Public Member Functions
282 
283  //- Read from dictionary
284  virtual bool read(const dictionary& dict);
285 
286  //- Calculate and write
287  virtual bool write();
288 };
289 
290 
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 
293 } // End namespace fieldValues
294 } // End namespace functionObjects
295 } // End namespace Foam
296 
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
298 
299 #ifdef NoRepository
300  #include "volFieldValueTemplates.C"
301 #endif
302 
303 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
304 
305 #endif
306 
307 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::functionObjects::fieldValues::volFieldValue::opWeightedSum
Weighted sum.
Definition: volFieldValue.H:269
Foam::functionObjects::fieldValues::volFieldValue::~volFieldValue
virtual ~volFieldValue()=default
Destructor.
Foam::Enum< operationType >
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::functionObjects::fieldValues::volFieldValue::opNone
No operation.
Definition: volFieldValue.H:256
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionObjects::fieldValues::volFieldValue::usesWeight
bool usesWeight() const
True if the operation variant uses a weight-field.
Definition: volFieldValue.C:94
Foam::functionObjects::volRegion
Volume (cell) region selection class.
Definition: volRegion.H:115
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::functionObjects::fieldValues::volFieldValue::opMax
Maximum.
Definition: volFieldValue.H:258
Foam::functionObjects::fieldValues::volFieldValue::volFieldValue
volFieldValue(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
Definition: volFieldValue.C:203
Foam::functionObjects::fieldValues::volFieldValue::opWeightedVolIntegrate
Weighted volume integral.
Definition: volFieldValue.H:278
Foam::functionObjects::fieldValues::volFieldValue::typeBase
Base operation.
Definition: volFieldValue.H:247
Foam::functionObjects::fieldValue::dict
const dictionary & dict() const
Return the reference to the construction dictionary.
Definition: fieldValueI.H:30
Foam::functionObjects::fieldValues::volFieldValue::processValues
Type processValues(const Field< Type > &values, const scalarField &V, const scalarField &weightField) const
Apply the 'operation' to the values.
Definition: volFieldValueTemplates.C:79
Foam::functionObjects::fieldValues::volFieldValue::typeWeighted
Operation using weighting.
Definition: volFieldValue.H:248
Foam::functionObjects::fieldValues::volFieldValue::read
virtual bool read(const dictionary &dict)
Read from dictionary.
Definition: volFieldValue.C:238
Foam::functionObjects::fieldValues::volFieldValue::getFieldValues
tmp< Field< Type > > getFieldValues(const word &fieldName, const bool mustGet=false) const
Insert field values into values list.
Foam::functionObjects::fieldValues::volFieldValue::opCoV
Coefficient of variation.
Definition: volFieldValue.H:264
Foam::functionObjects::fieldValues::volFieldValue::opMin
Minimum.
Definition: volFieldValue.H:257
Foam::functionObjects::fieldValues::volFieldValue::opSumMag
Magnitude of sum.
Definition: volFieldValue.H:260
Foam::functionObjects::fieldValues::volFieldValue::operation_
operationType operation_
Operation to apply to values.
Definition: volFieldValue.H:290
Foam::functionObjects::fieldValues::volFieldValue::write
virtual bool write()
Calculate and write.
Definition: volFieldValue.C:249
Foam::functionObjects::fieldValues::volFieldValue::operationType
operationType
Operation type enumeration.
Definition: volFieldValue.H:252
Foam::functionObjects::fieldValues::volFieldValue::weightFieldName_
word weightFieldName_
Weight field name - only used for weighted modes.
Definition: volFieldValue.H:293
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::functionObjects::fieldValues::volFieldValue::opAverage
Average.
Definition: volFieldValue.H:261
Foam::functionObjects::fieldValues::volFieldValue::validField
bool validField(const word &fieldName) const
Return true if the field name is valid.
Definition: volFieldValueTemplates.C:36
Foam::functionObjects::fieldValues::volFieldValue
Provides a 'volRegion' specialization of the fieldValue function object.
Definition: volFieldValue.H:234
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::Field< scalar >
Foam::functionObjects::fieldValues::volFieldValue::opWeightedAverage
Weighted average.
Definition: volFieldValue.H:272
Foam::functionObjects::fieldValues::volFieldValue::operationVariant
operationVariant
Bitmask values for operation variants.
Definition: volFieldValue.H:245
Foam::functionObjects::fieldValues::volFieldValue::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
Output file header information.
Definition: volFieldValue.C:144
field
rDeltaTY field()
Foam::functionObjects::fieldValues::volFieldValue::operationTypeNames_
static const Enum< operationType > operationTypeNames_
Operation type names.
Definition: volFieldValue.H:282
Foam::functionObjects::fieldValues::volFieldValue::writeValues
bool writeValues(const word &fieldName, const scalarField &V, const scalarField &weightField)
Templated helper function to output field values.
Definition: volFieldValueTemplates.C:193
Foam::functionObjects::fieldValues::volFieldValue::initialise
void initialise(const dictionary &dict)
Initialise, e.g. cell addressing.
Definition: volFieldValue.C:115
Foam::functionObjects::fieldValues::volFieldValue::filterField
tmp< Field< Type > > filterField(const Field< Type > &field) const
Filter a field according to cellIds.
volFieldValueTemplates.C
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::functionObjects::fieldValues::volFieldValue::TypeName
TypeName("volFieldValue")
Run-time type information.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
volRegion.H
Foam::functionObject::name
const word & name() const
Return the name of this functionObject.
Definition: functionObject.C:131
fieldValue.H
Foam::functionObjects::fieldValue
Base class for field value-based function objects.
Definition: fieldValue.H:65
Foam::functionObjects::regionFunctionObject::obr
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
Definition: regionFunctionObject.C:47
Foam::functionObjects::fieldValues::volFieldValue::opSum
Sum.
Definition: volFieldValue.H:259
Foam::functionObjects::fieldValues::volFieldValue::opWeightedVolAverage
Weighted volume average.
Definition: volFieldValue.H:275
Foam::functionObjects::fieldValues::volFieldValue::opVolAverage
Volume average.
Definition: volFieldValue.H:262
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::functionObjects::fieldValues::volFieldValue::canWeight
bool canWeight(const scalarField &weightField) const
True if operation variant uses a weight-field that is available.
Definition: volFieldValue.C:102
Foam::functionObjects::volRegion::V
scalar V() const
Return total volume of the selected region.
Definition: volRegionI.H:62
Foam::functionObjects::fieldValues::volFieldValue::writeAll
label writeAll(const scalarField &V, const scalarField &weightField)
Helper function to output field values.
Definition: volFieldValue.C:167
Foam::functionObjects::fieldValues::volFieldValue::opVolIntegrate
Volume integral.
Definition: volFieldValue.H:263
Foam::functionObjects::fieldValues::volFieldValue::usesVol
bool usesVol() const
True if the operation needs the cell-volume.
Definition: volFieldValue.C:76