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-2019 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 class fileID
143  {
144  mainFile = 0,
145  binsFile = 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?
209  bool binCumulative_;
210 
211 
212  //- Initialised flag
214 
215 
216  // Protected Member Functions
217 
218  using logFiles::file;
219 
220  Ostream& file(const fileID fid)
221  {
222  return logFiles::file(label(fid));
223  }
224 
225  //- Create file names for forces and bins
226  wordList createFileNames(const dictionary& dict) const;
227 
228  //- Output file header information
229  virtual void writeFileHeader(const label i);
230 
231  //- Initialise the fields
232  void initialise();
233 
234  //- Return the effective viscous stress (laminar + turbulent).
236 
237  //- Dynamic viscosity field
238  tmp<volScalarField> mu() const;
239 
240  //- Return rho if specified otherwise rhoRef
241  tmp<volScalarField> rho() const;
242 
243  //- Return rhoRef if the pressure field is dynamic, i.e. p/rho
244  // otherwise return 1
245  scalar rho(const volScalarField& p) const;
247  //- Accumulate bin data
248  void applyBins
249  (
250  const vectorField& Md,
251  const vectorField& fN,
252  const vectorField& fT,
253  const vectorField& fP,
254  const vectorField& d
255  );
256 
257  //- Helper function to write force data
258  void writeForces();
259 
260  //- Helper function to write bin data
261  void writeBins();
262 
263 
264 public:
265 
266  //- Runtime type information
267  TypeName("forces");
268 
269 
270  // Constructors
271 
272  //- Construct from Time and dictionary
274  (
275  const word& name,
276  const Time& runTime,
278  );
279 
280  //- Construct from objectRegistry and dictionary
281  forces
282  (
283  const word& name,
284  const objectRegistry& obr,
285  const dictionary&
286  );
287 
288  //- Disallow default bitwise copy construction
289  forces(const forces&) = delete;
290 
291 
292  //- Destructor
293  virtual ~forces();
294 
295 
296  // Member Functions
297 
298  //- Read the forces data
299  virtual bool read(const dictionary&);
300 
301  //- Calculate the forces and moments
302  virtual void calcForcesMoment();
303 
304  //- Return the total force
305  virtual vector forceEff() const;
306 
307  //- Return the total moment
308  virtual vector momentEff() const;
309 
310  //- Execute, currently does nothing
311  virtual bool execute();
312 
313  //- Write the forces
314  virtual bool write();
315 
316 
317  // Member Operators
318 
319  //- Disallow default bitwise assignment
320  void operator=(const forces&) = delete;
321 };
322 
323 
324 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 
326 } // End namespace functionObjects
327 } // End namespace Foam
328 
329 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 
331 #endif
332 
333 // ************************************************************************* //
virtual vector momentEff() const
Return the total moment.
Definition: forces.C:882
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:158
forces(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: forces.C:532
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
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:876
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.
void operator=(const forces &)=delete
Disallow default bitwise assignment.
word rhoName_
Name of density field (optional)
Definition: forces.H:231
virtual bool read(const dictionary &)
Read the forces data.
Definition: forces.C:609
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:450
bool binCumulative_
Should bin data be cumulative?
Definition: forces.H:273
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:208
virtual bool execute()
Execute, currently does nothing.
Definition: forces.C:888
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:743
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:369
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
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:405
scalar pRef_
Reference pressure.
Definition: forces.H:243
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
OFstream & file()
Return access to the file (if only 1)
Definition: logFiles.C:120
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:603
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:894
wordList createFileNames(const dictionary &dict) const
Create file names for forces and bins.
Definition: forces.C:49
Namespace for OpenFOAM.