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