bladeForces.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2024-2025 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::functionObjects::bladeForces
28 
29 Group
30  grpForcesFunctionObjects
31 
32 Description
33  Computes forces and coefficients over a given list of patches by integrating
34  pressure and viscous forces and moments.
35 
36  Forces and moments are output in their constituent components
37  within the user-defined cylindrical coordinate system:
38  - thrust
39  - drag
40  - torque
41 
42  Operands:
43  \table
44  Operand | Type | Location
45  input | - | -
46  output file | dat | postProcessing/<FO>/<time>/<file>s
47  \endtable
48 
49  where \c <file>s:
50  \verbatim
51  force.dat | Forces (thrust drag torque)
52  C_d.dat | Cd values (per bin)
53  C_l.dat | Cl values (per bin)
54  C_p.dat | Cp values (per bin)
55  \endverbatim
56 
57 Usage
58  Minimal example by using \c system/controlDict.functions:
59  \verbatim
60  <namePrefix>
61  {
62  // Mandatory entries
63  type bladeForces;
64  libs (forces);
65  patches (<wordRes>);
66 
67  // Optional entries
68  writeFields <bool>;
69  fieldsInterval <int>;
70  useNamePrefix <bool>;
71 
72  // Mandatory entries
73  origin (0 0 0);
74  axis (1 0 0);
75  n 25;
76 
77  // Conditional optional entries
78  p <word>;
79  U <word>;
80  rho <word>;
81  rhoInf <scalar>; // enabled if rho=rhoInf
82  pRef <scalar>;
83  Uref <scalar>;
84 
85  // Inherited entries
86  ...
87  }
88  \endverbatim
89 
90  where the entries mean:
91  \table
92  Property | Description | Type | Reqd | Deflt
93  type | Type name: bladeForces | word | yes | -
94  libs | Library name: forces | word | yes | -
95  patches | Names of operand patches | wordRes | yes | -
96  writeFields | Flag to write surface with fields | bool | no | false
97  fieldsInterval | Frequency of writeInterval for writeFields | int | no | 0
98  useNamePrefix | Flag to include prefix for field names | bool | no | false
99  outputName | Name for registered surface and VTP output | word | no | <name>
100  origin | Origin of cylindrical coordinate system | vector | yes | -
101  axis | Axis of cylindrical coordinate system | vector | yes | -
102  n | Rotation speed [rev/sec] | scalar | yes | -
103  rpm | Rotation speed [rev/min] | scalar | no | -
104  p | Name of pressure field | word | no | p
105  U | Name of velocity field | word | no | U
106  rho | Name of density field | word | no | rho
107  rhoInf | Value of reference density | scalar | cndtnl | 1
108  pRef | Value of reference pressure | scalar | cndtnl | 0
109  Uref | Magnitude of inlet reference axial velocity | scalar | yes | -
110 
111  radius | The blade outer radius | scalar | no | 1
112  nRadial | Divisions in radial direction | label | no | 10
113  lefthand | Using a left-hand blade | bool | false | false
114  nearCellValue | Patch velocity extrapolated from fluid | bool | no | false
115  \endtable
116 
117  Experimental entries (may be removed in the future):
118  \table
119  Property | Description | Type | Reqd | Deflt
120  geometricVelocity | Patch velocity based on position | bool | no | false
121  mag.thrust | Ignore sign for thrust values | bool | false | false
122  mag.drag | Ignore sign for drag values | bool | false | false
123  \endtable
124 
125  The inherited entries are elaborated in:
126  - \link functionObject.H \endlink
127  - \link writeFile.H \endlink
128  - \link coordinateSystem.H \endlink
129 
130 Note
131  - For incompressible cases, set \c rho to \c rhoInf.
132  You will then be required to provide a \c rhoInf
133  value corresponding to the constant freestream density.
134  - \c writeControl and \c writeInterval entries of function
135  object do control when to output force/coefficients files and fields.
136 
137 SourceFiles
138  bladeForces.cxx
139 
140 \*---------------------------------------------------------------------------*/
141 
142 #ifndef Foam_functionObjects_bladeForces_H
143 #define Foam_functionObjects_bladeForces_H
144 
145 #include "fvMeshFunctionObject.H"
146 #include "writeFile.H"
147 #include "cylindricalCS.H"
148 #include "volFieldsFwd.H"
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 namespace Foam
153 {
154 namespace functionObjects
155 {
156 
157 /*---------------------------------------------------------------------------*\
158  Class bladeForces Declaration
159 \*---------------------------------------------------------------------------*/
160 
161 class bladeForces
162 :
163  public fvMeshFunctionObject,
164  public writeFile
165 {
166  // Private Data
167 
168  // Results
169 
170  //- Sum of thrust forces (axial)
171  scalar sumThrust_;
172 
173  //- Sum of drag forces (tangential)
174  scalar sumDrag_;
175 
176  //- Sum of torque moments (tangential)
177  scalar sumTorque_;
178 
179  //- Overall blade area (single side)
180  scalar totalArea_;
181 
182  //- Overall drag coefficient (area-averaged of bin coefficients)
183  scalar totalCd_;
184 
185  //- Overall lift coefficient (area-averaged of bin coefficients)
186  scalar totalCl_;
187 
188  //- Overall pressure coefficient (area-averaged of bin coefficients)
189  scalar totalCp_;
190 
191  //- Blade area (single side) per radial band
192  scalarList bandArea_;
193 
194  //- Drag coefficient per radial band
195  scalarList bandCd_;
196 
197  //- Lift coefficient per radial band
198  scalarList bandCl_;
199 
200  //- Pressure coefficient per radial band
201  scalarList bandCp_;
202 
203 
204  // Geometric Information
205 
206  //- Selected operand patches
207  labelList patchIDs_;
208 
209  //- Max (or reference) blade radius
210  scalar refRadius_;
211 
212  //- Number of divisions in radial direction
213  label nRadialDiv_;
214 
215  //- Rotational speed (revolutions per second)
216  scalar revPerSec_;
217 
218  //- Cylindrical coordinate system used for force and torque
219  coordSystem::cylindrical cylCoord_;
220 
221 
222  // Read from dictionary
223 
224  //- Reference axial velocity
225  scalar Uref_;
226 
227  //- Reference pressure
228  scalar pRef_;
229 
230  //- Reference density (for incompressible)
231  scalar rhoRef_;
232 
233  //- Name of pressure field (default: "p")
234  word pName_;
235 
236  //- Name of velocity field (default: "U")
237  word UName_;
238 
239  //- Name of density field (default: "rho")
240  word rhoName_;
241 
242  //- Name for registred surface and VTP output.
243  // Default is the functionObject::name()
244  word outputName_;
245 
246  //- Internal counter, incremented when write() is called.
247  label writeCounter_;
248 
249  //- Write surface/fields interval.
250  // A value <= 1 means write surface/fields at each write().
251  label fieldsInterval_;
252 
253  //- Flag of initialisation (internal)
254  bool initialised_;
255 
256  //- Flag to write force and moment fields
257  bool writeFields_;
258 
259  //- Using a left-hand blade (flips orientation of drag value)
260  bool lefthand_;
261 
262  //- Extrapolate velocity to patch
263  bool nearCellValue_;
264 
265  //- Blade speed based on position [experimental]
266  bool useGeometricVelocity_;
267 
268  //- Ignore sign for thrust values [experimental]
269  bool useMagThrust_;
270 
271  //- Ignore sign for drag values [experimental]
272  bool useMagDrag_;
273 
274 
275  // File streams
276 
277  //- File stream for forces, torque and summary
278  autoPtr<OFstream> forceFilePtr_;
279 
280  //- File stream for areas (in radial bins)
281  autoPtr<OFstream> areaFilePtr_;
282 
283  //- File stream for coefficient of drag (in radial bins)
284  autoPtr<OFstream> CdFilePtr_;
285 
286  //- File stream for coefficient of lift (in radial bins)
287  autoPtr<OFstream> ClFilePtr_;
288 
289  //- File stream for coefficient of pressure (in radial bins)
290  autoPtr<OFstream> CpFilePtr_;
291 
292 
293  // Private Member Functions
294 
295  //- Initialise containers and fields
296  void initialise();
297 
298  //- Write surface (VTK format) and fields
299  void writeSurface() const;
300 
301 
302  // Evaluation
303 
304  //- Return the effective stress (viscous + turbulent) for patch
305  tmp<symmTensorField> devRhoReff
306  (
307  const tensorField& gradUp,
308  const label patchi
309  ) const;
310 
311  //- Return dynamic viscosity field
312  tmp<volScalarField> mu() const;
313 
314  //- Return rho if specified otherwise rhoRef
315  tmp<volScalarField> rho() const;
316 
317  //- Return rho if specified otherwise rhoRef for patch
318  tmp<scalarField> rho(const label patchi) const;
319 
320  //- Return rhoRef if the pressure field is dynamic (i.e. p/rho),
321  //- otherwise return 1
322  scalar rho(const volScalarField& p) const;
323 
324 
325  // I-O
326 
327  //- Create the integrated-data files
328  void createIntegratedDataFiles();
329 
330  //- Write integrated data to files
331  void writeIntegratedDataFiles();
332 
333 
334 public:
335 
336  //- Runtime type information
337  TypeName("bladeForces");
338 
339 
340  // Constructors
341 
342  //- Construct from Time and dictionary
344  (
345  const word& name,
346  const Time& runTime,
347  const dictionary& dict,
348  const bool readFields = true
349  );
350 
351  //- Construct from objectRegistry and dictionary
353  (
354  const word& name,
355  const objectRegistry& obr,
356  const dictionary& dict,
357  const bool readFields = true
358  );
359 
360  //- No copy construct
361  bladeForces(const bladeForces&) = delete;
362 
363  //- No copy assignment
364  void operator=(const bladeForces&) = delete;
365 
366 
367  //- Destructor
368  virtual ~bladeForces() = default;
369 
370 
371  // Member Functions
372 
373  //- The integrated thrust force (axial)
374  scalar thrust() const noexcept { return sumThrust_; }
375 
376  //- The integrated drag force (tangential)
377  scalar drag() const noexcept { return sumDrag_; }
378 
379  //- The integrated torque
380  scalar torque() const noexcept { return sumTorque_; }
381 
382  //- Calculate forces, torque, coefficients
383  void calculate();
384 
385 
386  //- Read the dictionary
387  virtual bool read(const dictionary& dict);
388 
389  //- Execute the function object
390  virtual bool execute();
391 
392  //- Write to data files/fields and to streams
393  virtual bool write();
394 };
395 
396 
397 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
398 
399 } // End namespace functionObjects
400 } // End namespace Foam
401 
402 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
403 
404 #endif
405 
406 // ************************************************************************* //
List< scalar > scalarList
List of scalar.
Definition: scalarList.H:32
dictionary dict
TypeName("bladeForces")
Runtime type information.
scalar torque() const noexcept
The integrated torque.
Definition: bladeForces.H:656
Forwards and collection of common volume field types.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
engineTime & runTime
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
virtual bool execute()
Execute the function object.
const word & name() const noexcept
Return the name of this functionObject.
void calculate()
Calculate forces, torque, coefficients.
scalar drag() const noexcept
The integrated drag force (tangential)
Definition: bladeForces.H:651
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:72
bladeForces(const word &name, const Time &runTime, const dictionary &dict, const bool readFields=true)
Construct from Time and dictionary.
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual ~bladeForces()=default
Destructor.
const direction noexcept
Definition: scalarImpl.H:255
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Definition: readFields.H:151
virtual bool read(const dictionary &dict)
Read the dictionary.
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
Computes forces and coefficients over a given list of patches by integrating pressure and viscous for...
Definition: bladeForces.H:325
virtual bool write()
Write to data files/fields and to streams.
List< label > labelList
A List of labels.
Definition: List.H:61
volScalarField & p
Registry of regIOobjects.
scalar thrust() const noexcept
The integrated thrust force (axial)
Definition: bladeForces.H:646
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
Namespace for OpenFOAM.
void operator=(const bladeForces &)=delete
No copy assignment.