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 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::functionObjects::forces
29 
30 Group
31  grpForcesFunctionObjects
32 
33 Description
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 
68 Usage
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 
157 Note
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 
165 SourceFiles
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 
180 namespace Foam
181 {
182 
183 namespace functionObjects
184 {
185 
186 /*---------------------------------------------------------------------------*\
187  Class forces Declaration
188 \*---------------------------------------------------------------------------*/
189 
190 class forces
191 :
192  public fvMeshFunctionObject,
193  public writeFile
194 {
195 protected:
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
256  bool directForceDensity_;
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
314  void addToPatchFields
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
324  void addToInternalField
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
357  void logIntegratedData
358  (
359  const string& descriptor,
360  const vector& pres,
361  const vector& vis,
362  const vector& internal
363  ) const;
365 
366 public:
367 
368  //- Runtime type information
369  TypeName("forces");
370 
371 
372  // Constructors
373 
374  //- Construct from 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  //- Read the dictionary
406  virtual bool read(const dictionary& dict);
408  //- Calculate forces and moments
409  virtual void calcForcesMoments();
410 
411  //- Return the total force
412  virtual vector forceEff() const;
413 
414  //- Return the total moment
415  virtual vector momentEff() const;
416 
417  //- Execute the function object
418  virtual bool execute();
419 
420  //- Write to data files/fields and to streams
421  virtual bool write();
422 };
423 
424 
425 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
426 
427 } // End namespace functionObjects
428 } // End namespace Foam
429 
430 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
431 
432 #endif
433 
434 // ************************************************************************* //
bool writeFields_
Flag to write force and moment fields.
Definition: forces.H:427
virtual vector momentEff() const
Return the total moment.
Definition: forces.C:802
vector sumInternalForces_
Sum of internal forces.
Definition: forces.H:351
dictionary dict
vector sumPatchMomentsV_
Sum of patch viscous moments.
Definition: forces.H:346
word UName_
Name of velocity field.
Definition: forces.H:402
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:129
autoPtr< OFstream > forceFilePtr_
File stream for forces.
Definition: forces.H:364
Output to file stream, using an OSstream.
Definition: OFstream.H:49
vector sumPatchMomentsP_
Sum of patch pressure moments.
Definition: forces.H:341
engineTime & runTime
volVectorField & force()
Return access to the force field.
Definition: forces.C:83
virtual vector forceEff() const
Return the total force.
Definition: forces.C:796
word pName_
Name of pressure field.
Definition: forces.H:397
TypeName("forces")
Runtime type information.
void operator=(const forces &)=delete
No copy assignment.
word rhoName_
Name of density field.
Definition: forces.H:407
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:82
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:360
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
virtual bool read(const dictionary &dict)
Read the dictionary.
Definition: forces.C:602
void writeIntegratedDataFiles()
Write integrated data to files.
Definition: forces.C:450
tmp< symmTensorField > devRhoReff(const tensorField &gradUp, const label patchi) const
Return the effective stress (viscous + turbulent) for patch.
Definition: forces.C:213
const word & name() const noexcept
Return the name of this functionObject.
void writeIntegratedDataFile(const vector &pres, const vector &vis, const vector &internal, OFstream &os) const
Write integrated data to a file.
Definition: forces.C:473
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:81
virtual ~forces()=default
Destructor.
virtual bool execute()
Execute the function object.
Definition: forces.C:808
virtual void calcForcesMoments()
Calculate forces and moments.
Definition: forces.C:678
A class for handling words, derived from Foam::string.
Definition: word.H:63
tmp< volScalarField > mu() const
Return dynamic viscosity field.
Definition: forces.C:268
scalar rhoRef_
Reference density needed for incompressible calculations.
Definition: forces.H:387
bool initialised_
Flag of initialisation (internal)
Definition: forces.H:432
static const word null
An empty word.
Definition: word.H:84
vector sumPatchForcesP_
Sum of patch pressure forces.
Definition: forces.H:331
vector sumPatchForcesV_
Sum of patch viscous forces.
Definition: forces.H:336
Vector< scalar > vector
Definition: vector.H:57
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:383
tmp< volScalarField > rho() const
Return rho if specified otherwise rhoRef.
Definition: forces.C:303
void createIntegratedDataFiles()
Create the integrated-data files.
Definition: forces.C:406
volVectorField & moment()
Return access to the moment field.
Definition: forces.C:111
autoPtr< OFstream > momentFilePtr_
File stream for moments.
Definition: forces.H:369
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
void reset()
Reset containers and fields.
Definition: forces.C:181
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Definition: readFields.H:151
void initialise()
Initialise containers and fields.
Definition: forces.C:139
OBJstream os(runTime.globalPath()/outputName)
bool porosity_
Flag to include porosity effects.
Definition: forces.H:422
labelList f(nPoints)
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
labelList patchIDs_
Selected operand patches.
Definition: forces.H:382
scalar pRef_
Reference pressure.
Definition: forces.H:392
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
autoPtr< coordinateSystem > coordSysPtr_
Coordinate system used when evaluating forces and moments.
Definition: forces.H:377
forces(const word &name, const Time &runTime, const dictionary &dict, const bool readFields=true)
Construct from Time and dictionary.
Definition: forces.C:523
vector sumInternalMoments_
Sum of internal moments.
Definition: forces.H:356
Computes forces and moments over a given list of patches by integrating pressure and viscous forces a...
Definition: forces.H:317
List< label > labelList
A List of labels.
Definition: List.H:62
word fDName_
Name of force density field.
Definition: forces.H:412
volScalarField & p
void writeIntegratedDataFileHeader(const word &header, OFstream &os) const
Write header for an integrated-data file.
Definition: forces.C:423
Registry of regIOobjects.
void logIntegratedData(const string &descriptor, const vector &pres, const vector &vis, const vector &internal) const
Write integrated data to stream.
Definition: forces.C:496
labelList cellIDs
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
virtual bool write()
Write to data files/fields and to streams.
Definition: forces.C:839
Namespace for OpenFOAM.
bool directForceDensity_
Flag to directly supply force density.
Definition: forces.H:417