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 | Copyright (C) 2015 OpenCFD Ltd.
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
222  (
223  faceList& faces,
225  ) const;
226 
227  //- Combine surface faces and points from multiple processors
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  //- Total area of the faceSource
261  scalar totalArea_;
262 
263  //- Optionally write the area of the faceSource
264  bool writeArea_;
265 
266  //- Global number of faces
267  label nFaces_;
268 
269 
270  // If operating on mesh faces (faceZone, patch)
271 
272  //- Local list of face IDs
274 
275  //- Local list of patch ID per face
277 
278  //- List of +1/-1 representing face flip map
279  // (1 use as is, -1 negate)
281 
282 
283  // If operating on sampledSurface
284 
285  //- Underlying sampledSurface
286  autoPtr<sampledSurface> surfacePtr_;
287 
288 
289  // Protected Member Functions
290 
291  //- Initialise, e.g. face addressing
292  void initialise(const dictionary& dict);
293 
294  //- Return true if the field name is valid
295  template<class Type>
296  bool validField(const word& fieldName) const;
297 
298  //- Return field values by looking up field name
299  template<class Type>
300  tmp<Field<Type> > setFieldValues
301  (
302  const word& fieldName,
303  const bool mustGet = false,
304  const bool applyOrientation = false
305  ) const;
306 
307  //- Apply the 'operation' to the values. Operation has to
308  // preserve Type.
309  template<class Type>
311  (
312  const Field<Type>& values,
313  const vectorField& Sf,
314  const scalarField& weightField
315  ) const;
316 
317  //- Apply the 'operation' to the values. Wrapper around
318  // processSameTypeValues. See also template specialisation below.
319  template<class Type>
320  Type processValues
321  (
322  const Field<Type>& values,
323  const vectorField& Sf,
324  const scalarField& weightField
325  ) const;
326 
327  //- Output file header information
328  virtual void writeFileHeader(Ostream& os) const;
329 
330 
331 public:
332 
333  //- Run-time type information
334  TypeName("faceSource");
335 
336 
337  //- Construct from components
339  (
340  const word& name,
342  const dictionary& dict,
343  const bool loadFromFiles = false
344  );
345 
346 
347  //- Destructor
348  virtual ~faceSource();
349 
350 
351  // Public Member Functions
352 
353  // Access
354 
355  //- Return the source type
356  inline const sourceType& source() const;
357 
358  //- Return the local list of face IDs
359  inline const labelList& faceId() const;
360 
361  //- Return the local list of patch ID per face
362  inline const labelList& facePatch() const;
363 
364  //- Return the list of +1/-1 representing face flip map
365  inline const labelList& faceSign() const;
366 
367 
368  // Function object functions
369 
370  //- Read from dictionary
371  virtual void read(const dictionary&);
372 
373  //- Calculate and write
374  virtual void write();
375 
376  //- Templated helper function to output field values
377  template<class Type>
378  bool writeValues
379  (
380  const word& fieldName,
381  const scalarField& weightField,
382  const bool orient
383  );
384 
385  //- Filter a surface field according to faceIds
386  template<class Type>
388  (
390  const bool applyOrientation
391  ) const;
392 
393  //- Filter a volume field according to faceIds
394  template<class Type>
396  (
398  const bool applyOrientation
399  ) const;
400 };
401 
402 
403 //- Specialisation of processing scalars
404 template<>
406 (
407  const Field<scalar>& values,
408  const vectorField& Sf,
409  const scalarField& weightField
410 ) const;
411 
412 
413 //- Specialisation of processing vectors
414 template<>
416 (
417  const Field<vector>& values,
418  const vectorField& Sf,
419  const scalarField& weightField
420 ) const;
421 
422 
423 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
424 
425 } // End namespace fieldValues
426 } // End namespace Foam
427 
428 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
429 
430 #include "faceSourceI.H"
431 
432 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
433 
434 #ifdef NoRepository
435  #include "faceSourceTemplates.C"
436 #endif
437 
438 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
439 
440 #endif
441 
442 // ************************************************************************* //
Foam::fieldValues::faceSource::write
virtual void write()
Calculate and write.
Definition: faceSource.C:659
Foam::fieldValues::faceSource::nFaces_
label nFaces_
Global number of faces.
Definition: faceSource.H:408
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
volFieldsFwd.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
Foam::fieldValues::faceSource::setPatchFaces
void setPatchFaces()
Set faces to evaluate based on a patch.
Definition: faceSource.C:172
Foam::fieldValues::faceSource::opWeightedAverage
@ opWeightedAverage
Definition: faceSource.H:333
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
faceSourceI.H
Foam::fieldValues::faceSource::opAreaNormalAverage
@ opAreaNormalAverage
Definition: faceSource.H:340
NamedEnum.H
Foam::fieldValues::faceSource::sampledSurfaceFaces
void sampledSurfaceFaces(const dictionary &)
Set faces according to sampledSurface.
Definition: faceSource.C:209
Foam::fieldValues::faceSource::surfacePtr_
autoPtr< sampledSurface > surfacePtr_
Underlying sampledSurface.
Definition: faceSource.H:427
Foam::fieldValues::faceSource::faceSign_
labelList faceSign_
List of +1/-1 representing face flip map.
Definition: faceSource.H:421
Foam::fieldValues::faceSource::source
const sourceType & source() const
Return the source type.
Definition: faceSourceI.H:31
Foam::fieldValues::faceSource::opAreaNormalIntegrate
@ opAreaNormalIntegrate
Definition: faceSource.H:341
surfaceWriter.H
Foam::fieldValues::faceSource::opSumMag
@ opSumMag
Definition: faceSource.H:329
Foam::fieldValues::faceSource::opCoV
@ opCoV
Definition: faceSource.H:339
Foam::fieldValues::faceSource::faceSign
const labelList & faceSign() const
Return the list of +1/-1 representing face flip map.
Definition: faceSourceI.H:52
Foam::fieldValues::faceSource
This function object provides a 'face source' variant of the fieldValues function object....
Definition: faceSource.H:303
Foam::fieldValues::faceSource::validField
bool validField(const word &fieldName) const
Return true if the field name is valid.
Definition: faceSourceTemplates.C:35
Foam::fieldValues::faceSource::faceId
const labelList & faceId() const
Return the local list of face IDs.
Definition: faceSourceI.H:38
Foam::fieldValues::faceSource::orientedFieldsStart_
label orientedFieldsStart_
Start index of fields that require application of flipMap.
Definition: faceSource.H:399
Foam::fieldValues::faceSource::stSampledSurface
@ stSampledSurface
Definition: faceSource.H:317
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::label
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::fieldValues::faceSource::processValues
Type processValues(const Field< Type > &values, const vectorField &Sf, const scalarField &weightField) const
Apply the 'operation' to the values. Wrapper around.
Definition: faceSourceTemplates.C:261
Foam::fieldValues::faceSource::operation_
operationType operation_
Operation to apply to values.
Definition: faceSource.H:390
Foam::fieldValue::obr
const objectRegistry & obr() const
Return the reference to the object registry.
Definition: fieldValueI.H:37
Foam::fieldValues::faceSource::opNone
@ opNone
Definition: faceSource.H:327
Foam::fieldValues::faceSource::combineSurfaceGeometry
void combineSurfaceGeometry(faceList &faces, pointField &points) const
Combine surface faces and points from multiple processors.
Definition: faceSource.C:344
Foam::fieldValues::faceSource::writeArea_
bool writeArea_
Optionally write the area of the faceSource.
Definition: faceSource.H:405
Foam::fieldValues::faceSource::opAverage
@ opAverage
Definition: faceSource.H:332
Foam::fieldValues::faceSource::stPatch
@ stPatch
Definition: faceSource.H:316
faceSourceTemplates.C
Foam::fieldValues::faceSource::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
Output file header information.
Definition: faceSource.C:508
Foam::fieldValue::name
const word & name() const
Return the name of the geometric source.
Definition: fieldValueI.H:31
Foam::fieldValues::faceSource::TypeName
TypeName("faceSource")
Run-time type information.
Foam::fieldValues::faceSource::initialise
void initialise(const dictionary &dict)
Initialise, e.g. face addressing.
Definition: faceSource.C:401
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::fieldValues::faceSource::opSum
@ opSum
Definition: faceSource.H:328
Foam::fieldValues::faceSource::setFieldValues
tmp< Field< Type > > setFieldValues(const word &fieldName, const bool mustGet=false, const bool applyOrientation=false) const
Return field values by looking up field name.
Foam::fieldValues::faceSource::opMin
@ opMin
Definition: faceSource.H:337
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::fieldValues::faceSource::sourceType
sourceType
Source type enumeration.
Definition: faceSource.H:313
Foam::fieldValues::faceSource::~faceSource
virtual ~faceSource()
Destructor.
Definition: faceSource.C:641
Foam::fieldValues::faceSource::read
virtual void read(const dictionary &)
Read from dictionary.
Definition: faceSource.C:647
Foam::fieldValues::faceSource::opMax
@ opMax
Definition: faceSource.H:338
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::fieldValues::faceSource::filterField
tmp< Field< Type > > filterField(const GeometricField< Type, fvsPatchField, surfaceMesh > &field, const bool applyOrientation) const
Filter a surface field according to faceIds.
Foam::fieldValues::faceSource::source_
sourceType source_
Source type.
Definition: faceSource.H:387
Foam::fieldValue::dict
const dictionary & dict() const
Return the reference to the construction dictionary.
Definition: fieldValueI.H:43
Foam::fieldValues::faceSource::opAreaAverage
@ opAreaAverage
Definition: faceSource.H:334
Foam::fieldValues::faceSource::facePatch
const labelList & facePatch() const
Return the local list of patch ID per face.
Definition: faceSourceI.H:45
Foam::fieldValues::faceSource::processSameTypeValues
Type processSameTypeValues(const Field< Type > &values, const vectorField &Sf, const scalarField &weightField) const
Apply the 'operation' to the values. Operation has to.
Definition: faceSourceTemplates.C:124
Foam::fieldValues::faceSource::operationType
operationType
Operation type enumeration.
Definition: faceSource.H:325
Foam::fieldValue
Base class for field value-based function objects.
Definition: fieldValue.H:63
fieldValue.H
Foam::faceList
List< face > faceList
Definition: faceListFwd.H:43
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::fieldValues::faceSource::weightFieldName_
word weightFieldName_
Weight field name - optional.
Definition: faceSource.H:393
Foam::fieldValues::faceSource::opSumDirection
@ opSumDirection
Definition: faceSource.H:330
points
const pointField & points
Definition: gmvOutputHeader.H:1
surfaceFieldsFwd.H
Foam::fieldValues::faceSource::operationTypeNames_
static const NamedEnum< operationType, 15 > operationTypeNames_
Operation type names.
Definition: faceSource.H:345
Foam::fieldValues::faceSource::faceSource
faceSource(const word &name, const objectRegistry &obr, const dictionary &dict, const bool loadFromFiles=false)
Construct from components.
Definition: faceSource.C:611
Foam::fieldValues::faceSource::surfaceWriterPtr_
autoPtr< surfaceWriter > surfaceWriterPtr_
Surface writer.
Definition: faceSource.H:384
Foam::fieldValues::faceSource::totalArea_
scalar totalArea_
Total area of the faceSource.
Definition: faceSource.H:402
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::fieldValues::faceSource::orientWeightField_
bool orientWeightField_
Flag to indicate if flipMap should be applied to the weight field.
Definition: faceSource.H:396
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::fieldValues::faceSource::opAreaIntegrate
@ opAreaIntegrate
Definition: faceSource.H:336
Foam::fieldValues::faceSource::facePatchId_
labelList facePatchId_
Local list of patch ID per face.
Definition: faceSource.H:417
Foam::fieldValues::faceSource::stFaceZone
@ stFaceZone
Definition: faceSource.H:315
Foam::fieldValues::faceSource::opWeightedAreaAverage
@ opWeightedAreaAverage
Definition: faceSource.H:335
Foam::fieldValues::faceSource::opSumDirectionBalance
@ opSumDirectionBalance
Definition: faceSource.H:331
Foam::fieldValues::faceSource::totalArea
scalar totalArea() const
Calculate and return total area of the faceSource: sum(magSf)
Definition: faceSource.C:382
Foam::fieldValues::faceSource::writeValues
bool writeValues(const word &fieldName, const scalarField &weightField, const bool orient)
Templated helper function to output field values.
Definition: faceSourceTemplates.C:276
Foam::fieldValues::faceSource::combineMeshGeometry
void combineMeshGeometry(faceList &faces, pointField &points) const
Combine mesh faces and points from multiple processors.
Definition: faceSource.C:223
Foam::fieldValues::faceSource::faceId_
labelList faceId_
Local list of face IDs.
Definition: faceSource.H:414
Foam::fieldValues::faceSource::setFaceZoneFaces
void setFaceZoneFaces()
Set faces to evaluate based on a face zone.
Definition: faceSource.C:87
Foam::NamedEnum< sourceType, 3 >
Foam::fieldValues::faceSource::sourceTypeNames_
static const NamedEnum< sourceType, 3 > sourceTypeNames_
Source type names.
Definition: faceSource.H:321