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-2022 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  phase | Phase name for phase-fraction | no |
64  CofR | Centre of rotation (see below) | no |
65  directForceDensity | Force density supplied directly (see below)|no|no
66  fD | Name of force density field (see below) | no | fD
67  \endtable
68 
69  Bin data is optional, but if the dictionary is present, the entries must
70  be defined according o
71  \table
72  nBin | number of data bins | yes |
73  direction | direction along which bins are defined | yes |
74  cumulative | bin data accumulated with increasing distance | yes |
75  \endtable
76 
77  Note
78  - For incompressible cases, set \c rho to \c rhoInf and provide
79  a \c rhoInf value corresponding to the free-stream constant density.
80  - If the \c phase name is specified the corresponding phase-fraction field
81  \c alpha.<phase> is used to filter the surface force field
82  before integration.
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  origin (0 0 0);
95  coordinateRotation
96  {
97  type axesRotation;
98  e1 (1 0 0);
99  e3 (0 0 1);
100  }
101  \endverbatim
102 
103 See also
104  Foam::functionObject
105  Foam::functionObjects::fvMeshFunctionObject
106  Foam::functionObjects::logFiles
107  Foam::functionObjects::timeControl
108  Foam::forceCoeffs
109 
110 SourceFiles
111  forces.C
112 
113 \*---------------------------------------------------------------------------*/
114 
115 #ifndef functionObjects_forces_H
116 #define functionObjects_forces_H
117 
118 #include "fvMeshFunctionObject.H"
119 #include "logFiles.H"
120 #include "coordinateSystem.H"
121 #include "volFieldsFwd.H"
122 #include "HashSet.H"
123 
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 
126 namespace Foam
127 {
128 namespace functionObjects
129 {
130 
131 /*---------------------------------------------------------------------------*\
132  Class forces Declaration
133 \*---------------------------------------------------------------------------*/
134 
135 class forces
136 :
137  public fvMeshFunctionObject,
138  public logFiles
139 {
140 
141 protected:
142 
143  // Protected data
144 
145  //- Enumeration for ensuring the right file is accessed
146  enum class fileID
147  {
148  mainFile = 0,
149  binsFile = 1
150  };
151 
152  //- Pressure, viscous and porous force per bin
153  List<Field<vector>> force_;
154 
155  //- Pressure, viscous and porous moment per bin
156  List<Field<vector>> moment_;
157 
158 
159  // Read from dictionary
160 
161  //- Patches to integrate forces over
163 
164  //- Name of pressure field
165  word pName_;
166 
167  //- Name of velocity field
168  word UName_;
169 
170  //- Name of density field (optional)
171  word rhoName_;
172 
173  //- The name of the phase (optional)
174  word phaseName_;
175 
176  //- Is the force density being supplied directly?
177  Switch directForceDensity_;
178 
179  //- The name of the force density (fD) field
180  word fDName_;
181 
182  //- Reference density needed for incompressible calculations
183  scalar rhoRef_;
184 
185  //- Reference pressure
186  scalar pRef_;
187 
188  //- Coordinate system used when evaluating forces/moments
189  coordinateSystem coordSys_;
190 
191  //- Flag to indicate whether we are using a local co-ordinate sys
192  bool localSystem_;
193 
194  //- Flag to include porosity effects
195  bool porosity_;
196 
197 
198  // Bin information
199 
200  //- Number of bins
201  label nBin_;
202 
203  //- Direction used to determine bin orientation
205 
206  //- Distance between bin divisions
207  scalar binDx_;
208 
209  //- Minimum bin bounds
210  scalar binMin_;
211 
212  //- Bin positions along binDir
214 
215  //- Should bin data be cumulative?
216  bool binCumulative_;
217 
218 
219  //- Initialised flag
220  bool initialised_;
221 
223  // Protected Member Functions
224 
226 
227  Ostream& file(const fileID fid)
228  {
229  return logFiles::file(label(fid));
230  }
232  //- Create file names for forces and bins
233  wordList createFileNames(const dictionary& dict) const;
235  //- Output file header information
236  virtual void writeFileHeader(const label i);
238  //- Initialise the fields
239  void initialise();
241  //- Return the effective viscous stress (laminar + turbulent).
244  //- Dynamic viscosity field
245  tmp<volScalarField> mu() const;
247  //- Return rho if specified otherwise rhoRef
248  tmp<volScalarField> rho() const;
250  //- Return rhoRef if the pressure field is dynamic, i.e. p/rho
251  // otherwise return 1
252  scalar rho(const volScalarField& p) const;
253 
254  //- Get the volume fraction field
256 
257  //- Get the volume fraction field on a patch
259 
260  //- Accumulate bin data
262  (
263  const vectorField& Md,
264  const vectorField& fN,
265  const vectorField& fT,
266  const vectorField& fP,
267  const vectorField& d
268  );
269 
270  //- Helper function to write force data
271  void writeForces();
272 
273  //- Helper function to write bin data
274  void writeBins();
275 
277 public:
278 
279  //- Runtime type information
280  TypeName("forces");
281 
283  // Constructors
284 
285  //- Construct from Time and dictionary
286  forces
287  (
288  const word& name,
289  const Time& runTime,
290  const dictionary& dict
291  );
292 
293  //- Construct from objectRegistry and dictionary
294  forces
295  (
296  const word& name,
297  const objectRegistry& obr,
298  const dictionary&
299  );
300 
301  //- Disallow default bitwise copy construction
302  forces(const forces&) = delete;
303 
304 
305  //- Destructor
306  virtual ~forces();
307 
308 
309  // Member Functions
310 
311  //- Read the forces data
312  virtual bool read(const dictionary&);
313 
314  //- Return the list of fields required
315  virtual wordList fields() const
316  {
317  return wordList::null();
318  }
319 
320  //- Calculate the forces and moments
321  virtual void calcForcesMoment();
322 
323  //- Return the total force
324  virtual vector forceEff() const;
325 
326  //- Return the total moment
327  virtual vector momentEff() const;
328 
329  //- Execute, currently does nothing
330  virtual bool execute();
331 
332  //- Write the forces
333  virtual bool write();
334 
335 
336  // Member Operators
337 
338  //- Disallow default bitwise assignment
339  void operator=(const forces&) = delete;
340 };
341 
342 
343 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
344 
345 } // End namespace functionObjects
346 } // End namespace Foam
347 
348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
349 
350 #endif
351 
352 // ************************************************************************* //
virtual vector momentEff() const
Return the total moment.
Definition: forces.C:1025
word phaseName_
The name of the phase (optional)
Definition: forces.H:243
dictionary dict
virtual void writeFileHeader(const label i)
Output file header information.
Definition: forces.C:78
List< Field< vector > > moment_
Pressure, viscous and porous moment per bin.
Definition: forces.H:225
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
labelHashSet patchSet_
Patches to integrate forces over.
Definition: forces.H:231
const word & name() const
Return the name of this functionObject.
word UName_
Name of velocity field.
Definition: forces.H:237
virtual wordList fields() const
Return the list of fields required.
Definition: forces.H:384
vector binDir_
Direction used to determine bin orientation.
Definition: forces.H:273
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
forces(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: forces.C:650
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
coordinateSystem coordSys_
Coordinate system used when evaluating forces/moments.
Definition: forces.H:258
virtual vector forceEff() const
Return the total force.
Definition: forces.C:1019
bool localSystem_
Flag to indicate whether we are using a local co-ordinate sys.
Definition: forces.H:261
word pName_
Name of pressure field.
Definition: forces.H:234
TypeName("forces")
Runtime type information.
void operator=(const forces &)=delete
Disallow default bitwise assignment.
static const List< T > & null()
Return a null List.
Definition: ListI.H:118
word rhoName_
Name of density field (optional)
Definition: forces.H:240
virtual bool read(const dictionary &)
Read the forces data.
Definition: forces.C:727
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
void writeBins()
Helper function to write bin data.
Definition: forces.C:543
bool binCumulative_
Should bin data be cumulative?
Definition: forces.H:285
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:211
virtual bool execute()
Execute, currently does nothing.
Definition: forces.C:1031
A class for handling words, derived from string.
Definition: word.H:59
tmp< volScalarField > mu() const
Dynamic viscosity field.
Definition: forces.C:297
scalar rhoRef_
Reference density needed for incompressible calculations.
Definition: forces.H:252
bool initialised_
Initialised flag.
Definition: forces.H:289
List< point > binPoints_
Bin positions along binDir.
Definition: forces.H:282
virtual void calcForcesMoment()
Calculate the forces and moments.
Definition: forces.C:884
tmp< volScalarField > rho() const
Return rho if specified otherwise rhoRef.
Definition: forces.C:365
void applyBins(const vectorField &Md, const vectorField &fN, const vectorField &fT, const vectorField &fP, const vectorField &d)
Accumulate bin data.
Definition: forces.C:447
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:180
bool porosity_
Flag to include porosity effects.
Definition: forces.H:264
scalar binMin_
Minimum bin bounds.
Definition: forces.H:279
void writeForces()
Helper function to write force data.
Definition: forces.C:483
scalar pRef_
Reference pressure.
Definition: forces.H:255
label patchi
tmp< volSymmTensorField > devTau() const
Return the effective viscous stress (laminar + turbulent).
Definition: forces.C:227
List< Field< vector > > force_
Pressure, viscous and porous force per bin.
Definition: forces.H:222
tmp< volScalarField > alpha() const
Get the volume fraction field.
Definition: forces.C:403
scalar binDx_
Distance between bin divisions.
Definition: forces.H:276
Switch directForceDensity_
Is the force density being supplied directly?
Definition: forces.H:246
OFstream & file()
Return access to the file (if only 1)
Definition: logFiles.C:107
Calculates the forces and moments by integrating the pressure and skin-friction forces over a given l...
Definition: forces.H:204
word fDName_
The name of the force density (fD) field.
Definition: forces.H:249
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:53
Registry of regIOobjects.
virtual ~forces()
Destructor.
Definition: forces.C:721
fileID
Enumeration for ensuring the right file is accessed.
Definition: forces.H:215
label nBin_
Number of bins.
Definition: forces.H:270
virtual bool write()
Write the forces.
Definition: forces.C:1037
wordList createFileNames(const dictionary &dict) const
Create file names for forces and bins.
Definition: forces.C:52
Namespace for OpenFOAM.