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-2025 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, patch or faceZone 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 integrals.
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  patch movingWall;
49 
50  operation areaAverage;
51 
52  fields
53  (
54  p
55  phi
56  U
57  );
58  }
59 
60  surfaceFieldValue1
61  {
62  type surfaceFieldValue;
63  libs ("libfieldFunctionObjects.so");
64 
65  log true;
66  writeControl writeTime;
67  writeFields true;
68 
69  surfaceFormat none;
70 
71  faceZone f0;
72 
73  operation sum;
74 
75  weightField alpha1;
76 
77  fields
78  (
79  p
80  phi
81  U
82  );
83  }
84  \endverbatim
85 
86 Usage
87  \table
88  Property | Description | Required | Default value
89  type | Type name: surfaceFieldValue | yes |
90  log | Write data to standard output | no | no
91  writeFields | Write the field values | yes |
92  writeNumberOfFaces | Write the number of faces in the surface | no | no
93  writeArea | Write the area of the surface | no | no
94  surfaceFormat | Output value format | if writeFields |
95  operation | Operation to perform | yes |
96  weightField | Name of field to apply weighting | no | none
97  weightFields | Names of fields to apply weighting | no | none
98  fields | List of fields to operate on | yes |
99  \endtable
100 
101  Where the supported selections are:
102  \plaintable
103  faceZone | requires a 'faceZone' entry to specify the faceZone \\
104  or dictionary to specify the zoneGenerator
105  patch | requires a 'patch' entry to specify the patch
106  patches | requires a 'patches' entry to specify the patches
107  sampledSurface | requires a 'sampledSurface' sub-dictionary
108  \endplaintable
109 
110  The \c operation is one of:
111  \plaintable
112  none | No operation
113  sum | Sum
114  sumMag | Sum of component magnitudes
115  orientedSum | Sum with face orientations
116  average | Ensemble average
117  areaAverage | Area weighted average
118  areaIntegrate | Area integral
119  min | Minimum
120  max | Maximum
121  minMag | Minimum magnitude
122  maxMag | Maximum magnitude
123  CoV | Coefficient of variation: (standard deviation)/mean
124  UI | Uniformity index: ???
125  areaNormalAverage | Area weighted average in face normal direction
126  areaNormalIntegrate | Area weighted integral in face normal direction
127  \endplaintable
128 
129  Note:
130  - Faces on empty patches get ignored.
131  - The `oriented' operations will flip the sign of the field so that all
132  the normals point in a consistent direction. This is only of relevance
133  when summing mesh-oriented fields, such as the flux, on faceZones.
134  - If the field is a volField then a \c faceZone can only consist of
135  boundary faces, because only these faces have a value associated with
136  them. No cell-to-face interpolation is performed.
137  - If the field is a surfaceField then the selection cannot be a \c
138  sampledSurface
139  - If a sampledSurface has interpolation set to false then the surface
140  face values will be taken directly from the cell that contains the
141  surface face centre
142  - If a \c sampledSurface has interpolation set to true then the field
143  will be interpolated to the vertices, then averaged onto the surface
144  faces
145 
146 See also
147  Foam::fieldValues
148  Foam::functionObject
149 
150 SourceFiles
151  surfaceFieldValue.C
152  surfaceFieldValueTemplates.C
153 
154 \*---------------------------------------------------------------------------*/
155 
156 #ifndef surfaceFieldValue_functionObject_H
157 #define surfaceFieldValue_functionObject_H
158 
159 #include "fieldValue.H"
160 #include "NamedEnum.H"
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 namespace Foam
165 {
166 
167 class generatedFaceZone;
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,
194  patches,
196  };
197 
198  //- Selection type names
199  static const NamedEnum<selectionTypes, 4> selectionTypeNames;
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,
216  UI,
219  };
220 
221  //- Operation type names
222  static const NamedEnum<operationType, 15> operationTypeNames_;
223 
224 
225 private:
226 
227  // Private Member Functions
228 
229  //- Convert patch names to patch indices
230  labelList patchis(const wordReList&) const;
231 
232  //- Set faces to evaluate from the faceZone
233  void setFaceZoneFaces();
234 
235  //- Set faces to evaluate based the list of patch names
236  void setPatchesFaces();
237 
238  //- Set faces according to the sampledSurface
239  void setSampledSurfaceFaces();
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 the area of the surface
256  scalar area() const;
257 
258 
259 protected:
260 
261  // Protected data
262 
263  //- Surface writer
264  autoPtr<surfaceWriter> surfaceWriterPtr_;
265 
266  //- Selection type
268 
269  //- Name of face selection (patch, faceZone, etc.)
270  string selectionName_;
271 
272  //- Operation to apply to values
274 
275  //- Weight field names - optional
277 
278  //- Global number of faces
279  label nFaces_;
280 
281  //- Area of the surface
282  scalar area_;
283 
284  //- Optionally write the number of faces in the surface
285  const bool writeNFaces_;
286 
287  //- Optionally write the area of the surface
288  const bool writeArea_;
289 
290 
291  // If operating on a faceZone
292 
293  //- The face-zone
294  autoPtr<generatedFaceZone> faceZonePtr_;
295 
296 
297  // If operating on a patch or patches
298 
299  //- The name(s) of the patches
301 
302 
303  // If operating on a faceZone, patch or patches to operate on
304 
305  //- Local list of face IDs
307 
308  //- Local list of patch ID per face
310 
311  //- List of +1/-1 representing face flip map
312  // (1 use as is, -1 negate)
314 
315 
316  // If operating on sampledSurface
317 
318  //- Underlying sampledSurface
320 
321 
322  // Protected Member Functions
323 
324  //- Return true if the field name is valid
325  template<class Type>
326  bool validField(const word& fieldName) const;
327 
328  //- Return field values by looking up field name
329  template<class Type>
330  tmp<Field<Type>> getFieldValues(const word& fieldName) const;
331 
332  //- Apply the operation to the values, and return true if successful.
333  // Does nothing unless overloaded below.
334  template<class Type, class ResultType>
335  bool processValues
336  (
337  const Field<Type>& values,
338  const scalarField& signs,
339  const scalarField& weights,
340  const vectorField& Sf,
341  ResultType& result
342  ) const;
343 
344  //- Apply Type -> Type operation to the values. Calls
345  // processValuesTypeType.
346  template<class Type>
347  bool processValues
348  (
349  const Field<Type>& values,
350  const scalarField& signs,
351  const scalarField& weights,
352  const vectorField& Sf,
353  Type& result
354  ) const;
355 
356  //- Apply Type -> scalar operation to the values. Tries to apply
357  // Type -> scalar specific operations, otherwise does nothing.
358  template<class Type>
359  bool processValues
360  (
361  const Field<Type>& values,
362  const scalarField& signs,
363  const scalarField& weights,
364  const vectorField& Sf,
365  scalar& result
366  ) const;
367 
368  //- Apply scalar -> scalar operation to the values. Tries to apply
369  // scalar -> scalar specific operations, otherwise calls
370  // processValuesTypeType.
371  bool processValues
372  (
373  const Field<scalar>& values,
374  const scalarField& signs,
375  const scalarField& weights,
376  const vectorField& Sf,
377  scalar& result
378  ) const;
379 
380  //- Apply vector -> scalar operation to the values. Tries to apply
381  // vector -> scalar specific operations, otherwise does nothing.
382  bool processValues
383  (
384  const Field<vector>& values,
385  const scalarField& signs,
386  const scalarField& weights,
387  const vectorField& Sf,
388  scalar& result
389  ) const;
390 
391  //- Apply a Type -> Type operation to the values
392  template<class Type>
394  (
395  const Field<Type>& values,
396  const scalarField& signs,
397  const scalarField& weights,
398  const vectorField& Sf,
399  Type& result
400  ) const;
401 
402  //- Output file header information
403  virtual void writeFileHeader(const label i);
404 
405  //- Update the surface following mesh motion
406  void moveMesh();
407 
408  //- Update the surface following mesh change
409  void changeMesh();
410 
411 
412 public:
413 
414  //- Run-time type information
415  TypeName("surfaceFieldValue");
416 
417 
418  // Constructors
419 
420  //- Construct from name, Time and dictionary
422  (
423  const word& name,
424  const Time& runTime,
425  const dictionary& dict
426  );
427 
428  //- Construct from name, objectRegistry and dictionary
430  (
431  const word& name,
432  const objectRegistry& obr,
433  const dictionary& dict
434  );
435 
436 
437  //- Destructor
439 
440 
441  // Public Member Functions
442 
443  //- Templated helper function to output field values
444  template<class Type>
445  void writeValues
446  (
447  const word& fieldName,
448  const Field<Type>& values,
449  const scalarField& signs,
450  const scalarField& weights,
451  const vectorField& Sf
452  );
453 
454  //- Filter a surface field according to faceIds
455  template<class Type>
457  (
458  const SurfaceField<Type>& field
459  ) const;
460 
461  //- Filter a volume field according to faceIds
462  template<class Type>
464  (
465  const VolField<Type>& field
466  ) const;
467 
468  //- Read from dictionary
469  virtual bool read(const dictionary&);
470 
471  //- Calculate and write
472  virtual bool write();
473 
474  //- Update for mesh point-motion
475  virtual void movePoints(const polyMesh&);
476 
477  //- Update topology using the given map
478  virtual void topoChange(const polyTopoChangeMap&);
479 
480  //- Update from another mesh using the given map
481  virtual void mapMesh(const polyMeshMap&);
482 
483  //- Redistribute or update using the given distribution map
484  virtual void distribute(const polyDistributionMap&);
485 };
486 
487 
488 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
489 
490 } // End namespace fieldValues
491 } // End namespace functionObjects
492 } // End namespace Foam
493 
494 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
495 
496 #ifdef NoRepository
498 #endif
499 
500 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
501 
502 #endif
503 
504 // ************************************************************************* //
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
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const word & name() const
Return the name of this functionObject.
const dictionary & dict() const
Return the reference to the construction dictionary.
surfaceFieldValue(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
void writeValues(const word &fieldName, const Field< Type > &values, const scalarField &signs, const scalarField &weights, const vectorField &Sf)
Templated helper function to output field values.
TypeName("surfaceFieldValue")
Run-time type information.
void changeMesh()
Update the surface following mesh change.
static const NamedEnum< selectionTypes, 4 > selectionTypeNames
Selection type names.
const bool writeArea_
Optionally write the area of the surface.
tmp< Field< Type > > getFieldValues(const word &fieldName) const
Return field values by looking up field name.
autoPtr< sampledSurface > surfacePtr_
Underlying sampledSurface.
wordReList patchNames_
The name(s) of the patches.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
void moveMesh()
Update the surface following mesh motion.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
static const NamedEnum< operationType, 15 > operationTypeNames_
Operation type names.
operationType operation_
Operation to apply to values.
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.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual void writeFileHeader(const label i)
Output file header information.
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.
string selectionName_
Name of face selection (patch, faceZone, etc.)
const bool writeNFaces_
Optionally write the number of faces in the surface.
autoPtr< generatedFaceZone > faceZonePtr_
The face-zone.
autoPtr< surfaceWriter > surfaceWriterPtr_
Surface writer.
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.
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.
labelList faceSign_
List of +1/-1 representing face flip map.
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< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
List< face > faceList
Definition: faceListFwd.H:41