Loading...
Searching...
No Matches
volFieldValue.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2016-2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::functionObjects::fieldValues::volFieldValue
29
30Group
31 grpFieldFunctionObjects
32
33Description
34 Provides a 'volRegion' specialization of the \c fieldValue function object.
35
36 Given a list of user-specified fields and a 'volRegion', a number of
37 operations can be performed, such as sums, averages and integrations.
38
39Usage
40 Minimal example by using \c system/controlDict.functions:
41 \verbatim
42 volFieldValueFO
43 {
44 // Mandatory entries
45 type volFieldValue;
46 libs (fieldFunctionObjects);
47 fields <wordList>; // (<field1> <field2> ... <fieldN>);
48 regionType <word>;
49 operation <word>;
50
51 // Optional entries
52 postOperation <word>;
53 weightField <word>; // alpha1;
54
55 // Inherited entries
56 ...
57 }
58 \endverbatim
59
60 where the entries mean:
61 \table
62 Property | Description | Type | Reqd | Deflt
63 type | Type name: volFieldValue | word | yes | -
64 libs | Library name: fieldFunctionObjects | word | yes | -
65 fields | Names of operand fields | wordList | yes | -
66 regionType | Face regionType: see below | word | yes | -
67 operation | Operation type: see below | word | yes | -
68 postOperation | Post-operation type: see below | word | no | none
69 weightField | Name of field to apply weighting | word | maybe |
70 weightFields | Names of fields to apply weighting | wordList | maybe |
71 \endtable
72
73 The inherited entries are elaborated in:
74 - \link fieldValue.H \endlink
75 - \link volRegion.H \endlink
76
77 Options for the \c regionType entry:
78 \plaintable
79 cellZone | requires a 'name' entry to specify the cellZone
80 all | all cells
81 \endplaintable
82
83 Options for the \c operation entry:
84 \plaintable
85 none | No operation
86 min | Minimum
87 max | Maximum
88 sum | Sum
89 sumMag | Sum of component magnitudes
90 average | Ensemble average
91 volAverage | Volume weighted average
92 volIntegrate | Volume integral
93 CoV | Coefficient of variation: standard deviation/mean
94 weightedSum | Weighted sum
95 weightedAverage | Weighted average
96 weightedVolAverage | Weighted volume average
97 weightedVolIntegrate | Weighted volume integral
98 \endplaintable
99
100 Options for the \c postOperation entry:
101 \plaintable
102 none | No additional operation after calculation
103 mag | Component-wise \c mag() after normal operation
104 sqrt | Component-wise \c sqrt() after normal operation
105 \endplaintable
106
107SourceFiles
108 volFieldValue.C
109 volFieldValueTemplates.C
110
111\*---------------------------------------------------------------------------*/
112
113#ifndef Foam_functionObjects_volFieldValue_H
114#define Foam_functionObjects_volFieldValue_H
115
116#include "fieldValue.H"
117#include "volRegion.H"
118
119// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
120
121namespace Foam
122{
123namespace functionObjects
124{
125namespace fieldValues
126{
127
128/*---------------------------------------------------------------------------*\
129 Class volFieldValue Declaration
130\*---------------------------------------------------------------------------*/
131
132class volFieldValue
133:
134 public fieldValue,
135 public volRegion
136{
137public:
138
139 // Public Data Types
140
141 //- Operation type enumeration
142 enum operationType
143 {
144 // Normal operations
145
146 opNone = 0,
147 opMin,
148 opMax,
149 opSum,
150 opSumMag,
151 opAverage,
154 opCoV,
155
156 // Operations returning scalar - bitmask value
157 typeScalar = 0x100,
158
159 // Weighted variants
160 // Operations using weighting - bitmask value
161 typeWeighted = 0x200,
162
165
168
171
174
175 // Variants using absolute weighting
176 // Operation using mag (eg, for weighting) - bitmask value
177 typeAbsolute = 0x400,
178 };
179
180 //- Operation type names
181 static const Enum<operationType> operationTypeNames_;
182
183
184 //- Post-operation type enumeration
186 {
187 postOpNone,
188 postOpMag,
190 };
191
192 //- Operation type names
193 static const Enum<postOperationType> postOperationTypeNames_;
194
195
196protected:
197
198 // Protected Data
199
200 //- Operation to apply to values
202
203 //- Optional post-evaluation operation
205
206 //- Weight field name(s) - optional
208
209
210 // Protected Member Functions
211
212 //- True if the operation needs the cell-volume
213 bool usesVol() const noexcept;
214
215 //- True if the operation variant uses mag
216 inline bool is_magOp() const noexcept;
217
218 //- True if the operation variant uses a weight-field
219 inline bool is_weightedOp() const noexcept;
220
221 //- True if field is non-empty on any processor.
222 inline bool canWeight(const scalarField& fld) const;
223
224 //- Return true if the field name is valid
225 template<class Type>
226 bool validField(const word& fieldName) const;
227
228 //- Insert field values into values list
229 template<class Type>
230 tmp<Field<Type>> getFieldValues
231 (
232 const word& fieldName,
233 const bool mandatory = false
234 ) const;
235
236 //- Apply the 'operation' to the values
237 template<class Type>
238 Type processValues
239 (
240 const Field<Type>& values,
241 const scalarField& V,
242 const scalarField& weightField
243 ) const;
244
245 //- Helper function to output field values
246 label writeAll
247 (
248 const scalarField& V,
249 const scalarField& weightField
250 );
251
252 //- Templated helper function to output field values
253 template<class Type>
254 bool writeValues
255 (
256 const word& fieldName,
257 const scalarField& V,
258 const scalarField& weightField
259 );
260
261 //- Filter a field according to cellIds
262 template<class Type>
263 tmp<Field<Type>> filterField(const Field<Type>& field) const;
264
265 //- Output file header information
266 virtual void writeFileHeader(Ostream& os) const;
267
268
269public:
271 //- Declare type-name, virtual type (with debug switch)
272 TypeName("volFieldValue");
275 // Constructors
277 //- Construct from name, Time and dictionary
279 (
280 const word& name,
281 const Time& runTime,
282 const dictionary& dict
283 );
285 //- Construct from name, objectRegistry and dictionary
288 const word& name,
289 const objectRegistry& obr,
291 );
292
293 //- No copy construct
294 volFieldValue(const volFieldValue&) = delete;
295
296 //- No copy assignment
297 void operator=(const volFieldValue&) = delete;
298
299
300 //- Destructor
301 virtual ~volFieldValue() = default;
302
303
304 // Member Functions
305
306 //- Read the function-object dictionary
307 virtual bool read(const dictionary& dict);
308
309 //- Write the function-object results
310 virtual bool write();
311};
313
314// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316} // End namespace fieldValues
317} // End namespace functionObjects
318} // End namespace Foam
319
320// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321
322#include "volFieldValueI.H"
323
324// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325
326#ifdef NoRepository
327 #include "volFieldValueTemplates.C"
328#endif
329
330// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331
332#endif
333
334// ************************************************************************* //
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const word & name() const noexcept
Return the name of this functionObject.
fieldValue(const word &name, const Time &runTime, const dictionary &dict, const word &valueType)
Construct from name, Time and dictionary.
Definition fieldValue.C:41
const dictionary & dict() const noexcept
Return the reference to the construction dictionary.
Definition fieldValueI.H:24
Provides a 'volRegion' specialization of the fieldValue function object.
bool writeValues(const word &fieldName, const scalarField &V, const scalarField &weightField)
Templated helper function to output field values.
tmp< Field< Type > > getFieldValues(const word &fieldName, const bool mandatory=false) const
Insert field values into values list.
postOperationType postOperation_
Optional post-evaluation operation.
Type processValues(const Field< Type > &values, const scalarField &V, const scalarField &weightField) const
Apply the 'operation' to the values.
bool usesVol() const noexcept
True if the operation needs the cell-volume.
bool canWeight(const scalarField &fld) const
True if field is non-empty on any processor.
postOperationType
Post-operation type enumeration.
@ postOpNone
No additional operation after calculation.
@ postOpSqrt
Component-wise sqrt after normal operation.
@ postOpMag
Component-wise mag after normal operation.
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
bool is_magOp() const noexcept
True if the operation variant uses mag.
operationType operation_
Operation to apply to values.
label writeAll(const scalarField &V, const scalarField &weightField)
Helper function to output field values.
static const Enum< operationType > operationTypeNames_
Operation type names.
volFieldValue(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
wordList weightFieldNames_
Weight field name(s) - optional.
virtual void writeFileHeader(Ostream &os) const
Output file header information.
bool validField(const word &fieldName) const
Return true if the field name is valid.
tmp< Field< Type > > filterField(const Field< Type > &field) const
Filter a field according to cellIds.
TypeName("volFieldValue")
Declare type-name, virtual type (with debug switch).
bool is_weightedOp() const noexcept
True if the operation variant uses a weight-field.
static const Enum< postOperationType > postOperationTypeNames_
Operation type names.
virtual bool write()
Write the function-object results.
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
scalar V() const
Return total volume of the selected region.
Definition volRegionI.H:52
volRegion(const fvMesh &mesh, const dictionary &dict)
Construct from fvMesh and dictionary.
Definition volRegion.C:143
Registry of regIOobjects.
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
rDeltaTY field()
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const direction noexcept
Definition scalarImpl.H:265