Loading...
Searching...
No Matches
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-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::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>/files
53 output field | volVectorField | <time>/outputFields
54 \endtable
55
56 where \c files:
57 \verbatim
58 force.dat | Forces
59 moment.dat | Moments
60 \endverbatim
61
62 where \c outputFields:
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 // Define the centre of rotation
94 // with implicit directions e1=(1 0 0) and e3=(0 0 1)
95 CofR (0 0 0); // Centre of rotation
96
97 // Define local coordinate system by origin + axes
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 // General coordinate system specification (always cartesian)
103 coordinateSystem
104 {
105 origin (0 0 0);
106 rotation
107 {
108 type axes;
109 e3 (0 0 1);
110 e1 (1 0 0); // (e1, e2) or (e2, e3) or (e3, e1)
111 }
112 }
113
114 // Conditional optional entries
115
116 // if directForceDensity == false
117 p <word>;
118 U <word>;
119 rho <word>;
120 rhoInf <scalar>; // enabled if rho=rhoInf
121 pRef <scalar>;
122
123 // Inherited entries
124 ...
125 }
126 \endverbatim
127
128 where the entries mean:
129 \table
130 Property | Description | Type | Reqd | Deflt
131 type | Type name: forces | word | yes | -
132 libs | Library name: forces | word | yes | -
133 patches | Names of operand patches | wordRes | yes | -
134 directForceDensity | Flag to directly supply force density <!--
135 --> | bool | no | false
136 porosity | Flag to include porosity contributions | bool | no | false
137 writeFields | Flag to write force and moment fields | bool | no | false
138 useNamePrefix | Flag to include prefix for field names | bool | no | false
139 coordinateSystem | Coordinate system specifier | dictionary | cndtnl | -
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 fD | Name of force density field | word | cndtnl | -
145 p | Name of pressure field | word | cndtnl | p
146 U | Name of velocity field | word | cndtnl | U
147 rho | Name of density field | word | cndtnl | rho
148 rhoInf | Value of reference density | scalar | cndtnl | -
149 pRef | Value of reference pressure | scalar | cndtnl | 0
150 \endtable
151
152 The inherited entries are elaborated in:
153 - \link functionObject.H \endlink
154 - \link writeFile.H \endlink
155 - \link coordinateSystem.H \endlink
156
157Note
158 - For incompressible cases, set \c rho to \c rhoInf.
159 You will then be required to provide a \c rhoInf
160 value corresponding to the constant freestream density.
161 - \c writeControl and \c writeInterval entries of function
162 object do control when to output force and moment files and fields.
163 - If a \c coordinateSystem entry exists, it is taken in favour of \c CofR.
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:
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 //- Selected 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
291 // Evaluation
292
293 //- Return the effective stress (viscous + turbulent) for patch
294 tmp<symmTensorField> devRhoReff
295 (
296 const tensorField& gradUp,
297 const label patchi
298 ) const;
299
300 //- Return dynamic viscosity field
301 tmp<volScalarField> mu() const;
302
303 //- Return rho if specified otherwise rhoRef
304 tmp<volScalarField> rho() const;
305
306 //- Return rho if specified otherwise rhoRef for patch
307 tmp<scalarField> rho(const label patchi) const;
308
309 //- Return rhoRef if the pressure field is
310 //- dynamic (i.e. p/rho), otherwise return 1
311 scalar rho(const volScalarField& p) const;
312
313 //- Add patch contributions to force and moment fields
315 (
316 const label patchi,
317 const vectorField& Md,
318 const vectorField& fP,
319 const vectorField& fV
320 );
321
322 //- Add cell contributions to force and
323 //- moment fields, and include porosity effects
325 (
326 const labelList& cellIDs,
327 const vectorField& Md,
328 const vectorField& f
329 );
330
332 // I-O
333
334 //- Create the integrated-data files
337 //- Write header for an integrated-data file
339 (
340 const word& header,
342 ) const;
343
344 //- Write integrated data to files
347 //- Write integrated data to a file
349 (
350 const vector& pres,
351 const vector& vis,
352 const vector& internal,
353 OFstream& os
354 ) const;
355
356 //- Write integrated data to stream
358 (
359 const string& descriptor,
360 const vector& pres,
361 const vector& vis,
362 const vector& internal
363 ) const;
365
366public:
367
368 //- Runtime type information
369 TypeName("forces");
370
371
372 // Constructors
373
374 //- Construct from name, Time and dictionary
375 forces
376 (
377 const word& name,
378 const Time& runTime,
379 const dictionary& dict,
380 const bool readFields = true
381 );
383 //- Construct from objectRegistry and dictionary
384 forces
385 (
386 const word& name,
388 const dictionary& dict,
389 const bool readFields = true
390 );
391
392 //- No copy construct
393 forces(const forces&) = delete;
394
395 //- No copy assignment
396 void operator=(const forces&) = delete;
398
399 //- Destructor
400 virtual ~forces() = default;
401
403 // Member Functions
404
405 //- Calculate forces and moments
406 virtual void calcForcesMoments();
408 //- Return the total force
409 virtual vector forceEff() const;
410
411 //- Return the total moment
412 virtual vector momentEff() const;
413
414 //I-O
415
416 //- Read the function-object dictionary
417 virtual bool read(const dictionary&);
418
419 //- Execute the function-object operations
420 virtual bool execute();
421
422 //- Write the function-object results
423 virtual bool write();
424};
425
426
427// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
428
429} // End namespace functionObjects
430} // End namespace Foam
431
432// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
433
434#endif
435
436// ************************************************************************* //
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Definition OFstream.H:75
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Computes forces and moments over a given list of patches by integrating pressure and viscous forces a...
Definition forces.H:321
virtual void calcForcesMoments()
Calculate forces and moments.
Definition forces.C:665
void writeIntegratedDataFileHeader(const word &header, OFstream &os) const
Write header for an integrated-data file.
Definition forces.C:410
word pName_
Name of pressure field.
Definition forces.H:397
scalar rhoRef_
Reference density needed for incompressible calculations.
Definition forces.H:387
bool porosity_
Flag to include porosity effects.
Definition forces.H:422
void initialise()
Initialise containers and fields.
Definition forces.C:139
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:349
bool directForceDensity_
Flag to directly supply force density.
Definition forces.H:417
word UName_
Name of velocity field.
Definition forces.H:402
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:437
vector sumPatchForcesP_
Sum of patch pressure forces.
Definition forces.H:331
vector sumInternalMoments_
Sum of internal moments.
Definition forces.H:356
volVectorField & moment()
Return access to the moment field.
Definition forces.C:111
void createIntegratedDataFiles()
Create the integrated-data files.
Definition forces.C:393
bool initialised_
Flag of initialisation (internal).
Definition forces.H:432
autoPtr< OFstream > forceFilePtr_
File stream for forces.
Definition forces.H:364
vector sumPatchMomentsV_
Sum of patch viscous moments.
Definition forces.H:346
tmp< volScalarField > mu() const
Return dynamic viscosity field.
Definition forces.C:264
vector sumInternalForces_
Sum of internal forces.
Definition forces.H:351
forces(const word &name, const Time &runTime, const dictionary &dict, const bool readFields=true)
Construct from name, Time and dictionary.
Definition forces.C:510
virtual vector forceEff() const
Return the total force.
Definition forces.C:783
void logIntegratedData(const string &descriptor, const vector &pres, const vector &vis, const vector &internal) const
Write integrated data to stream.
Definition forces.C:483
autoPtr< coordinateSystem > coordSysPtr_
Coordinate system used when evaluating forces and moments.
Definition forces.H:377
virtual vector momentEff() const
Return the total moment.
Definition forces.C:789
void addToInternalField(const labelList &cellIDs, const vectorField &Md, const vectorField &f)
Add cell contributions to force and moment fields, and include porosity effects.
Definition forces.C:370
TypeName("forces")
Runtime type information.
autoPtr< OFstream > momentFilePtr_
File stream for moments.
Definition forces.H:369
vector sumPatchMomentsP_
Sum of patch pressure moments.
Definition forces.H:341
word rhoName_
Name of density field.
Definition forces.H:407
forces(const forces &)=delete
No copy construct.
void writeIntegratedDataFile(const vector &pres, const vector &vis, const vector &internal, OFstream &os) const
Write integrated data to a file.
Definition forces.C:460
tmp< symmTensorField > devRhoReff(const tensorField &gradUp, const label patchi) const
Return the effective stress (viscous + turbulent) for patch.
Definition forces.C:212
bool writeFields_
Flag to write force and moment fields.
Definition forces.H:427
tmp< volScalarField > rho() const
Return rho if specified otherwise rhoRef.
Definition forces.C:296
void reset()
Reset containers and fields.
Definition forces.C:181
virtual bool execute()
Execute the function-object operations.
Definition forces.C:795
void operator=(const forces &)=delete
No copy assignment.
volVectorField & force()
Return access to the force field.
Definition forces.C:83
virtual bool write()
Write the function-object results.
Definition forces.C:826
scalar pRef_
Reference pressure.
Definition forces.H:392
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:45
word fDName_
Name of force density field.
Definition forces.H:412
labelList patchIDs_
Selected operand patches.
Definition forces.H:382
virtual bool read(const dictionary &)
Read the function-object dictionary.
Definition forces.C:589
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
fvMeshFunctionObject(const fvMeshFunctionObject &)=delete
No copy construct.
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Definition readFields.H:146
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:113
writeFile(const objectRegistry &obr, const fileName &prefix, const word &name="undefined", const bool writeToFile=true, const string &ext=".dat")
Construct from objectRegistry, prefix, fileName.
Definition writeFile.C:200
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
static const word null
An empty word.
Definition word.H:84
volScalarField & p
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
GeometricField< vector, fvPatchField, volMesh > volVectorField
List< label > labelList
A List of labels.
Definition List.H:62
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
Vector< scalar > vector
Definition vector.H:57
labelList f(nPoints)
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68
Forwards and collection of common volume field types.