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