volRegion.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-2016 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::volRegion
26 
27 Group
28  grpFieldFunctionObjects
29 
30 Description
31  This function object provides a 'cell region' variant of the fieldValues
32  function object. Given a list of user-specified fields and a selection
33  of mesh cells, a number of operations can be performed, such as sums,
34  averages and integrations.
35 
36 
37  Example of function object specification:
38  \verbatim
39  volRegion1
40  {
41  type volRegion;
42  libs ("libfieldFunctionObjects.so");
43  ...
44  log true;
45  writeFields true;
46  regionType cellZone;
47  name c0;
48  operation volAverage;
49  weightField alpha1;
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: volRegion | yes |
62  log | Write data to standard output | no | no
63  writeFields | Write the region field values | yes |
64  writeVolume | Write the volume of the volRegion | no |
65  regionType | cell regionType: see below | yes |
66  name | name of cell regionType if required | no |
67  operation | operation to perform | yes |
68  weightField | name of field 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  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  min | minimum
89  max | maximum
90  CoV | coefficient of variation: standard deviation/mean
91  \endplaintable
92 
93 See also
94  Foam::fieldValues
95  Foam::functionObject
96 
97 SourceFiles
98  volRegion.C
99 
100 \*---------------------------------------------------------------------------*/
101 
102 #ifndef functionObjects_volRegion_H
103 #define functionObjects_volRegion_H
104 
105 #include "fieldValue.H"
106 #include "NamedEnum.H"
107 
108 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
109 
110 namespace Foam
111 {
112 namespace functionObjects
113 {
114 namespace fieldValues
115 {
116 
117 /*---------------------------------------------------------------------------*\
118  Class volRegion Declaration
119 \*---------------------------------------------------------------------------*/
120 
121 class volRegion
122 :
123  public fieldValue
124 {
125 
126 public:
127 
128  // Public data types
129 
130  //- region type enumeration
131  enum regionTypes
132  {
133  stCellZone,
134  stAll
135  };
136 
137  //- region type names
138  static const NamedEnum<regionTypes, 2> regionTypeNames_;
139 
140 
141  //- Operation type enumeration
142  enum operationType
143  {
144  opNone,
145  opSum,
146  opSumMag,
147  opAverage,
149  opVolAverage,
152  opMin,
153  opMax,
154  opCoV
155  };
156 
157  //- Operation type names
158  static const NamedEnum<operationType, 11> operationTypeNames_;
159 
160 
161 private:
162 
163  // Private Member Functions
164 
165  //- Set cells to evaluate based on a cell zone
166  void setCellZoneCells();
167 
168  //- Set cells to evaluate based on a patch
169  void setPatchCells();
170 
171  //- Calculate and return volume of the volRegion: sum(V)
172  scalar volume() const;
173 
174 
175 protected:
176 
177  // Protected data
178 
179  //- region type
181 
182  //- Operation to apply to values
184 
185  //- Global number of cells
186  label nCells_;
187 
188  //- Local list of cell IDs
190 
191  //- Weight field name - only used for opWeightedAverage mode
192  word weightFieldName_;
193 
194  //- Volume of the volRegion
195  scalar volume_;
196 
197  //- Optionally write the volume of the volRegion
198  bool writeVolume_;
199 
200 
201  // Protected Member Functions
202 
203  //- Initialise, e.g. cell addressing
204  void initialise(const dictionary& dict);
205 
206  //- Return true if the field name is valid
207  template<class Type>
208  bool validField(const word& fieldName) const;
209 
210  //- Insert field values into values list
211  template<class Type>
212  tmp<Field<Type>> setFieldValues
213  (
214  const word& fieldName,
215  const bool mustGet = false
216  ) const;
217 
218  //- Apply the 'operation' to the values
219  template<class Type>
220  Type processValues
221  (
222  const Field<Type>& values,
223  const scalarField& V,
224  const scalarField& weightField
225  ) const;
226 
227  //- Output file header information
228  virtual void writeFileHeader(const label i);
229 
230 
231 public:
233  //- Run-time type information
234  TypeName("volRegion");
236 
237  // Constructors
238 
239  //- Construct from name, Time and dictionary
240  volRegion
241  (
242  const word& name,
243  const Time& runTime,
244  const dictionary& dict
245  );
247  //- Construct from name, objectRegistry and dictionary
249  (
250  const word& name,
251  const objectRegistry& obr,
253  );
256  //- Destructor
257  virtual ~volRegion();
258 
260  // Public Member Functions
261 
262  //- Return the region type
263  inline const regionTypes& regionType() const;
264 
265  //- Return the local list of cell IDs
266  inline const labelList& cellId() const;
267 
268  //- Templated helper function to output field values
269  template<class Type>
270  bool writeValues(const word& fieldName);
271 
272  //- Filter a field according to cellIds
273  template<class Type>
274  tmp<Field<Type>> filterField(const Field<Type>& field) const;
275 
276  //- Read from dictionary
277  virtual bool read(const dictionary&);
278 
279  //- Calculate and write
280  virtual bool write();
281 };
282 
283 
284 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 
286 } // End namespace fieldValues
287 } // End namespace functionObjects
288 } // End namespace Foam
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
292 #include "volRegionI.H"
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 
296 #ifdef NoRepository
297  #include "volRegionTemplates.C"
298 #endif
300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 
302 #endif
303 
304 // ************************************************************************* //
labelList cellId_
Local list of cell IDs.
Definition: volRegion.H:290
virtual bool write()
Calculate and write.
Definition: volRegion.C:278
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
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
tmp< Field< Type > > filterField(const Field< Type > &field) const
Filter a field according to cellIds.
bool writeValues(const word &fieldName)
Templated helper function to output field values.
bool validField(const word &fieldName) const
Return true if the field name is valid.
bool writeVolume_
Optionally write the volume of the volRegion.
Definition: volRegion.H:299
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
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: volRegion.C:144
static const NamedEnum< operationType, 11 > operationTypeNames_
Operation type names.
Definition: volRegion.H:259
const dictionary & dict() const
Return the reference to the construction dictionary.
Definition: fieldValueI.H:31
const word & name() const
Return the name of this functionObject.
Pre-declare SubField and related Field type.
Definition: Field.H:57
A class for handling words, derived from string.
Definition: word.H:59
label nCells_
Global number of cells.
Definition: volRegion.H:287
List< label > labelList
A List of labels.
Definition: labelList.H:56
const regionTypes & regionType() const
Return the region type.
Definition: volRegionI.H:31
const labelList & cellId() const
Return the local list of cell IDs.
Definition: volRegionI.H:38
word weightFieldName_
Weight field name - only used for opWeightedAverage mode.
Definition: volRegion.H:293
static const NamedEnum< regionTypes, 2 > regionTypeNames_
region type names
Definition: volRegion.H:239
virtual bool read(const dictionary &)
Read from dictionary.
Definition: volRegion.C:265
volRegion(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
Definition: volRegion.C:207
virtual void writeFileHeader(const label i)
Output file header information.
Definition: volRegion.C:176
A class for managing temporary objects.
Definition: PtrList.H:54
Registry of regIOobjects.
operationType operation_
Operation to apply to values.
Definition: volRegion.H:284
Type processValues(const Field< Type > &values, const scalarField &V, const scalarField &weightField) const
Apply the &#39;operation&#39; to the values.
Namespace for OpenFOAM.
TypeName("volRegion")
Run-time type information.
scalar volume_
Volume of the volRegion.
Definition: volRegion.H:296
operationType
Operation type enumeration.
Definition: volRegion.H:243