cellSource.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::cellSource
26 
27 Group
28  grpFieldFunctionObjects
29 
30 Description
31  This function object provides a 'cell source' variant of the fieldValues
32  function object. Given a list of user-specified fields and a selection
33  of mesh cells, a number of operations can be performed, such as sums,
34  averages and integrations.
35 
36 
37  Example of function object specification:
38  \verbatim
39  cellSource1
40  {
41  type cellSource;
42  functionObjectLibs ("libfieldFunctionObjects.so");
43  ...
44  log true;
45  valueOutput true;
46  source cellZone;
47  sourceName c0;
48  operation volAverage;
49  weightField alpha1;
50  fields
51  (
52  p
53  U
54  );
55  }
56  \endverbatim
57 
58  \heading Function object usage
59  \table
60  Property | Description | Required | Default value
61  type | Type name: cellSource | yes |
62  log | Write data to standard output | no | no
63  valueOutput | Write the raw output values | yes |
64  writeVolume | Write the volume of the cellSource | no |
65  source | Cell source: see below | yes |
66  sourceName | Name of cell source if required | no |
67  operation | Operation to perform | yes |
68  weightField | Name of field to apply weighting | no |
69  fields | List of fields to operate on | yes |
70  \endtable
71 
72  \linebreak
73  Where \c source is defined by
74  \plaintable
75  cellZone | requires a 'sourceName' entry to specify the cellZone
76  all | all cells
77  \endplaintable
78 
79  \linebreak
80  The \c operation is one of:
81  \plaintable
82  none | no operation
83  sum | sum
84  sumMag | sum of component magnitudes
85  average | ensemble average
86  weightedAverage | weighted average
87  volAverage | volume weighted average
88  weightedVolAverage | weighted volume average
89  volIntegrate | volume integral
90  min | minimum
91  max | maximum
92  CoV | coefficient of variation: standard deviation/mean
93  \endplaintable
94 
95 SeeAlso
96  Foam::fieldValues
97  Foam::functionObject
98  Foam::OutputFilterFunctionObject
99 
100 SourceFiles
101  cellSource.C
102 
103 \*---------------------------------------------------------------------------*/
104 
105 #ifndef cellSource_H
106 #define cellSource_H
107 
108 #include "NamedEnum.H"
109 #include "fieldValue.H"
110 #include "labelList.H"
111 #include "volFieldsFwd.H"
112 
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114 
115 namespace Foam
116 {
117 namespace fieldValues
118 {
119 
120 /*---------------------------------------------------------------------------*\
121  Class cellSource Declaration
122 \*---------------------------------------------------------------------------*/
123 
124 class cellSource
125 :
126  public fieldValue
127 {
128 
129 public:
130 
131  // Public data types
132 
133  //- Source type enumeration
134  enum sourceType
135  {
136  stCellZone,
137  stAll
138  };
139 
140  //- Source type names
141  static const NamedEnum<sourceType, 2> sourceTypeNames_;
142 
143 
144  //- Operation type enumeration
145  enum operationType
146  {
147  opNone,
148  opSum,
149  opSumMag,
150  opAverage,
152  opVolAverage,
155  opMin,
156  opMax,
157  opCoV
158  };
159 
160  //- Operation type names
161  static const NamedEnum<operationType, 11> operationTypeNames_;
162 
163 
164 private:
165 
166  // Private Member Functions
167 
168  //- Set cells to evaluate based on a cell zone
169  void setCellZoneCells();
170 
171  //- Set cells to evaluate based on a patch
172  void setPatchCells();
173 
174  //- Calculate and return volume of the cellSource: sum(V)
175  scalar volume() const;
176 
177 
178 protected:
179 
180  // Protected data
181 
182  //- Source type
184 
185  //- Operation to apply to values
187 
188  //- Global number of cells
189  label nCells_;
190 
191  //- Local list of cell IDs
193 
194  //- Weight field name - only used for opWeightedAverage mode
195  word weightFieldName_;
196 
197  //- Volume of the cellSource
198  scalar volume_;
199 
200  //- Optionally write the volume of the cellSource
201  bool writeVolume_;
202 
203 
204  // Protected Member Functions
205 
206  //- Initialise, e.g. cell addressing
207  void initialise(const dictionary& dict);
208 
209  //- Return true if the field name is valid
210  template<class Type>
211  bool validField(const word& fieldName) const;
212 
213  //- Insert field values into values list
214  template<class Type>
215  tmp<Field<Type> > setFieldValues
216  (
217  const word& fieldName,
218  const bool mustGet = false
219  ) const;
220 
221  //- Apply the 'operation' to the values
222  template<class Type>
223  Type processValues
224  (
225  const Field<Type>& values,
226  const scalarField& V,
227  const scalarField& weightField
228  ) const;
229 
230  //- Output file header information
231  virtual void writeFileHeader(Ostream& os) const;
232 
233 
234 public:
235 
236  //- Run-time type information
237  TypeName("cellSource");
238 
239 
240  //- Construct from components
241  cellSource
242  (
243  const word& name,
244  const objectRegistry& obr,
245  const dictionary& dict,
246  const bool loadFromFiles = false
247  );
248 
249 
250  //- Destructor
251  virtual ~cellSource();
252 
253 
254  // Public Member Functions
255 
256  // Access
257 
258  //- Return the source type
259  inline const sourceType& source() const;
260 
261  //- Return the local list of cell IDs
262  inline const labelList& cellId() const;
263 
264 
265  // Function object functions
266 
267  //- Read from dictionary
268  virtual void read(const dictionary&);
269 
270  //- Calculate and write
271  virtual void write();
272 
273  //- Templated helper function to output field values
274  template<class Type>
275  bool writeValues
276  (
277  const word& fieldName,
278  const scalarField& weightField
279  );
280 
281  //- Filter a field according to cellIds
282  template<class Type>
283  tmp<Field<Type> > filterField(const Field<Type>& field) const;
284 };
285 
286 
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288 
289 } // End namespace fieldValues
290 } // End namespace Foam
291 
292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 
294 #include "cellSourceI.H"
295 
296 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
297 
298 #ifdef NoRepository
300 #endif
301 
302 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
303 
304 #endif
305 
306 // ************************************************************************* //
Foam::fieldValues::cellSource::nCells_
label nCells_
Global number of cells.
Definition: cellSource.H:290
volFieldsFwd.H
Foam::fieldValues::cellSource::~cellSource
virtual ~cellSource()
Destructor.
Definition: cellSource.C:213
Foam::fieldValues::cellSource::opVolIntegrate
@ opVolIntegrate
Definition: cellSource.H:255
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::cellSource::sourceType
sourceType
Source type enumeration.
Definition: cellSource.H:235
Foam::fieldValues::cellSource::write
virtual void write()
Calculate and write.
Definition: cellSource.C:231
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::fieldValues::cellSource::operationTypeNames_
static const NamedEnum< operationType, 11 > operationTypeNames_
Operation type names.
Definition: cellSource.H:262
Foam::fieldValues::cellSource::setFieldValues
tmp< Field< Type > > setFieldValues(const word &fieldName, const bool mustGet=false) const
Insert field values into values list.
Foam::fieldValues::cellSource::initialise
void initialise(const dictionary &dict)
Initialise, e.g. cell addressing.
Definition: cellSource.C:127
Foam::fieldValues::cellSource::stCellZone
@ stCellZone
Definition: cellSource.H:237
NamedEnum.H
Foam::fieldValues::cellSource::opWeightedVolAverage
@ opWeightedVolAverage
Definition: cellSource.H:254
Foam::fieldValues::cellSource::volume
scalar volume() const
Calculate and return volume of the cellSource: sum(V)
Definition: cellSource.C:119
Foam::fieldValues::cellSource::weightFieldName_
word weightFieldName_
Weight field name - only used for opWeightedAverage mode.
Definition: cellSource.H:296
Foam::fieldValues::cellSource::sourceTypeNames_
static const NamedEnum< sourceType, 2 > sourceTypeNames_
Source type names.
Definition: cellSource.H:242
cellSourceTemplates.C
Foam::fieldValues::cellSource::TypeName
TypeName("cellSource")
Run-time type information.
Foam::fieldValues::cellSource::opVolAverage
@ opVolAverage
Definition: cellSource.H:253
Foam::fieldValues::cellSource::writeVolume_
bool writeVolume_
Optionally write the volume of the cellSource.
Definition: cellSource.H:302
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::fieldValues::cellSource::source_
sourceType source_
Source type.
Definition: cellSource.H:284
Foam::fieldValues::cellSource::processValues
Type processValues(const Field< Type > &values, const scalarField &V, const scalarField &weightField) const
Apply the 'operation' to the values.
Definition: cellSourceTemplates.C:72
Foam::fieldValues::cellSource::cellId
const labelList & cellId() const
Return the local list of cell IDs.
Definition: cellSourceI.H:38
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
labelList.H
Foam::Field< Type >
Foam::fieldValues::cellSource::opSumMag
@ opSumMag
Definition: cellSource.H:250
Foam::fieldValue::obr
const objectRegistry & obr() const
Return the reference to the object registry.
Definition: fieldValueI.H:37
Foam::fieldValues::cellSource::writeValues
bool writeValues(const word &fieldName, const scalarField &weightField)
Templated helper function to output field values.
Definition: cellSourceTemplates.C:171
Foam::fieldValues::cellSource::setPatchCells
void setPatchCells()
Set cells to evaluate based on a patch.
Foam::fieldValues::cellSource::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
Output file header information.
Definition: cellSource.C:160
Foam::fieldValues::cellSource::cellSource
cellSource(const word &name, const objectRegistry &obr, const dictionary &dict, const bool loadFromFiles=false)
Construct from components.
Definition: cellSource.C:188
Foam::fieldValue::name
const word & name() const
Return the name of the geometric source.
Definition: fieldValueI.H:31
Foam::fieldValues::cellSource::opAverage
@ opAverage
Definition: cellSource.H:251
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::fieldValues::cellSource::volume_
scalar volume_
Volume of the cellSource.
Definition: cellSource.H:299
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::fieldValues::cellSource::opCoV
@ opCoV
Definition: cellSource.H:258
Foam::fieldValues::cellSource::opMax
@ opMax
Definition: cellSource.H:257
Foam::fieldValue::dict
const dictionary & dict() const
Return the reference to the construction dictionary.
Definition: fieldValueI.H:43
Foam::fieldValues::cellSource::opNone
@ opNone
Definition: cellSource.H:248
Foam::fieldValue
Base class for field value-based function objects.
Definition: fieldValue.H:63
fieldValue.H
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::cellSource::filterField
tmp< Field< Type > > filterField(const Field< Type > &field) const
Filter a field according to cellIds.
Foam::fieldValues::cellSource::stAll
@ stAll
Definition: cellSource.H:238
cellSourceI.H
Foam::fieldValues::cellSource::validField
bool validField(const word &fieldName) const
Return true if the field name is valid.
Definition: cellSourceTemplates.C:32
Foam::fieldValues::cellSource::read
virtual void read(const dictionary &)
Read from dictionary.
Definition: cellSource.C:219
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::fieldValues::cellSource::operation_
operationType operation_
Operation to apply to values.
Definition: cellSource.H:287
Foam::fieldValues::cellSource::opWeightedAverage
@ opWeightedAverage
Definition: cellSource.H:252
Foam::fieldValues::cellSource::opSum
@ opSum
Definition: cellSource.H:249
Foam::fieldValues::cellSource::operationType
operationType
Operation type enumeration.
Definition: cellSource.H:246
Foam::NamedEnum< sourceType, 2 >
Foam::fieldValues::cellSource
This function object provides a 'cell source' variant of the fieldValues function object....
Definition: cellSource.H:225
Foam::fieldValues::cellSource::source
const sourceType & source() const
Return the source type.
Definition: cellSourceI.H:31
Foam::fieldValues::cellSource::opMin
@ opMin
Definition: cellSource.H:256
Foam::fieldValues::cellSource::setCellZoneCells
void setCellZoneCells()
Set cells to evaluate based on a cell zone.
Definition: cellSource.C:76
Foam::fieldValues::cellSource::cellId_
labelList cellId_
Local list of cell IDs.
Definition: cellSource.H:293