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