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  Result<scalar>& result,
197  const Op& op
198  ) const;
199 
200  //- Apply the operation to the values, and return true if successful.
201  // Does nothing unless overloaded below.
202  template<class Type, class ResultType>
203  bool processValues
204  (
205  const Field<Type>& values,
206  const scalarField& weights,
207  const scalarField& V,
208  Result<ResultType>& result
209  ) const;
210 
211  //- Apply Type -> Type operation to the values. Calls
212  // processValuesTypeType.
213  template<class Type>
214  bool processValues
215  (
216  const Field<Type>& values,
217  const scalarField& weights,
218  const scalarField& V,
219  Result<Type>& result
220  ) const;
221 
222  //- Apply Type -> scalar operation to the values
223  template<class Type>
224  bool processValues
225  (
226  const Field<Type>& values,
227  const scalarField& weights,
228  const scalarField& V,
230  ) const;
231 
232  //- Apply scalar -> scalar operation to the values. Calls
233  // processValuesTypeType.
234  bool processValues
235  (
236  const Field<scalar>& values,
237  const scalarField& weights,
238  const scalarField& V,
239  Result<scalar>& result
240  ) const;
241 
242  //- Apply a Type -> Type operation to the values
243  template<class Type>
245  (
246  const Field<Type>& values,
247  const scalarField& weights,
248  const scalarField& V,
249  Result<Type>& result
250  ) const;
251 
252  //- Output file header location information for a given type
253  template<class Type>
255 
256  //- Output file header information
257  virtual void writeFileHeader(const label i);
258 
259 
260 public:
261 
262  //- Run-time type information
263  TypeName("volFieldValue");
264 
265 
266  // Constructors
267 
268  //- Construct from name, Time and dictionary
270  (
271  const word& name,
272  const Time& runTime,
273  const dictionary& dict
274  );
275 
276  //- Construct from name, objectRegistry and dictionary
278  (
279  const word& name,
280  const objectRegistry& obr,
281  const dictionary& dict
282  );
283 
284 
285  //- Destructor
286  virtual ~volFieldValue();
287 
288 
289  // Public Member Functions
290 
291  //- Templated helper function to output field values
292  template<class Type>
293  bool writeValues
294  (
295  const word& fieldName,
296  const scalarField& weights,
297  const scalarField& V
298  );
299 
300  //- Templated helper function to output field values
301  template<class Type, class ResultType>
302  bool writeValues
303  (
304  const word& fieldName,
305  const Field<Type>& values,
306  const scalarField& weights,
307  const scalarField& V
308  );
309 
310  //- Filter a field according to cellIds
311  template<class Type>
312  tmp<Field<Type>> filterField(const Field<Type>& field) const;
313 
314  //- Read from dictionary
315  virtual bool read(const dictionary&);
316 
317  //- Calculate and write
318  virtual bool write();
319 };
320 
321 
322 template<>
323 void volFieldValue::writeFileHeaderLocation<scalar>();
324 
325 
326 /*---------------------------------------------------------------------------*\
327  Class volFieldValue::Result Declaration
328 \*---------------------------------------------------------------------------*/
329 
330 template<class Type>
332 {
333  Type value;
334  label celli;
335  label proci;
336  point cc;
337 };
338 
339 
340 template<class Type>
341 inline Istream& operator>>
342 (
343  Istream& is,
344  volFieldValue::Result<Type>& result
345 )
346 {
347  return is >> result.value >> result.celli >> result.proci >> result.cc;
348 }
349 
350 
351 template<class Type>
352 inline Ostream& operator<<
353 (
354  Ostream& os,
355  const volFieldValue::Result<Type>& result
356 )
357 {
358  return os << result.value << result.celli << result.proci << result.cc;
359 }
360 
361 
362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
363 
364 } // End namespace fieldValues
365 } // End namespace functionObjects
366 } // End namespace Foam
367 
368 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
369 
370 #ifdef NoRepository
371  #include "volFieldValueTemplates.C"
372 #endif
373 
374 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
375 
376 #endif
377 
378 // ************************************************************************* //
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:160
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.
void compareScalars(const scalarField &values, Result< scalar > &result, const Op &op) const
Apply a comparison operation to the values, returning the limiting.
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.
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