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 -------------------------------------------------------------------------------
10 License
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 
26 Class
27  Foam::functionObjects::momentum
28 
29 Group
30  grpFieldFunctionObjects
31 
32 Description
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 
44 Usage
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 
97 Note
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 
112 See also
113  - Foam::functionObject
114  - Foam::functionObjects::fvMeshFunctionObject
115  - Foam::functionObjects::volRegion
116  - Foam::functionObjects::writeFile
117  - ExtendedCodeGuide::functionObjects::field::momentum
118 
119 SourceFiles
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 
135 namespace Foam
136 {
137 
138 // Forward Declarations
139 class dimensionSet;
140 
141 namespace functionObjects
142 {
143 
144 /*---------------------------------------------------------------------------*\
145  Class momentum Declaration
146 \*---------------------------------------------------------------------------*/
147 
148 class 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 
172 protected:
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 
229 public:
230 
231  //- Runtime type information
232  TypeName("momentum");
233 
234 
235  // Constructors
236 
237  //- Construct from Time and dictionary
238  momentum
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();
276 
277  //- Update for changes of mesh
278  virtual void updateMesh(const mapPolyMesh&);
279 
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
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
292 #endif
293 
294 // ************************************************************************* //
Foam::functionObjects::momentum::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition: momentum.C:592
Foam::functionObjects::momentum::read
virtual bool read(const dictionary &)
Read the momentum data.
Definition: momentum.C:414
Foam::functionObjects::momentum::pName_
word pName_
The pressure field name (optional)
Definition: momentum.H:289
runTime
engineTime & runTime
Definition: createEngineTime.H:13
volFieldsFwd.H
writeFile.H
Foam::functionObjects::momentum::hasCsys_
bool hasCsys_
Are we using the cylindrical coordinate system?
Definition: momentum.H:301
Foam::functionObjects::momentum::write
virtual bool write()
Write the momentum, possibly angular momentum and velocity.
Definition: momentum.C:510
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
fvMeshFunctionObject.H
Foam::functionObjects::volRegion
Volume (cell) region selection class.
Definition: volRegion.H:115
Foam::functionObjects::momentum::writeVelocity_
bool writeVelocity_
Write fields flag.
Definition: momentum.H:307
Foam::functionObjects::momentum::initialised_
bool initialised_
Initialised flag.
Definition: momentum.H:313
Foam::functionObjects::momentum::momentum
momentum(const word &name, const Time &runTime, const dictionary &dict, const bool readFields=true)
Construct from Time and dictionary.
Definition: momentum.C:349
Foam::dimensionSet
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:108
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::momentum::sumMomentum_
vector sumMomentum_
Integral (linear) momentum.
Definition: momentum.H:276
Foam::functionObjects::momentum::csys_
coordSystem::cylindrical csys_
Coordinate system for evaluating angular momentum.
Definition: momentum.H:298
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::functionObjects::momentum::operator=
void operator=(const momentum &)=delete
No copy assignment.
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::functionObjects::momentum::execute
virtual bool execute()
Calculate and report the integral momentum.
Definition: momentum.C:484
Foam::functionObjects::momentum::rhoRef_
scalar rhoRef_
Reference density (for incompressible)
Definition: momentum.H:295
Foam::functionObjects::momentum::writePosition_
bool writePosition_
Write fields flag.
Definition: momentum.H:310
Foam::functionObjects::momentum::~momentum
virtual ~momentum()=default
Destructor.
cylindricalCS.H
Foam::coordSystem::cylindrical
A cylindrical coordinate system (r-theta-z). The coordinate system angle theta is always in radians.
Definition: cylindricalCS.H:71
Foam::functionObjects::momentum::TypeName
TypeName("momentum")
Runtime type information.
Foam::functionObjects::momentum
Computes linear/angular momentum, reporting integral values and optionally writing the fields.
Definition: momentum.H:247
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::momentum::rhoName_
word rhoName_
The density field name (optional)
Definition: momentum.H:292
Foam::functionObjects::momentum::writeFileHeader
virtual void writeFileHeader(Ostream &os)
Output file header information.
Definition: momentum.C:228
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::readFields
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.
Definition: ReadFieldsTemplates.C:312
volRegion.H
Foam::functionObjects::momentum::movePoints
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
Definition: momentum.C:599
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::functionObjects::momentum::UName_
word UName_
The velocity field name (optional)
Definition: momentum.H:285
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::functionObjects::momentum::initialise
void initialise()
Initialise the fields.
Definition: momentum.C:272
Foam::functionObjects::momentum::sumAngularMom_
vector sumAngularMom_
Integral angular momentum.
Definition: momentum.H:279
Foam::Vector< scalar >
Foam::functionObjects::momentum::writeValues
void writeValues(Ostream &os)
Write momentum data.
Definition: momentum.C:305
Foam::functionObjects::regionFunctionObject::obr
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
Definition: regionFunctionObject.C:47
Foam::functionObjects::momentum::writeMomentum_
bool writeMomentum_
Write fields flag.
Definition: momentum.H:304
Foam::functionObjects::readFields
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Definition: readFields.H:155
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:119
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56