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 |
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(const label i);
232 
233 
234 public:
236  //- Run-time type information
237  TypeName("cellSource");
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  );
250  //- Destructor
251  virtual ~cellSource();
254  // Public Member Functions
256  // Access
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(const word& fieldName);
276 
277  //- Filter a field according to cellIds
278  template<class Type>
279  tmp<Field<Type> > filterField(const Field<Type>& field) const;
280 };
281 
282 
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 } // End namespace fieldValues
286 } // End namespace Foam
288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 
290 #include "cellSourceI.H"
291 
292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
294 #ifdef NoRepository
295  #include "cellSourceTemplates.C"
296 #endif
297 
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
300 #endif
301 
302 // ************************************************************************* //
cellSource(const word &name, const objectRegistry &obr, const dictionary &dict, const bool loadFromFiles=false)
Construct from components.
Definition: cellSource.C:192
operationType operation_
Operation to apply to values.
Definition: cellSource.H:287
bool validField(const word &fieldName) const
Return true if the field name is valid.
labelList cellId_
Local list of cell IDs.
Definition: cellSource.H:293
Type processValues(const Field< Type > &values, const scalarField &V, const scalarField &weightField) const
Apply the &#39;operation&#39; to the values.
virtual void write()
Calculate and write.
Definition: cellSource.C:231
A class for handling words, derived from string.
Definition: word.H:59
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
scalar volume_
Volume of the cellSource.
Definition: cellSource.H:299
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
const dictionary & dict() const
Return the reference to the construction dictionary.
Definition: fieldValueI.H:43
sourceType source_
Source type.
Definition: cellSource.H:284
tmp< Field< Type > > setFieldValues(const word &fieldName, const bool mustGet=false) const
Insert field values into values list.
static const NamedEnum< sourceType, 2 > sourceTypeNames_
Source type names.
Definition: cellSource.H:242
const word & name() const
Return the name of the geometric source.
Definition: fieldValueI.H:31
void initialise(const dictionary &dict)
Initialise, e.g. cell addressing.
Definition: cellSource.C:129
virtual ~cellSource()
Destructor.
Definition: cellSource.C:213
const labelList & cellId() const
Return the local list of cell IDs.
Definition: cellSourceI.H:38
Pre-declare SubField and related Field type.
Definition: Field.H:57
label nCells_
Global number of cells.
Definition: cellSource.H:290
virtual void read(const dictionary &)
Read from dictionary.
Definition: cellSource.C:219
tmp< Field< Type > > filterField(const Field< Type > &field) const
Filter a field according to cellIds.
sourceType
Source type enumeration.
Definition: cellSource.H:235
const objectRegistry & obr() const
Return the reference to the object registry.
Definition: fieldValueI.H:37
const sourceType & source() const
Return the source type.
Definition: cellSourceI.H:31
virtual void writeFileHeader(const label i)
Output file header information.
Definition: cellSource.C:163
Registry of regIOobjects.
List< label > labelList
A List of labels.
Definition: labelList.H:56
TypeName("cellSource")
Run-time type information.
bool writeVolume_
Optionally write the volume of the cellSource.
Definition: cellSource.H:302
operationType
Operation type enumeration.
Definition: cellSource.H:246
bool writeValues(const word &fieldName)
Templated helper function to output field values.
word weightFieldName_
Weight field name - only used for opWeightedAverage mode.
Definition: cellSource.H:296
A class for managing temporary objects.
Definition: PtrList.H:118
static const NamedEnum< operationType, 11 > operationTypeNames_
Operation type names.
Definition: cellSource.H:262