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-2025 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 'fvCellZone' specialisation of the fieldValue function object.
29 
30  Given a list of user-specified fields and a 'fvCellZone', 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  cellZone c0;
45  operation volAverage;
46 
47  weightField alpha1;
48 
49  fields
50  (
51  p
52  U
53  );
54  }
55  \endverbatim
56 
57 Usage
58  \table
59  Property | Description | Required | Default value
60  type | Type name: volFieldValue | yes |
61  log | Write data to standard output | no | no
62  writeFields | Write the region field values | yes |
63  writeNumberOfCells | Write the number of cells in the zone | no | no
64  writeVolume | Write the volume of the zone | no | no
65  writeLocation| Write the location (if available) | no | no
66  cellZone | cellZone | yes |
67  operation | Operation to perform | yes |
68  weightField | Name of field to apply weighting | no | none
69  weightFields | Names of fields to apply weighting | no | none
70  fields | List of fields to operate on | yes |
71  \endtable
72 
73  Where \c cellZone options are:
74  \plaintable
75  cellZone <name> | Looks-up the named cellZone
76  cellZone {type <zoneGeneratorType>;...} | \\
77  Generates the cellZone locally
78  cellZone all | Selects all cells
79  \endplaintable
80 
81  The \c operation is one of:
82  \plaintable
83  none | No operation
84  sum | Sum
85  sumMag | Sum of component magnitudes
86  average | Ensemble average
87  volAverage | Volume weighted average
88  volIntegrate | Volume integral
89  min | Minimum
90  max | Maximum
91  minMag | Minimum magnitude
92  maxMag | Maximum magnitude
93  CoV | Coefficient of variation: (standard deviation)/mean
94  UI | Uniformity index: ???
95  \endplaintable
96 
97 See also
98  Foam::functionObjects::fieldValues::fieldValue
99  Foam::Foam::fvCellZone
100  Foam::functionObject
101 
102 SourceFiles
103  volFieldValue.C
104 
105 \*---------------------------------------------------------------------------*/
106 
107 #ifndef volFieldValue_functionObject_H
108 #define volFieldValue_functionObject_H
109 
110 #include "fieldValue.H"
111 #include "fvCellZone.H"
112 
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114 
115 namespace Foam
116 {
117 namespace functionObjects
118 {
119 namespace fieldValues
120 {
121 
122 /*---------------------------------------------------------------------------*\
123  Class volFieldValue Declaration
124 \*---------------------------------------------------------------------------*/
125 
126 class volFieldValue
127 :
128  public fieldValue
129 {
130 
131 public:
132 
133  // Public data types
134 
135  //- Operation type enumeration
136  enum class operationType
137  {
138  none,
139  sum,
140  sumMag,
141  average,
142  volAverage,
143  volIntegrate,
144  min,
145  max,
146  minMag,
147  maxMag,
148  CoV,
149  UI
150  };
151 
152  //- Operation type names
153  static const NamedEnum<operationType, 12> operationTypeNames_;
154 
155 
156  // Public classes
157 
158  //- Forward declare the result structure
159  template<class Type>
160  struct Result;
161 
162 
163 protected:
164 
165  // Protected data
166 
167  //- The cellZone to operate on
168  fvCellZone zone_;
169 
170  //- Operation to apply to values
172 
173  //- Weight field names
175 
176  //- Scale factor
177  scalar scaleFactor_;
178 
179  //- Optionally write the number of faces in the surface
180  const bool writeNCells_;
181 
182  //- Optionally write the area of the surface
183  const bool writeVolume_;
184 
185  //- Optionally write the location if available for this operation
186  const bool writeLocation_;
187 
188 
189  // Protected Member Functions
190 
191  //- Return true if the field name is valid
192  template<class Type>
193  bool validField(const word& fieldName) const;
194 
195  //- Insert field values into values list
196  template<class Type>
197  tmp<Field<Type>> getFieldValues(const word& fieldName) const;
198 
199  //- Apply a comparison operation to the values, returning the limiting
200  // value, its index and processor index
201  template<class Op>
202  void compareScalars
203  (
204  const scalarField& values,
205  const scalar emptyVal,
206  Result<scalar>& result,
207  const Op& op
208  ) const;
209 
210  //- Apply the operation to the values, and return true if successful.
211  // Does nothing unless overloaded below.
212  template<class Type, class ResultType>
213  bool processValues
214  (
215  const Field<Type>& values,
216  const scalarField& weights,
217  const scalarField& V,
218  Result<ResultType>& result
219  ) const;
220 
221  //- Apply Type -> Type operation to the values. Calls
222  // processValuesTypeType.
223  template<class Type>
224  bool processValues
225  (
226  const Field<Type>& values,
227  const scalarField& weights,
228  const scalarField& V,
229  Result<Type>& result
230  ) const;
231 
232  //- Apply Type -> scalar operation to the values
233  template<class Type>
234  bool processValues
235  (
236  const Field<Type>& values,
237  const scalarField& weights,
238  const scalarField& V,
239  Result<scalar>& result
240  ) const;
241 
242  //- Apply scalar -> scalar operation to the values. Calls
243  // processValuesTypeType.
245  (
246  const Field<scalar>& values,
247  const scalarField& weights,
248  const scalarField& V,
249  Result<scalar>& result
250  ) const;
251 
252  //- Apply a Type -> Type operation to the values
253  template<class Type>
255  (
256  const Field<Type>& values,
257  const scalarField& weights,
258  const scalarField& V,
259  Result<Type>& result
260  ) const;
261 
262  //- Output file header location information for a given type
263  template<class Type>
265 
266  //- Output file header information
267  virtual void writeFileHeader(const label i);
268 
269 
270 public:
271 
272  //- Run-time type information
273  TypeName("volFieldValue");
274 
275 
276  // Constructors
277 
278  //- Construct from name, Time and dictionary
280  (
281  const word& name,
282  const Time& runTime,
283  const dictionary& dict
284  );
285 
286  //- Construct from name, objectRegistry and dictionary
288  (
289  const word& name,
290  const objectRegistry& obr,
291  const dictionary& dict
292  );
293 
294 
295  //- Destructor
296  virtual ~volFieldValue();
297 
298 
299  // Public Member Functions
300 
301  //- Templated helper function to output field values
302  template<class Type>
303  bool writeValues
304  (
305  const word& fieldName,
306  const scalarField& weights,
307  const scalarField& V
308  );
309 
310  //- Templated helper function to output field values
311  template<class Type, class ResultType>
312  bool writeValues
313  (
314  const word& fieldName,
315  const Field<Type>& values,
316  const scalarField& weights,
317  const scalarField& V
318  );
319 
320  //- Filter a field according to cellIds
321  template<class Type>
322  tmp<Field<Type>> filterField(const Field<Type>& field) const;
323 
324  //- Read from dictionary
325  virtual bool read(const dictionary&);
326 
327  //- Calculate and write
328  virtual bool write();
329 
330 
331  // Mesh changes
332 
333  //- Update for mesh motion
334  virtual void movePoints(const polyMesh&);
335 
336  //- Update topology using the given map
337  virtual void topoChange(const polyTopoChangeMap&);
338 
339  //- Update from another mesh using the given map
340  virtual void mapMesh(const polyMeshMap&);
341 
342  //- Redistribute or update using the given distribution map
343  virtual void distribute(const polyDistributionMap&);
344 };
345 
346 
347 template<>
348 void volFieldValue::writeFileHeaderLocation<scalar>();
349 
350 
351 /*---------------------------------------------------------------------------*\
352  Class volFieldValue::Result Declaration
353 \*---------------------------------------------------------------------------*/
354 
355 template<class Type>
357 {
358  Type value;
359  label celli;
360  label proci;
361  point cc;
362 };
363 
364 
365 template<class Type>
366 inline Istream& operator>>
367 (
368  Istream& is,
369  volFieldValue::Result<Type>& result
370 )
371 {
372  return is >> result.value >> result.celli >> result.proci >> result.cc;
373 }
374 
375 
376 template<class Type>
377 inline Ostream& operator<<
378 (
379  Ostream& os,
380  const volFieldValue::Result<Type>& result
381 )
382 {
383  return os << result.value << result.celli << result.proci << result.cc;
384 }
385 
386 
387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
388 
389 } // End namespace fieldValues
390 } // End namespace functionObjects
391 } // End namespace Foam
392 
393 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
394 
395 #ifdef NoRepository
396  #include "volFieldValueTemplates.C"
397 #endif
398 
399 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
400 
401 #endif
402 
403 // ************************************************************************* //
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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.
const bool writeVolume_
Optionally write the area of the surface.
bool writeValues(const word &fieldName, const scalarField &weights, const scalarField &V)
Templated helper function to output field values.
const bool writeNCells_
Optionally write the number of faces in the surface.
bool processValuesTypeType(const Field< Type > &values, const scalarField &weights, const scalarField &V, Result< Type > &result) const
Apply a Type -> Type operation to the values.
fvCellZone zone_
The cellZone to operate on.
tmp< Field< Type > > getFieldValues(const word &fieldName) const
Insert field values into values list.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
void writeFileHeaderLocation()
Output file header location information for a given type.
Definition: volFieldValue.C:75
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.
static const NamedEnum< operationType, 12 > operationTypeNames_
Operation type names.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual void writeFileHeader(const label i)
Output file header information.
virtual void movePoints(const polyMesh &)
Update for mesh motion.
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.
const bool writeLocation_
Optionally write the location if available for this operation.
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.
Registry of regIOobjects.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
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