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-2020 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 increasing 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  origin (0 0 0);
92  coordinateRotation
93  {
94  type axesRotation;
95  e1 (1 0 0);
96  e3 (0 0 1);
97  }
98  \endverbatim
99 
100 See also
101  Foam::functionObject
102  Foam::functionObjects::fvMeshFunctionObject
103  Foam::functionObjects::logFiles
104  Foam::functionObjects::timeControl
105  Foam::forceCoeffs
106 
107 SourceFiles
108  forces.C
109 
110 \*---------------------------------------------------------------------------*/
111 
112 #ifndef functionObjects_forces_H
113 #define functionObjects_forces_H
114 
115 #include "fvMeshFunctionObject.H"
116 #include "logFiles.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 fvMeshFunctionObject,
135  public logFiles
136 {
137 
138 protected:
139 
140  // Protected data
141 
142  //- Enumeration for ensuring the right file is accessed
143  enum class fileID
144  {
145  mainFile = 0,
146  binsFile = 1
147  };
148 
149  //- Pressure, viscous and porous force per bin
150  List<Field<vector>> force_;
151 
152  //- Pressure, viscous and porous moment per bin
153  List<Field<vector>> moment_;
154 
155 
156  // Read from dictionary
157 
158  //- Patches to integrate forces over
160 
161  //- Name of pressure field
162  word pName_;
163 
164  //- Name of velocity field
165  word UName_;
166 
167  //- Name of density field (optional)
168  word rhoName_;
169 
170  //- Is the force density being supplied directly?
171  Switch directForceDensity_;
172 
173  //- The name of the force density (fD) field
174  word fDName_;
175 
176  //- Reference density needed for incompressible calculations
177  scalar rhoRef_;
178 
179  //- Reference pressure
180  scalar pRef_;
181 
182  //- Coordinate system used when evaluating forces/moments
183  coordinateSystem coordSys_;
184 
185  //- Flag to indicate whether we are using a local co-ordinate sys
186  bool localSystem_;
187 
188  //- Flag to include porosity effects
189  bool porosity_;
190 
191 
192  // Bin information
193 
194  //- Number of bins
195  label nBin_;
197  //- Direction used to determine bin orientation
198  vector binDir_;
199 
200  //- Distance between bin divisions
201  scalar binDx_;
202 
203  //- Minimum bin bounds
204  scalar binMin_;
205 
206  //- Bin positions along binDir
208 
209  //- Should bin data be cumulative?
210  bool binCumulative_;
211 
212 
213  //- Initialised flag
215 
216 
217  // Protected Member Functions
218 
219  using logFiles::file;
220 
221  Ostream& file(const fileID fid)
222  {
223  return logFiles::file(label(fid));
224  }
225 
226  //- Create file names for forces and bins
227  wordList createFileNames(const dictionary& dict) const;
228 
229  //- Output file header information
230  virtual void writeFileHeader(const label i);
231 
232  //- Initialise the fields
233  void initialise();
234 
235  //- Return the effective viscous stress (laminar + turbulent).
237 
238  //- Dynamic viscosity field
239  tmp<volScalarField> mu() const;
240 
241  //- Return rho if specified otherwise rhoRef
242  tmp<volScalarField> rho() const;
243 
244  //- Return rhoRef if the pressure field is dynamic, i.e. p/rho
245  // otherwise return 1
246  scalar rho(const volScalarField& p) const;
248  //- Accumulate bin data
249  void applyBins
250  (
251  const vectorField& Md,
252  const vectorField& fN,
253  const vectorField& fT,
254  const vectorField& fP,
255  const vectorField& d
256  );
257 
258  //- Helper function to write force data
259  void writeForces();
260 
261  //- Helper function to write bin data
262  void writeBins();
263 
264 
265 public:
266 
267  //- Runtime type information
268  TypeName("forces");
269 
270 
271  // Constructors
272 
273  //- Construct from Time and dictionary
275  (
276  const word& name,
277  const Time& runTime,
279  );
280 
281  //- Construct from objectRegistry and dictionary
282  forces
283  (
284  const word& name,
285  const objectRegistry& obr,
286  const dictionary&
287  );
288 
289  //- Disallow default bitwise copy construction
290  forces(const forces&) = delete;
291 
292 
293  //- Destructor
294  virtual ~forces();
295 
296 
297  // Member Functions
298 
299  //- Read the forces data
300  virtual bool read(const dictionary&);
301 
302  //- Calculate the forces and moments
303  virtual void calcForcesMoment();
304 
305  //- Return the total force
306  virtual vector forceEff() const;
307 
308  //- Return the total moment
309  virtual vector momentEff() const;
310 
311  //- Execute, currently does nothing
312  virtual bool execute();
313 
314  //- Write the forces
315  virtual bool write();
316 
317 
318  // Member Operators
319 
320  //- Disallow default bitwise assignment
321  void operator=(const forces&) = delete;
322 };
323 
324 
325 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
326 
327 } // End namespace functionObjects
328 } // End namespace Foam
329 
330 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331 
332 #endif
333 
334 // ************************************************************************* //
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:217
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:223
const word & name() const
Return the name of this functionObject.
word UName_
Name of velocity field.
Definition: forces.H:229
vector binDir_
Direction used to determine bin orientation.
Definition: forces.H:262
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:247
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:250
word pName_
Name of pressure field.
Definition: forces.H:226
TypeName("forces")
Runtime type information.
void operator=(const forces &)=delete
Disallow default bitwise assignment.
word rhoName_
Name of density field (optional)
Definition: forces.H:232
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:274
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:211
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:241
bool initialised_
Initialised flag.
Definition: forces.H:278
List< point > binPoints_
Bin positions along binDir.
Definition: forces.H:271
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:54
void initialise()
Initialise the fields.
Definition: forces.C:172
bool porosity_
Flag to include porosity effects.
Definition: forces.H:253
scalar binMin_
Minimum bin bounds.
Definition: forces.H:268
void writeForces()
Helper function to write force data.
Definition: forces.C:405
scalar pRef_
Reference pressure.
Definition: forces.H:244
tmp< volSymmTensorField > devTau() const
Return the effective viscous stress (laminar + turbulent).
Definition: forces.C:219
List< Field< vector > > force_
Pressure, viscous and porous force per bin.
Definition: forces.H:214
scalar binDx_
Distance between bin divisions.
Definition: forces.H:265
Switch directForceDensity_
Is the force density being supplied directly?
Definition: forces.H:235
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:196
word fDName_
The name of the force density (fD) field.
Definition: forces.H:238
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:207
label nBin_
Number of bins.
Definition: forces.H:259
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.