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-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::fieldValues::volFieldValue
29 
30 Group
31  grpFieldFunctionObjects
32 
33 Description
34  Provides a 'volRegion' specialization of the \c 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  Minimal example by using \c system/controlDict.functions:
41  \verbatim
42  volFieldValue1
43  {
44  // Mandatory entries (unmodifiable)
45  type volFieldValue;
46  libs (fieldFunctionObjects);
47 
48  // Mandatory entries (runtime modifiable)
49  fields (<field1> <field2> ... <fieldN>);
50  operation <operationType>;
51  regionType <volRegion>;
52 
53  // Optional entries (runtime modifiable)
54  postOperation none;
55  weightField alpha1;
56 
57  // Optional (inherited) entries
58  ...
59  }
60  \endverbatim
61 
62  where the entries mean:
63  \table
64  Property | Description | Type | Req'd | Dflt
65  type | Type name: volFieldValue | word | yes | -
66  libs | Library name: fieldFunctionObjects | word | yes | -
67  fields | Names of operand fields | wordList | yes | -
68  regionType | Face regionType: see below | word | yes | -
69  name | Name for regionType | word | yes | -
70  operation | Operation type: see below | word | yes | -
71  postOperation | Post-operation type: see below | word | no | none
72  weightField | Name of field to apply weighting | word | maybe |
73  weightFields | Names of fields to apply weighting | wordList | maybe |
74  \endtable
75 
76  The inherited entries are elaborated in:
77  - \link fieldValue.H \endlink
78  - \link volRegion.H \endlink
79 
80  Options for the \c regionType entry:
81  \plaintable
82  cellZone | requires a 'name' entry to specify the cellZone
83  all | all cells
84  \endplaintable
85 
86  Options for the \c operation entry:
87  \plaintable
88  none | No operation
89  min | Minimum
90  max | Maximum
91  sum | Sum
92  sumMag | Sum of component magnitudes
93  average | Ensemble average
94  volAverage | Volume weighted average
95  volIntegrate | Volume integral
96  CoV | Coefficient of variation: standard deviation/mean
97  weightedSum | Weighted sum
98  weightedAverage | Weighted average
99  weightedVolAverage | Weighted volume average
100  weightedVolIntegrate | Weighted volume integral
101  \endplaintable
102 
103  Options for the \c postOperation entry:
104  \plaintable
105  none | No additional operation after calculation
106  mag | Component-wise \c mag() after normal operation
107  sqrt | Component-wise \c sqrt() after normal operation
108  \endplaintable
109 
110  Usage by the \c postProcess utility is not available.
111 
112 See also
113  - Foam::functionObject
114  - Foam::functionObjects::fieldValues::fieldValue
115  - Foam::functionObjects::volRegion
116 
117 SourceFiles
118  volFieldValue.C
119  volFieldValueTemplates.C
120 
121 \*---------------------------------------------------------------------------*/
122 
123 #ifndef functionObjects_volFieldValue_H
124 #define functionObjects_volFieldValue_H
125 
126 #include "fieldValue.H"
127 #include "volRegion.H"
128 
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
130 
131 namespace Foam
132 {
133 namespace functionObjects
134 {
135 namespace fieldValues
136 {
137 
138 /*---------------------------------------------------------------------------*\
139  Class volFieldValue Declaration
140 \*---------------------------------------------------------------------------*/
141 
142 class volFieldValue
143 :
144  public fieldValue,
145  public volRegion
146 {
147 public:
148 
149  // Public Data Types
150 
151  //- Bitmask values for operation variants
152  enum operationVariant
153  {
154  typeBase = 0,
155  typeScalar = 0x100,
156  typeWeighted = 0x200,
157  typeAbsolute = 0x400,
158  };
159 
160  //- Operation type enumeration
161  enum operationType
162  {
163  // Normal operations
164 
165  opNone = 0,
166  opMin,
167  opMax,
168  opSum,
169  opSumMag,
170  opAverage,
171  opVolAverage,
173  opCoV,
174 
175  // Weighted variants
176 
179 
182 
185 
188 
189  // Variants using absolute weighting
190  };
191 
192  //- Operation type names
193  static const Enum<operationType> operationTypeNames_;
194 
195 
196  //- Post-operation type enumeration
197  enum postOperationType
198  {
199  postOpNone,
200  postOpMag,
201  postOpSqrt
202  };
203 
204  //- Operation type names
205  static const Enum<postOperationType> postOperationTypeNames_;
206 
207 
208 protected:
209 
210  // Protected Data
211 
212  //- Operation to apply to values
214 
215  //- Optional post-evaluation operation
217 
218  //- Weight field name(s) - optional
220 
221 
222  // Protected Member Functions
223 
224  //- True if the operation needs the cell-volume
225  bool usesVol() const;
226 
227  //- True if the operation variant uses mag
228  bool usesMag() const;
229 
230  //- True if the operation variant uses a weight-field
231  bool usesWeight() const;
232 
233  //- True if operation variant uses a weight-field that is available.
234  // Checks for availability on any processor.
235  inline bool canWeight(const scalarField& weightField) const;
236 
237  //- Return true if the field name is valid
238  template<class Type>
239  bool validField(const word& fieldName) const;
240 
241  //- Insert field values into values list
242  template<class Type>
243  tmp<Field<Type>> getFieldValues
244  (
245  const word& fieldName,
246  const bool mandatory = false
247  ) const;
248 
249  //- Apply the 'operation' to the values
250  template<class Type>
251  Type processValues
252  (
253  const Field<Type>& values,
254  const scalarField& V,
255  const scalarField& weightField
256  ) const;
257 
258  //- Helper function to output field values
259  label writeAll
260  (
261  const scalarField& V,
262  const scalarField& weightField
263  );
264 
265  //- Templated helper function to output field values
266  template<class Type>
267  bool writeValues
268  (
269  const word& fieldName,
270  const scalarField& V,
271  const scalarField& weightField
272  );
273 
274  //- Filter a field according to cellIds
275  template<class Type>
277 
278  //- Output file header information
279  virtual void writeFileHeader(Ostream& os) const;
280 
281 
282 public:
283 
284  //- Declare type-name, virtual type (with debug switch)
285  TypeName("volFieldValue");
286 
287 
288  // Constructors
289 
290  //- Construct from name, Time and dictionary
292  (
293  const word& name,
294  const Time& runTime,
295  const dictionary& dict
296  );
297 
298  //- Construct from name, objectRegistry and dictionary
300  (
301  const word& name,
304  );
305 
306  //- No copy construct
307  volFieldValue(const volFieldValue&) = delete;
308 
309  //- No copy assignment
310  void operator=(const volFieldValue&) = delete;
311 
312 
313  //- Destructor
314  virtual ~volFieldValue() = default;
315 
316 
317  // Member Functions
318 
319  //- Read from dictionary
320  virtual bool read(const dictionary& dict);
321 
322  //- Calculate and write
323  virtual bool write();
324 };
325 
326 
327 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
328 
329 } // End namespace fieldValues
330 } // End namespace functionObjects
331 } // End namespace Foam
332 
333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334 
335 #ifdef NoRepository
337 #endif
338 
339 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
340 
341 #endif
342 
343 // ************************************************************************* //
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:309
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:296
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:112
Foam::functionObjects::volRegion
Volume (cell) region selection class.
Definition: volRegion.H:115
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::functionObjects::fieldValues::volFieldValue::postOperationType
postOperationType
Post-operation type enumeration.
Definition: volFieldValue.H:328
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::typeScalar
Operation returns a scalar.
Definition: volFieldValue.H:286
Foam::functionObjects::fieldValues::volFieldValue::opMax
Maximum value.
Definition: volFieldValue.H:298
Foam::functionObjects::fieldValues::volFieldValue::volFieldValue
volFieldValue(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
Definition: volFieldValue.C:200
Foam::functionObjects::fieldValues::volFieldValue::opWeightedVolIntegrate
Weighted volume integral.
Definition: volFieldValue.H:318
Foam::functionObjects::fieldValues::volFieldValue::typeBase
Base operation.
Definition: volFieldValue.H:285
Foam::functionObjects::fieldValue::dict
const dictionary & dict() const
Return the reference to the construction dictionary.
Definition: fieldValueI.H:31
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:84
Foam::functionObjects::fieldValues::volFieldValue::typeWeighted
Operation using weighting.
Definition: volFieldValue.H:287
Foam::functionObjects::fieldValues::volFieldValue::operator=
void operator=(const volFieldValue &)=delete
No copy assignment.
Foam::functionObjects::fieldValues::volFieldValue::read
virtual bool read(const dictionary &dict)
Read from dictionary.
Definition: volFieldValue.C:255
Foam::functionObjects::fieldValues::volFieldValue::opCoV
Coefficient of variation.
Definition: volFieldValue.H:304
Foam::functionObjects::fieldValues::volFieldValue::opMin
Minimum value.
Definition: volFieldValue.H:297
Foam::functionObjects::fieldValues::volFieldValue::typeAbsolute
Operation using mag (eg, for weighting)
Definition: volFieldValue.H:288
Foam::functionObjects::fieldValues::volFieldValue::opSumMag
Sum of component magnitudes.
Definition: volFieldValue.H:300
Foam::functionObjects::fieldValues::volFieldValue::operation_
operationType operation_
Operation to apply to values.
Definition: volFieldValue.H:344
Foam::functionObjects::fieldValues::volFieldValue::write
virtual bool write()
Calculate and write.
Definition: volFieldValue.C:316
Foam::functionObjects::fieldValues::volFieldValue::operationType
operationType
Operation type enumeration.
Definition: volFieldValue.H:292
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:59
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::functionObjects::fieldValues::volFieldValue::opAverage
Ensemble average.
Definition: volFieldValue.H:301
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::postOperationTypeNames_
static const Enum< postOperationType > postOperationTypeNames_
Operation type names.
Definition: volFieldValue.H:336
Foam::functionObjects::fieldValues::volFieldValue
Provides a 'volRegion' specialization of the fieldValue function object.
Definition: volFieldValue.H:273
Foam::Field< scalar >
Foam::functionObjects::fieldValues::volFieldValue::opWeightedAverage
Weighted average.
Definition: volFieldValue.H:312
Foam::functionObjects::fieldValues::volFieldValue::operationVariant
operationVariant
Bitmask values for operation variants.
Definition: volFieldValue.H:283
Foam::functionObjects::fieldValues::volFieldValue::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
Output file header information.
Definition: volFieldValue.C:133
field
rDeltaTY field()
Foam::functionObjects::fieldValues::volFieldValue::operationTypeNames_
static const Enum< operationType > operationTypeNames_
Operation type names.
Definition: volFieldValue.H:324
Foam::functionObjects::fieldValues::volFieldValue::postOperation_
postOperationType postOperation_
Optional post-evaluation operation.
Definition: volFieldValue.H:347
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:198
Foam::functionObjects::fieldValues::volFieldValue::usesMag
bool usesMag() const
True if the operation variant uses mag.
Definition: volFieldValue.C:105
Foam::functionObjects::fieldValues::volFieldValue::filterField
tmp< Field< Type > > filterField(const Field< Type > &field) const
Filter a field according to cellIds.
Foam::functionObjects::fieldValues::volFieldValue::weightFieldNames_
wordList weightFieldNames_
Weight field name(s) - optional.
Definition: volFieldValue.H:350
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")
Declare type-name, virtual type (with debug switch)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
volRegion.H
Foam::functionObjects::fieldValues::volFieldValue::postOpSqrt
Component-wise sqrt after normal operation.
Definition: volFieldValue.H:332
Foam::functionObjects::fieldValues::volFieldValue::getFieldValues
tmp< Field< Type > > getFieldValues(const word &fieldName, const bool mandatory=false) const
Insert field values into values list.
Foam::functionObject::name
const word & name() const
Return the name of this functionObject.
Definition: functionObject.C:131
fieldValue.H
Foam::List< word >
Foam::functionObjects::fieldValue
Intermediate class for handling field value-based function objects.
Definition: fieldValue.H:119
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 of values.
Definition: volFieldValue.H:299
Foam::functionObjects::fieldValues::volFieldValue::opWeightedVolAverage
Weighted volume average.
Definition: volFieldValue.H:315
Foam::functionObjects::fieldValues::volFieldValue::opVolAverage
Volume average.
Definition: volFieldValue.H:302
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:120
Foam::functionObjects::volRegion::V
scalar V() const
Return total volume of the selected region.
Definition: volRegionI.H:62
Foam::functionObjects::fieldValues::volFieldValue::postOpNone
No additional operation after calculation.
Definition: volFieldValue.H:330
Foam::functionObjects::fieldValues::volFieldValue::writeAll
label writeAll(const scalarField &V, const scalarField &weightField)
Helper function to output field values.
Definition: volFieldValue.C:164
Foam::functionObjects::fieldValues::volFieldValue::opVolIntegrate
Volume integral.
Definition: volFieldValue.H:303
Foam::functionObjects::fieldValues::volFieldValue::usesVol
bool usesVol() const
True if the operation needs the cell-volume.
Definition: volFieldValue.C:87
Foam::functionObjects::fieldValues::volFieldValue::postOpMag
Component-wise mag after normal operation.
Definition: volFieldValue.H:331