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-2023 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  //- Operation type enumeration
152  enum operationType
153  {
154  // Normal operations
155 
156  opNone = 0,
157  opMin,
158  opMax,
159  opSum,
160  opSumMag,
161  opAverage,
162  opVolAverage,
164  opCoV,
165 
166  // Operations returning scalar - bitmask value
167  typeScalar = 0x100,
168 
169  // Weighted variants
170  // Operations using weighting - bitmask value
171  typeWeighted = 0x200,
172 
175 
178 
181 
184 
185  // Variants using absolute weighting
186  // Operation using mag (eg, for weighting) - bitmask value
187  typeAbsolute = 0x400,
188  };
189 
190  //- Operation type names
191  static const Enum<operationType> operationTypeNames_;
192 
193 
194  //- Post-operation type enumeration
195  enum postOperationType
196  {
197  postOpNone,
198  postOpMag,
199  postOpSqrt
200  };
201 
202  //- Operation type names
203  static const Enum<postOperationType> postOperationTypeNames_;
204 
205 
206 protected:
207 
208  // Protected Data
209 
210  //- Operation to apply to values
212 
213  //- Optional post-evaluation operation
215 
216  //- Weight field name(s) - optional
218 
219 
220  // Protected Member Functions
221 
222  //- True if the operation needs the cell-volume
223  bool usesVol() const noexcept;
224 
225  //- True if the operation variant uses mag
226  inline bool is_magOp() const noexcept;
227 
228  //- True if the operation variant uses a weight-field
229  inline bool is_weightedOp() const noexcept;
230 
231  //- True if field is non-empty on any processor.
232  inline bool canWeight(const scalarField& fld) const;
233 
234  //- Return true if the field name is valid
235  template<class Type>
236  bool validField(const word& fieldName) const;
237 
238  //- Insert field values into values list
239  template<class Type>
240  tmp<Field<Type>> getFieldValues
241  (
242  const word& fieldName,
243  const bool mandatory = false
244  ) const;
245 
246  //- Apply the 'operation' to the values
247  template<class Type>
248  Type processValues
249  (
250  const Field<Type>& values,
251  const scalarField& V,
252  const scalarField& weightField
253  ) const;
254 
255  //- Helper function to output field values
256  label writeAll
257  (
258  const scalarField& V,
259  const scalarField& weightField
260  );
261 
262  //- Templated helper function to output field values
263  template<class Type>
264  bool writeValues
265  (
266  const word& fieldName,
267  const scalarField& V,
268  const scalarField& weightField
269  );
270 
271  //- Filter a field according to cellIds
272  template<class Type>
273  tmp<Field<Type>> filterField(const Field<Type>& field) const;
274 
275  //- Output file header information
276  virtual void writeFileHeader(Ostream& os) const;
277 
278 
279 public:
280 
281  //- Declare type-name, virtual type (with debug switch)
283 
284 
285  // Constructors
287  //- Construct from name, Time and dictionary
289  (
290  const word& name,
291  const Time& runTime,
293  );
294 
295  //- Construct from name, objectRegistry and dictionary
297  (
298  const word& name,
299  const objectRegistry& obr,
301  );
302 
303  //- No copy construct
304  volFieldValue(const volFieldValue&) = delete;
305 
306  //- No copy assignment
307  void operator=(const volFieldValue&) = delete;
308 
310  //- Destructor
311  virtual ~volFieldValue() = default;
313 
314  // Member Functions
315 
316  //- Read from dictionary
317  virtual bool read(const dictionary& dict);
318 
319  //- Calculate and write
320  virtual bool write();
321 };
323 
324 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 
326 } // End namespace fieldValues
327 } // End namespace functionObjects
328 } // End namespace Foam
329 
330 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
332 #include "volFieldValueI.H"
333 
334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 
336 #ifdef NoRepository
337  #include "volFieldValueTemplates.C"
338 #endif
339 
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
341 
342 #endif
343 
344 // ************************************************************************* //
operationType operation_
Operation to apply to values.
bool writeValues(const word &fieldName, const scalarField &V, const scalarField &weightField)
Templated helper function to output field values.
static const Enum< operationType > operationTypeNames_
Operation type names.
rDeltaTY field()
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
static const Enum< postOperationType > postOperationTypeNames_
Operation type names.
No additional operation after calculation.
virtual void writeFileHeader(Ostream &os) const
Output file header information.
engineTime & runTime
tmp< Field< Type > > getFieldValues(const word &fieldName, const bool mandatory=false) const
Insert field values into values list.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
const word & name() const noexcept
Return the name of this functionObject.
const dictionary & dict() const noexcept
Return the reference to the construction dictionary.
Definition: fieldValueI.H:24
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
Generic templated field type.
Definition: Field.H:62
bool validField(const word &fieldName) const
Return true if the field name is valid.
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
postOperationType postOperation_
Optional post-evaluation operation.
tmp< Field< Type > > filterField(const Field< Type > &field) const
Filter a field according to cellIds.
Type processValues(const Field< Type > &values, const scalarField &V, const scalarField &weightField) const
Apply the &#39;operation&#39; to the values.
virtual bool read(const dictionary &dict)
Read from dictionary.
Component-wise mag after normal operation.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
scalar V() const
Return total volume of the selected region.
Definition: volRegionI.H:52
TypeName("volFieldValue")
Declare type-name, virtual type (with debug switch)
OBJstream os(runTime.globalPath()/outputName)
postOperationType
Post-operation type enumeration.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
label writeAll(const scalarField &V, const scalarField &weightField)
Helper function to output field values.
List< word > wordList
List of word.
Definition: fileName.H:59
wordList weightFieldNames_
Weight field name(s) - optional.
bool is_magOp() const noexcept
True if the operation variant uses mag.
Provides a &#39;volRegion&#39; specialization of the fieldValue function object.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Registry of regIOobjects.
bool is_weightedOp() const noexcept
True if the operation variant uses a weight-field.
virtual bool write()
Calculate and write.
Component-wise sqrt after normal operation.
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
bool usesVol() const noexcept
True if the operation needs the cell-volume.
Definition: volFieldValue.C:80
Namespace for OpenFOAM.
bool canWeight(const scalarField &fld) const
True if field is non-empty on any processor.