momentum.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) 2018-2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::functionObjects::momentum
28
29Group
30 grpFieldFunctionObjects
31
32Description
33 Computes linear/angular momentum, reporting integral values
34 and optionally writing the fields.
35
36 Operands:
37 \table
38 Operand | Type | Location
39 input | - | -
40 output file | dat | $FOAM_CASE/postProcessing/<FO>/<time>/<file>
41 output field | - | -
42 \endtable
43
44Usage
45 Minimal example by using \c system/controlDict.functions:
46 \verbatim
47 momentum1
48 {
49 // Mandatory entries (unmodifiable)
50 type momentum;
51 libs (fieldFunctionObjects);
52
53 // Optional entries (runtime modifiable)
54 regionType all;
55 writeMomentum yes;
56 writePosition yes;
57 writeVelocity yes;
58 p p;
59 U U;
60 rho rho;
61 rhoRef 1.0;
62
63 cylindrical true;
64 origin (0 0 0);
65 e1 (1 0 0);
66 e3 (0 0 1);
67
68 // Optional (inherited) entries
69 ...
70 }
71 \endverbatim
72
73 where the entries mean:
74 \table
75 Property | Description | Type | Req'd | Dflt
76 type | Type name: momentum | word | yes | -
77 libs | Library name: fieldFunctionObjects | word | yes | -
78 regionType | Selection type: all/cellSet/cellZone | word | no | all
79 writeMomentum | Write (linear, angular) momentum fields | bool | no | no
80 writePosition | Write angular position component fields | bool | no | no
81 writeVelocity | Write angular velocity fields | bool | no | no
82 p | Pressure field name | word | no | p
83 U | Velocity field name | word | no | U
84 rho | Density field name | word | no | rho
85 rhoRef | Reference density (incompressible) | scalar | no | 1.0
86 cylindrical | Use cylindrical coordinates | bool | no | no
87 origin | Origin for cylindrical coordinates | vector | conditional | -
88 name | Name of cellSet/cellZone if required | word | conditional | -
89 \endtable
90
91 The inherited entries are elaborated in:
92 - \link functionObject.H \endlink
93 - \link writeFile.H \endlink
94
95 Usage by the \c postProcess utility is not available.
96
97Note
98 - For incompressible cases, the value of \c rhoRef is used.
99 - When specifying the cylindrical coordinate system, the rotation
100 can be specified directly with e1/e2/e3 axes, or via a \c rotation
101 sub-dictionary
102 For example,
103 \verbatim
104 origin (0 0 0);
105 rotation
106 {
107 type cylindrical;
108 axis (0 0 1);
109 }
110 \endverbatim
111
112See also
113 - Foam::functionObject
114 - Foam::functionObjects::fvMeshFunctionObject
115 - Foam::functionObjects::volRegion
116 - Foam::functionObjects::writeFile
117 - ExtendedCodeGuide::functionObjects::field::momentum
118
119SourceFiles
120 momentum.C
121
122\*---------------------------------------------------------------------------*/
123
124#ifndef functionObjects_momentum_H
125#define functionObjects_momentum_H
126
127#include "fvMeshFunctionObject.H"
128#include "writeFile.H"
129#include "cylindricalCS.H"
130#include "volFieldsFwd.H"
131#include "volRegion.H"
132
133// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134
135namespace Foam
136{
137
138// Forward Declarations
139class dimensionSet;
140
141namespace functionObjects
142{
143
144/*---------------------------------------------------------------------------*\
145 Class momentum Declaration
146\*---------------------------------------------------------------------------*/
147
148class momentum
149:
150 public fvMeshFunctionObject,
151 public volRegion,
152 public writeFile
153{
154 // Private Member Functions
155
156 //- Remove calculated fields from the registry
157 void purgeFields();
158
159 //- Calculate the fields and integral values
160 void calc();
161
162 //- Allocate a new zero geometric field
163 template<class GeoField>
164 autoPtr<GeoField> newField
165 (
166 const word& baseName,
167 const dimensionSet& dims,
168 bool registerObject=true
169 ) const;
170
171
172protected:
173
174 // Protected Data
175
176 //- Integral (linear) momentum
178
179 //- Integral angular momentum
181
182
183 // Read from dictionary
184
185 //- The velocity field name (optional)
186 word UName_;
187
188 //- The pressure field name (optional)
189 // Only used to determine incompressible/compressible
190 word pName_;
191
192 //- The density field name (optional)
193 word rhoName_;
194
195 //- Reference density (for incompressible)
196 scalar rhoRef_;
197
198 //- Coordinate system for evaluating angular momentum
199 coordSystem::cylindrical csys_;
200
201 //- Are we using the cylindrical coordinate system?
202 bool hasCsys_;
203
204 //- Write fields flag
205 bool writeMomentum_;
206
207 //- Write fields flag
208 bool writeVelocity_;
209
210 //- Write fields flag
211 bool writePosition_;
212
213 //- Initialised flag
214 bool initialised_;
215
216
217 // Protected Member Functions
218
219 //- Initialise the fields
220 void initialise();
221
222 //- Output file header information
223 virtual void writeFileHeader(Ostream& os);
224
225 //- Write momentum data
226 void writeValues(Ostream& os);
227
228
229public:
230
231 //- Runtime type information
232 TypeName("momentum");
233
234
235 // Constructors
236
237 //- Construct from Time and dictionary
239 (
240 const word& name,
241 const Time& runTime,
242 const dictionary& dict,
243 const bool readFields = true
244 );
245
246 //- Construct from objectRegistry and dictionary
248 (
249 const word& name,
250 const objectRegistry& obr,
251 const dictionary& dict,
252 const bool readFields = true
253 );
254
255 //- No copy construct
256 momentum(const momentum&) = delete;
257
258 //- No copy assignment
259 void operator=(const momentum&) = delete;
260
261
262 //- Destructor
263 virtual ~momentum() = default;
264
265
266 // Member Functions
267
268 //- Read the momentum data
269 virtual bool read(const dictionary&);
270
271 //- Calculate and report the integral momentum
272 virtual bool execute();
273
274 //- Write the momentum, possibly angular momentum and velocity
275 virtual bool write();
277 //- Update for changes of mesh
278 virtual void updateMesh(const mapPolyMesh&);
280 //- Update for mesh point-motion
281 virtual void movePoints(const polyMesh&);
282};
283
284
285// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
286
287} // End namespace functionObjects
288} // End namespace Foam
290// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291
292#endif
293
294// ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A cylindrical coordinate system (r-theta-z). The coordinate system angle theta is always in radians.
Definition: cylindricalCS.H:74
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:109
const word & name() const noexcept
Return the name of this functionObject.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Computes linear/angular momentum, reporting integral values and optionally writing the fields.
Definition: momentum.H:252
word pName_
The pressure field name (optional)
Definition: momentum.H:289
scalar rhoRef_
Reference density (for incompressible)
Definition: momentum.H:295
void initialise()
Initialise the fields.
Definition: momentum.C:272
void operator=(const momentum &)=delete
No copy assignment.
word UName_
The velocity field name (optional)
Definition: momentum.H:285
bool hasCsys_
Are we using the cylindrical coordinate system?
Definition: momentum.H:301
momentum(const momentum &)=delete
No copy construct.
bool writePosition_
Write fields flag.
Definition: momentum.H:310
bool writeMomentum_
Write fields flag.
Definition: momentum.H:304
bool initialised_
Initialised flag.
Definition: momentum.H:313
void writeValues(Ostream &os)
Write momentum data.
Definition: momentum.C:305
momentum(const word &name, const Time &runTime, const dictionary &dict, const bool readFields=true)
Construct from Time and dictionary.
Definition: momentum.C:349
vector sumMomentum_
Integral (linear) momentum.
Definition: momentum.H:276
virtual ~momentum()=default
Destructor.
TypeName("momentum")
Runtime type information.
word rhoName_
The density field name (optional)
Definition: momentum.H:292
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
Definition: momentum.C:599
vector sumAngularMom_
Integral angular momentum.
Definition: momentum.H:279
virtual void writeFileHeader(Ostream &os)
Output file header information.
Definition: momentum.C:228
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition: momentum.C:592
virtual bool execute()
Calculate and report the integral momentum.
Definition: momentum.C:484
virtual bool write()
Write the momentum, possibly angular momentum and velocity.
Definition: momentum.C:510
coordSystem::cylindrical csys_
Coordinate system for evaluating angular momentum.
Definition: momentum.H:298
bool writeVelocity_
Write fields flag.
Definition: momentum.H:307
virtual bool read(const dictionary &)
Read the momentum data.
Definition: momentum.C:414
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Definition: readFields.H:158
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
Volume (cell) region selection class.
Definition: volRegion.H:116
Base class for writing single files from the function objects.
Definition: writeFile.H:120
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:162
Registry of regIOobjects.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
A class for handling words, derived from Foam::string.
Definition: word.H:68
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73