forces.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::functionObjects::forces
26 
27 Description
28  Calculates the forces and moments by integrating the pressure and
29  skin-friction forces over a given list of patches.
30 
31  Member function forces::write() calculates the forces/moments and
32  writes the forces/moments into the file <timeDir>/forces.dat and bin
33  data (if selected) to the file <timeDir>/forces_bin.dat
34 
35  Example of function object specification:
36  \verbatim
37  forces1
38  {
39  type forces;
40  libs ("libforces.so");
41  ...
42  log yes;
43  patches (walls);
44 
45  binData
46  {
47  nBin 20;
48  direction (1 0 0);
49  cumulative yes;
50  }
51  }
52  \endverbatim
53 
54 Usage
55  \table
56  Property | Description | Required | Default value
57  type | Type name: forces | yes |
58  log | Write force data to standard output | no | no
59  patches | Patches included in the forces calculation | yes |
60  p | Pressure field name | no | p
61  U | Velocity field name | no | U
62  rho | Density field name (see below) | no | rho
63  CofR | Centre of rotation (see below) | no |
64  directForceDensity | Force density supplied directly (see below)|no|no
65  fD | Name of force density field (see below) | no | fD
66  \endtable
67 
68  Bin data is optional, but if the dictionary is present, the entries must
69  be defined according o
70  \table
71  nBin | number of data bins | yes |
72  direction | direction along which bins are defined | yes |
73  cumulative | bin data accumulated with incresing distance | yes |
74  \endtable
75 
76 Note
77  - For incompressible cases, set \c rho to \c rhoInf. You will then be
78  required to provide a \c rhoInf value corresponding to the free-stream
79  constant density.
80  - If the force density is supplied directly, set the \c directForceDensity
81  flag to 'yes', and supply the force density field using the \c
82  fDName entry
83  - The centre of rotation (CofR) for moment calculations can either be
84  specified by an \c CofR entry, or be taken from origin of the local
85  coordinate system. For example,
86  \verbatim
87  CofR (0 0 0);
88  \endverbatim
89  or
90  \verbatim
91  coordinateSystem
92  {
93  origin (0 0 0);
94  e3 (0 0 1);
95  e1 (1 0 0);
96  }
97  \endverbatim
98 
99 See also
100  Foam::functionObject
101  Foam::functionObjects::fvMeshFunctionObject
102  Foam::functionObjects::logFiles
103  Foam::functionObjects::timeControl
104  Foam::forceCoeffs
105 
106 SourceFiles
107  forces.C
108 
109 \*---------------------------------------------------------------------------*/
110 
111 #ifndef functionObjects_forces_H
112 #define functionObjects_forces_H
113 
114 #include "fvMeshFunctionObject.H"
115 #include "logFiles.H"
116 #include "coordinateSystem.H"
117 #include "volFieldsFwd.H"
118 #include "HashSet.H"
119 
120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121 
122 namespace Foam
123 {
124 namespace functionObjects
125 {
126 
127 /*---------------------------------------------------------------------------*\
128  Class forces Declaration
129 \*---------------------------------------------------------------------------*/
130 
131 class forces
132 :
133  public fvMeshFunctionObject,
134  public logFiles
135 {
136 
137 protected:
138 
139  // Protected data
140 
141  //- Enumeration for ensuring the right file is accessed
142  enum fileID
143  {
144  MAIN_FILE = 0,
145  BINS_FILE = 1
146  };
147 
148  //- Pressure, viscous and porous force per bin
149  List<Field<vector>> force_;
150 
151  //- Pressure, viscous and porous moment per bin
152  List<Field<vector>> moment_;
153 
154 
155  // Read from dictionary
156 
157  //- Patches to integrate forces over
159 
160  //- Name of pressure field
161  word pName_;
162 
163  //- Name of velocity field
164  word UName_;
165 
166  //- Name of density field (optional)
167  word rhoName_;
168 
169  //- Is the force density being supplied directly?
170  Switch directForceDensity_;
171 
172  //- The name of the force density (fD) field
173  word fDName_;
174 
175  //- Reference density needed for incompressible calculations
176  scalar rhoRef_;
177 
178  //- Reference pressure
179  scalar pRef_;
180 
181  //- Coordinate system used when evaluating forces/moments
182  coordinateSystem coordSys_;
183 
184  //- Flag to indicate whether we are using a local co-ordinate sys
185  bool localSystem_;
186 
187  //- Flag to include porosity effects
188  bool porosity_;
189 
190 
191  // Bin information
192 
193  //- Number of bins
194  label nBin_;
196  //- Direction used to determine bin orientation
197  vector binDir_;
198 
199  //- Distance between bin divisions
200  scalar binDx_;
201 
202  //- Minimum bin bounds
203  scalar binMin_;
204 
205  //- Bin positions along binDir
207 
208  //- Should bin data be cumulative?
210 
211 
212  //- Initialised flag
214 
215 
216  // Protected Member Functions
217 
218  //- Create file names for forces and bins
219  wordList createFileNames(const dictionary& dict) const;
220 
221  //- Output file header information
222  virtual void writeFileHeader(const label i);
223 
224  //- Initialise the fields
225  void initialise();
226 
227  //- Return the effective viscous stress (laminar + turbulent).
229 
230  //- Dynamic viscosity field
232 
233  //- Return rho if specified otherwise rhoRef
235 
236  //- Return rhoRef if the pressure field is dynamic, i.e. p/rho
237  // otherwise return 1
238  scalar rho(const volScalarField& p) const;
239 
240  //- Accumulate bin data
241  void applyBins
242  (
243  const vectorField& Md,
244  const vectorField& fN,
245  const vectorField& fT,
246  const vectorField& fP,
247  const vectorField& d
248  );
250  //- Helper function to write force data
251  void writeForces();
253  //- Helper function to write bin data
254  void writeBins();
255 
256  //- Disallow default bitwise copy construct
257  forces(const forces&);
259  //- Disallow default bitwise assignment
260  void operator=(const forces&);
262 
263 public:
265  //- Runtime type information
266  TypeName("forces");
268 
269  // Constructors
271  //- Construct from Time and dictionary
272  forces
273  (
274  const word& name,
275  const Time& runTime,
276  const dictionary& dict
277  );
278 
279  //- Construct from objectRegistry and dictionary
280  forces
281  (
282  const word& name,
283  const objectRegistry& obr,
284  const dictionary&
285  );
286 
287 
288  //- Destructor
289  virtual ~forces();
290 
291 
292  // Member Functions
293 
294  //- Read the forces data
295  virtual bool read(const dictionary&);
296 
297  //- Calculate the forces and moments
298  virtual void calcForcesMoment();
299 
300  //- Return the total force
301  virtual vector forceEff() const;
302 
303  //- Return the total moment
304  virtual vector momentEff() const;
305 
306  //- Execute, currently does nothing
307  virtual bool execute();
308 
309  //- Write the forces
310  virtual bool write();
311 };
312 
313 
314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
315 
316 } // End namespace functionObjects
317 } // End namespace Foam
318 
319 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
320 
321 #endif
322 
323 // ************************************************************************* //
virtual vector momentEff() const
Return the total moment.
Definition: forces.C:890
dictionary dict
virtual void writeFileHeader(const label i)
Output file header information.
Definition: forces.C:75
List< Field< vector > > moment_
Pressure, viscous and porous moment per bin.
Definition: forces.H:216
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
labelHashSet patchSet_
Patches to integrate forces over.
Definition: forces.H:222
const word & name() const
Return the name of this functionObject.
word UName_
Name of velocity field.
Definition: forces.H:228
vector binDir_
Direction used to determine bin orientation.
Definition: forces.H:261
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
engineTime & runTime
coordinateSystem coordSys_
Coordinate system used when evaluating forces/moments.
Definition: forces.H:246
virtual vector forceEff() const
Return the total force.
Definition: forces.C:884
bool localSystem_
Flag to indicate whether we are using a local co-ordinate sys.
Definition: forces.H:249
word pName_
Name of pressure field.
Definition: forces.H:225
TypeName("forces")
Runtime type information.
word rhoName_
Name of density field (optional)
Definition: forces.H:231
virtual bool read(const dictionary &)
Read the forces data.
Definition: forces.C:617
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
void writeBins()
Helper function to write bin data.
Definition: forces.C:458
bool binCumulative_
Should bin data be cumulative?
Definition: forces.H:273
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:210
virtual bool execute()
Execute, currently does nothing.
Definition: forces.C:896
A class for handling words, derived from string.
Definition: word.H:59
tmp< volScalarField > mu() const
Dynamic viscosity field.
Definition: forces.C:286
scalar rhoRef_
Reference density needed for incompressible calculations.
Definition: forces.H:240
bool initialised_
Initialised flag.
Definition: forces.H:277
List< point > binPoints_
Bin positions along binDir.
Definition: forces.H:270
virtual void calcForcesMoment()
Calculate the forces and moments.
Definition: forces.C:751
tmp< volScalarField > rho() const
Return rho if specified otherwise rhoRef.
Definition: forces.C:330
void applyBins(const vectorField &Md, const vectorField &fN, const vectorField &fT, const vectorField &fP, const vectorField &d)
Accumulate bin data.
Definition: forces.C:377
forces(const forces &)
Disallow default bitwise copy construct.
tmp< volSymmTensorField > devRhoReff() const
Return the effective viscous stress (laminar + turbulent).
Definition: forces.C:219
void initialise()
Initialise the fields.
Definition: forces.C:172
bool porosity_
Flag to include porosity effects.
Definition: forces.H:252
scalar binMin_
Minimum bin bounds.
Definition: forces.H:267
void writeForces()
Helper function to write force data.
Definition: forces.C:413
scalar pRef_
Reference pressure.
Definition: forces.H:243
void operator=(const forces &)
Disallow default bitwise assignment.
List< Field< vector > > force_
Pressure, viscous and porous force per bin.
Definition: forces.H:213
scalar binDx_
Distance between bin divisions.
Definition: forces.H:264
Switch directForceDensity_
Is the force density being supplied directly?
Definition: forces.H:234
Calculates the forces and moments by integrating the pressure and skin-friction forces over a given l...
Definition: forces.H:195
word fDName_
The name of the force density (fD) field.
Definition: forces.H:237
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:53
Registry of regIOobjects.
virtual ~forces()
Destructor.
Definition: forces.C:611
fileID
Enumeration for ensuring the right file is accessed.
Definition: forces.H:206
label nBin_
Number of bins.
Definition: forces.H:258
virtual bool write()
Write the forces.
Definition: forces.C:902
wordList createFileNames(const dictionary &dict) const
Create file names for forces and bins.
Definition: forces.C:49
Namespace for OpenFOAM.