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-2018 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  fields | List of fields to operate on | yes |
69  \endtable
70 
71  Where \c regionType is defined by
72  \plaintable
73  cellZone | requires a 'name' entry to specify the cellZone
74  all | all cells
75  \endplaintable
76 
77  The \c operation is one of:
78  \plaintable
79  none | No operation
80  sum | Sum
81  weightedSum | Weighted sum
82  sumMag | Sum of component magnitudes
83  average | Ensemble average
84  weightedAverage | Weighted average
85  volAverage | Volume weighted average
86  weightedVolAverage | Weighted volume average
87  volIntegrate | Volume integral
88  weightedVolIntegrate | Weighted volume integral
89  min | Minimum
90  max | Maximum
91  CoV | Coefficient of variation: standard deviation/mean
92  \endplaintable
93 
94 See also
95  Foam::functionObjects::fieldValues::fieldValue
96  Foam::functionObjects::volRegion
97  Foam::functionObject
98 
99 SourceFiles
100  volFieldValue.C
101 
102 \*---------------------------------------------------------------------------*/
103 
104 #ifndef functionObjects_volFieldValue_H
105 #define functionObjects_volFieldValue_H
106 
107 #include "fieldValue.H"
108 #include "volRegion.H"
109 
110 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
111 
112 namespace Foam
113 {
114 namespace functionObjects
115 {
116 namespace fieldValues
117 {
118 
119 /*---------------------------------------------------------------------------*\
120  Class volFieldValue Declaration
121 \*---------------------------------------------------------------------------*/
122 
123 class volFieldValue
124 :
125  public fieldValue,
126  public volRegion
127 {
128 
129 public:
130 
131  // Public data types
132 
133  //- Operation type enumeration
134  enum class operationType
135  {
136  none,
137  sum,
138  weightedSum,
139  sumMag,
140  average,
142  volAverage,
144  volIntegrate,
146  min,
147  max,
148  CoV
149  };
150 
151  //- Operation type names
152  static const NamedEnum<operationType, 13> operationTypeNames_;
153 
154 
155 protected:
156 
157  // Protected data
158 
159  //- Operation to apply to values
161 
162  //- Weight field name - only used for weighted modes
163  word weightFieldName_;
164 
165 
166  // Protected Member Functions
167 
168  //- Initialise, e.g. cell addressing
169  void initialise(const dictionary& dict);
170 
171  //- Return true if the field name is valid
172  template<class Type>
173  bool validField(const word& fieldName) const;
174 
175  //- Insert field values into values list
176  template<class Type>
177  tmp<Field<Type>> setFieldValues
178  (
179  const word& fieldName,
180  const bool mustGet = false
181  ) const;
182 
183  //- Apply the 'operation' to the values
184  template<class Type>
185  Type processValues
186  (
187  const Field<Type>& values,
188  const scalarField& V,
189  const scalarField& weightField
190  ) const;
191 
192  //- Output file header information
193  virtual void writeFileHeader(const label i);
194 
195 
196 public:
197 
198  //- Run-time type information
199  TypeName("volFieldValue");
200 
201 
202  // Constructors
203 
204  //- Construct from name, Time and dictionary
206  (
207  const word& name,
208  const Time& runTime,
209  const dictionary& dict
210  );
211 
212  //- Construct from name, objectRegistry and dictionary
214  (
215  const word& name,
216  const objectRegistry& obr,
217  const dictionary& dict
218  );
219 
220 
221  //- Destructor
222  virtual ~volFieldValue();
223 
224 
225  // Public Member Functions
226 
227  //- Templated helper function to output field values
228  template<class Type>
229  bool writeValues(const word& fieldName);
230 
231  //- Filter a field according to cellIds
232  template<class Type>
233  tmp<Field<Type>> filterField(const Field<Type>& field) const;
234 
235  //- Read from dictionary
236  virtual bool read(const dictionary&);
237 
238  //- Calculate and write
239  virtual bool write();
240 };
241 
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 } // End namespace fieldValues
246 } // End namespace functionObjects
247 } // End namespace Foam
248 
249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250 
251 #ifdef NoRepository
252  #include "volFieldValueTemplates.C"
253 #endif
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 #endif
258 
259 // ************************************************************************* //
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.
word weightFieldName_
Weight field name - only used for weighted modes.
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.
A class for handling words, derived from string.
Definition: word.H:59
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.
virtual void writeFileHeader(const label i)
Output file header information.
Definition: volFieldValue.C:93
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.