faceSource.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 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::fieldValues::faceSource
26 
27 Group
28  grpFieldFunctionObjects
29 
30 Description
31  This function object provides a 'face source' variant of the fieldValues
32  function object. Given a list of user-specified fields and a selection
33  of mesh (or general surface) faces, a number of operations can be
34  performed, such as sums, averages and integrations.
35 
36  \linebreak
37  For example, to calculate the volumetric or mass flux across a patch,
38  apply the 'sum' operator to the flux field (typically \c phi)
39 
40  Example of function object specification:
41  \verbatim
42  faceSource1
43  {
44  type faceSource;
45  functionObjectLibs ("libfieldFunctionObjects.so");
46  ...
47  log yes;
48  valueOutput true;
49  surfaceFormat none;
50  source faceZone;
51  sourceName f0;
52  operation sum;
53  weightField alpha1;
54  fields
55  (
56  p
57  phi
58  U
59  );
60  }
61  \endverbatim
62 
63  \heading Function object usage
64  \table
65  Property | Description | Required | Default value
66  type | type name: faceSource | yes |
67  log | write data to standard output | no | no
68  valueOutput | write the output values | yes |
69  writeArea | Write the area of the faceSource | no |
70  surfaceFormat | output value format | no |
71  source | face source: see below | yes |
72  sourceName | name of face source if required | no |
73  operation | operation to perform | yes |
74  weightField | name of field to apply weighting | no |
75  orientedWeightField | name of oriented field to apply weighting | no |
76  scaleFactor | scale factor | no | 1
77  fields | list of fields to operate on | yes |
78  orientedFields | list of oriented fields to operate on | no |
79  \endtable
80 
81  \linebreak
82  Where \c source is defined by
83  \plaintable
84  faceZone | requires a 'sourceName' entry to specify the faceZone
85  patch | requires a 'sourceName' entry to specify the patch
86  sampledSurface | requires a 'sampledSurfaceDict' sub-dictionary
87  \endplaintable
88 
89  \linebreak
90  The \c operation is one of:
91  \plaintable
92  none | no operation
93  sum | sum
94  sumMag | sum of component magnitudes
95  sumDirection | sum values which are positive in given direction
96  sumDirectionBalance | sum of balance of values in given direction
97  average | ensemble average
98  weightedAverage | weighted average
99  areaAverage | area weighted average
100  weightedAreaAverage | weighted area average
101  areaIntegrate | area integral
102  min | minimum
103  max | maximum
104  CoV | coefficient of variation: standard deviation/mean
105  areaNormalAverage| area weighted average in face normal direction
106  areaNormalIntegrate | area weighted integral in face normal directon
107  \endplaintable
108 
109 Note
110  - The values reported by the areaNormalAverage and areaNormalIntegrate
111  operations are written as the first component of a field with the same
112  rank as the input field.
113  - faces on empty patches get ignored
114  - if the field is a volField the \c faceZone can only consist of boundary
115  faces
116  - the `oriented' entries relate to mesh-oriented fields, such as the
117  flux, phi. These fields will be oriented according to the face normals.
118  - using \c sampledSurfaces:
119  - not available for surface fields
120  - if interpolate=true they use \c interpolationCellPoint
121  otherwise they use cell values
122  - each triangle in \c sampledSurface is logically only in one cell
123  so interpolation will be wrong when triangles are larger than
124  cells. This can only happen for sampling on a \c triSurfaceMesh
125  - take care when using isoSurfaces - these might have duplicate
126  triangles and so integration might be wrong
127 
128 SeeAlso
129  Foam::fieldValues
130  Foam::functionObject
131  Foam::OutputFilterFunctionObject
132 
133 SourceFiles
134  faceSource.C
135  faceSourceTemplates.C
136 
137 \*---------------------------------------------------------------------------*/
138 
139 #ifndef faceSource_H
140 #define faceSource_H
141 
142 #include "NamedEnum.H"
143 #include "fieldValue.H"
144 #include "surfaceFieldsFwd.H"
145 #include "volFieldsFwd.H"
146 #include "surfaceWriter.H"
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 namespace Foam
151 {
152 
153 class sampledSurface;
154 
155 namespace fieldValues
156 {
157 
158 /*---------------------------------------------------------------------------*\
159  Class faceSource Declaration
160 \*---------------------------------------------------------------------------*/
161 
162 class faceSource
163 :
164  public fieldValue
165 {
166 
167 public:
168 
169  // Public data types
170 
171  //- Source type enumeration
172  enum sourceType
173  {
174  stFaceZone,
175  stPatch,
177  };
178 
179  //- Source type names
180  static const NamedEnum<sourceType, 3> sourceTypeNames_;
181 
182 
183  //- Operation type enumeration
184  enum operationType
185  {
186  opNone,
187  opSum,
188  opSumMag,
191  opAverage,
196  opMin,
197  opMax,
198  opCoV,
201  };
202 
203  //- Operation type names
204  static const NamedEnum<operationType, 15> operationTypeNames_;
205 
206 
207 private:
208 
209  // Private Member Functions
210 
211  //- Set faces to evaluate based on a face zone
212  void setFaceZoneFaces();
213 
214  //- Set faces to evaluate based on a patch
215  void setPatchFaces();
216 
217  //- Set faces according to sampledSurface
218  void sampledSurfaceFaces(const dictionary&);
219 
220  //- Combine mesh faces and points from multiple processors
221  void combineMeshGeometry
222  (
223  faceList& faces,
225  ) const;
226 
227  //- Combine surface faces and points from multiple processors
228  void combineSurfaceGeometry
229  (
230  faceList& faces,
232  ) const;
233 
234  //- Calculate and return total area of the faceSource: sum(magSf)
235  scalar totalArea() const;
236 
237 
238 protected:
239 
240  // Protected data
241 
242  //- Surface writer
243  autoPtr<surfaceWriter> surfaceWriterPtr_;
244 
245  //- Source type
247 
248  //- Operation to apply to values
250 
251  //- Weight field name - optional
252  word weightFieldName_;
253 
254  //- Flag to indicate if flipMap should be applied to the weight field
255  bool orientWeightField_;
256 
257  //- Start index of fields that require application of flipMap
259 
260  //- Scale factor - optional
261  scalar scaleFactor_;
262 
263  //- Total area of the faceSource
264  scalar totalArea_;
265 
266  //- Optionally write the area of the faceSource
267  bool writeArea_;
268 
269  //- Global number of faces
270  label nFaces_;
271 
272 
273  // If operating on mesh faces (faceZone, patch)
274 
275  //- Local list of face IDs
277 
278  //- Local list of patch ID per face
280 
281  //- List of +1/-1 representing face flip map
282  // (1 use as is, -1 negate)
284 
285 
286  // If operating on sampledSurface
287 
288  //- Underlying sampledSurface
289  autoPtr<sampledSurface> surfacePtr_;
290 
291 
292  // Protected Member Functions
293 
294  //- Initialise, e.g. face addressing
295  void initialise(const dictionary& dict);
296 
297  //- Return true if the field name is valid
298  template<class Type>
299  bool validField(const word& fieldName) const;
300 
301  //- Return field values by looking up field name
302  template<class Type>
304  (
305  const word& fieldName,
306  const bool mustGet = false,
307  const bool applyOrientation = false
308  ) const;
309 
310  //- Apply the 'operation' to the values. Operation has to
311  // preserve Type.
312  template<class Type>
314  (
315  const Field<Type>& values,
316  const vectorField& Sf,
317  const scalarField& weightField
318  ) const;
319 
320  //- Apply the 'operation' to the values. Wrapper around
321  // processSameTypeValues. See also template specialisation below.
322  template<class Type>
323  Type processValues
324  (
325  const Field<Type>& values,
326  const vectorField& Sf,
327  const scalarField& weightField
328  ) const;
330  //- Output file header information
331  virtual void writeFileHeader(const label i);
334 public:
336  //- Run-time type information
337  TypeName("faceSource");
340  //- Construct from components
342  (
343  const word& name,
344  const objectRegistry& obr,
345  const dictionary& dict,
346  const bool loadFromFiles = false
347  );
348 
349 
350  //- Destructor
351  virtual ~faceSource();
352 
353 
354  // Public Member Functions
355 
356  // Access
357 
358  //- Return the source type
359  inline const sourceType& source() const;
360 
361  //- Return the local list of face IDs
362  inline const labelList& faceId() const;
363 
364  //- Return the local list of patch ID per face
365  inline const labelList& facePatch() const;
366 
367  //- Return the list of +1/-1 representing face flip map
368  inline const labelList& faceSign() const;
369 
370 
371  // Function object functions
372 
373  //- Read from dictionary
374  virtual void read(const dictionary&);
375 
376  //- Calculate and write
377  virtual void write();
378 
379  //- Templated helper function to output field values
380  template<class Type>
381  bool writeValues
382  (
383  const word& fieldName,
384  const scalarField& weightField,
385  const bool orient
386  );
388  //- Filter a surface field according to faceIds
389  template<class Type>
391  (
393  const bool applyOrientation
394  ) const;
395 
396  //- Filter a volume field according to faceIds
397  template<class Type>
399  (
401  const bool applyOrientation
402  ) const;
403 };
404 
406 //- Specialisation of processing scalars
407 template<>
409 (
410  const Field<scalar>& values,
411  const vectorField& Sf,
412  const scalarField& weightField
413 ) const;
414 
415 
416 //- Specialisation of processing vectors
417 template<>
419 (
420  const Field<vector>& values,
421  const vectorField& Sf,
422  const scalarField& weightField
423 ) const;
425 
426 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
427 
428 } // End namespace fieldValues
429 } // End namespace Foam
431 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
432 
433 #include "faceSourceI.H"
434 
435 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
436 
437 #ifdef NoRepository
438  #include "faceSourceTemplates.C"
439 #endif
440 
441 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
442 
443 #endif
444 
445 // ************************************************************************* //
labelList faceSign_
List of +1/-1 representing face flip map.
Definition: faceSource.H:424
static const NamedEnum< operationType, 15 > operationTypeNames_
Operation type names.
Definition: faceSource.H:345
const labelList & facePatch() const
Return the local list of patch ID per face.
Definition: faceSourceI.H:45
labelList faceId_
Local list of face IDs.
Definition: faceSource.H:417
A class for managing temporary objects.
Definition: PtrList.H:118
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
bool writeValues(const word &fieldName, const scalarField &weightField, const bool orient)
Templated helper function to output field values.
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
labelList facePatchId_
Local list of patch ID per face.
Definition: faceSource.H:420
TypeName("faceSource")
Run-time type information.
autoPtr< sampledSurface > surfacePtr_
Underlying sampledSurface.
Definition: faceSource.H:430
operationType
Operation type enumeration.
Definition: faceSource.H:325
const labelList & faceId() const
Return the local list of face IDs.
Definition: faceSourceI.H:38
void initialise(const dictionary &dict)
Initialise, e.g. face addressing.
Definition: faceSource.C:401
autoPtr< surfaceWriter > surfaceWriterPtr_
Surface writer.
Definition: faceSource.H:384
faceSource(const word &name, const objectRegistry &obr, const dictionary &dict, const bool loadFromFiles=false)
Construct from components.
Definition: faceSource.C:638
const pointField & points
virtual void writeFileHeader(const label i)
Output file header information.
Definition: faceSource.C:533
tmp< Field< Type > > filterField(const GeometricField< Type, fvsPatchField, surfaceMesh > &field, const bool applyOrientation) const
Filter a surface field according to faceIds.
label nFaces_
Global number of faces.
Definition: faceSource.H:411
sourceType source_
Source type.
Definition: faceSource.H:387
const objectRegistry & obr() const
Return the reference to the object registry.
Definition: fieldValueI.H:37
A class for handling words, derived from string.
Definition: word.H:59
virtual ~faceSource()
Destructor.
Definition: faceSource.C:665
bool writeArea_
Optionally write the area of the faceSource.
Definition: faceSource.H:408
const labelList & faceSign() const
Return the list of +1/-1 representing face flip map.
Definition: faceSourceI.H:52
Generic GeometricField class.
List< label > labelList
A List of labels.
Definition: labelList.H:56
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
tmp< Field< Type > > getFieldValues(const word &fieldName, const bool mustGet=false, const bool applyOrientation=false) const
Return field values by looking up field name.
List< face > faceList
Definition: faceListFwd.H:43
const dictionary & dict() const
Return the reference to the construction dictionary.
Definition: fieldValueI.H:43
sourceType
Source type enumeration.
Definition: faceSource.H:313
virtual void write()
Calculate and write.
Definition: faceSource.C:682
scalar scaleFactor_
Scale factor - optional.
Definition: faceSource.H:402
virtual void read(const dictionary &)
Read from dictionary.
Definition: faceSource.C:671
word weightFieldName_
Weight field name - optional.
Definition: faceSource.H:393
const sourceType & source() const
Return the source type.
Definition: faceSourceI.H:31
const word & name() const
Return the name of the geometric source.
Definition: fieldValueI.H:31
bool orientWeightField_
Flag to indicate if flipMap should be applied to the weight field.
Definition: faceSource.H:396
label orientedFieldsStart_
Start index of fields that require application of flipMap.
Definition: faceSource.H:399
Type processSameTypeValues(const Field< Type > &values, const vectorField &Sf, const scalarField &weightField) const
Apply the 'operation' to the values. Operation has to.
Type processValues(const Field< Type > &values, const vectorField &Sf, const scalarField &weightField) const
Apply the 'operation' to the values. Wrapper around.
operationType operation_
Operation to apply to values.
Definition: faceSource.H:390
bool validField(const word &fieldName) const
Return true if the field name is valid.
Registry of regIOobjects.
scalar totalArea_
Total area of the faceSource.
Definition: faceSource.H:405
Pre-declare SubField and related Field type.
Definition: Field.H:57
static const NamedEnum< sourceType, 3 > sourceTypeNames_
Source type names.
Definition: faceSource.H:321