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 and optionally
34  writing the fields.
35 
36  Operands:
37  \table
38  Operand | Type | Location
39  input | - | -
40  output file | dat | postProcessing/<FO>/<time>/file
41  output field | - | -
42  \endtable
43 
44 Usage
45  Minimal example by using \c system/controlDict.functions:
46  \verbatim
47  momentumFO
48  {
49  // Mandatory entries
50  type momentum;
51  libs (fieldFunctionObjects);
52 
53  // Optional entries
54  regionType <word>;;
55  writeMomentum <bool>;
56  writePosition <bool>;
57  writeVelocity <bool>;
58  p <word>;
59  U <word>;
60  rho <word>;
61  rhoRef <scalar>;
62  cylindrical <bool>;
63 
64  // Conditional entries
65 
66  // when 'cylindrical' is 'true'
67  origin (0 0 0);
68  e1 (1 0 0);
69  e3 (0 0 1);
70 
71  // Inherited entries
72  ...
73  }
74  \endverbatim
75 
76  where the entries mean:
77  \table
78  Property | Description | Type | Reqd | Deflt
79  type | Type name: momentum | word | yes | -
80  libs | Library name: fieldFunctionObjects | word | yes | -
81  regionType | Selection type: all/cellSet/cellZone | word | no | all
82  writeMomentum | Write (linear, angular) momentum fields | bool | no | no
83  writePosition | Write angular position component fields | bool | no | no
84  writeVelocity | Write angular velocity fields | bool | no | no
85  p | Pressure field name | word | no | p
86  U | Velocity field name | word | no | U
87  rho | Density field name | word | no | rho
88  rhoRef | Reference density (incompressible) | scalar | no | 1.0
89  cylindrical | Use cylindrical coordinates | bool | no | no
90  origin | Origin for cylindrical coordinates | vector | conditional | -
91  name | Name of cellSet/cellZone if required | word | conditional | -
92  \endtable
93 
94  The inherited entries are elaborated in:
95  - \link functionObject.H \endlink
96  - \link writeFile.H \endlink
97 
98 Note
99  - For incompressible cases, the value of \c rhoRef is used.
100  - When specifying the cylindrical coordinate system, the rotation
101  can be specified directly with e1/e2/e3 axes, or via a \c rotation
102  sub-dictionary
103  For example,
104  \verbatim
105  origin (0 0 0);
106  rotation
107  {
108  type cylindrical;
109  axis (0 0 1);
110  }
111  \endverbatim
112 
113 SourceFiles
114  momentum.C
115 
116 \*---------------------------------------------------------------------------*/
117 
118 #ifndef Foam_functionObjects_momentum_H
119 #define Foam_functionObjects_momentum_H
120 
121 #include "fvMeshFunctionObject.H"
122 #include "writeFile.H"
123 #include "cylindricalCS.H"
124 #include "volFieldsFwd.H"
125 #include "volRegion.H"
126 
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128 
129 namespace Foam
130 {
131 
132 // Forward Declarations
133 class dimensionSet;
134 
135 namespace functionObjects
136 {
137 
138 /*---------------------------------------------------------------------------*\
139  Class momentum Declaration
140 \*---------------------------------------------------------------------------*/
141 
142 class momentum
143 :
144  public fvMeshFunctionObject,
145  public volRegion,
146  public writeFile
147 {
148  // Private Member Functions
149 
150  //- Remove calculated fields from the registry
151  void purgeFields();
152 
153  //- Calculate the fields and integral values
154  void calc();
155 
156  //- Allocate a new zero geometric field
157  template<class GeoField>
158  autoPtr<GeoField> newField
159  (
160  const word& baseName,
161  const dimensionSet& dims,
162  bool registerObject=true
163  ) const;
164 
165 
166 protected:
167 
168  // Protected Data
169 
170  //- Integral (linear) momentum
172 
173  //- Integral angular momentum
175 
176 
177  // Read from dictionary
178 
179  //- The velocity field name (optional)
180  word UName_;
181 
182  //- The pressure field name (optional)
183  // Only used to determine incompressible/compressible
184  word pName_;
185 
186  //- The density field name (optional)
187  word rhoName_;
188 
189  //- Reference density (for incompressible)
190  scalar rhoRef_;
191 
192  //- Coordinate system for evaluating angular momentum
193  coordSystem::cylindrical csys_;
194 
195  //- Are we using the cylindrical coordinate system?
196  bool hasCsys_;
197 
198  //- Write fields flag
199  bool writeMomentum_;
200 
201  //- Write fields flag
202  bool writeVelocity_;
203 
204  //- Write fields flag
205  bool writePosition_;
206 
207  //- Initialised flag
208  bool initialised_;
209 
210 
211  // Protected Member Functions
212 
213  //- Initialise the fields
214  void initialise();
215 
216  //- Output file header information
217  virtual void writeFileHeader(Ostream& os);
218 
219  //- Write momentum data
220  void writeValues(Ostream& os);
221 
222 
223 public:
224 
225  //- Runtime type information
226  TypeName("momentum");
227 
228 
229  // Constructors
230 
231  //- Construct from name, Time and dictionary
232  momentum
233  (
234  const word& name,
235  const Time& runTime,
236  const dictionary& dict,
237  const bool readFields = true
238  );
239 
240  //- Construct from objectRegistry and dictionary
241  momentum
242  (
243  const word& name,
244  const objectRegistry& obr,
245  const dictionary& dict,
246  const bool readFields = true
247  );
248 
249  //- No copy construct
250  momentum(const momentum&) = delete;
251 
252  //- No copy assignment
253  void operator=(const momentum&) = delete;
254 
255 
256  //- Destructor
257  virtual ~momentum() = default;
258 
259 
260  // Member Functions
261 
262  //- Read the function-object dictionary
263  virtual bool read(const dictionary& dict);
264 
265  //- Execute the function-object operations
266  virtual bool execute();
267 
268  //- Write the function-object results
269  virtual bool write();
270 
271  //- Update for changes of mesh
272  virtual void updateMesh(const mapPolyMesh&);
273 
274  //- Update for mesh point-motion
275  virtual void movePoints(const polyMesh&);
276 };
277 
278 
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 
281 } // End namespace functionObjects
282 } // End namespace Foam
283 
284 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 
286 #endif
288 // ************************************************************************* //
Computes linear/angular momentum, reporting integral values and optionally writing the fields...
Definition: momentum.H:237
dictionary dict
bool writeMomentum_
Write fields flag.
Definition: momentum.H:319
void operator=(const momentum &)=delete
No copy assignment.
momentum(const word &name, const Time &runTime, const dictionary &dict, const bool readFields=true)
Construct from name, Time and dictionary.
Definition: momentum.C:343
Forwards and collection of common volume field types.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:130
vector sumMomentum_
Integral (linear) momentum.
Definition: momentum.H:274
bool hasCsys_
Are we using the cylindrical coordinate system?
Definition: momentum.H:314
engineTime & runTime
bool writePosition_
Write fields flag.
Definition: momentum.H:329
virtual bool execute()
Execute the function-object operations.
Definition: momentum.C:478
scalar rhoRef_
Reference density (for incompressible)
Definition: momentum.H:304
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
const word & name() const noexcept
Return the name of this functionObject.
bool initialised_
Initialised flag.
Definition: momentum.H:334
word UName_
The velocity field name (optional)
Definition: momentum.H:287
coordSystem::cylindrical csys_
Coordinate system for evaluating angular momentum.
Definition: momentum.H:309
A class for handling words, derived from Foam::string.
Definition: word.H:63
vector sumAngularMom_
Integral angular momentum.
Definition: momentum.H:279
void writeValues(Ostream &os)
Write momentum data.
Definition: momentum.C:299
Vector< scalar > vector
Definition: vector.H:57
void initialise()
Initialise the fields.
Definition: momentum.C:266
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Definition: readFields.H:143
OBJstream os(runTime.globalPath()/outputName)
virtual ~momentum()=default
Destructor.
TypeName("momentum")
Runtime type information.
word pName_
The pressure field name (optional)
Definition: momentum.H:294
word rhoName_
The density field name (optional)
Definition: momentum.H:299
virtual bool write()
Write the function-object results.
Definition: momentum.C:504
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition: momentum.C:586
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
virtual void writeFileHeader(Ostream &os)
Output file header information.
Definition: momentum.C:222
bool writeVelocity_
Write fields flag.
Definition: momentum.H:324
Registry of regIOobjects.
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
Definition: momentum.C:408
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
Definition: momentum.C:593
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
Namespace for OpenFOAM.