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