forcesBase.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-2024 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::forcesBase
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 See also
32  Foam::functionObject
33  Foam::functionObjects::fvMeshFunctionObject
34  Foam::functionObjects::logFiles
35  Foam::functionObjects::timeControl
36 
37 SourceFiles
38  forcesBase.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef functionObjects_forcesBase_H
43 #define functionObjects_forcesBase_H
44 
45 #include "fvMeshFunctionObject.H"
46 #include "logFiles.H"
47 #include "volFields.H"
48 #include "HashSet.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 namespace functionObjects
55 {
56 
57 /*---------------------------------------------------------------------------*\
58  Class forcesBase Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 class forcesBase
62 :
63  public fvMeshFunctionObject,
64  public logFiles
65 {
66 
67 protected:
68 
69  // Protected data
70 
71  //- Enumeration for ensuring the right file is accessed
72  enum class fileID
73  {
74  mainFile = 0,
75  binsFile = 1
76  };
77 
78  //- Pressure, viscous and porous force per bin
80 
81  //- Pressure, viscous and porous moment per bin
83 
84 
85  // Read from dictionary
86 
87  //- Patches to integrate forces over
89 
90  //- Name of pressure field
91  word pName_;
92 
93  //- Name of velocity field
94  word UName_;
95 
96  //- Name of density field (optional)
97  word rhoName_;
98 
99  //- The name of the phase (optional)
101 
102  //- Is the force density being supplied directly?
104 
105  //- The name of the force density (fD) field
106  word fDName_;
107 
108  //- Reference density needed for incompressible calculations
109  scalar rhoRef_;
110 
111  //- Reference pressure
112  scalar pRef_;
113 
114  //- Flag to include porosity effects
115  bool porosity_;
116 
117 
118  // Bin information
119 
120  //- Number of bins
121  label nBin_;
122 
123  //- Direction used to determine bin orientation
124  vector binDir_;
125 
126  //- Distance between bin divisions
127  scalar binDx_;
128 
129  //- Minimum bin bounds
130  scalar binMin_;
131 
132  //- Bin positions along binDir
134 
135  //- Should bin data be cumulative?
136  bool binCumulative_;
137 
138 
139  //- Initialised flag
140  bool initialised_;
141 
142 
143  // Protected Member Functions
144 
145  using logFiles::file;
146 
147  Ostream& file(const fileID fid)
148  {
149  return logFiles::file(label(fid));
150  }
151 
152  //- Create file names for forces and bins
153  wordList createFileNames(const dictionary& dict) const;
154 
155  //- Output file header information
156  virtual void writeFileHeader(const label i);
157 
158  //- Initialise the fields
159  void initialise();
160 
161  //- Return the effective viscous stress (laminar + turbulent).
163 
164  //- Dynamic viscosity field
165  tmp<volScalarField> mu() const;
166 
167  //- Return rho if specified otherwise rhoRef
168  tmp<volScalarField> rho() const;
169 
170  //- Return rhoRef if the pressure field is dynamic, i.e. p/rho
171  // otherwise return 1
172  scalar rho(const volScalarField& p) const;
173 
174  //- Get the volume fraction field
175  tmp<volScalarField> alpha() const;
176 
177  //- Get the volume fraction field on a patch
178  tmp<scalarField> alpha(const label patchi) const;
179 
180  //- Accumulate bin data
181  void applyBins
182  (
183  const vectorField& Md,
184  const vectorField& fN,
185  const vectorField& fT,
186  const vectorField& fP,
187  const vectorField& d
188  );
189 
190  //- Calculate the forces and moments
191  void calcForcesMoments(const vector& CofR);
192 
193  //- Return the current centre of the rigid body
194  virtual vector CofR() const = 0;
195 
196  //- Write the constant centre of rotation value in the header
197  // Not written by default
198  virtual void writeCoRValueHeader(Ostream& file);
199 
200  //- Write the time varying centre of rotation column header
201  virtual void writeCoRHeader(Ostream& file);
202 
203  //- Write the time varying centre of rotation
204  virtual void writeCofR(Ostream& file);
205 
206  //- Helper function to write force data
207  void writeForces();
208 
209  //- Helper function to write bin data
210  void writeBins();
211 
212 
213 public:
214 
215  //- Runtime type information
216  TypeName("forcesBase");
217 
218 
219  // Constructors
220 
221  //- Construct from Time and dictionary
222  forcesBase
223  (
224  const word& name,
225  const Time& runTime,
226  const dictionary& dict
227  );
228 
229  //- Construct from objectRegistry and dictionary
230  forcesBase
231  (
232  const word& name,
233  const objectRegistry& obr,
234  const dictionary&
235  );
236 
237  //- Disallow default bitwise copy construction
238  forcesBase(const forcesBase&) = delete;
239 
240 
241  //- Destructor
242  virtual ~forcesBase();
243 
244 
245  // Member Functions
246 
247  //- Read the forces data
248  virtual bool read(const dictionary&);
249 
250  //- Return the list of fields required
251  virtual wordList fields() const
252  {
253  return wordList::null();
254  }
255 
256  //- Calculate the forces and moments
257  virtual void calcForcesMoments();
258 
259  //- Return the total force
260  virtual vector forceEff() const;
261 
262  //- Return the total moment
263  virtual vector momentEff() const;
264 
265  //- Execute, currently does nothing
266  virtual bool execute();
267 
268  //- Write the forces
269  virtual bool write();
270 
271 
272  // Member Operators
273 
274  //- Disallow default bitwise assignment
275  void operator=(const forcesBase&) = delete;
276 };
277 
278 
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 
281 } // End namespace functionObjects
282 } // End namespace Foam
283 
284 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 
286 #endif
287 
288 // ************************************************************************* //
Generic GeometricField class.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
static const List< word > & null()
Return a null List.
Definition: ListI.H:118
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
const word & name() const
Return the name of this functionObject.
Calculates the forces and moments by integrating the pressure and skin-friction forces over a given l...
Definition: forcesBase.H:64
Switch directForceDensity_
Is the force density being supplied directly?
Definition: forcesBase.H:102
virtual void calcForcesMoments()
Calculate the forces and moments.
Definition: forcesBase.C:925
List< Field< vector > > moment_
Pressure, viscous and porous moment per bin.
Definition: forcesBase.H:81
word pName_
Name of pressure field.
Definition: forcesBase.H:90
scalar rhoRef_
Reference density needed for incompressible calculations.
Definition: forcesBase.H:108
bool porosity_
Flag to include porosity effects.
Definition: forcesBase.H:114
tmp< volScalarField > alpha() const
Get the volume fraction field.
Definition: forcesBase.C:387
List< point > binPoints_
Bin positions along binDir.
Definition: forcesBase.H:132
void initialise()
Initialise the fields.
Definition: forcesBase.C:161
word UName_
Name of velocity field.
Definition: forcesBase.H:93
virtual wordList fields() const
Return the list of fields required.
Definition: forcesBase.H:250
virtual void writeCoRHeader(Ostream &file)
Write the time varying centre of rotation column header.
Definition: forcesBase.C:471
word phaseName_
The name of the phase (optional)
Definition: forcesBase.H:99
scalar binMin_
Minimum bin bounds.
Definition: forcesBase.H:129
label nBin_
Number of bins.
Definition: forcesBase.H:120
bool initialised_
Initialised flag.
Definition: forcesBase.H:139
tmp< volSymmTensorField > devTau() const
Return the effective viscous stress (laminar + turbulent).
Definition: forcesBase.C:208
void applyBins(const vectorField &Md, const vectorField &fN, const vectorField &fT, const vectorField &fP, const vectorField &d)
Accumulate bin data.
Definition: forcesBase.C:431
tmp< volScalarField > mu() const
Dynamic viscosity field.
Definition: forcesBase.C:278
virtual vector CofR() const =0
Return the current centre of the rigid body.
void operator=(const forcesBase &)=delete
Disallow default bitwise assignment.
virtual vector forceEff() const
Return the total force.
Definition: forcesBase.C:931
forcesBase(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: forcesBase.C:580
TypeName("forcesBase")
Runtime type information.
virtual vector momentEff() const
Return the total moment.
Definition: forcesBase.C:937
virtual void writeCoRValueHeader(Ostream &file)
Write the constant centre of rotation value in the header.
Definition: forcesBase.C:467
void writeBins()
Helper function to write bin data.
Definition: forcesBase.C:522
virtual ~forcesBase()
Destructor.
Definition: forcesBase.C:647
virtual void writeFileHeader(const label i)
Output file header information.
Definition: forcesBase.C:76
word rhoName_
Name of density field (optional)
Definition: forcesBase.H:96
OFstream & file()
Return access to the file (if only 1)
Definition: logFiles.C:113
labelHashSet patchSet_
Patches to integrate forces over.
Definition: forcesBase.H:87
bool binCumulative_
Should bin data be cumulative?
Definition: forcesBase.H:135
List< Field< vector > > force_
Pressure, viscous and porous force per bin.
Definition: forcesBase.H:78
void writeForces()
Helper function to write force data.
Definition: forcesBase.C:483
tmp< volScalarField > rho() const
Return rho if specified otherwise rhoRef.
Definition: forcesBase.C:346
fileID
Enumeration for ensuring the right file is accessed.
Definition: forcesBase.H:72
vector binDir_
Direction used to determine bin orientation.
Definition: forcesBase.H:123
virtual bool execute()
Execute, currently does nothing.
Definition: forcesBase.C:943
scalar binDx_
Distance between bin divisions.
Definition: forcesBase.H:126
virtual bool write()
Write the forces.
Definition: forcesBase.C:949
scalar pRef_
Reference pressure.
Definition: forcesBase.H:111
virtual void writeCofR(Ostream &file)
Write the time varying centre of rotation.
Definition: forcesBase.C:477
word fDName_
The name of the force density (fD) field.
Definition: forcesBase.H:105
virtual bool read(const dictionary &)
Read the forces data.
Definition: forcesBase.C:653
wordList createFileNames(const dictionary &dict) const
Create file names for forces and bins.
Definition: forcesBase.C:50
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:60
OFstream & file()
Return access to the file (if only 1)
Definition: logFiles.C:113
Registry of regIOobjects.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
label patchi
Namespace for OpenFOAM.
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
dictionary dict
volScalarField & p