All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
volFieldValue.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-2023 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::volFieldValue
26 
27 Description
28  Provides a 'fvCellSet' specialisation of the fieldValue function object.
29 
30  Given a list of user-specified fields and a 'fvCellSet', a number of
31  operations can be performed, such as sums, averages and integrations.
32 
33  Example of function object specification:
34  \verbatim
35  volFieldValue1
36  {
37  type volFieldValue;
38  libs ("libfieldFunctionObjects.so");
39 
40  log true;
41  writeControl writeTime;
42  writeFields true;
43 
44  select cellZone;
45  cellZone c0;
46  operation volAverage;
47 
48  weightField alpha1;
49 
50  fields
51  (
52  p
53  U
54  );
55  }
56  \endverbatim
57 
58 Usage
59  \table
60  Property | Description | Required | Default value
61  type | Type name: volFieldValue | yes |
62  log | Write data to standard output | no | no
63  writeFields | Write the region field values | yes |
64  writeLocation| Write the location (if available) | no | no
65  select | fvCellSet type: see below | yes |
66  name | Name of fvCellSet if required | no |
67  operation | Operation to perform | yes |
68  weightField | Name of field to apply weighting | no |
69  weightFields | Names of fields to apply weighting | no |
70  fields | List of fields to operate on | yes |
71  \endtable
72 
73  Where \c select options are:
74  \plaintable
75  cellZone | requires a 'name' entry to specify the cellZone
76  all | all cells
77  \endplaintable
78 
79  The \c operation is one of:
80  \plaintable
81  none | No operation
82  sum | Sum
83  sumMag | Sum of component magnitudes
84  average | Ensemble average
85  volAverage | Volume weighted average
86  volIntegrate | Volume integral
87  min | Minimum
88  max | Maximum
89  minMag | Minimum magnitude
90  maxMag | Maximum magnitude
91  CoV | Coefficient of variation: standard deviation/mean
92  \endplaintable
93 
94 See also
95  Foam::functionObjects::fieldValues::fieldValue
96  Foam::Foam::fvCellSet
97  Foam::functionObject
98 
99 SourceFiles
100  volFieldValue.C
101 
102 \*---------------------------------------------------------------------------*/
103 
104 #ifndef functionObjects_volFieldValue_H
105 #define functionObjects_volFieldValue_H
106 
107 #include "fieldValue.H"
108 #include "fvCellSet.H"
109 
110 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
111 
112 namespace Foam
113 {
114 namespace functionObjects
115 {
116 namespace fieldValues
117 {
118 
119 /*---------------------------------------------------------------------------*\
120  Class volFieldValue Declaration
121 \*---------------------------------------------------------------------------*/
122 
123 class volFieldValue
124 :
125  public fieldValue,
126  public fvCellSet
127 {
128 
129 public:
130 
131  // Public data types
132 
133  //- Operation type enumeration
134  enum class operationType
135  {
136  none,
137  sum,
138  sumMag,
139  average,
140  volAverage,
141  volIntegrate,
142  min,
143  max,
144  minMag,
145  maxMag,
146  CoV
147  };
148 
149  //- Operation type names
150  static const NamedEnum<operationType, 11> operationTypeNames_;
151 
152 
153  // Public classes
154 
155  //- Forward declare the result structure
156  template<class Type>
157  struct Result;
158 
159 
160 protected:
161 
162  // Protected data
163 
164  //- Write the location if available for this operation - optional
165  Switch writeLocation_;
166 
167  //- Operation to apply to values
169 
170  //- Weight field names
172 
173  //- Scale factor - optional
174  scalar scaleFactor_;
175 
176 
177  // Protected Member Functions
178 
179  //- Initialise, e.g. cell addressing
180  void initialise(const dictionary& dict);
181 
182  //- Return true if the field name is valid
183  template<class Type>
184  bool validField(const word& fieldName) const;
185 
186  //- Insert field values into values list
187  template<class Type>
188  tmp<Field<Type>> getFieldValues(const word& fieldName) const;
189 
190  //- Apply a comparison operation to the values, returning the limiting
191  // value, its index and processor index
192  template<class Op>
193  void compareScalars
194  (
195  const scalarField& values,
196  const scalar emptyVal,
197  Result<scalar>& result,
198  const Op& op
199  ) const;
200 
201  //- Apply the operation to the values, and return true if successful.
202  // Does nothing unless overloaded below.
203  template<class Type, class ResultType>
204  bool processValues
205  (
206  const Field<Type>& values,
207  const scalarField& weights,
208  const scalarField& V,
209  Result<ResultType>& result
210  ) const;
211 
212  //- Apply Type -> Type operation to the values. Calls
213  // processValuesTypeType.
214  template<class Type>
215  bool processValues
216  (
217  const Field<Type>& values,
218  const scalarField& weights,
219  const scalarField& V,
220  Result<Type>& result
221  ) const;
222 
223  //- Apply Type -> scalar operation to the values
224  template<class Type>
225  bool processValues
226  (
227  const Field<Type>& values,
228  const scalarField& weights,
229  const scalarField& V,
230  Result<scalar>& result
231  ) const;
232 
233  //- Apply scalar -> scalar operation to the values. Calls
234  // processValuesTypeType.
235  bool processValues
236  (
237  const Field<scalar>& values,
238  const scalarField& weights,
239  const scalarField& V,
241  ) const;
242 
243  //- Apply a Type -> Type operation to the values
244  template<class Type>
246  (
247  const Field<Type>& values,
248  const scalarField& weights,
249  const scalarField& V,
250  Result<Type>& result
251  ) const;
252 
253  //- Output file header location information for a given type
254  template<class Type>
256 
257  //- Output file header information
258  virtual void writeFileHeader(const label i);
259 
260 
261 public:
262 
263  //- Run-time type information
264  TypeName("volFieldValue");
265 
266 
267  // Constructors
268 
269  //- Construct from name, Time and dictionary
271  (
272  const word& name,
273  const Time& runTime,
275  );
276 
277  //- Construct from name, objectRegistry and dictionary
279  (
280  const word& name,
281  const objectRegistry& obr,
282  const dictionary& dict
283  );
284 
285 
286  //- Destructor
287  virtual ~volFieldValue();
288 
289 
290  // Public Member Functions
291 
292  //- Templated helper function to output field values
293  template<class Type>
295  (
296  const word& fieldName,
297  const scalarField& weights,
298  const scalarField& V
299  );
300 
301  //- Templated helper function to output field values
302  template<class Type, class ResultType>
303  bool writeValues
304  (
305  const word& fieldName,
306  const Field<Type>& values,
307  const scalarField& weights,
308  const scalarField& V
309  );
310 
311  //- Filter a field according to cellIds
312  template<class Type>
313  tmp<Field<Type>> filterField(const Field<Type>& field) const;
314 
315  //- Read from dictionary
316  virtual bool read(const dictionary&);
317 
318  //- Calculate and write
319  virtual bool write();
320 };
321 
322 
323 template<>
324 void volFieldValue::writeFileHeaderLocation<scalar>();
325 
326 
327 /*---------------------------------------------------------------------------*\
328  Class volFieldValue::Result Declaration
329 \*---------------------------------------------------------------------------*/
330 
331 template<class Type>
333 {
334  Type value;
335  label celli;
336  label proci;
337  point cc;
338 };
339 
340 
341 template<class Type>
342 inline Istream& operator>>
343 (
344  Istream& is,
345  volFieldValue::Result<Type>& result
346 )
347 {
348  return is >> result.value >> result.celli >> result.proci >> result.cc;
349 }
350 
351 
352 template<class Type>
353 inline Ostream& operator<<
354 (
355  Ostream& os,
356  const volFieldValue::Result<Type>& result
357 )
358 {
359  return os << result.value << result.celli << result.proci << result.cc;
360 }
361 
362 
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364 
365 } // End namespace fieldValues
366 } // End namespace functionObjects
367 } // End namespace Foam
368 
369 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
370 
371 #ifdef NoRepository
372  #include "volFieldValueTemplates.C"
373 #endif
374 
375 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
376 
377 #endif
378 
379 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
const word & name() const
Return the name of this functionObject.
const dictionary & dict() const
Return the reference to the construction dictionary.
Definition: fieldValueI.H:31
scalar scaleFactor_
Scale factor - optional.
bool writeValues(const word &fieldName, const scalarField &weights, const scalarField &V)
Templated helper function to output field values.
static const NamedEnum< operationType, 11 > operationTypeNames_
Operation type names.
bool processValuesTypeType(const Field< Type > &values, const scalarField &weights, const scalarField &V, Result< Type > &result) const
Apply a Type -> Type operation to the values.
tmp< Field< Type > > getFieldValues(const word &fieldName) const
Insert field values into values list.
Switch writeLocation_
Write the location if available for this operation - optional.
void initialise(const dictionary &dict)
Initialise, e.g. cell addressing.
Definition: volFieldValue.C:78
void writeFileHeaderLocation()
Output file header location information for a given type.
operationType operation_
Operation to apply to values.
tmp< Field< Type > > filterField(const Field< Type > &field) const
Filter a field according to cellIds.
volFieldValue(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
virtual void writeFileHeader(const label i)
Output file header information.
bool validField(const word &fieldName) const
Return true if the field name is valid.
TypeName("volFieldValue")
Run-time type information.
virtual bool write()
Calculate and write.
bool processValues(const Field< Type > &values, const scalarField &weights, const scalarField &V, Result< ResultType > &result) const
Apply the operation to the values, and return true if successful.
virtual bool read(const dictionary &)
Read from dictionary.
void compareScalars(const scalarField &values, const scalar emptyVal, Result< scalar > &result, const Op &op) const
Apply a comparison operation to the values, returning the limiting.
scalar V() const
Return const access to the total cell volume.
Definition: fvCellSetI.H:28
Registry of regIOobjects.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
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
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
#define Op(opName, op)
Definition: ops.H:100