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