volFieldValue.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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 Class
25  Foam::functionObjects::fieldValues::volFieldValue
26 
27 Description
28  Provides a 'volRegion' specialization of the fieldValue function object.
29 
30  Given a list of user-specified fields and a 'volRegion', a number of
31  operations can be performed, such as sums, averages and integrations.
32 
33  Example of function object specification:
34  \verbatim
35  volFieldValue1
36  {
37  type volFieldValue;
38  libs ("libfieldFunctionObjects.so");
39 
40  log true;
41  writeControl writeTime;
42  writeFields true;
43 
44  regionType cellZone;
45  name c0;
46  operation volAverage;
47 
48  weightField alpha1;
49 
50  fields
51  (
52  p
53  U
54  );
55  }
56  \endverbatim
57 
58 Usage
59  \table
60  Property | Description | Required | Default value
61  type | Type name: volFieldValue | yes |
62  log | Write data to standard output | no | no
63  writeFields | Write the region field values | yes |
64  regionType | volRegion type: see below | yes |
65  name | Name of volRegion if required | no |
66  operation | Operation to perform | yes |
67  weightField | Name of field to apply weighting | no |
68  weightFields | Names of fields to apply weighting | no |
69  fields | List of fields to operate on | yes |
70  \endtable
71 
72  Where \c regionType is defined by
73  \plaintable
74  cellZone | requires a 'name' entry to specify the cellZone
75  all | all cells
76  \endplaintable
77 
78  The \c operation is one of:
79  \plaintable
80  none | No operation
81  sum | Sum
82  weightedSum | Weighted sum
83  sumMag | Sum of component magnitudes
84  average | Ensemble average
85  weightedAverage | Weighted average
86  volAverage | Volume weighted average
87  weightedVolAverage | Weighted volume average
88  volIntegrate | Volume integral
89  weightedVolIntegrate | Weighted volume integral
90  min | Minimum
91  max | Maximum
92  CoV | Coefficient of variation: standard deviation/mean
93  \endplaintable
94 
95 See also
96  Foam::functionObjects::fieldValues::fieldValue
97  Foam::functionObjects::volRegion
98  Foam::functionObject
99 
100 SourceFiles
101  volFieldValue.C
102 
103 \*---------------------------------------------------------------------------*/
104 
105 #ifndef functionObjects_volFieldValue_H
106 #define functionObjects_volFieldValue_H
107 
108 #include "fieldValue.H"
109 #include "volRegion.H"
110 
111 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
112 
113 namespace Foam
114 {
115 namespace functionObjects
116 {
117 namespace fieldValues
118 {
119 
120 /*---------------------------------------------------------------------------*\
121  Class volFieldValue Declaration
122 \*---------------------------------------------------------------------------*/
123 
124 class volFieldValue
125 :
126  public fieldValue,
127  public volRegion
128 {
129 
130 public:
131 
132  // Public data types
133 
134  //- Operation type enumeration
135  enum class operationType
136  {
137  none,
138  sum,
139  weightedSum,
140  sumMag,
141  average,
143  volAverage,
145  volIntegrate,
147  min,
148  max,
149  CoV
150  };
151 
152  //- Operation type names
153  static const NamedEnum<operationType, 13> operationTypeNames_;
154 
155 
156 protected:
157 
158  // Protected data
159 
160  //- Operation to apply to values
162 
163  //- Weight field names - only used for weighted modes
165 
166 
167  // Protected Member Functions
168 
169  //- Initialise, e.g. cell addressing
170  void initialise(const dictionary& dict);
171 
172  //- Return true if the field name is valid
173  template<class Type>
174  bool validField(const word& fieldName) const;
175 
176  //- Insert field values into values list
177  template<class Type>
178  tmp<Field<Type>> setFieldValues
179  (
180  const word& fieldName,
181  const bool mustGet = false
182  ) const;
183 
184  //- Apply the 'operation' to the values
185  template<class Type>
186  Type processValues
187  (
188  const Field<Type>& values,
189  const scalarField& V,
190  const scalarField& weightField
191  ) const;
192 
193  //- Output file header information
194  virtual void writeFileHeader(const label i);
195 
196 
197 public:
198 
199  //- Run-time type information
200  TypeName("volFieldValue");
201 
202 
203  // Constructors
204 
205  //- Construct from name, Time and dictionary
207  (
208  const word& name,
209  const Time& runTime,
210  const dictionary& dict
211  );
212 
213  //- Construct from name, objectRegistry and dictionary
215  (
216  const word& name,
217  const objectRegistry& obr,
218  const dictionary& dict
219  );
220 
221 
222  //- Destructor
223  virtual ~volFieldValue();
224 
225 
226  // Public Member Functions
227 
228  //- Templated helper function to output field values
229  template<class Type>
230  bool writeValues(const word& fieldName);
231 
232  //- Filter a field according to cellIds
233  template<class Type>
235 
236  //- Read from dictionary
237  virtual bool read(const dictionary&);
238 
239  //- Calculate and write
240  virtual bool write();
241 };
242 
243 
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 
246 } // End namespace fieldValues
247 } // End namespace functionObjects
248 } // End namespace Foam
249 
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 
252 #ifdef NoRepository
253  #include "volFieldValueTemplates.C"
254 #endif
255 
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 
258 #endif
259 
260 // ************************************************************************* //
operationType operation_
Operation to apply to values.
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:59
static const NamedEnum< operationType, 13 > operationTypeNames_
Operation type names.
const word & name() const
Return the name of this functionObject.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
tmp< Field< Type > > setFieldValues(const word &fieldName, const bool mustGet=false) const
Insert field values into values list.
void initialise(const dictionary &dict)
Initialise, e.g. cell addressing.
Definition: volFieldValue.C:79
engineTime & runTime
volFieldValue(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
Pre-declare SubField and related Field type.
Definition: Field.H:56
bool validField(const word &fieldName) const
Return true if the field name is valid.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
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.
const dictionary & dict() const
Return the reference to the construction dictionary.
Definition: fieldValueI.H:31
scalar V() const
Return total volume of the region.
Definition: volRegion.C:181
TypeName("volFieldValue")
Run-time type information.
List< word > wordList
A List of words.
Definition: fileName.H:54
virtual void writeFileHeader(const label i)
Output file header information.
wordList weightFieldNames_
Weight field names - only used for weighted modes.
rDeltaTY field()
A class for managing temporary objects.
Definition: PtrList.H:53
bool writeValues(const word &fieldName)
Templated helper function to output field values.
virtual bool write()
Calculate and write.
virtual bool read(const dictionary &)
Read from dictionary.
Namespace for OpenFOAM.