surfaceRegion.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::surfaceRegion
26 
27 Group
28  grpFieldFunctionObjects
29 
30 Description
31  This function object provides a 'face regionType' variant of the fieldValues
32  function object. Given a list of user-specified fields and a selection
33  of mesh (or general surface) faces, a number of operations can be
34  performed, such as sums, averages and integrations.
35 
36  For example, to calculate the volumetric or mass flux across a patch,
37  apply the 'sum' operator to the flux field (typically \c phi)
38 
39  Example of function object specification:
40  \verbatim
41  surfaceRegion1
42  {
43  type surfaceRegion;
44  libs ("libfieldFunctionObjects.so");
45  ...
46  log yes;
47  writeFields true;
48  surfaceFormat none;
49  regionType faceZone;
50  name f0;
51  operation sum;
52  weightField alpha1;
53  fields
54  (
55  p
56  phi
57  U
58  );
59  }
60  \endverbatim
61 
62 Usage
63  \table
64  Property | Description | Required | Default value
65  type | type name: surfaceRegion | yes |
66  log | write data to standard output | no | no
67  writeFields | Write the region field values | yes |
68  writeArea | Write the area of the surfaceRegion | no |
69  surfaceFormat | output value format | no |
70  regionType | face regionType: see below | yes |
71  name | name of face regionType if required | no |
72  operation | operation to perform | yes |
73  weightField | name of field to apply weighting | no |
74  orientedWeightField | name of oriented field to apply weighting | no |
75  scaleFactor | scale factor | no | 1
76  fields | list of fields to operate on | yes |
77  orientedFields | list of oriented fields to operate on | no |
78  \endtable
79 
80  Where \c regionType is defined by
81  \plaintable
82  faceZone | requires a 'name' entry to specify the faceZone
83  patch | requires a 'name' entry to specify the patch
84  sampledSurface | requires a 'sampledSurfaceDict' sub-dictionary
85  \endplaintable
86 
87  The \c operation is one of:
88  \plaintable
89  none | no operation
90  sum | sum
91  sumMag | sum of component magnitudes
92  sumDirection | sum values which are positive in given direction
93  sumDirectionBalance | sum of balance of values in given direction
94  average | ensemble average
95  weightedAverage | weighted average
96  areaAverage | area weighted average
97  weightedAreaAverage | weighted area average
98  areaIntegrate | area integral
99  min | minimum
100  max | maximum
101  CoV | coefficient of variation: standard deviation/mean
102  areaNormalAverage| area weighted average in face normal direction
103  areaNormalIntegrate | area weighted integral in face normal directon
104  \endplaintable
105 
106 Note
107  - The values reported by the areaNormalAverage and areaNormalIntegrate
108  operations are written as the first component of a field with the same
109  rank as the input field.
110  - faces on empty patches get ignored
111  - if the field is a volField the \c faceZone can only consist of boundary
112  faces
113  - the `oriented' entries relate to mesh-oriented fields, such as the
114  flux, phi. These fields will be oriented according to the face normals.
115  - using \c sampledSurfaces:
116  - not available for surface fields
117  - if interpolate=true they use \c interpolationCellPoint
118  otherwise they use cell values
119  - each triangle in \c sampledSurface is logically only in one cell
120  so interpolation will be wrong when triangles are larger than
121  cells. This can only happen for sampling on a \c triSurfaceMesh
122  - take care when using isoSurfaces - these might have duplicate
123  triangles and so integration might be wrong
124 
125 See also
126  Foam::fieldValues
127  Foam::functionObject
128 
129 SourceFiles
130  surfaceRegion.C
131  surfaceRegionTemplates.C
132 
133 \*---------------------------------------------------------------------------*/
134 
135 #ifndef functionObjects_surfaceRegion_H
136 #define functionObjects_surfaceRegion_H
137 
138 #include "fieldValue.H"
139 #include "NamedEnum.H"
140 
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 
143 namespace Foam
144 {
145 
146 class sampledSurface;
147 class surfaceWriter;
148 
149 namespace functionObjects
150 {
151 namespace fieldValues
152 {
153 
154 /*---------------------------------------------------------------------------*\
155  Class surfaceRegion Declaration
156 \*---------------------------------------------------------------------------*/
157 
158 class surfaceRegion
159 :
160  public fieldValue
161 {
162 
163 public:
164 
165  // Public data types
166 
167  //- region type enumeration
168  enum regionTypes
169  {
170  stFaceZone,
171  stPatch,
173  };
174 
175  //- region type names
176  static const NamedEnum<regionTypes, 3> regionTypeNames_;
177 
178 
179  //- Operation type enumeration
180  enum operationType
181  {
182  opNone,
183  opSum,
184  opSumMag,
187  opAverage,
192  opMin,
193  opMax,
194  opCoV,
197  };
198 
199  //- Operation type names
200  static const NamedEnum<operationType, 15> operationTypeNames_;
201 
202 
203 private:
204 
205  // Private Member Functions
206 
207  //- Set faces to evaluate based on a face zone
208  void setFaceZoneFaces();
209 
210  //- Set faces to evaluate based on a patch
211  void setPatchFaces();
212 
213  //- Set faces according to sampledSurface
214  void sampledSurfaceFaces(const dictionary&);
215 
216  //- Combine mesh faces and points from multiple processors
217  void combineMeshGeometry
218  (
219  faceList& faces,
221  ) const;
222 
223  //- Combine surface faces and points from multiple processors
224  void combineSurfaceGeometry
225  (
226  faceList& faces,
228  ) const;
229 
230  //- Calculate and return total area of the surfaceRegion: sum(magSf)
231  scalar totalArea() const;
232 
233 
234 protected:
235 
236  // Protected data
237 
238  //- Surface writer
239  autoPtr<surfaceWriter> surfaceWriterPtr_;
240 
241  //- region type
243 
244  //- Operation to apply to values
246 
247  //- Weight field name - optional
248  word weightFieldName_;
249 
250  //- Flag to indicate if flipMap should be applied to the weight field
251  bool orientWeightField_;
252 
253  //- Start index of fields that require application of flipMap
255 
256  //- Scale factor - optional
257  scalar scaleFactor_;
258 
259  //- Total area of the surfaceRegion
260  scalar totalArea_;
261 
262  //- Optionally write the area of the surfaceRegion
263  bool writeArea_;
264 
265  //- Global number of faces
266  label nFaces_;
267 
268 
269  // If operating on mesh faces (faceZone, patch)
270 
271  //- Local list of face IDs
273 
274  //- Local list of patch ID per face
276 
277  //- List of +1/-1 representing face flip map
278  // (1 use as is, -1 negate)
280 
281 
282  // If operating on sampledSurface
283 
284  //- Underlying sampledSurface
285  autoPtr<sampledSurface> surfacePtr_;
286 
287 
288  // Protected Member Functions
289 
290  //- Initialise, e.g. face addressing
291  void initialise(const dictionary& dict);
292 
293  //- Return true if the field name is valid
294  template<class Type>
295  bool validField(const word& fieldName) const;
296 
297  //- Return field values by looking up field name
298  template<class Type>
300  (
301  const word& fieldName,
302  const bool mustGet = false,
303  const bool applyOrientation = false
304  ) const;
305 
306  //- Apply the 'operation' to the values. Operation has to
307  // preserve Type.
308  template<class Type>
310  (
311  const Field<Type>& values,
312  const vectorField& Sf,
313  const scalarField& weightField
314  ) const;
315 
316  //- Apply the 'operation' to the values. Wrapper around
317  // processSameTypeValues. See also template specialisation below.
318  template<class Type>
319  Type processValues
320  (
321  const Field<Type>& values,
322  const vectorField& Sf,
323  const scalarField& weightField
324  ) const;
326  //- Output file header information
327  virtual void writeFileHeader(const label i);
330 public:
332  //- Run-time type information
333  TypeName("surfaceRegion");
336  // Constructors
338  //- Construct from name, Time and dictionary
340  (
341  const word& name,
342  const Time& runTime,
343  const dictionary& dict
344  );
345 
346  //- Construct from name, objectRegistry and dictionary
348  (
349  const word& name,
350  const objectRegistry& obr,
351  const dictionary& dict
352  );
353 
354 
355  //- Destructor
356  virtual ~surfaceRegion();
357 
358 
359  // Public Member Functions
360 
361  //- Return the region type
362  inline const regionTypes& regionType() const;
363 
364  //- Return the local list of face IDs
365  inline const labelList& faceId() const;
366 
367  //- Return the local list of patch ID per face
368  inline const labelList& facePatch() const;
369 
370  //- Return the list of +1/-1 representing face flip map
371  inline const labelList& faceSign() const;
372 
373  //- Templated helper function to output field values
374  template<class Type>
375  bool writeValues
376  (
377  const word& fieldName,
378  const scalarField& weightField,
379  const bool orient
380  );
381 
382  //- Filter a surface field according to faceIds
383  template<class Type>
385  (
387  const bool applyOrientation
388  ) const;
390  //- Filter a volume field according to faceIds
391  template<class Type>
393  (
395  const bool applyOrientation
396  ) const;
397 
398  //- Read from dictionary
399  virtual bool read(const dictionary&);
400 
401  //- Calculate and write
402  virtual bool write();
403 };
405 
406 //- Specialisation for scalar
407 template<>
409 (
410  const Field<scalar>& values,
411  const vectorField& Sf,
412  const scalarField& weightField
413 ) const;
414 
415 
416 //- Specialisation for vector
417 template<>
419 (
420  const Field<vector>& values,
421  const vectorField& Sf,
422  const scalarField& weightField
423 ) const;
424 
425 
426 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
427 
428 } // End namespace fieldValues
429 } // End namespace functionObjects
430 } // End namespace Foam
431 
432 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
433 
434 #include "surfaceRegionI.H"
435 
436 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
437 
438 #ifdef NoRepository
439  #include "surfaceRegionTemplates.C"
440 #endif
441 
442 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
443 
444 #endif
445 
446 // ************************************************************************* //
const labelList & facePatch() const
Return the local list of patch ID per face.
bool validField(const word &fieldName) const
Return true if the field name is valid.
bool orientWeightField_
Flag to indicate if flipMap should be applied to the weight field.
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
virtual bool write()
Calculate and write.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
tmp< Field< Type > > getFieldValues(const word &fieldName, const bool mustGet=false, const bool applyOrientation=false) const
Return field values by looking up field name.
List< face > faceList
Definition: faceListFwd.H:43
Generic GeometricField class.
labelList faceSign_
List of +1/-1 representing face flip map.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
static const NamedEnum< operationType, 15 > operationTypeNames_
Operation type names.
void initialise(const dictionary &dict)
Initialise, e.g. face addressing.
surfaceRegion(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
const dictionary & dict() const
Return the reference to the construction dictionary.
Definition: fieldValueI.H:31
labelList facePatchId_
Local list of patch ID per face.
const pointField & points
const word & name() const
Return the name of this functionObject.
word weightFieldName_
Weight field name - optional.
Pre-declare SubField and related Field type.
Definition: Field.H:57
TypeName("surfaceRegion")
Run-time type information.
A class for handling words, derived from string.
Definition: word.H:59
autoPtr< surfaceWriter > surfaceWriterPtr_
Surface writer.
scalar scaleFactor_
Scale factor - optional.
List< label > labelList
A List of labels.
Definition: labelList.H:56
scalar totalArea_
Total area of the surfaceRegion.
static const NamedEnum< regionTypes, 3 > regionTypeNames_
region type names
Type processValues(const Field< Type > &values, const vectorField &Sf, const scalarField &weightField) const
Apply the &#39;operation&#39; to the values. Wrapper around.
tmp< Field< Type > > filterField(const GeometricField< Type, fvsPatchField, surfaceMesh > &field, const bool applyOrientation) const
Filter a surface field according to faceIds.
labelList faceId_
Local list of face IDs.
bool writeValues(const word &fieldName, const scalarField &weightField, const bool orient)
Templated helper function to output field values.
Type processSameTypeValues(const Field< Type > &values, const vectorField &Sf, const scalarField &weightField) const
Apply the &#39;operation&#39; to the values. Operation has to.
operationType operation_
Operation to apply to values.
bool writeArea_
Optionally write the area of the surfaceRegion.
virtual bool read(const dictionary &)
Read from dictionary.
const labelList & faceId() const
Return the local list of face IDs.
label orientedFieldsStart_
Start index of fields that require application of flipMap.
virtual void writeFileHeader(const label i)
Output file header information.
A class for managing temporary objects.
Definition: PtrList.H:54
Registry of regIOobjects.
const labelList & faceSign() const
Return the list of +1/-1 representing face flip map.
Namespace for OpenFOAM.
autoPtr< sampledSurface > surfacePtr_
Underlying sampledSurface.
const regionTypes & regionType() const
Return the region type.