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-2013 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::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  functionObjectLibs ("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  \heading Function object 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  pName | pressure field name | no | p
64  UName | velocity field name | no | U
65  rhoName | 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  fDName | 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 rhoName 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 SeeAlso
103  Foam::functionObject
104  Foam::OutputFilterFunctionObject
105  Foam::forceCoeffs
106 
107 SourceFiles
108  forces.C
109  IOforces.H
110 
111 \*---------------------------------------------------------------------------*/
112 
113 #ifndef forces_H
114 #define forces_H
115 
116 #include "functionObjectFile.H"
117 #include "coordinateSystem.H"
118 #include "coordinateSystems.H"
119 #include "primitiveFieldsFwd.H"
120 #include "volFieldsFwd.H"
121 #include "HashSet.H"
122 #include "Tuple2.H"
123 #include "OFstream.H"
124 #include "Switch.H"
125 #include "writer.H"
126 
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128 
129 namespace Foam
130 {
131 
132 // Forward declaration of classes
133 class objectRegistry;
134 class dictionary;
135 class polyMesh;
136 class mapPolyMesh;
137 
138 /*---------------------------------------------------------------------------*\
139  Class forces Declaration
140 \*---------------------------------------------------------------------------*/
141 
142 class forces
143 :
144  public functionObjectFile
145 {
146 protected:
147 
148  // Protected data
149 
150  //- Name of this set of forces,
151  // Also used as the name of the probes directory.
152  word name_;
153 
154  const objectRegistry& obr_;
155 
156  //- On/off switch
157  bool active_;
158 
159  //- Switch to send output to Info as well as to file
160  Switch log_;
161 
162  //- Pressure, viscous and porous force per bin
163  List<Field<vector> > force_;
164 
165  //- Pressure, viscous and porous moment per bin
166  List<Field<vector> > moment_;
167 
168 
169  // Read from dictionary
170 
171  //- Patches to integrate forces over
173 
174  //- Name of pressure field
175  word pName_;
176 
177  //- Name of velocity field
178  word UName_;
179 
180  //- Name of density field (optional)
181  word rhoName_;
182 
183  //- Is the force density being supplied directly?
184  Switch directForceDensity_;
185 
186  //- The name of the force density (fD) field
187  word fDName_;
188 
189  //- Reference density needed for incompressible calculations
190  scalar rhoRef_;
191 
192  //- Reference pressure
193  scalar pRef_;
194 
195  //- Coordinate system used when evaluting forces/moments
196  coordinateSystem coordSys_;
197 
198  //- Flag to indicate whether we are using a local co-ordinate sys
199  bool localSystem_;
200 
201  //- Flag to include porosity effects
202  bool porosity_;
203 
204 
205  // Bin information
207  //- Number of bins
208  label nBin_;
209 
210  //- Direction used to determine bin orientation
211  vector binDir_;
212 
213  //- Distance between bin divisions
214  scalar binDx_;
215 
216  //- Minimum bin bounds
217  scalar binMin_;
219  //- Bin positions along binDir
222  //- Should bin data be cumulative?
223  bool binCumulative_;
225 
226  //- Initialised flag
228 
229 
230  // Protected Member Functions
231 
232  //- Create file names for forces and bins
233  wordList createFileNames(const dictionary& dict) const;
234 
235  //- Output file header information
236  virtual void writeFileHeader(const label i);
237 
238  //- Initialise the fields
239  void initialise();
240 
241  //- Return the effective viscous stress (laminar + turbulent).
243 
244  //- Dynamic viscosity field
246 
247  //- Return rho if rhoName is specified otherwise rhoRef
249 
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  //- Accumulate bin data
255  void applyBins
256  (
257  const vectorField& Md,
258  const vectorField& fN,
259  const vectorField& fT,
260  const vectorField& fP,
261  const vectorField& d
262  );
264  //- Helper function to write force data
265  void writeForces();
267  //- Helper function to write bin data
268  void writeBins();
269 
270  //- Disallow default bitwise copy construct
271  forces(const forces&);
273  //- Disallow default bitwise assignment
274  void operator=(const forces&);
276 
277 public:
279  //- Runtime type information
280  TypeName("forces");
282 
283  // Constructors
285  //- Construct for given objectRegistry and dictionary.
286  // Allow the possibility to load fields from files
288  (
289  const word& name,
290  const objectRegistry&,
291  const dictionary&,
292  const bool loadFromFiles = false,
293  const bool readFields = true
294  );
295 
296 
297  //- Construct from components
298  forces
299  (
300  const word& name,
301  const objectRegistry&,
302  const labelHashSet& patchSet,
303  const word& pName,
304  const word& UName,
305  const word& rhoName,
306  const scalar rhoInf,
307  const scalar pRef,
308  const coordinateSystem& coordSys
309  );
310 
311 
312  //- Destructor
313  virtual ~forces();
314 
315 
316  // Member Functions
317 
318  //- Return name of the set of forces
319  virtual const word& name() const
320  {
321  return name_;
322  }
323 
324  //- Read the forces data
325  virtual void read(const dictionary&);
326 
327  //- Execute, currently does nothing
328  virtual void execute();
329 
330  //- Execute at the final time-loop, currently does nothing
331  virtual void end();
332 
333  //- Called when time was set at the end of the Time::operator++
334  virtual void timeSet();
335 
336  //- Write the forces
337  virtual void write();
338 
339  //- Calculate the forces and moments
340  virtual void calcForcesMoment();
341 
342  //- Return the total force
343  virtual vector forceEff() const;
344 
345  //- Return the total moment
346  virtual vector momentEff() const;
347 
348  //- Update for changes of mesh
349  virtual void updateMesh(const mapPolyMesh&)
350  {}
351 
352  //- Update for changes of mesh
353  virtual void movePoints(const polyMesh&)
354  {}
355 };
356 
357 
358 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
359 
360 } // End namespace Foam
361 
362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
363 
364 #endif
365 
366 // ************************************************************************* //
word name_
Name of this set of forces,.
Definition: forces.H:216
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: forces.C:781
scalar binDx_
Distance between bin divisions.
Definition: forces.H:278
vector binDir_
Direction used to determine bin orientation.
Definition: forces.H:275
word UName_
Name of velocity field.
Definition: forces.H:242
List< Field< vector > > moment_
Pressure, viscous and porous moment per bin.
Definition: forces.H:230
void writeBins()
Helper function to write bin data.
Definition: forces.C:435
TypeName("forces")
Runtime type information.
virtual void calcForcesMoment()
Calculate the forces and moments.
Definition: forces.C:809
labelHashSet patchSet_
Patches to integrate forces over.
Definition: forces.H:236
Switch directForceDensity_
Is the force density being supplied directly?
Definition: forces.H:248
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition: forces.H:413
tmp< volScalarField > rho() const
Return rho if rhoName is specified otherwise rhoRef.
Definition: forces.C:306
tmp< volSymmTensorField > devRhoReff() const
Return the effective viscous stress (laminar + turbulent).
Definition: forces.C:205
Base class for other coordinate system specifications.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
coordinateSystem coordSys_
Coordinate system used when evaluting forces/moments.
Definition: forces.H:260
bool porosity_
Flag to include porosity effects.
Definition: forces.H:266
This function object calculates the forces and moments by integrating the pressure and skin-friction ...
Definition: forces.H:206
List< Field< vector > > force_
Pressure, viscous and porous force per bin.
Definition: forces.H:227
scalar binMin_
Minimum bin bounds.
Definition: forces.H:281
A class for handling words, derived from string.
Definition: word.H:59
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
virtual void write()
Write the forces.
Definition: forces.C:787
bool localSystem_
Flag to indicate whether we are using a local co-ordinate sys.
Definition: forces.H:263
word rhoName_
Name of density field (optional)
Definition: forces.H:245
forces(const forces &)
Disallow default bitwise copy construct.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
void applyBins(const vectorField &Md, const vectorField &fN, const vectorField &fT, const vectorField &fP, const vectorField &d)
Accumulate bin data.
Definition: forces.C:355
bool binCumulative_
Should bin data be cumulative?
Definition: forces.H:287
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
dictionary dict
tmp< volScalarField > mu() const
Dynamic viscosity field.
Definition: forces.C:267
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
scalar pRef_
Reference pressure.
Definition: forces.H:257
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: forces.C:775
volScalarField & p
Definition: createFields.H:51
bool initialised_
Initialised flag.
Definition: forces.H:291
virtual void movePoints(const polyMesh &)
Update for changes of mesh.
Definition: forces.H:417
Switch log_
Switch to send output to Info as well as to file.
Definition: forces.H:224
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:210
virtual vector momentEff() const
Return the total moment.
Definition: forces.C:960
scalar rhoRef_
Reference density needed for incompressible calculations.
Definition: forces.H:254
virtual const word & name() const
Return name of the set of forces.
Definition: forces.H:383
bool active_
On/off switch.
Definition: forces.H:221
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
void operator=(const forces &)
Disallow default bitwise assignment.
void writeForces()
Helper function to write force data.
Definition: forces.C:391
word pName_
Name of pressure field.
Definition: forces.H:239
virtual void read(const dictionary &)
Read the forces data.
Definition: forces.C:634
Registry of regIOobjects.
List< point > binPoints_
Bin positions along binDir.
Definition: forces.H:284
virtual void execute()
Execute, currently does nothing.
Definition: forces.C:769
virtual void writeFileHeader(const label i)
Output file header information.
Definition: forces.C:68
void initialise()
Initialise the fields.
Definition: forces.C:156
word fDName_
The name of the force density (fD) field.
Definition: forces.H:251
virtual ~forces()
Destructor.
Definition: forces.C:628
scalar pRef
Definition: createFields.H:19
This function object reads fields from the time directories and adds them to the mesh database for fu...
Definition: readFields.H:102
label nBin_
Number of bins.
Definition: forces.H:272
virtual vector forceEff() const
Return the total force.
Definition: forces.C:954
A class for managing temporary objects.
Definition: PtrList.H:118
wordList createFileNames(const dictionary &dict) const
Create file names for forces and bins.
Definition: forces.C:46
const objectRegistry & obr_
Definition: forces.H:218