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-2022 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
134  the normals point in a consistent direction. This is only of relevance
135  when 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  //- Input dictionary
263  dictionary dict_;
264 
265  //- Surface writer
266  autoPtr<surfaceWriter> surfaceWriterPtr_;
267 
268  //- region type
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;
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
347  template<class Type>
348  bool processValues
349  (
350  const Field<Type>& values,
351  const scalarField& signs,
352  const scalarField& weights,
353  const vectorField& Sf,
354  scalar& result
355  ) const;
356 
357  //- Apply scalar -> scalar operation to the values. Tries to apply
358  // scalar -> scalar specific operations, otherwise calls
359  // processValuesTypeType.
360  bool processValues
361  (
362  const Field<scalar>& values,
363  const scalarField& signs,
364  const scalarField& weights,
365  const vectorField& Sf,
366  scalar& result
367  ) const;
368 
369  //- Apply vector -> vector operation to the values.
370  bool processValues
371  (
372  const Field<vector>& values,
373  const scalarField& signs,
374  const scalarField& weights,
375  const vectorField& Sf,
376  scalar& result
377  ) const;
378 
379  //- Apply vector -> vector operation to the values. Tries to apply
380  // vector -> vector specific operations, otherwise calls
381  // processValuesTypeType.
382  bool processValues
383  (
384  const Field<vector>& values,
385  const scalarField& signs,
386  const scalarField& weights,
387  const vectorField& Sf,
388  vector& 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 
406 public:
407 
408  //- Run-time type information
409  TypeName("surfaceFieldValue");
410 
411 
412  // Constructors
413 
414  //- Construct from name, Time and dictionary
416  (
417  const word& name,
418  const Time& runTime,
419  const dictionary& dict
420  );
422  //- Construct from name, objectRegistry and dictionary
424  (
425  const word& name,
426  const objectRegistry& obr,
428  );
429 
430 
431  //- Destructor
432  virtual ~surfaceFieldValue();
434 
435  // Public Member Functions
437  //- Return the region type
438  inline const regionTypes& regionType() const;
439 
440  //- Return the local list of face IDs
441  inline const labelList& faceId() const;
442 
443  //- Return the local list of patch ID per face
444  inline const labelList& facePatch() const;
445 
446  //- Return the list of +1/-1 representing face flip map
447  inline const labelList& faceSign() const;
448 
449  //- Return the output directory
450  inline fileName outputDir() const;
451 
452  //- Templated helper function to output field values
453  template<class Type>
454  bool writeValues
455  (
456  const word& fieldName,
457  const scalarField& signs,
458  const scalarField& weights,
459  const vectorField& Sf
460  );
461 
462  //- Templated helper function to output field values
463  template<class Type, class ResultType>
464  bool writeValues
465  (
466  const word& fieldName,
467  const Field<Type>& values,
468  const scalarField& signs,
469  const scalarField& weights,
470  const vectorField& Sf
471  );
472 
473  //- Filter a surface field according to faceIds
474  template<class Type>
476  (
478  ) const;
479 
480  //- Filter a volume field according to faceIds
481  template<class Type>
483  (
485  ) const;
486 
487  //- Read from dictionary
488  virtual bool read(const dictionary&);
489 
490  //- Calculate and write
491  virtual bool write();
492 
493  //- Update for mesh point-motion
494  virtual void movePoints(const polyMesh&);
495 
496  //- Update topology using the given map
497  virtual void topoChange(const polyTopoChangeMap&);
498 
499  //- Update from another mesh using the given map
500  virtual void mapMesh(const polyMeshMap&);
501 };
502 
503 
504 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
505 
506 } // End namespace fieldValues
507 } // End namespace functionObjects
508 } // End namespace Foam
509 
510 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
511 
512 #include "surfaceFieldValueI.H"
513 
514 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
515 
516 #ifdef NoRepository
518 #endif
519 
520 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
521 
522 #endif
523 
524 // ************************************************************************* //
labelList faceSign_
List of +1/-1 representing face flip map.
wordList weightFieldNames_
Weight field names - optional.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
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
static const NamedEnum< operationType, 16 > operationTypeNames_
Operation type names.
fileName outputDir() const
Return the output directory.
List< face > faceList
Definition: faceListFwd.H:43
Generic GeometricField class.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
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
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
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.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
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.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
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 void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
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
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
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.
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:50
Namespace for OpenFOAM.
virtual void writeFileHeader(const label i)
Output file header information.
dimensioned< scalar > sumMag(const DimensionedField< Type, GeoMesh > &df)