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-2021 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 'orientedSum' 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  weightFields | Names of fields to apply weighting | no |
100  scaleFactor | scale factor | no | 1
101  fields | list of fields to operate on | yes |
102  \endtable
103 
104  Where \c regionType is defined by
105  \plaintable
106  faceZone | requires a 'name' entry to specify the faceZone
107  patch | requires a 'name' entry to specify the patch
108  sampledSurface | requires a 'sampledSurfaceDict' sub-dictionary
109  \endplaintable
110 
111  The \c operation is one of:
112  \plaintable
113  none | no operation
114  sum | sum
115  sumMag | sum of component magnitudes
116  sumDirection | sum values which are positive in given direction
117  sumDirectionBalance | sum of balance of values in given direction
118  orientedSum | sum with face orientations
119  average | ensemble average
120  areaAverage | area weighted average
121  areaIntegrate | area integral
122  min | minimum
123  max | maximum
124  minMag | minimum magnitude
125  maxMag | maximum magnitude
126  CoV | coefficient of variation: standard deviation/mean
127  areaNormalAverage | area weighted average in face normal direction
128  areaNormalIntegrate | area weighted integral in face normal direction
129  \endplaintable
130 
131 Note
132  - Faces on empty patches get ignored.
133  - The `oriented' operations will flip the sign of the field so that all the
134  normals point in a consistent direction. This is only of relevance when
135  summing mesh-oriented fields, such as the flux, on faceZones.
136  - If the field is a volField then a \c faceZone can only consist of
137  boundary faces, because only these faces have a value associated with
138  them. No cell-to-face interpolation is performed.
139  - If the field is a surfaceField then the region cannot be a \c
140  sampledSurface
141  - If a sampledSurface has interpolation set to false then the surface
142  face values will be taken directly from the cell that contains the
143  surface face centre
144  - If a \c sampledSurface has interpolation set to true then the field
145  will be interpolated to the vertices, then averaged onto the surface
146  faces
147 
148 See also
149  Foam::fieldValues
150  Foam::functionObject
151 
152 SourceFiles
153  surfaceFieldValue.C
154  surfaceFieldValueTemplates.C
155 
156 \*---------------------------------------------------------------------------*/
157 
158 #ifndef functionObjects_surfaceFieldValue_H
159 #define functionObjects_surfaceFieldValue_H
160 
161 #include "fieldValue.H"
162 #include "NamedEnum.H"
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 namespace Foam
167 {
168 
169 class sampledSurface;
170 class surfaceWriter;
171 
172 namespace functionObjects
173 {
174 namespace fieldValues
175 {
176 
177 /*---------------------------------------------------------------------------*\
178  Class surfaceFieldValue Declaration
179 \*---------------------------------------------------------------------------*/
180 
181 class surfaceFieldValue
182 :
183  public fieldValue
184 {
185 
186 public:
187 
188  // Public data types
189 
190  //- region type enumeration
191  enum class regionTypes
192  {
193  faceZone,
194  patch,
196  };
197 
198  //- region type names
199  static const NamedEnum<regionTypes, 3> regionTypeNames_;
200 
201 
202  //- Operation type enumeration
203  enum class operationType
204  {
205  none,
206  sum,
207  sumMag,
208  sumDirection,
209  sumDirectionBalance,
210  orientedSum,
211  average,
212  areaAverage,
213  areaIntegrate,
214  min,
215  max,
216  minMag,
217  maxMag,
218  CoV,
219  areaNormalAverage,
220  areaNormalIntegrate
221  };
222 
223  //- Operation type names
224  static const NamedEnum<operationType, 16> operationTypeNames_;
225 
226 
227 private:
228 
229  // Private Member Functions
230 
231  //- Set faces to evaluate based on a face zone
232  void setFaceZoneFaces();
233 
234  //- Set faces to evaluate based on a patch
235  void setPatchFaces();
236 
237  //- Set faces according to sampledSurface
238  void sampledSurfaceFaces(const dictionary&);
239 
240  //- Combine mesh faces and points from multiple processors
241  void combineMeshGeometry
242  (
243  faceList& faces,
245  ) const;
246 
247  //- Combine surface faces and points from multiple processors
248  void combineSurfaceGeometry
249  (
250  faceList& faces,
252  ) const;
253 
254  //- Calculate and return total area of the surfaceFieldValue: sum(magSf)
255  scalar totalArea() const;
256 
257 
258 protected:
259 
260  // Protected data
261 
262  //- Surface writer
263  autoPtr<surfaceWriter> surfaceWriterPtr_;
264 
265  //- region type
267 
268  //- Operation to apply to values
270 
271  //- Weight field names - optional
273 
274  //- Scale factor - optional
275  scalar scaleFactor_;
276 
277  //- Total area of the surfaceFieldValue
278  scalar totalArea_;
279 
280  //- Optionally write the area of the surfaceFieldValue
281  bool writeArea_;
282 
283  //- Global number of faces
284  label nFaces_;
285 
286 
287  // If operating on mesh faces (faceZone, patch)
288 
289  //- Local list of face IDs
291 
292  //- Local list of patch ID per face
294 
295  //- List of +1/-1 representing face flip map
296  // (1 use as is, -1 negate)
298 
299 
300  // If operating on sampledSurface
301 
302  //- Underlying sampledSurface
303  autoPtr<sampledSurface> surfacePtr_;
304 
305 
306  // Protected Member Functions
307 
308  //- Initialise, e.g. face addressing
309  void initialise(const dictionary& dict);
310 
311  //- Return true if the field name is valid
312  template<class Type>
313  bool validField(const word& fieldName) const;
314 
315  //- Return field values by looking up field name
316  template<class Type>
317  tmp<Field<Type>> getFieldValues(const word& fieldName) const;
318 
319  //- Apply the operation to the values, and return true if successful.
320  // Does nothing unless overloaded below.
321  template<class Type, class ResultType>
322  bool processValues
323  (
324  const Field<Type>& values,
325  const scalarField& signs,
326  const scalarField& weights,
327  const vectorField& Sf,
328  ResultType& result
329  ) const;
330 
331  //- Apply Type -> Type operation to the values. Calls
332  // processValuesTypeType.
333  template<class Type>
334  bool processValues
335  (
336  const Field<Type>& values,
337  const scalarField& signs,
338  const scalarField& weights,
339  const vectorField& Sf,
340  Type& result
341  ) const;
342 
343  //- Apply Type -> scalar operation to the values
344  template<class Type>
345  bool processValues
346  (
347  const Field<Type>& values,
348  const scalarField& signs,
349  const scalarField& weights,
350  const vectorField& Sf,
351  scalar& result
352  ) const;
353 
354  //- Apply scalar -> scalar operation to the values. Tries to apply
355  // scalar -> scalar specific operations, otherwise calls
356  // processValuesTypeType.
357  bool processValues
358  (
359  const Field<scalar>& values,
360  const scalarField& signs,
361  const scalarField& weights,
362  const vectorField& Sf,
363  scalar& result
364  ) const;
365 
366  //- Apply vector -> vector operation to the values.
367  bool processValues
368  (
369  const Field<vector>& values,
370  const scalarField& signs,
371  const scalarField& weights,
372  const vectorField& Sf,
373  scalar& result
374  ) const;
375 
376  //- Apply vector -> vector operation to the values. Tries to apply
377  // vector -> vector specific operations, otherwise calls
378  // processValuesTypeType.
379  bool processValues
380  (
381  const Field<vector>& values,
382  const scalarField& signs,
383  const scalarField& weights,
384  const vectorField& Sf,
385  vector& result
386  ) const;
387 
388  //- Apply a Type -> Type operation to the values
389  template<class Type>
391  (
392  const Field<Type>& values,
393  const scalarField& signs,
394  const scalarField& weights,
395  const vectorField& Sf,
396  Type& result
397  ) const;
398 
399  //- Output file header information
400  virtual void writeFileHeader(const label i);
401 
402 
403 public:
404 
405  //- Run-time type information
406  TypeName("surfaceFieldValue");
407 
408 
409  // Constructors
410 
411  //- Construct from name, Time and dictionary
413  (
414  const word& name,
415  const Time& runTime,
416  const dictionary& dict
417  );
419  //- Construct from name, objectRegistry and dictionary
421  (
422  const word& name,
423  const objectRegistry& obr,
425  );
426 
427 
428  //- Destructor
429  virtual ~surfaceFieldValue();
431 
432  // Public Member Functions
434  //- Return the region type
435  inline const regionTypes& regionType() const;
436 
437  //- Return the local list of face IDs
438  inline const labelList& faceId() const;
439 
440  //- Return the local list of patch ID per face
441  inline const labelList& facePatch() const;
442 
443  //- Return the list of +1/-1 representing face flip map
444  inline const labelList& faceSign() const;
445 
446  //- Return the output directory
447  inline fileName outputDir() const;
448 
449  //- Templated helper function to output field values
450  template<class Type>
451  bool writeValues
452  (
453  const word& fieldName,
454  const scalarField& signs,
455  const scalarField& weights,
456  const vectorField& Sf
457  );
458 
459  //- Templated helper function to output field values
460  template<class Type, class ResultType>
461  bool writeValues
462  (
463  const word& fieldName,
464  const Field<Type>& values,
465  const scalarField& signs,
466  const scalarField& weights,
467  const vectorField& Sf
468  );
469 
470  //- Filter a surface field according to faceIds
471  template<class Type>
473  (
475  ) const;
476 
477  //- Filter a volume field according to faceIds
478  template<class Type>
480  (
482  ) const;
483 
484  //- Read from dictionary
485  virtual bool read(const dictionary&);
486 
487  //- Calculate and write
488  virtual bool write();
489 };
490 
491 
492 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
493 
494 } // End namespace fieldValues
495 } // End namespace functionObjects
496 } // End namespace Foam
497 
498 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
499 
500 #include "surfaceFieldValueI.H"
501 
502 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
503 
504 #ifdef NoRepository
506 #endif
507 
508 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
509 
510 #endif
511 
512 // ************************************************************************* //
labelList faceSign_
List of +1/-1 representing face flip map.
wordList weightFieldNames_
Weight field names - optional.
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:79
surfaceFieldValue(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
bool processValuesTypeType(const Field< Type > &values, const scalarField &signs, const scalarField &weights, const vectorField &Sf, Type &result) const
Apply a Type -> Type operation to the values.
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:156
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
static const NamedEnum< operationType, 16 > operationTypeNames_
Operation type names.
fileName outputDir() const
Return the output directory.
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.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
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:56
A class for handling words, derived from string.
Definition: word.H:59
labelList facePatchId_
Local list of patch ID per face.
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.
bool processValues(const Field< Type > &values, const scalarField &signs, const scalarField &weights, const vectorField &Sf, ResultType &result) const
Apply the operation to the values, and return true if successful.
tmp< Field< Type > > filterField(const GeometricField< Type, fvsPatchField, surfaceMesh > &field) const
Filter a surface field according to faceIds.
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
Return field values by looking up field name.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
const labelList & faceId() const
Return the local list of face IDs.
autoPtr< surfaceWriter > surfaceWriterPtr_
Surface writer.
List< word > wordList
A List of words.
Definition: fileName.H:54
virtual bool read(const dictionary &)
Read from dictionary.
tmp< GeometricField< Type, fvPatchField, volMesh > > average(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Area-weighted average a surfaceField creating a volField.
Definition: fvcAverage.C:46
operationType operation_
Operation to apply to values.
static const NamedEnum< regionTypes, 3 > regionTypeNames_
region type names
bool writeValues(const word &fieldName, const scalarField &signs, const scalarField &weights, const vectorField &Sf)
Templated helper function to output field values.
rDeltaTY field()
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.
dimensioned< scalar > sumMag(const DimensionedField< Type, GeoMesh > &df)