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-2020 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  Calculates the forces and moments by integrating the pressure and
35  skin-friction forces over a given list of patches, and the resistance
36  from porous zones.
37 
38  Forces and moments are calculated in a global Cartesian coordinate system
39  by default, or using a user-defined system. Contributions can be 'binned'
40  according to a user-defined number of uniform-width collection zones (bins)
41  that span the input geometries, oriented by a user-defined direction vector.
42 
43  Results are written to multiple files as a function of time in the
44  postProcessing/<functionObjectName> directory:
45  - force.dat : forces
46  - moment.dat : moments
47  - forceBin.dat : force bins
48  - momentBin.dat : moment bins
49 
50 Usage
51  Example of function object specification:
52  \verbatim
53  forces1
54  {
55  type forces;
56  libs (forces);
57  ...
58  log yes;
59  writeFields yes;
60  patches (walls);
61 
62  binData
63  {
64  nBin 20;
65  direction (1 0 0);
66  cumulative yes;
67  }
68  }
69  \endverbatim
70 
71  Where the entries comprise:
72  \table
73  Property | Description | Required | Default value
74  type | Type name: forces | yes |
75  log | Write force data to standard output | no | no
76  writeFields | Write the force and moment fields | no | no
77  patches | Patches included in the forces calculation | yes |
78  p | Pressure field name | no | p
79  U | Velocity field name | no | U
80  rho | Density field name (see below) | no | rho
81  CofR | Centre of rotation (see below) | no |
82  porosity | flag to include porosity contributions | no | no
83  directForceDensity | Force density supplied directly (see below)|no|no
84  fD | Name of force density field (see below) | no | fD
85  \endtable
86 
87  Bin data is optional, but if the dictionary is present, the entries must
88  be defined according o
89  \table
90  nBin | number of data bins | yes |
91  direction | direction along which bins are defined | yes |
92  cumulative | bin data accumulated with incresing distance | yes |
93  \endtable
94 
95 Note
96  - For incompressible cases, set \c rho to \c rhoInf. You will then be
97  required to provide a \c rhoInf value corresponding to the free-stream
98  constant density.
99  - If the force density is supplied directly, set the \c directForceDensity
100  flag to 'yes', and supply the force density field using the \c
101  fDName entry
102  - The centre of rotation (CofR) for moment calculations can either be
103  specified by an \c CofR entry, or be taken from origin of the local
104  coordinate system. For example,
105  \verbatim
106  CofR (0 0 0);
107  \endverbatim
108  or
109  \verbatim
110  origin (0 0 0);
111  e1 (0 1 0);
112  e3 (0 0 1);
113  \endverbatim
114  or
115  \verbatim
116  coordinateSystem
117  {
118  origin (0 0 0);
119  rotation
120  {
121  type axes;
122  e3 (0 0 1);
123  e1 (1 0 0);
124  }
125  }
126  \endverbatim
127 
128 See also
129  Foam::functionObject
130  Foam::functionObjects::fvMeshFunctionObject
131  Foam::functionObjects::writeFile
132  Foam::functionObjects::timeControl
133 
134 SourceFiles
135  forces.C
136 
137 \*---------------------------------------------------------------------------*/
138 
139 #ifndef functionObjects_forces_H
140 #define functionObjects_forces_H
141 
142 #include "fvMeshFunctionObject.H"
143 #include "writeFile.H"
144 #include "coordinateSystem.H"
145 #include "volFieldsFwd.H"
146 #include "HashSet.H"
147 #include "Tuple2.H"
148 #include "OFstream.H"
149 #include "Switch.H"
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 namespace Foam
154 {
155 namespace functionObjects
156 {
157 
158 /*---------------------------------------------------------------------------*\
159  Class forces Declaration
160 \*---------------------------------------------------------------------------*/
161 
162 class forces
163 :
164  public fvMeshFunctionObject,
165  public writeFile
166 {
167 
168 protected:
169 
170  // Protected data
171 
172  //- Pressure, viscous and porous force per bin
173  List<Field<vector>> force_;
174 
175  //- Pressure, viscous and porous moment per bin
176  List<Field<vector>> moment_;
177 
178  // File streams
179 
180  //- Forces
181  autoPtr<OFstream> forceFilePtr_;
182 
183  //- Moments
184  autoPtr<OFstream> momentFilePtr_;
185 
186  //- Force bins
187  autoPtr<OFstream> forceBinFilePtr_;
188 
189  //- Moment bins
190  autoPtr<OFstream> momentBinFilePtr_;
191 
192 
193  // Read from dictionary
194 
195  //- Patches to integrate forces over
197 
198  //- Name of pressure field
199  word pName_;
200 
201  //- Name of velocity field
202  word UName_;
203 
204  //- Name of density field (optional)
205  word rhoName_;
206 
207  //- Is the force density being supplied directly?
208  Switch directForceDensity_;
209 
210  //- The name of the force density (fD) field
211  word fDName_;
212 
213  //- Reference density needed for incompressible calculations
214  scalar rhoRef_;
215 
216  //- Reference pressure
217  scalar pRef_;
218 
219  //- Coordinate system used when evaluating forces/moments
220  autoPtr<coordinateSystem> coordSysPtr_;
221 
222  //- Flag to include porosity effects
223  bool porosity_;
224 
225 
226  // Bin information
227 
228  //- Number of bins
229  label nBin_;
230 
231  //- Direction used to determine bin orientation
232  vector binDir_;
233 
234  //- Distance between bin divisions
235  scalar binDx_;
236 
237  //- Minimum bin bounds
238  scalar binMin_;
239 
240  //- Maximum bin bounds
241  scalar binMax_;
242 
243  //- Bin positions along binDir
245 
246  //- Should bin data be cumulative?
248 
249 
250  //- Write fields flag
251  bool writeFields_;
252 
253  //- Initialised flag
254  bool initialised_;
255 
256 
257  // Protected Member Functions
258 
259  //- Create the output files
260  void createFiles();
261 
262  //- Write header for integrated data
263  void writeIntegratedHeader(const word& header, Ostream& os) const;
264 
265  //- Write header for binned data
266  void writeBinHeader(const word& header, Ostream& os) const;
267 
268  //- Set the co-ordinate system from dictionary and axes names
270  (
271  const dictionary& dict,
272  const word& e3Name = word::null,
273  const word& e1Name = word::null
274  );
275 
276  //- Initialise the fields
277  void initialise();
278 
279  //- Initialise the collection bins
280  void initialiseBins();
281 
282  //- Reset the fields prior to accumulation of force/moments
283  void resetFields();
284 
285  //- Return the effective viscous stress (laminar + turbulent).
287 
288  //- Dynamic viscosity field
289  tmp<volScalarField> mu() const;
290 
291  //- Return rho if specified otherwise rhoRef
292  tmp<volScalarField> rho() const;
293 
294  //- Return rhoRef if the pressure field is dynamic, i.e. p/rho
295  // otherwise return 1
296  scalar rho(const volScalarField& p) const;
297 
298  //- Accumulate bin data
299  void applyBins
300  (
301  const vectorField& Md,
302  const vectorField& fN,
303  const vectorField& fT,
304  const vectorField& fP,
305  const vectorField& d
306  );
307 
308  //- Add patch contributions to force and moment fields
310  (
311  const label patchi,
312  const vectorField& Md,
313  const vectorField& fN,
314  const vectorField& fT,
315  const vectorField& fP
316  );
317 
318  //- Add cell contributions to force and moment fields
319  void addToFields
320  (
321  const labelList& cellIDs,
322  const vectorField& Md,
323  const vectorField& fN,
324  const vectorField& fT,
325  const vectorField& fP
326  );
327 
328  //- Helper function to write integrated forces and moments
330  (
331  const string& descriptor,
332  const vectorField& fm0,
333  const vectorField& fm1,
334  const vectorField& fm2,
335  autoPtr<OFstream>& osPtr
336  ) const;
337 
338  //- Write force data
339  void writeForces();
340 
341  //- Helper function to write binned forces and moments
343  (
344  const List<Field<vector>>& fm,
345  autoPtr<OFstream>& osPtr
346  ) const;
347 
348  //- Write binned data
349  void writeBins();
350 
351  //- No copy construct
352  forces(const forces&) = delete;
353 
354  //- No copy assignment
355  void operator=(const forces&) = delete;
356 
357 
358 public:
359 
360  //- Runtime type information
361  TypeName("forces");
362 
363 
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 
385  //- Destructor
386  virtual ~forces() = default;
387 
388 
389  // Member Functions
390 
391  //- Read the forces data
392  virtual bool read(const dictionary&);
393 
394  //- Calculate the forces and moments
395  virtual void calcForcesMoment();
396 
397  //- Return the total force
398  virtual vector forceEff() const;
399 
400  //- Return the total moment
401  virtual vector momentEff() const;
402 
403  //- Execute, currently does nothing
404  virtual bool execute();
405 
406  //- Write the forces
407  virtual bool write();
408 };
409 
410 
411 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
412 
413 } // End namespace functionObjects
414 } // End namespace Foam
415 
416 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
417 
418 #endif
419 
420 // ************************************************************************* //
Foam::functionObjects::forces::forceEff
virtual vector forceEff() const
Return the total force.
Definition: forces.C:1073
runTime
engineTime & runTime
Definition: createEngineTime.H:13
volFieldsFwd.H
writeFile.H
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:77
Foam::functionObjects::forces::binMin_
scalar binMin_
Minimum bin bounds.
Definition: forces.H:312
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::functionObjects::forces::mu
tmp< volScalarField > mu() const
Dynamic viscosity field.
Definition: forces.C:397
Foam::functionObjects::forces::initialised_
bool initialised_
Initialised flag.
Definition: forces.H:328
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObjects::forces::pName_
word pName_
Name of pressure field.
Definition: forces.H:273
fvMeshFunctionObject.H
Foam::functionObjects::forces::writeForces
void writeForces()
Write force data.
Definition: forces.C:603
Foam::functionObjects::forces::patchSet_
labelHashSet patchSet_
Patches to integrate forces over.
Definition: forces.H:270
Foam::functionObjects::forces
Calculates the forces and moments by integrating the pressure and skin-friction forces over a given l...
Definition: forces.H:236
Tuple2.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::functionObjects::forces::directForceDensity_
Switch directForceDensity_
Is the force density being supplied directly?
Definition: forces.H:282
Foam::functionObjects::forces::write
virtual bool write()
Write the forces.
Definition: forces.C:1113
Foam::functionObjects::forces::operator=
void operator=(const forces &)=delete
No copy assignment.
Foam::functionObjects::forces::momentBinFilePtr_
autoPtr< OFstream > momentBinFilePtr_
Moment bins.
Definition: forces.H:264
Foam::functionObjects::forces::writeBinHeader
void writeBinHeader(const word &header, Ostream &os) const
Write header for binned data.
Definition: forces.C:97
Foam::functionObjects::forces::binMax_
scalar binMax_
Maximum bin bounds.
Definition: forces.H:315
Foam::functionObjects::forces::moment_
List< Field< vector > > moment_
Pressure, viscous and porous moment per bin.
Definition: forces.H:250
Foam::functionObjects::forces::writeIntegratedForceMoment
void writeIntegratedForceMoment(const string &descriptor, const vectorField &fm0, const vectorField &fm1, const vectorField &fm2, autoPtr< OFstream > &osPtr) const
Helper function to write integrated forces and moments.
Definition: forces.C:560
Foam::functionObjects::forces::writeBins
void writeBins()
Write binned data.
Definition: forces.C:676
Foam::functionObjects::forces::UName_
word UName_
Name of velocity field.
Definition: forces.H:276
Foam::functionObjects::forces::fDName_
word fDName_
The name of the force density (fD) field.
Definition: forces.H:285
Foam::HashSet< label, Hash< label > >
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::forces::binDir_
vector binDir_
Direction used to determine bin orientation.
Definition: forces.H:306
Foam::functionObjects::forces::setCoordinateSystem
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:153
coordinateSystem.H
Foam::functionObjects::forces::forceFilePtr_
autoPtr< OFstream > forceFilePtr_
Forces.
Definition: forces.H:255
Foam::functionObjects::forces::momentFilePtr_
autoPtr< OFstream > momentFilePtr_
Moments.
Definition: forces.H:258
OFstream.H
Foam::functionObjects::forces::calcForcesMoment
virtual void calcForcesMoment()
Calculate the forces and moments.
Definition: forces.C:951
Foam::functionObjects::forces::initialiseBins
void initialiseBins()
Initialise the collection bins.
Definition: forces.C:241
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::functionObjects::forces::coordSysPtr_
autoPtr< coordinateSystem > coordSysPtr_
Coordinate system used when evaluating forces/moments.
Definition: forces.H:294
Foam::functionObjects::forces::rho
tmp< volScalarField > rho() const
Return rho if specified otherwise rhoRef.
Definition: forces.C:433
Foam::functionObjects::forces::porosity_
bool porosity_
Flag to include porosity effects.
Definition: forces.H:297
Foam::functionObjects::forces::binPoints_
List< point > binPoints_
Bin positions along binDir.
Definition: forces.H:318
Foam::functionObjects::forces::momentEff
virtual vector momentEff() const
Return the total moment.
Definition: forces.C:1079
Foam::functionObjects::forces::resetFields
void resetFields()
Reset the fields prior to accumulation of force/moments.
Definition: forces.C:316
Foam::Field< vector >
Foam::functionObjects::forces::nBin_
label nBin_
Number of bins.
Definition: forces.H:303
Foam::functionObjects::forces::initialise
void initialise()
Initialise the fields.
Definition: forces.C:196
Foam::functionObjects::forces::force_
List< Field< vector > > force_
Pressure, viscous and porous force per bin.
Definition: forces.H:247
Foam::functionObjects::forces::devRhoReff
tmp< volSymmTensorField > devRhoReff() const
Return the effective viscous stress (laminar + turbulent).
Definition: forces.C:342
Foam::functionObjects::forces::TypeName
TypeName("forces")
Runtime type information.
Foam::functionObjects::forces::rhoName_
word rhoName_
Name of density field (optional)
Definition: forces.H:279
Switch.H
Foam::functionObjects::forces::read
virtual bool read(const dictionary &)
Read the forces data.
Definition: forces.C:799
Foam::functionObjects::forces::binCumulative_
bool binCumulative_
Should bin data be cumulative?
Definition: forces.H:321
Foam::functionObjects::forces::rhoRef_
scalar rhoRef_
Reference density needed for incompressible calculations.
Definition: forces.H:288
Foam::functionObjects::forces::forceBinFilePtr_
autoPtr< OFstream > forceBinFilePtr_
Force bins.
Definition: forces.H:261
HashSet.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::functionObjects::forces::addToFields
void addToFields(const label patchi, const vectorField &Md, const vectorField &fN, const vectorField &fT, const vectorField &fP)
Add patch contributions to force and moment fields.
Definition: forces.C:510
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::functionObjects::forces::execute
virtual bool execute()
Execute, currently does nothing.
Definition: forces.C:1085
os
OBJstream os(runTime.globalPath()/outputName)
Foam::functionObjects::forces::writeIntegratedHeader
void writeIntegratedHeader(const word &header, Ostream &os) const
Write header for integrated data.
Definition: forces.C:74
Foam::functionObjects::forces::writeFields_
bool writeFields_
Write fields flag.
Definition: forces.H:325
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::functionObjects::forces::writeBinnedForceMoment
void writeBinnedForceMoment(const List< Field< vector >> &fm, autoPtr< OFstream > &osPtr) const
Helper function to write binned forces and moments.
Definition: forces.C:632
Foam::functionObjects::forces::pRef_
scalar pRef_
Reference pressure.
Definition: forces.H:291
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::functionObjects::forces::applyBins
void applyBins(const vectorField &Md, const vectorField &fN, const vectorField &fT, const vectorField &fP, const vectorField &d)
Accumulate bin data.
Definition: forces.C:473
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::functionObjects::forces::createFiles
void createFiles()
Create the output files.
Definition: forces.C:51
Foam::functionObjects::regionFunctionObject::obr
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
Definition: regionFunctionObject.C:47
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
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::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
Foam::labelHashSet
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
Foam::functionObjects::forces::binDx_
scalar binDx_
Distance between bin divisions.
Definition: forces.H:309
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::functionObjects::forces::forces
forces(const forces &)=delete
No copy construct.
Foam::functionObjects::forces::~forces
virtual ~forces()=default
Destructor.