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  This function object calculates the forces and moments by integrating the
32  pressure and 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::writeFiles
105  Foam::functionObjects::timeControl
106  Foam::forceCoeffs
107 
108 SourceFiles
109  forces.C
110 
111 \*---------------------------------------------------------------------------*/
112 
113 #ifndef functionObjects_forces_H
114 #define functionObjects_forces_H
115 
116 #include "writeFiles.H"
117 #include "coordinateSystem.H"
118 #include "volFieldsFwd.H"
119 #include "HashSet.H"
120 
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
122 
123 namespace Foam
124 {
125 namespace functionObjects
126 {
127 
128 /*---------------------------------------------------------------------------*\
129  Class forces Declaration
130 \*---------------------------------------------------------------------------*/
131 
132 class forces
133 :
134  public writeFiles
135 {
136 protected:
137 
138  // Protected data
139 
140  //- Pressure, viscous and porous force per bin
141  List<Field<vector>> force_;
142 
143  //- Pressure, viscous and porous moment per bin
144  List<Field<vector>> moment_;
145 
146 
147  // Read from dictionary
148 
149  //- Patches to integrate forces over
151 
152  //- Name of pressure field
153  word pName_;
154 
155  //- Name of velocity field
156  word UName_;
157 
158  //- Name of density field (optional)
159  word rhoName_;
160 
161  //- Is the force density being supplied directly?
162  Switch directForceDensity_;
163 
164  //- The name of the force density (fD) field
165  word fDName_;
166 
167  //- Reference density needed for incompressible calculations
168  scalar rhoRef_;
169 
170  //- Reference pressure
171  scalar pRef_;
172 
173  //- Coordinate system used when evaluting forces/moments
174  coordinateSystem coordSys_;
175 
176  //- Flag to indicate whether we are using a local co-ordinate sys
177  bool localSystem_;
178 
179  //- Flag to include porosity effects
180  bool porosity_;
181 
182 
183  // Bin information
184 
185  //- Number of bins
186  label nBin_;
187 
188  //- Direction used to determine bin orientation
189  vector binDir_;
190 
191  //- Distance between bin divisions
192  scalar binDx_;
193 
194  //- Minimum bin bounds
195  scalar binMin_;
197  //- Bin positions along binDir
199 
200  //- Should bin data be cumulative?
201  bool binCumulative_;
202 
203 
204  //- Initialised flag
206 
207 
208  // Protected Member Functions
209 
210  //- Create file names for forces and bins
211  wordList createFileNames(const dictionary& dict) const;
212 
213  //- Output file header information
214  virtual void writeFileHeader(const label i);
215 
216  //- Initialise the fields
217  void initialise();
218 
219  //- Return the effective viscous stress (laminar + turbulent).
221 
222  //- Dynamic viscosity field
224 
225  //- Return rho if specified otherwise rhoRef
227 
228  //- Return rhoRef if the pressure field is dynamic, i.e. p/rho
229  // otherwise return 1
230  scalar rho(const volScalarField& p) const;
231 
232  //- Accumulate bin data
233  void applyBins
234  (
235  const vectorField& Md,
236  const vectorField& fN,
237  const vectorField& fT,
238  const vectorField& fP,
239  const vectorField& d
240  );
242  //- Helper function to write force data
243  void writeForces();
245  //- Helper function to write bin data
246  void writeBins();
247 
248  //- Disallow default bitwise copy construct
249  forces(const forces&);
251  //- Disallow default bitwise assignment
252  void operator=(const forces&);
254 
255 public:
257  //- Runtime type information
258  TypeName("forces");
260 
261  // Constructors
263  //- Construct from Time and dictionary
264  forces
265  (
266  const word& name,
267  const Time& runTime,
268  const dictionary& dict
269  );
270 
271  //- Construct from objectRegistry and dictionary
272  forces
273  (
274  const word& name,
275  const objectRegistry& obr,
276  const dictionary&
277  );
278 
279 
280  //- Destructor
281  virtual ~forces();
282 
283 
284  // Member Functions
285 
286  //- Read the forces data
287  virtual bool read(const dictionary&);
288 
289  //- Calculate the forces and moments
290  virtual void calcForcesMoment();
291 
292  //- Return the total force
293  virtual vector forceEff() const;
294 
295  //- Return the total moment
296  virtual vector momentEff() const;
297 
298  //- Execute, currently does nothing
299  virtual bool execute();
300 
301  //- Write the forces
302  virtual bool write();
303 };
304 
305 
306 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
307 
308 } // End namespace functionObjects
309 } // End namespace Foam
310 
311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
312 
313 #endif
314 
315 // ************************************************************************* //
dictionary dict
virtual void writeFileHeader(const label i)
Output file header information.
Definition: forces.C:72
List< Field< vector > > moment_
Pressure, viscous and porous moment per bin.
Definition: forces.H:208
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:214
word UName_
Name of velocity field.
Definition: forces.H:220
vector binDir_
Direction used to determine bin orientation.
Definition: forces.H:253
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:59
virtual vector forceEff() const
Return the total force.
Definition: forces.C:887
coordinateSystem coordSys_
Coordinate system used when evaluting forces/moments.
Definition: forces.H:238
bool localSystem_
Flag to indicate whether we are using a local co-ordinate sys.
Definition: forces.H:241
word pName_
Name of pressure field.
Definition: forces.H:217
TypeName("forces")
Runtime type information.
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
word rhoName_
Name of density field (optional)
Definition: forces.H:223
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:443
tmp< volSymmTensorField > devRhoReff() const
Return the effective viscous stress (laminar + turbulent).
Definition: forces.C:207
bool binCumulative_
Should bin data be cumulative?
Definition: forces.H:265
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:210
tmp< volScalarField > mu() const
Dynamic viscosity field.
Definition: forces.C:269
virtual bool execute()
Execute, currently does nothing.
Definition: forces.C:899
const word & name() const
Return the name of this functionObject.
A class for handling words, derived from string.
Definition: word.H:59
scalar rhoRef_
Reference density needed for incompressible calculations.
Definition: forces.H:232
bool initialised_
Initialised flag.
Definition: forces.H:269
List< point > binPoints_
Bin positions along binDir.
Definition: forces.H:262
virtual void calcForcesMoment()
Calculate the forces and moments.
Definition: forces.C:747
void applyBins(const vectorField &Md, const vectorField &fN, const vectorField &fT, const vectorField &fP, const vectorField &d)
Accumulate bin data.
Definition: forces.C:362
forces(const forces &)
Disallow default bitwise copy construct.
void initialise()
Initialise the fields.
Definition: forces.C:160
bool porosity_
Flag to include porosity effects.
Definition: forces.H:244
virtual vector momentEff() const
Return the total moment.
Definition: forces.C:893
scalar binMin_
Minimum bin bounds.
Definition: forces.H:259
void writeForces()
Helper function to write force data.
Definition: forces.C:398
scalar pRef_
Reference pressure.
Definition: forces.H:235
void operator=(const forces &)
Disallow default bitwise assignment.
List< Field< vector > > force_
Pressure, viscous and porous force per bin.
Definition: forces.H:205
scalar binDx_
Distance between bin divisions.
Definition: forces.H:256
Switch directForceDensity_
Is the force density being supplied directly?
Definition: forces.H:226
This function object calculates the forces and moments by integrating the pressure and skin-friction ...
Definition: forces.H:196
word fDName_
The name of the force density (fD) field.
Definition: forces.H:229
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:54
Registry of regIOobjects.
virtual ~forces()
Destructor.
Definition: forces.C:606
tmp< volScalarField > rho() const
Return rho if specified otherwise rhoRef.
Definition: forces.C:313
wordList createFileNames(const dictionary &dict) const
Create file names for forces and bins.
Definition: forces.C:49
label nBin_
Number of bins.
Definition: forces.H:250
virtual bool write()
Write the forces.
Definition: forces.C:905
Namespace for OpenFOAM.