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 "cartesianCS.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  coordSystem::cartesian coordSys_;
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 a field name
260  word fieldName(const word& name) const;
261 
262  //- Create the output files
263  void createFiles();
264 
265  //- Write header for integrated data
266  void writeIntegratedHeader(const word& header, Ostream& os) const;
267 
268  //- Write header for binned data
269  void writeBinHeader(const word& header, Ostream& os) const;
270 
271  //- Set the co-ordinate system from dictionary and axes names
273  (
274  const dictionary& dict,
275  const word& e3Name = word::null,
276  const word& e1Name = word::null
277  );
278 
279  //- Initialise the fields
280  void initialise();
281 
282  //- Initialise the collection bins
283  void initialiseBins();
284 
285  //- Reset the fields prior to accumulation of force/moments
286  void resetFields();
287 
288  //- Return the effective viscous stress (laminar + turbulent).
290 
291  //- Dynamic viscosity field
292  tmp<volScalarField> mu() const;
293 
294  //- Return rho if specified otherwise rhoRef
295  tmp<volScalarField> rho() const;
296 
297  //- Return rhoRef if the pressure field is dynamic, i.e. p/rho
298  // otherwise return 1
299  scalar rho(const volScalarField& p) const;
300 
301  //- Accumulate bin data
302  void applyBins
303  (
304  const vectorField& Md,
305  const vectorField& fN,
306  const vectorField& fT,
307  const vectorField& fP,
308  const vectorField& d
309  );
310 
311  //- Add patch contributions to force and moment fields
313  (
314  const label patchi,
315  const vectorField& Md,
316  const vectorField& fN,
317  const vectorField& fT,
318  const vectorField& fP
319  );
320 
321  //- Add cell contributions to force and moment fields
322  void addToFields
323  (
324  const labelList& cellIDs,
325  const vectorField& Md,
326  const vectorField& fN,
327  const vectorField& fT,
328  const vectorField& fP
329  );
330 
331  //- Helper function to write integrated forces and moments
333  (
334  const string& descriptor,
335  const vectorField& fm0,
336  const vectorField& fm1,
337  const vectorField& fm2,
338  autoPtr<OFstream>& osPtr
339  ) const;
340 
341  //- Write force data
342  void writeForces();
343 
344  //- Helper function to write binned forces and moments
346  (
347  const List<Field<vector>>& fm,
348  autoPtr<OFstream>& osPtr
349  ) const;
350 
351  //- Write binned data
352  void writeBins();
353 
354  //- No copy construct
355  forces(const forces&) = delete;
356 
357  //- No copy assignment
358  void operator=(const forces&) = delete;
359 
360 
361 public:
362 
363  //- Runtime type information
364  TypeName("forces");
365 
366 
367  // Constructors
368 
369  //- Construct from Time and dictionary
370  forces
371  (
372  const word& name,
373  const Time& runTime,
374  const dictionary& dict,
375  const bool readFields = true
376  );
377 
378  //- Construct from objectRegistry and dictionary
379  forces
380  (
381  const word& name,
382  const objectRegistry& obr,
383  const dictionary& dict,
384  const bool readFields = true
385  );
386 
387 
388  //- Destructor
389  virtual ~forces() = default;
390 
391 
392  // Member Functions
393 
394  //- Read the forces data
395  virtual bool read(const dictionary&);
396 
397  //- Calculate the forces and moments
398  virtual void calcForcesMoment();
399 
400  //- Return the total force
401  virtual vector forceEff() const;
402 
403  //- Return the total moment
404  virtual vector momentEff() const;
405 
406  //- Execute, currently does nothing
407  virtual bool execute();
408 
409  //- Write the forces
410  virtual bool write();
411 };
412 
413 
414 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
415 
416 } // End namespace functionObjects
417 } // End namespace Foam
418 
419 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
420 
421 #endif
422 
423 // ************************************************************************* //
Foam::functionObjects::forces::forceEff
virtual vector forceEff() const
Return the total force.
Definition: forces.C:1083
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:407
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:62
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:613
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:1123
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:103
Foam::functionObjects::forces::fieldName
word fieldName(const word &name) const
Create a field name.
Definition: forces.C:51
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:570
Foam::functionObjects::forces::writeBins
void writeBins()
Write binned data.
Definition: forces.C:684
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
cartesianCS.H
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:159
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:957
Foam::functionObjects::forces::initialiseBins
void initialiseBins()
Initialise the collection bins.
Definition: forces.C:247
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::functionObjects::forces::rho
tmp< volScalarField > rho() const
Return rho if specified otherwise rhoRef.
Definition: forces.C:443
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:1089
Foam::functionObjects::forces::resetFields
void resetFields()
Reset the fields prior to accumulation of force/moments.
Definition: forces.C:322
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:202
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:348
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:805
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:520
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::functionObjects::forces::execute
virtual bool execute()
Execute, currently does nothing.
Definition: forces.C:1095
Foam::functionObjects::forces::writeIntegratedHeader
void writeIntegratedHeader(const word &header, Ostream &os) const
Write header for integrated data.
Definition: forces.C:80
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:640
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::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:483
Foam::functionObject::name
const word & name() const
Return the name of this functionObject.
Definition: functionObject.C:131
Foam::coordSystem::cartesian
A Cartesian coordinate system.
Definition: cartesianCS.H:69
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:57
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:77
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 with label keys and label hasher.
Definition: HashSet.H:409
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::coordSys_
coordSystem::cartesian coordSys_
Coordinate system used when evaluating forces/moments.
Definition: forces.H:294
Foam::functionObjects::forces::~forces
virtual ~forces()=default
Destructor.