forces.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-2016 OpenFOAM Foundation
9 Copyright (C) 2015-2022 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::forces
29
30Group
31 grpForcesFunctionObjects
32
33Description
34 Computes forces and moments over a given list of patches by integrating
35 pressure and viscous forces and moments, and optionally resistance forces
36 and moments from porous zones.
37
38 Forces and moments are output in their total and constituent components:
39 - total forces and moments
40 - pressure contributions
41 - viscous contributions
42 - porous resistance contributions (optional)
43
44 Forces and moments can be computed and output in:
45 - the global Cartesian coordinate system (default)
46 - a user-defined Cartesian coordinate system
47
48 Operands:
49 \table
50 Operand | Type | Location
51 input | - | -
52 output file | dat | postProcessing/<FO>/<time>/<file>s
53 output field | volVectorField | <time>/<outField>s
54 \endtable
55
56 where \c <file>s:
57 \verbatim
58 force.dat | Forces
59 moment.dat | Moments
60 \endverbatim
61
62 where \c <outField>s:
63 \verbatim
64 <namePrefix>:force | Force field
65 <namePrefix>:moment | Moment field
66 \endverbatim
67
68Usage
69 Minimal example by using \c system/controlDict.functions:
70 \verbatim
71 <namePrefix>
72 {
73 // Mandatory entries
74 type forces;
75 libs (forces);
76 patches (<wordRes>);
77
78 // Optional entries
79 directForceDensity <bool>;
80 porosity <bool>;
81 writeFields <bool>;
82 useNamePrefix <bool>;
83
84 // Conditional mandatory entries
85
86 // if directForceDensity == true
87 fD <word>;
88
89
90 // Cartesian coordinate system specification when
91 // evaluating forces and moments, either of the below
92
93 // Option-1, i.e. the centre of rotation
94 // by inherently using e3=(0 0 1) and e1=(1 0 0)
95 CofR (0 0 0); // Centre of rotation
96
97 // Option-2, i.e. local coordinate system specification
98 origin (0 0 0);
99 e1 (1 0 0);
100 e3 (0 0 1); // (e1, e2) or (e2, e3) or (e3, e1)
101
102 // Option-3, i.e. general coordinate system specification
103 coordinateSystem
104 {
105 type cartesian;
106 origin (0 0 0);
107 rotation
108 {
109 type axes;
110 e3 (0 0 1);
111 e1 (1 0 0); // (e1, e2) or (e2, e3) or (e3, e1)
112 }
113 }
114
115 // Conditional optional entries
116
117 // if directForceDensity == false
118 p <word>;
119 U <word>;
120 rho <word>;
121 rhoInf <scalar>; // enabled if rho=rhoInf
122 pRef <scalar>;
123
124 // Inherited entries
125 ...
126 }
127 \endverbatim
128
129 where the entries mean:
130 \table
131 Property | Description | Type | Reqd | Deflt
132 type | Type name: forces | word | yes | -
133 libs | Library name: forces | word | yes | -
134 patches | Names of operand patches | wordRes | yes | -
135 directForceDensity | Flag to directly supply force density <!--
136 --> | bool | no | false
137 porosity | Flag to include porosity contributions | bool | no | false
138 writeFields | Flag to write force and moment fields | bool | no | false
139 useNamePrefix | Flag to include prefix for field names | bool | no | false
140 CofR | Centre of rotation | vector | cndtnl | -
141 origin | Origin of coordinate system | vector | cndtnl | -
142 e3 | e3 coordinate axis | vector | cndtnl | -
143 e1 | e1 coordinate axis | vector | cndtnl | -
144 coordinateSystem | Coordinate system specifier | dictionary | cndtnl | -
145 fD | Name of force density field | word | cndtnl | -
146 p | Name of pressure field | word | cndtnl | p
147 U | Name of velocity field | word | cndtnl | U
148 rho | Name of density field | word | cndtnl | rho
149 rhoInf | Value of reference density | scalar | cndtnl | -
150 pRef | Value of reference pressure | scalar | cndtnl | 0
151 \endtable
152
153 The inherited entries are elaborated in:
154 - \link functionObject.H \endlink
155 - \link writeFile.H \endlink
156 - \link coordinateSystem.H \endlink
157
158Note
159 - For incompressible cases, set \c rho to \c rhoInf.
160 You will then be required to provide a \c rhoInf
161 value corresponding to the constant freestream density.
162 - \c writeControl and \c writeInterval entries of function
163 object do control when to output force and moment files and fields.
164
165SourceFiles
166 forces.C
167
168\*---------------------------------------------------------------------------*/
169
170#ifndef Foam_functionObjects_forces_H
171#define Foam_functionObjects_forces_H
172
173#include "fvMeshFunctionObject.H"
174#include "writeFile.H"
175#include "coordinateSystem.H"
176#include "volFieldsFwd.H"
177
178// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179
180namespace Foam
181{
182
183namespace functionObjects
184{
185
186/*---------------------------------------------------------------------------*\
187 Class forces Declaration
188\*---------------------------------------------------------------------------*/
189
190class forces
191:
192 public fvMeshFunctionObject,
193 public writeFile
194{
195protected:
196
197 // Protected Data
198
199 // Fields
200
201 //- Sum of patch pressure forces
203
204 //- Sum of patch viscous forces
206
207 //- Sum of patch pressure moments
209
210 //- Sum of patch viscous moments
212
213 //- Sum of internal forces
215
216 //- Sum of internal moments
218
219
220 // File streams
221
222 //- File stream for forces
223 autoPtr<OFstream> forceFilePtr_;
224
225 //- File stream for moments
226 autoPtr<OFstream> momentFilePtr_;
227
228
229 // Read from dictionary
230
231 //- Coordinate system used when evaluating forces and moments
232 autoPtr<coordinateSystem> coordSysPtr_;
233
234 //- Names of operand patches
236
237 //- Reference density needed for incompressible calculations
238 scalar rhoRef_;
239
240 //- Reference pressure
241 scalar pRef_;
242
243 //- Name of pressure field
244 word pName_;
245
246 //- Name of velocity field
247 word UName_;
248
249 //- Name of density field
250 word rhoName_;
251
252 //- Name of force density field
253 word fDName_;
254
255 //- Flag to directly supply force density
257
258 //- Flag to include porosity effects
259 bool porosity_;
260
261 //- Flag to write force and moment fields
262 bool writeFields_;
263
264 //- Flag of initialisation (internal)
265 bool initialised_;
266
267
268 // Protected Member Functions
269
270 //- Set the co-ordinate system from dictionary and axes names
272 (
273 const dictionary& dict,
274 const word& e3Name = word::null,
275 const word& e1Name = word::null
276 );
277
278 //- Return access to the force field
280
281 //- Return access to the moment field
283
284 //- Initialise containers and fields
285 void initialise();
286
287 //- Reset containers and fields
288 void reset();
289
290 // Evaluation
291
292 //- Return the effective stress (viscous + turbulent)
293 tmp<volSymmTensorField> devRhoReff() const;
294
295 //- Return dynamic viscosity field
296 tmp<volScalarField> mu() const;
297
298 //- Return rho if specified otherwise rhoRef
299 tmp<volScalarField> rho() const;
300
301 //- Return rhoRef if the pressure field is
302 //- dynamic (i.e. p/rho), otherwise return 1
303 scalar rho(const volScalarField& p) const;
304
305 //- Add patch contributions to force and moment fields
307 (
308 const label patchi,
309 const vectorField& Md,
310 const vectorField& fP,
311 const vectorField& fV
312 );
313
314 //- Add cell contributions to force and
315 //- moment fields, and include porosity effects
317 (
318 const labelList& cellIDs,
319 const vectorField& Md,
320 const vectorField& f
321 );
322
323
324 // I-O
325
326 //- Create the integrated-data files
328
329 //- Write header for an integrated-data file
331 (
332 const word& header,
334 ) const;
335
336 //- Write integrated data to files
338
339 //- Write integrated data to a file
341 (
342 const vector& pres,
343 const vector& vis,
344 const vector& internal,
346 ) const;
347
348 //- Write integrated data to stream
350 (
351 const string& descriptor,
352 const vector& pres,
353 const vector& vis,
354 const vector& internal
355 ) const;
356
358public:
359
360 //- Runtime type information
361 TypeName("forces");
362
364 // Constructors
365
366 //- Construct from Time and dictionary
367 forces
368 (
369 const word& name,
370 const Time& runTime,
371 const dictionary& dict,
372 const bool readFields = true
373 );
374
375 //- Construct from objectRegistry and dictionary
376 forces
377 (
378 const word& name,
379 const objectRegistry& obr,
380 const dictionary& dict,
381 const bool readFields = true
382 );
383
384 //- No copy construct
385 forces(const forces&) = delete;
386
387 //- No copy assignment
388 void operator=(const forces&) = delete;
389
391 //- Destructor
392 virtual ~forces() = default;
394
395 // Member Functions
397 //- Read the dictionary
398 virtual bool read(const dictionary& dict);
399
400 //- Calculate forces and moments
401 virtual void calcForcesMoments();
402
403 //- Return the total force
404 virtual vector forceEff() const;
405
406 //- Return the total moment
407 virtual vector momentEff() const;
408
409 //- Execute the function object
410 virtual bool execute();
411
412 //- Write to data files/fields and to streams
413 virtual bool write();
414};
415
416
417// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
418
419} // End namespace functionObjects
420} // End namespace Foam
421
422// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
423
424#endif
425
426// ************************************************************************* //
labelList cellIDs
Output to file stream, using an OSstream.
Definition: OFstream.H:57
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 list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const word & name() const noexcept
Return the name of this functionObject.
Computes forces and moments over a given list of patches by integrating pressure and viscous forces a...
Definition: forces.H:325
virtual void calcForcesMoments()
Calculate forces and moments.
Definition: forces.C:660
void writeIntegratedDataFileHeader(const word &header, OFstream &os) const
Write header for an integrated-data file.
Definition: forces.C:402
word pName_
Name of pressure field.
Definition: forces.H:375
scalar rhoRef_
Reference density needed for incompressible calculations.
Definition: forces.H:369
bool porosity_
Flag to include porosity effects.
Definition: forces.H:390
void initialise()
Initialise containers and fields.
Definition: forces.C:148
void addToPatchFields(const label patchi, const vectorField &Md, const vectorField &fP, const vectorField &fV)
Add patch contributions to force and moment fields.
Definition: forces.C:341
bool directForceDensity_
Flag to directly supply force density.
Definition: forces.H:387
word UName_
Name of velocity field.
Definition: forces.H:378
vector sumPatchForcesV_
Sum of patch viscous forces.
Definition: forces.H:336
virtual ~forces()=default
Destructor.
void writeIntegratedDataFiles()
Write integrated data to files.
Definition: forces.C:429
vector sumPatchForcesP_
Sum of patch pressure forces.
Definition: forces.H:333
vector sumInternalMoments_
Sum of internal moments.
Definition: forces.H:348
volVectorField & moment()
Return access to the moment field.
Definition: forces.C:121
void createIntegratedDataFiles()
Create the integrated-data files.
Definition: forces.C:385
bool initialised_
Flag of initialisation (internal)
Definition: forces.H:396
autoPtr< OFstream > forceFilePtr_
File stream for forces.
Definition: forces.H:354
vector sumPatchMomentsV_
Sum of patch viscous moments.
Definition: forces.H:342
tmp< volScalarField > mu() const
Return dynamic viscosity field.
Definition: forces.C:266
vector sumInternalForces_
Sum of internal forces.
Definition: forces.H:345
virtual bool read(const dictionary &dict)
Read the dictionary.
Definition: forces.C:583
virtual vector forceEff() const
Return the total force.
Definition: forces.C:774
void logIntegratedData(const string &descriptor, const vector &pres, const vector &vis, const vector &internal) const
Write integrated data to stream.
Definition: forces.C:475
autoPtr< coordinateSystem > coordSysPtr_
Coordinate system used when evaluating forces and moments.
Definition: forces.H:363
virtual vector momentEff() const
Return the total moment.
Definition: forces.C:780
void addToInternalField(const labelList &cellIDs, const vectorField &Md, const vectorField &f)
Definition: forces.C:362
TypeName("forces")
Runtime type information.
autoPtr< OFstream > momentFilePtr_
File stream for moments.
Definition: forces.H:357
vector sumPatchMomentsP_
Sum of patch pressure moments.
Definition: forces.H:339
word rhoName_
Name of density field.
Definition: forces.H:381
forces(const forces &)=delete
No copy construct.
labelHashSet patchSet_
Names of operand patches.
Definition: forces.H:366
void writeIntegratedDataFile(const vector &pres, const vector &vis, const vector &internal, OFstream &os) const
Write integrated data to a file.
Definition: forces.C:452
bool writeFields_
Flag to write force and moment fields.
Definition: forces.H:393
tmp< volScalarField > rho() const
Return rho if specified otherwise rhoRef.
Definition: forces.C:301
void reset()
Reset containers and fields.
Definition: forces.C:190
virtual bool execute()
Execute the function object.
Definition: forces.C:786
void operator=(const forces &)=delete
No copy assignment.
volVectorField & force()
Return access to the force field.
Definition: forces.C:94
virtual bool write()
Write to data files/fields and to streams.
Definition: forces.C:817
tmp< volSymmTensorField > devRhoReff() const
Return the effective stress (viscous + turbulent)
Definition: forces.C:208
scalar pRef_
Reference pressure.
Definition: forces.H:372
void setCoordinateSystem(const dictionary &dict, const word &e3Name=word::null, const word &e1Name=word::null)
Set the co-ordinate system from dictionary and axes names.
Definition: forces.C:52
word fDName_
Name of force density field.
Definition: forces.H:384
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
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.
Base class for writing single files from the function objects.
Definition: writeFile.H:120
Registry of regIOobjects.
A class for managing temporary objects.
Definition: tmp.H:65
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
static const word null
An empty word.
Definition: word.H:80
volScalarField & p
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:83
List< label > labelList
A List of labels.
Definition: List.H:66
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:82
Field< vector > vectorField
Specialisation of Field<T> for vector.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
labelList f(nPoints)
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73