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-2023 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  Surface (face) region selection class.
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  select 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 
72  select faceZone;
73  name f0;
74 
75  operation sum;
76 
77  weightField alpha1;
78 
79  fields
80  (
81  p
82  phi
83  U
84  );
85  }
86  \endverbatim
87 
88 Usage
89  \table
90  Property | Description | Required | Default value
91  type | type name: surfaceFieldValue | yes |
92  log | write data to standard output | no | no
93  writeFields | Write the field values | yes |
94  writeArea | Write the area of the surfaceFieldValue | no |
95  surfaceFormat | output value format | no |
96  select | face selection: see below | yes |
97  name | name of face select if required | no |
98  operation | operation to perform | yes |
99  weightField | name of field to apply weighting | no |
100  weightFields | Names of fields to apply weighting | no |
101  scaleFactor | scale factor | no | 1
102  fields | list of fields to operate on | yes |
103  \endtable
104 
105  Where the supported \c select options are:
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  sumMag | sum of component magnitudes
117  sumDirection | sum values which are positive in given direction
118  sumDirectionBalance | sum of balance of values in given direction
119  orientedSum | sum with face orientations
120  average | ensemble average
121  areaAverage | area weighted average
122  areaIntegrate | area integral
123  min | minimum
124  max | maximum
125  minMag | minimum magnitude
126  maxMag | maximum magnitude
127  CoV | coefficient of variation: standard deviation/mean
128  areaNormalAverage | area weighted average in face normal direction
129  areaNormalIntegrate | area weighted integral in face normal direction
130  \endplaintable
131 
132  Note:
133  - Faces on empty patches get ignored.
134  - The `oriented' operations will flip the sign of the field so that all
135  the normals point in a consistent direction. This is only of relevance
136  when summing mesh-oriented fields, such as the flux, on faceZones.
137  - If the field is a volField then a \c faceZone can only consist of
138  boundary faces, because only these faces have a value associated with
139  them. No cell-to-face interpolation is performed.
140  - If the field is a surfaceField then the selection cannot be a \c
141  sampledSurface
142  - If a sampledSurface has interpolation set to false then the surface
143  face values will be taken directly from the cell that contains the
144  surface face centre
145  - If a \c sampledSurface has interpolation set to true then the field
146  will be interpolated to the vertices, then averaged onto the surface
147  faces
148 
149 See also
150  Foam::fieldValues
151  Foam::functionObject
152 
153 SourceFiles
154  surfaceFieldValue.C
155  surfaceFieldValueTemplates.C
156 
157 \*---------------------------------------------------------------------------*/
158 
159 #ifndef functionObjects_surfaceFieldValue_H
160 #define functionObjects_surfaceFieldValue_H
161 
162 #include "fieldValue.H"
163 #include "NamedEnum.H"
164 
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166 
167 namespace Foam
168 {
169 
170 class sampledSurface;
171 class surfaceWriter;
172 
173 namespace functionObjects
174 {
175 namespace fieldValues
176 {
177 
178 /*---------------------------------------------------------------------------*\
179  Class surfaceFieldValue Declaration
180 \*---------------------------------------------------------------------------*/
181 
182 class surfaceFieldValue
183 :
184  public fieldValue
185 {
186 
187 public:
188 
189  // Public data types
190 
191  //- Selection type enumeration
192  enum class selectionTypes
193  {
194  faceZone,
195  patch,
197  };
198 
199  //- Selection type names
200  static const NamedEnum<selectionTypes, 3> selectionTypeNames;
201 
202 
203  //- Operation type enumeration
204  enum class operationType
205  {
206  none,
207  sum,
208  sumMag,
209  sumDirection,
211  orientedSum,
212  average,
213  areaAverage,
215  min,
216  max,
217  minMag,
218  maxMag,
219  CoV,
222  };
223 
224  //- Operation type names
225  static const NamedEnum<operationType, 16> operationTypeNames_;
226 
227 
228 private:
229 
230  // Private Member Functions
231 
232  //- Set faces to evaluate based on a face zone
233  void setFaceZoneFaces();
234 
235  //- Set faces to evaluate based on a patch
236  void setPatchFaces();
237 
238  //- Set faces according to sampledSurface
239  void sampledSurfaceFaces(const dictionary&);
240 
241  //- Combine mesh faces and points from multiple processors
242  void combineMeshGeometry
243  (
244  faceList& faces,
246  ) const;
247 
248  //- Combine surface faces and points from multiple processors
249  void combineSurfaceGeometry
250  (
251  faceList& faces,
253  ) const;
254 
255  //- Calculate and return total area of the surfaceFieldValue: sum(magSf)
256  scalar totalArea() const;
257 
258 
259 protected:
260 
261  // Protected data
262 
263  //- Input dictionary
264  dictionary dict_;
265 
266  //- Surface writer
267  autoPtr<surfaceWriter> surfaceWriterPtr_;
268 
269  //- Selection type
271 
272  //- Name of face selection (patch, faceZone, etc.)
273  word selectionName_;
274 
275  //- Operation to apply to values
277 
278  //- Weight field names - optional
280 
281  //- Scale factor - optional
282  scalar scaleFactor_;
283 
284  //- Total area of the surfaceFieldValue
285  scalar totalArea_;
286 
287  //- Optionally write the area of the surfaceFieldValue
288  bool writeArea_;
289 
290  //- Global number of faces
291  label nFaces_;
292 
293 
294  // If operating on mesh faces (faceZone, patch)
295 
296  //- Local list of face IDs
298 
299  //- Local list of patch ID per face
301 
302  //- List of +1/-1 representing face flip map
303  // (1 use as is, -1 negate)
305 
306 
307  // If operating on sampledSurface
308 
309  //- Underlying sampledSurface
310  autoPtr<sampledSurface> surfacePtr_;
311 
312 
313  // Protected Member Functions
314 
315  //- Initialise, e.g. face addressing
316  void initialise(const dictionary& dict);
317 
318  //- Return true if the field name is valid
319  template<class Type>
320  bool validField(const word& fieldName) const;
321 
322  //- Return field values by looking up field name
323  template<class Type>
324  tmp<Field<Type>> getFieldValues(const word& fieldName) const;
325 
326  //- Apply the operation to the values, and return true if successful.
327  // Does nothing unless overloaded below.
328  template<class Type, class ResultType>
329  bool processValues
330  (
331  const Field<Type>& values,
332  const scalarField& signs,
333  const scalarField& weights,
334  const vectorField& Sf,
335  ResultType& result
336  ) const;
337 
338  //- Apply Type -> Type operation to the values. Calls
339  // processValuesTypeType.
340  template<class Type>
341  bool processValues
342  (
343  const Field<Type>& values,
344  const scalarField& signs,
345  const scalarField& weights,
346  const vectorField& Sf,
347  Type& result
348  ) const;
349 
350  //- Apply Type -> scalar operation to the values
351  template<class Type>
352  bool processValues
353  (
354  const Field<Type>& values,
355  const scalarField& signs,
356  const scalarField& weights,
357  const vectorField& Sf,
358  scalar& result
359  ) const;
360 
361  //- Apply scalar -> scalar operation to the values. Tries to apply
362  // scalar -> scalar specific operations, otherwise calls
363  // processValuesTypeType.
364  bool processValues
365  (
366  const Field<scalar>& values,
367  const scalarField& signs,
368  const scalarField& weights,
369  const vectorField& Sf,
370  scalar& result
371  ) const;
372 
373  //- Apply vector -> vector operation to the values.
374  bool processValues
375  (
376  const Field<vector>& values,
377  const scalarField& signs,
378  const scalarField& weights,
379  const vectorField& Sf,
380  scalar& result
381  ) const;
382 
383  //- Apply vector -> vector operation to the values. Tries to apply
384  // vector -> vector specific operations, otherwise calls
385  // processValuesTypeType.
386  bool processValues
387  (
388  const Field<vector>& values,
389  const scalarField& signs,
390  const scalarField& weights,
391  const vectorField& Sf,
392  vector& result
393  ) const;
394 
395  //- Apply a Type -> Type operation to the values
396  template<class Type>
398  (
399  const Field<Type>& values,
400  const scalarField& signs,
401  const scalarField& weights,
402  const vectorField& Sf,
403  Type& result
404  ) const;
405 
406  //- Output file header information
407  virtual void writeFileHeader(const label i);
408 
409 
410 public:
411 
412  //- Run-time type information
413  TypeName("surfaceFieldValue");
414 
415 
416  // Constructors
417 
418  //- Construct from name, Time and dictionary
420  (
421  const word& name,
422  const Time& runTime,
423  const dictionary& dict
424  );
425 
426  //- Construct from name, objectRegistry and dictionary
428  (
429  const word& name,
430  const objectRegistry& obr,
432  );
433 
434 
435  //- Destructor
436  virtual ~surfaceFieldValue();
437 
438 
439  // Public Member Functions
440 
441  //- Return the selection type
442  inline const selectionTypes& selectionType() const;
443 
444  //- Return the selection name
445  inline const word& selectionName() const;
446 
447  //- Return the local list of face IDs
448  inline const labelList& faceId() const;
449 
450  //- Return the local list of patch ID per face
451  inline const labelList& facePatch() const;
452 
453  //- Return the list of +1/-1 representing face flip map
454  inline const labelList& faceSign() const;
455 
456  //- Return the output directory
457  inline fileName outputDir() const;
458 
459  //- Templated helper function to output field values
460  template<class Type>
461  bool writeValues
462  (
463  const word& fieldName,
464  const scalarField& signs,
465  const scalarField& weights,
466  const vectorField& Sf
467  );
468 
469  //- Templated helper function to output field values
470  template<class Type, class ResultType>
471  bool writeValues
472  (
473  const word& fieldName,
474  const Field<Type>& values,
475  const scalarField& signs,
476  const scalarField& weights,
477  const vectorField& Sf
478  );
479 
480  //- Filter a surface field according to faceIds
481  template<class Type>
483  (
484  const SurfaceField<Type>& field
485  ) const;
486 
487  //- Filter a volume field according to faceIds
488  template<class Type>
490  (
491  const VolField<Type>& field
492  ) const;
493 
494  //- Read from dictionary
495  virtual bool read(const dictionary&);
496 
497  //- Calculate and write
498  virtual bool write();
499 
500  //- Update for mesh point-motion
501  virtual void movePoints(const polyMesh&);
502 
503  //- Update topology using the given map
504  virtual void topoChange(const polyTopoChangeMap&);
505 
506  //- Update from another mesh using the given map
507  virtual void mapMesh(const polyMeshMap&);
508 
509  //- Redistribute or update using the given distribution map
510  virtual void distribute(const polyDistributionMap&);
511 };
512 
513 
514 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
515 
516 } // End namespace fieldValues
517 } // End namespace functionObjects
518 } // End namespace Foam
519 
520 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
521 
522 #include "surfaceFieldValueI.H"
523 
524 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
525 
526 #ifdef NoRepository
528 #endif
529 
530 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
531 
532 #endif
533 
534 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:82
Generic GeometricField class.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A class for handling file names.
Definition: fileName.H:82
const word & name() const
Return the name of this functionObject.
const dictionary & dict() const
Return the reference to the construction dictionary.
Definition: fieldValueI.H:31
surfaceFieldValue(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
TypeName("surfaceFieldValue")
Run-time type information.
const labelList & faceSign() const
Return the list of +1/-1 representing face flip map.
static const NamedEnum< operationType, 16 > operationTypeNames_
Operation type names.
bool writeArea_
Optionally write the area of the surfaceFieldValue.
tmp< Field< Type > > getFieldValues(const word &fieldName) const
Return field values by looking up field name.
bool writeValues(const word &fieldName, const scalarField &signs, const scalarField &weights, const vectorField &Sf)
Templated helper function to output field values.
autoPtr< sampledSurface > surfacePtr_
Underlying sampledSurface.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
void initialise(const dictionary &dict)
Initialise, e.g. face addressing.
operationType operation_
Operation to apply to values.
const selectionTypes & selectionType() const
Return the selection type.
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.
word selectionName_
Name of face selection (patch, faceZone, etc.)
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual void writeFileHeader(const label i)
Output file header information.
fileName outputDir() const
Return the output directory.
wordList weightFieldNames_
Weight field names - optional.
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
bool validField(const word &fieldName) const
Return true if the field name is valid.
autoPtr< surfaceWriter > surfaceWriterPtr_
Surface writer.
static const NamedEnum< selectionTypes, 3 > selectionTypeNames
Selection type names.
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.
const labelList & faceId() const
Return the local list of face IDs.
const word & selectionName() const
Return the selection name.
labelList facePatchId_
Local list of patch ID per face.
tmp< Field< Type > > filterField(const SurfaceField< Type > &field) const
Filter a surface field according to faceIds.
scalar totalArea_
Total area of the surfaceFieldValue.
labelList faceSign_
List of +1/-1 representing face flip map.
const labelList & facePatch() const
Return the local list of patch ID per face.
virtual bool read(const dictionary &)
Read from dictionary.
Registry of regIOobjects.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
const pointField & points
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
List< face > faceList
Definition: faceListFwd.H:43