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-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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, and
33  the resistance from porous zones.
34 
35  Forces and moments are calculated, with optional co-ordinate system and
36  writing of binned data, where force and moment contributions are collected
37  into a user-defined number of bins that span the input geometries for a
38  user-defined direction vector.
39 
40  Data is written into multiple files in the
41  postProcessing/<functionObjectName> directory:
42  - force.dat : forces in global Cartesian co-ordinate system
43  - moment.dat : moments in global Cartesian co-ordinate system
44  - forceBin.dat : force bins in global Cartesian co-ordinate system
45  - momentBin.dat : moment bins in global Cartesian co-ordinate system
46  - localForce.dat : forces in local co-ordinate system
47  - localMoment.dat : moments in local co-ordinate system
48  - localForceBin.dat : force bins in local co-ordinate system
49  - localMomentBin.dat : moment bins in local co-ordinate system
50 
51  Example of function object specification:
52  \verbatim
53  forces1
54  {
55  type forces;
56  functionObjectLibs ("libforces.so");
57  ...
58  log yes;
59  writeFields yes;
60  patches (walls);
61 
62  binData
63  {
64  nBin 20;
65  direction (1 0 0);
66  cumulative yes;
67  }
68  }
69  \endverbatim
70 
71  \heading Function object usage
72  \table
73  Property | Description | Required | Default value
74  type | type name: forces | yes |
75  log | write force data to standard output | no | no
76  writeFields | write the force and moment fields | no | no
77  patches | patches included in the forces calculation | yes |
78  pName | pressure field name | no | p
79  UName | velocity field name | no | U
80  rhoName | density field name (see below) | no | rho
81  CofR | centre of rotation (see below) | no |
82  porosity | flag to include porosity contributions | no | no
83  directForceDensity | force density supplied directly (see below)|no|no
84  fDName | name of force density field (see below) | no | fD
85  \endtable
86 
87  Bin data is optional, but if the dictionary is present, the entries must
88  be defined according o
89  \table
90  nBin | number of data bins | yes |
91  direction | direction along which bins are defined | yes |
92  cumulative | bin data accumulated with incresing distance | yes |
93  \endtable
94 
95 Note
96  - For incompressible cases, set \c rhoName to \c rhoInf. You will then be
97  required to provide a \c rhoInf value corresponding to the free-stream
98  constant density.
99  - If the force density is supplied directly, set the \c directForceDensity
100  flag to 'yes', and supply the force density field using the \c
101  fDName entry
102  - The centre of rotation (CofR) for moment calculations can either be
103  specified by an \c CofR entry, or be taken from origin of the local
104  coordinate system. For example,
105  \verbatim
106  CofR (0 0 0);
107  \endverbatim
108  or
109  \verbatim
110  coordinateSystem
111  {
112  origin (0 0 0);
113  e3 (0 0 1);
114  e1 (1 0 0);
115  }
116  \endverbatim
117 
118 SeeAlso
119  Foam::functionObject
120  Foam::functionObjectFile
121  Foam::functionObjectState
122  Foam::OutputFilterFunctionObject
123  Foam::forceCoeffs
124 
125 SourceFiles
126  forces.C
127  IOforces.H
128 
129 \*---------------------------------------------------------------------------*/
130 
131 #ifndef forces_H
132 #define forces_H
133 
134 #include "functionObjectState.H"
135 #include "functionObjectFile.H"
136 #include "coordinateSystem.H"
137 #include "coordinateSystems.H"
138 #include "primitiveFieldsFwd.H"
139 #include "volFieldsFwd.H"
140 #include "HashSet.H"
141 #include "Tuple2.H"
142 #include "OFstream.H"
143 #include "Switch.H"
144 
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146 
147 namespace Foam
148 {
149 
150 // Forward declaration of classes
151 class objectRegistry;
152 class dictionary;
153 class polyMesh;
154 class mapPolyMesh;
155 
156 /*---------------------------------------------------------------------------*\
157  Class forces Declaration
158 \*---------------------------------------------------------------------------*/
159 
160 class forces
161 :
162  public functionObjectState,
163  public functionObjectFile
164 {
165 protected:
166 
167  // Protected data
168 
169  //- Reference to the database
170  const objectRegistry& obr_;
171 
172  //- Switch to send output to Info as well as to file
173  Switch log_;
174 
175  //- Pressure, viscous and porous force per bin
177 
178  //- Pressure, viscous and porous moment per bin
180 
181  // File streams
182 
183  //- Forces
184  autoPtr<OFstream> forceFilePtr_;
185 
186  //- Moments
187  autoPtr<OFstream> momentFilePtr_;
188 
189  //- Force bins
190  autoPtr<OFstream> forceBinFilePtr_;
191 
192  //- Moment bins
193  autoPtr<OFstream> momentBinFilePtr_;
194 
195  //- Local force
196  autoPtr<OFstream> localForceFilePtr_;
197 
198  //- Local moment
199  autoPtr<OFstream> localMomentFilePtr_;
200 
201  //- Local force bins
202  autoPtr<OFstream> localForceBinFilePtr_;
203 
204  //- Local moment bins
205  autoPtr<OFstream> localMomentBinFilePtr_;
206 
207 
208  // Read from dictionary
209 
210  //- Patches to integrate forces over
212 
213  //- Name of pressure field
214  word pName_;
215 
216  //- Name of velocity field
217  word UName_;
218 
219  //- Name of density field (optional)
220  word rhoName_;
221 
222  //- Is the force density being supplied directly?
223  Switch directForceDensity_;
224 
225  //- The name of the force density (fD) field
226  word fDName_;
227 
228  //- Reference density needed for incompressible calculations
229  scalar rhoRef_;
230 
231  //- Reference pressure
232  scalar pRef_;
233 
234  //- Coordinate system used when evaluting forces/moments
236 
237  //- Flag to indicate whether we are using a local co-ordinate sys
238  bool localSystem_;
239 
240  //- Flag to include porosity effects
241  bool porosity_;
242 
243 
244  // Bin information
245 
246  //- Number of bins
248 
249  //- Direction used to determine bin orientation
251 
252  //- Distance between bin divisions
253  scalar binDx_;
254 
255  //- Minimum bin bounds
256  scalar binMin_;
257 
258  //- Bin positions along binDir
260 
261  //- Should bin data be cumulative?
262  bool binCumulative_;
263 
264 
265  //- Write fields flag
266  bool writeFields_;
267 
268  //- Initialised flag
269  bool initialised_;
270 
271 
272  // Protected Member Functions
273 
274  //- Create a field name
275  word fieldName(const word& name) const;
276 
277  //- Create the output files
278  void createFiles();
279 
280  //- Write header for integrated data
281  void writeIntegratedHeader(const word& header, Ostream& os) const;
282 
283  //- Write header for binned data
284  void writeBinHeader(const word& header, Ostream& os) const;
285 
286  //- Initialise the fields
287  void initialise();
288 
289  //- Initialise the collection bins
290  void initialiseBins();
291 
292  //- Reset the fields prior to accumulation of force/moments
293  void resetFields();
294 
295  //- Return the effective viscous stress (laminar + turbulent).
297 
298  //- Dynamic viscosity field
299  tmp<volScalarField> mu() const;
300 
301  //- Return rho if rhoName is specified otherwise rhoRef
302  tmp<volScalarField> rho() const;
303 
304  //- Return rhoRef if the pressure field is dynamic, i.e. p/rho
305  // otherwise return 1
306  scalar rho(const volScalarField& p) const;
307 
308  //- Accumulate bin data
310  (
311  const vectorField& Md,
312  const vectorField& fN,
313  const vectorField& fT,
314  const vectorField& fP,
315  const vectorField& d
316  );
317 
318  //- Add patch contributions to force and moment fields
319  void addToFields
320  (
321  const label patchI,
322  const vectorField& Md,
323  const vectorField& fN,
324  const vectorField& fT,
325  const vectorField& fP
326  );
327 
328  //- Add cell contributions to force and moment fields
329  void addToFields
330  (
331  const labelList& cellIDs,
332  const vectorField& Md,
333  const vectorField& fN,
334  const vectorField& fT,
335  const vectorField& fP
336  );
337 
338  //- Helper function to write integrated forces and moments
340  (
341  const string& descriptor,
342  const vectorField& fm0,
343  const vectorField& fm1,
344  const vectorField& fm2,
345  autoPtr<OFstream>& osPtr
346  ) const;
347 
348  //- Write force data
349  void writeForces();
350 
351  //- Helper function to write binned forces and moments
353  (
354  const List<Field<vector> >& fm,
355  autoPtr<OFstream>& osPtr
356  ) const;
357 
358  //- Write binned data
359  void writeBins();
360 
361  //- Disallow default bitwise copy construct
362  forces(const forces&);
363 
364  //- Disallow default bitwise assignment
365  void operator=(const forces&);
366 
367 
368 public:
369 
370  //- Runtime type information
371  TypeName("forces");
372 
373 
374  // Constructors
375 
376  //- Construct for given objectRegistry and dictionary.
377  // Allow the possibility to load fields from files
378  forces
379  (
380  const word& name,
381  const objectRegistry&,
382  const dictionary&,
383  const bool loadFromFiles = false,
384  const bool readFields = true
385  );
386 
387 
388  //- Construct from components
389  forces
390  (
391  const word& name,
392  const objectRegistry&,
393  const labelHashSet& patchSet,
394  const word& pName,
395  const word& UName,
396  const word& rhoName,
397  const scalar rhoInf,
398  const scalar pRef,
399  const coordinateSystem& coordSys
400  );
401 
402 
403  //- Destructor
404  virtual ~forces();
405 
406 
407  // Member Functions
408 
409  //- Return name of the set of forces
410  virtual const word& name() const
411  {
412  return name_;
413  }
414 
415  //- Read the forces data
416  virtual void read(const dictionary&);
417 
418  //- Execute, currently does nothing
419  virtual void execute();
420 
421  //- Execute at the final time-loop, currently does nothing
422  virtual void end();
423 
424  //- Called when time was set at the end of the Time::operator++
425  virtual void timeSet();
426 
427  //- Write the forces
428  virtual void write();
429 
430  //- Calculate the forces and moments
431  virtual void calcForcesMoment();
432 
433  //- Return the total force
434  virtual vector forceEff() const;
435 
436  //- Return the total moment
437  virtual vector momentEff() const;
438 
439  //- Update for changes of mesh
440  virtual void updateMesh(const mapPolyMesh&)
441  {}
442 
443  //- Update for changes of mesh
444  virtual void movePoints(const polyMesh&)
445  {}
446 };
447 
448 
449 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
450 
451 } // End namespace Foam
452 
453 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
454 
455 #endif
456 
457 // ************************************************************************* //
Foam::forces::localMomentFilePtr_
autoPtr< OFstream > localMomentFilePtr_
Local moment.
Definition: forces.H:273
Foam::forces::createFiles
void createFiles()
Create the output files.
Definition: forces.C:52
volFieldsFwd.H
Foam::forces::binPoints_
List< point > binPoints_
Bin positions along binDir.
Definition: forces.H:333
primitiveFieldsFwd.H
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:60
Foam::forces::localForceBinFilePtr_
autoPtr< OFstream > localForceBinFilePtr_
Local force bins.
Definition: forces.H:276
Foam::forces::writeBinnedForceMoment
void writeBinnedForceMoment(const List< Field< vector > > &fm, autoPtr< OFstream > &osPtr) const
Helper function to write binned forces and moments.
Definition: forces.C:669
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::forces::~forces
virtual ~forces()
Destructor.
Definition: forces.C:852
Foam::functionObjectState
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: functionObjectState.H:54
Tuple2.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::forces::movePoints
virtual void movePoints(const polyMesh &)
Update for changes of mesh.
Definition: forces.H:518
Foam::forces::applyBins
void applyBins(const vectorField &Md, const vectorField &fN, const vectorField &fT, const vectorField &fP, const vectorField &d)
Accumulate bin data.
Definition: forces.C:470
Foam::forces::nBin_
label nBin_
Number of bins.
Definition: forces.H:321
functionObjectState.H
Foam::forces::writeIntegratedHeader
void writeIntegratedHeader(const word &header, Ostream &os) const
Write header for integrated data.
Definition: forces.C:91
Foam::forces::fieldName
word fieldName(const word &name) const
Create a field name.
Definition: forces.C:46
Foam::forces::patchSet_
labelHashSet patchSet_
Patches to integrate forces over.
Definition: forces.H:285
Foam::forces::pRef_
scalar pRef_
Reference pressure.
Definition: forces.H:306
Foam::forces::TypeName
TypeName("forces")
Runtime type information.
Foam::forces::obr_
const objectRegistry & obr_
Reference to the database.
Definition: forces.H:244
Foam::forces::forceFilePtr_
autoPtr< OFstream > forceFilePtr_
Forces.
Definition: forces.H:258
Foam::forces::operator=
void operator=(const forces &)
Disallow default bitwise assignment.
Foam::forces::rhoRef_
scalar rhoRef_
Reference density needed for incompressible calculations.
Definition: forces.H:303
Foam::forces::write
virtual void write()
Write the forces.
Definition: forces.C:1048
Foam::forces::forceEff
virtual vector forceEff() const
Return the total force.
Definition: forces.C:1214
Foam::readFields
This function object reads fields from the time directories and adds them to the mesh database for fu...
Definition: readFields.H:104
Foam::HashSet< label, Hash< label > >
Foam::forces::rhoName_
word rhoName_
Name of density field (optional)
Definition: forces.H:294
Foam::forces::momentFilePtr_
autoPtr< OFstream > momentFilePtr_
Moments.
Definition: forces.H:261
coordinateSystem.H
Foam::forces::pName_
word pName_
Name of pressure field.
Definition: forces.H:288
Foam::forces::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: forces.C:1036
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
OFstream.H
Foam::forces::force_
List< Field< vector > > force_
Pressure, viscous and porous force per bin.
Definition: forces.H:250
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::forces::forceBinFilePtr_
autoPtr< OFstream > forceBinFilePtr_
Force bins.
Definition: forces.H:264
Foam::forces::resetFields
void resetFields()
Reset the fields prior to accumulation of force/moments.
Definition: forces.C:289
Foam::forces::writeBins
void writeBins()
Write binned data.
Definition: forces.C:713
Foam::forces::initialiseBins
void initialiseBins()
Initialise the collection bins.
Definition: forces.C:215
Foam::forces::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition: forces.H:514
Foam::label
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::forces::execute
virtual void execute()
Execute, currently does nothing.
Definition: forces.C:999
Foam::forces::writeForces
void writeForces()
Write force data.
Definition: forces.C:621
Foam::forces::localSystem_
bool localSystem_
Flag to indicate whether we are using a local co-ordinate sys.
Definition: forces.H:312
Switch.H
Foam::forces::fDName_
word fDName_
The name of the force density (fD) field.
Definition: forces.H:300
Foam::forces::binDx_
scalar binDx_
Distance between bin divisions.
Definition: forces.H:327
HashSet.H
Foam::forces::name
virtual const word & name() const
Return name of the set of forces.
Definition: forces.H:484
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
pRef
scalar pRef
Definition: createFields.H:19
Foam::forces::initialised_
bool initialised_
Initialised flag.
Definition: forces.H:343
Foam::forces::writeFields_
bool writeFields_
Write fields flag.
Definition: forces.H:340
Foam::forces::calcForcesMoment
virtual void calcForcesMoment()
Calculate the forces and moments.
Definition: forces.C:1063
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::forces::localForceFilePtr_
autoPtr< OFstream > localForceFilePtr_
Local force.
Definition: forces.H:270
Foam::forces::binDir_
vector binDir_
Direction used to determine bin orientation.
Definition: forces.H:324
Foam::forces::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: forces.C:1042
Foam::forces::writeIntegratedForceMoment
void writeIntegratedForceMoment(const string &descriptor, const vectorField &fm0, const vectorField &fm1, const vectorField &fm2, autoPtr< OFstream > &osPtr) const
Helper function to write integrated forces and moments.
Definition: forces.C:576
Foam::forces::binMin_
scalar binMin_
Minimum bin bounds.
Definition: forces.H:330
Foam::forces::localMomentBinFilePtr_
autoPtr< OFstream > localMomentBinFilePtr_
Local moment bins.
Definition: forces.H:279
Foam::forces::coordSys_
coordinateSystem coordSys_
Coordinate system used when evaluting forces/moments.
Definition: forces.H:309
Foam::forces
This function object calculates the forces and moments by integrating the pressure and skin-friction ...
Definition: forces.H:234
Foam::forces::log_
Switch log_
Switch to send output to Info as well as to file.
Definition: forces.H:247
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::forces::addToFields
void addToFields(const label patchI, const vectorField &Md, const vectorField &fN, const vectorField &fT, const vectorField &fP)
Add patch contributions to force and moment fields.
Definition: forces.C:507
Foam::forces::porosity_
bool porosity_
Flag to include porosity effects.
Definition: forces.H:315
functionObjectFile.H
Foam::forces::mu
tmp< volScalarField > mu() const
Dynamic viscosity field.
Definition: forces.C:382
Foam::forces::momentEff
virtual vector momentEff() const
Return the total moment.
Definition: forces.C:1220
Foam::functionObjectState::name_
const word name_
Name of model.
Definition: functionObjectState.H:72
Foam::Vector< scalar >
Foam::List
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
Foam::forces::moment_
List< Field< vector > > moment_
Pressure, viscous and porous moment per bin.
Definition: forces.H:253
Foam::functionObjectFile
Base class for output file data handling.
Definition: functionObjectFile.H:57
Foam::forces::read
virtual void read(const dictionary &)
Read the forces data.
Definition: forces.C:858
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Foam::forces::writeBinHeader
void writeBinHeader(const word &header, Ostream &os) const
Write header for binned data.
Definition: forces.C:113
List
Definition: Test.C:19
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::forces::initialise
void initialise()
Initialise the fields.
Definition: forces.C:164
Foam::labelHashSet
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:210
Foam::forces::UName_
word UName_
Name of velocity field.
Definition: forces.H:291
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::forces::devRhoReff
tmp< volSymmTensorField > devRhoReff() const
Return the effective viscous stress (laminar + turbulent).
Definition: forces.C:320
Foam::forces::directForceDensity_
Switch directForceDensity_
Is the force density being supplied directly?
Definition: forces.H:297
coordinateSystems.H
Foam::forces::rho
tmp< volScalarField > rho() const
Return rho if rhoName is specified otherwise rhoRef.
Definition: forces.C:421
Foam::forces::momentBinFilePtr_
autoPtr< OFstream > momentBinFilePtr_
Moment bins.
Definition: forces.H:267
Foam::forces::forces
forces(const forces &)
Disallow default bitwise copy construct.
Foam::coordinateSystem
Base class for other coordinate system specifications.
Definition: coordinateSystem.H:85
Foam::forces::binCumulative_
bool binCumulative_
Should bin data be cumulative?
Definition: forces.H:336