Loading...
Searching...
No Matches
forceCoeffs.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2019-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::functionObjects::forceCoeffs
29
30Group
31 grpForcesFunctionObjects
32
33Description
34 Computes force and moment coefficients over a given list of patches, and
35 optionally over given porous zones. The following coefficients can be
36 selected and output:
37
38 \verbatim
39 Cd | Drag coefficient
40 Cs | Side-force coefficient
41 Cl | Lift coefficient
42 CmRoll | Roll-moment coefficient
43 CmPitch | Pitch-moment coefficient
44 CmYaw | Yaw-moment coefficient
45 \endverbatim
46
47 The force coefficients can also be optionally output in terms of their
48 front and rear axle constituents:
49 \verbatim
50 Cd{f,r} = 0.5*Cd {+,-} CmRoll
51 Cs{f,r} = 0.5*Cs {+,-} CmYaw
52 Cl{f,r} = 0.5*Cl {+,-} CmPitch
53 \endverbatim
54 where \c f and \c r represent front and rear axles, respectively.
55
56 Force and moment coefficients are output in their total and constituent
57 components:
58 - total force and moment coefficients
59 - pressure contributions
60 - viscous contributions
61 - porous resistance contributions (optional)
62
63 Force and moment coefficients can be computed and output in:
64 - the global Cartesian coordinate system (default)
65 - a user-defined Cartesian coordinate system
66
67 Operands:
68 \table
69 Operand | Type | Location
70 input | - | -
71 output file | dat | postProcessing/<FO>/<time>/files
72 output field | volVectorField | <time>/outputFields
73 \endtable
74
75 where \c files:
76 \verbatim
77 coefficient.dat | Integrated coefficients over all patches
78 \endverbatim
79
80 where \c outputFields:
81 \verbatim
82 <namePrefix>:forceCoeff | Force coefficient field
83 <namePrefix>:momentCoeff | Moment coefficient field
84 \endverbatim
85
86Usage
87 Minimal example by using \c system/controlDict.functions:
88 \verbatim
89 forceCoeffsFO
90 {
91 // Mandatory entries
92 type forceCoeffs;
93 libs (forces);
94 patches (<wordRes>); // (wall1 "(wall2|wall3)");
95 magUInf <scalar>;
96 lRef <scalar>;
97 Aref <scalar>;
98
99 // Optional entries
100 coefficients (<wordHashSet>);
101 directForceDensity <bool>;
102 porosity <bool>;
103 writeFields <bool>;
104 useNamePrefix <bool>;
105
106 // Conditional mandatory entries
107
108 // Cartesian coordinate system specification when evaluating
109 // force and moment coefficients, either of the below
110
111 // Define the centre of rotation
112 // with implicit directions e1=(1 0 0) and e3=(0 0 1)
113 CofR (0 0 0); // Centre of rotation
114
115 // Define local coordinate system by origin + axes
116 origin (0 0 0);
117 e1 (1 0 0);
118 e3 (0 0 1); // (e1, e2) or (e2, e3) or (e3, e1)
119
120 // General coordinate system specification (always cartesian)
121 coordinateSystem
122 {
123 origin (0 0 0);
124 rotation
125 {
126 type ...;
127 ...
128 }
129 }
130
131 // Conditional optional entries
132
133 // if directForceDensity == true
134 fD <word>;
135
136 // if directForceDensity == false
137 p <word>;
138 U <word>;
139 rho <word>;
140 rhoInf <scalar>; // redundant for incompressible-flow cases
141 pRef <scalar>;
142
143 // Inherited entries
144 ...
145 }
146 \endverbatim
147
148 where the entries mean:
149 \table
150 Property | Description | Type | Reqd | Deflt
151 type | Type name: forceCoeffs | word | yes | -
152 libs | Library name: forces | word | yes | -
153 patches | Names of operand patches | wordRes | yes | -
154 coefficients | Names of operand coefficients | wordHashSet | no | -
155 magUInf | Reference velocity magnitude | scalar | yes | -
156 lRef | Reference length scale for moment calculations <!--
157 --> | scalar | yes | -
158 Aref | Reference area | scalar | yes | -
159 directForceDensity | Flag to directly supply force density <!--
160 --> | bool | no | false
161 porosity | Flag to include porosity contributions | bool | no | false
162 writeFields | Flag to write force and moment fields | bool | no | false
163 useNamePrefix | Flag to include prefix for field names | bool | no | false
164 CofR | Centre of rotation | vector | cndtnl | -
165 origin | Origin of coordinate system | vector | cndtnl | -
166 e3 | e3 coordinate axis | vector | cndtnl | -
167 e1 | e1 coordinate axis | vector | cndtnl | -
168 coordinateSystem | Coordinate system specifier | dictionary | cndtnl | -
169 fD | Name of force density field | word | cndtnl-no | fD
170 p | Name of pressure field | word | cndtnl-no | p
171 U | Name of velocity field | word | cndtnl-no | U
172 rho | Name of density field | word | cndtnl-no | rho
173 rhoInf | Value of reference density | scalar | cndtnl-yes | -
174 pRef | Value of reference pressure | scalar | cndtnl-no | 0
175 \endtable
176
177 Options for the \c coefficients entry:
178 \verbatim
179 Cd | Drag coefficient
180 Cs | Side-force coefficient
181 Cl | Lift coefficient
182 CmRoll | Roll-moment coefficient
183 CmPitch | Pitch-moment coefficient
184 CmYaw | Yaw-moment coefficient
185 Cd(f) | Front-axle drag coefficient
186 Cs(f) | Front-axle side-force coefficient
187 Cl(f) | Front-axle lift coefficient
188 Cd(r) | Rear-axle drag coefficient
189 Cs(r) | Rear-axle side-force coefficient
190 Cl(r) | Rear-axle lift coefficient
191 \endverbatim
192
193 The inherited entries are elaborated in:
194 - \link functionObject.H \endlink
195 - \link writeFile.H \endlink
196 - \link coordinateSystem.H \endlink
197 - \link forces.H \endlink
198
199Note
200 - \c rhoInf is always redundant for incompressible computations.
201 That is, \c rhoInf is always equal to 1 in incompressible
202 computations no matter which input value is assigned to \c rhoInf.
203 The value of \c rhoInf is only used for compressible computations.
204 - \c writeControl and \c writeInterval entries of function
205 object do control when to output force and moment files and fields.
206 - Input for force/moment coefficient directions
207 require an origin and two orthogonal directions where
208 the remaining orthogonal direction is automatically computed.
209 - The default direction relations are shown below:
210
211 \table
212 Property | Description | Alias | Direction
213 dragDir | Drag direction | e1 | (1 0 0)
214 sideDir | Side force direction | e2 | (0 1 0)
215 liftDir | Lift direction | e3 | (0 0 1)
216 rollAxis | Roll axis | e1 | (1 0 0)
217 pitchAxis | Pitch axis | e2 | (0 1 0)
218 yawAxis | Yaw axis | e3 | (0 0 1)
219 \endtable
220
221 - If a \c coordinateSystem entry exists, it is taken in favour of \c CofR.
222
223SourceFiles
224 forceCoeffs.C
225
226\*---------------------------------------------------------------------------*/
227
228#ifndef Foam_functionObjects_forceCoeffs_H
229#define Foam_functionObjects_forceCoeffs_H
230
231#include "forces.H"
232#include "HashSet.H"
233#include "Enum.H"
234
235// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236
237namespace Foam
238{
239namespace functionObjects
240{
241
242/*---------------------------------------------------------------------------*\
243 Class forceCoeffs Declaration
244\*---------------------------------------------------------------------------*/
245
246class forceCoeffs
247:
248 public forces
249{
250public:
251
252 // Container for force and moment components
253 class forceComponents
254 {
255 // Private Data
256
257 //- Pressure force/moment component
258 vector pressure_;
259
260 //- Viscous force/moment component
261 vector viscous_;
262
263 //- Internal force/moment component
264 vector internal_;
265
266
267 public:
268
269 // Constructors
270
271 //- Default construct
273 :
274 pressure_(Zero),
275 viscous_(Zero),
276 internal_(Zero)
277 {}
278
279
280 // Member Functions
281
282 //- Return the sum of the components
283 const vector total() const noexcept
284 {
285 return pressure_ + viscous_ + internal_;
286 }
287
288 //- Reset the components to zero
289 void reset() noexcept
290 {
291 pressure_ = Zero;
292 viscous_ = Zero;
293 internal_ = Zero;
294 }
295
296 //- Reset the components to given values
297 void reset
298 (
299 const vector& pressure,
300 const vector& viscous,
301 const vector& internal
302 ) noexcept
303 {
304 pressure_ = pressure;
305 viscous_ = viscous;
306 internal_ = internal;
307 }
308
309
310 // Member Operators
311
312 //- Return components in a given direction
313 vector operator[](const label cmpt) const
314 {
315 return vector(pressure_[cmpt], viscous_[cmpt], internal_[cmpt]);
316 }
317 };
318
319
320 //- Coefficients description
321 struct coeffDesc
322 {
323 enum splitType
324 {
325 stFront,
326 stRear,
327 stNone
328 };
329
330 string desc_;
331 word name_;
332 label c0_;
333 label c1_;
334 bool active_;
336
337 // Constructors
338
339 //- Construct from components
341 (
342 const string& description,
343 const word& name,
344 const label c0,
345 const label c1 = -1
346 )
347 :
348 desc_(description),
349 name_(name),
350 c0_(c0),
351 c1_(c1),
352 active_(false),
354 {}
355
356 //- Return name with front-name appendix
357 const word frontName() const noexcept
358 {
359 return name_ + "(f)";
360 }
361
362 //- Return name with rear-name appendix
363 const word rearName() const noexcept
364 {
365 return name_ + "(r)";
366 }
367
368 //- Print description
369 void print(Ostream& os) const
370 {
371 os << desc_.c_str() << ": " << name_;
372 }
373
374 //- Return force/moment components based on the specified split type
375 vector value(const forceComponents& f, const forceComponents& m) const
376 {
377 if (c1_ == -1)
378 {
379 return m[c0_];
380 }
381 else
382 {
383 switch (splitType_)
384 {
385 case stFront:
386 {
387 return 0.5*f[c0_] + m[c1_];
388 }
389 case stRear:
390 {
391 return 0.5*f[c0_] - m[c1_];
392 }
393 case stNone:
394 {
395 return f[c0_];
396 }
397 }
398 }
399
401 << "Cannot determine value"
402 << abort(FatalError);
403
404 return vector::zero;
405 }
406
407 //- Return front-axle coefficient description
408 coeffDesc front() const
409 {
410 coeffDesc coeff(*this);
411 coeff.name_ = coeff.frontName();
412 coeff.desc_ = coeff.desc_ + " front";
413 coeff.splitType_ = stFront;
414 return coeff;
415 }
416
417 //- Return rear-axle coefficient description
418 coeffDesc rear() const
419 {
420 coeffDesc coeff(*this);
421 coeff.name_ = coeff.rearName();
422 coeff.desc_ = coeff.desc_ + " rear";
423 coeff.splitType_ = stRear;
424 return coeff;
425 }
426 };
427
428
429private:
430
431 // Private Data
432
433 //- Force components
435
436 //- Moment components
437 forceComponents Cm_;
438
439 //- Operand force and moment coefficients
440 HashTable<coeffDesc> coeffs_;
442
443 // File streams
444
445 //- File stream for integrated operand coefficients
446 autoPtr<OFstream> coeffFilePtr_;
447
448
449 // Reference scales
450
451 //- Reference velocity magnitude [m/s]
452 scalar magUInf_;
453
454 //- Reference length scale [m]
455 scalar lRef_;
456
457 //- Reference area [m^2]
458 scalar Aref_;
459
460
461 //- Flag of initialisation (internal)
462 bool initialised_;
463
464
465protected:
466
467 // Protected Member Functions
469 //- Initialise containers and fields
470 void initialise();
471
472 //- Return access to the force coefficients field
474
475 //- Return access to the moment coefficients field
477
478
479 //- Reset containers and fields
480 void reset();
482
483 // Evaluation
484
485 //- Return the operand coefficients
487
488 //- Calculate force coefficients
490
491 //- Calculate moment coefficients
492 void calcMomentCoeffs();
493
494 //- Return integrated {total, pressure, viscous, porous} components
495 List<scalar> integrateData(const List<Field<scalar>>& coeff) const;
496
497
498 // I-O
500 //- Create the integrated-coefficient file
502
503 //- Write header to the integrated-coefficient file
505 (
506 const word& header,
507 OFstream& os
508 ) const;
509
510 //- Write integrated coefficients to the integrated-coefficient file
512
513
514public:
515
516 //- Runtime type information
517 TypeName("forceCoeffs");
518
519
520 // Constructors
521
522 //- Construct from name, Time and dictionary
524 (
525 const word& name,
526 const Time& runTime,
528 const bool readFields = true
529 );
530
531 //- No copy construct
532 forceCoeffs(const forceCoeffs&) = delete;
534 //- No copy assignment
535 void operator=(const forceCoeffs&) = delete;
538 //- Destructor
539 virtual ~forceCoeffs() = default;
542 // Member Functions
543
544 //- Read the function-object dictionary
545 virtual bool read(const dictionary&);
546
547 //- Execute the function-object operations
548 virtual bool execute();
549
550 //- Write the function-object results
551 virtual bool write();
552};
553
554} // End namespace functionObjects
555
556
557// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
558
559// Output operator
560inline Ostream& operator<<
561(
562 Ostream& os,
564)
565{
566 coeff.print(os);
567 return os;
568}
569
570
571// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
572
573} // End namespace Foam
574
575// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
576
577#endif
578
579// ************************************************************************* //
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
A HashTable similar to std::unordered_map.
Definition HashTable.H:124
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Definition OFstream.H:75
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
static const Form zero
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
void reset() noexcept
Reset the components to zero.
vector operator[](const label cmpt) const
Return components in a given direction.
void reset(const vector &pressure, const vector &viscous, const vector &internal) noexcept
Reset the components to given values.
const vector total() const noexcept
Return the sum of the components.
Computes force and moment coefficients over a given list of patches, and optionally over given porous...
volVectorField & momentCoeff()
Return access to the moment coefficients field.
Definition forceCoeffs.C:85
void calcMomentCoeffs()
Calculate moment coefficients.
HashTable< coeffDesc > selectCoeffs() const
Return the operand coefficients.
void writeIntegratedDataFileHeader(const word &header, OFstream &os) const
Write header to the integrated-coefficient file.
void initialise()
Initialise containers and fields.
Definition forceCoeffs.C:46
List< scalar > integrateData(const List< Field< scalar > > &coeff) const
Return integrated {total, pressure, viscous, porous} components.
virtual ~forceCoeffs()=default
Destructor.
void calcForceCoeffs()
Calculate force coefficients.
TypeName("forceCoeffs")
Runtime type information.
forceCoeffs(const forceCoeffs &)=delete
No copy construct.
void operator=(const forceCoeffs &)=delete
No copy assignment.
void reset()
Reset containers and fields.
void createIntegratedDataFile()
Create the integrated-coefficient file.
virtual bool execute()
Execute the function-object operations.
virtual bool write()
Write the function-object results.
forceCoeffs(const word &name, const Time &runTime, const dictionary &dict, const bool readFields=true)
Construct from name, Time and dictionary.
virtual bool read(const dictionary &)
Read the function-object dictionary.
void writeIntegratedDataFile()
Write integrated coefficients to the integrated-coefficient file.
volVectorField & forceCoeff()
Return access to the force coefficients field.
Definition forceCoeffs.C:57
Computes forces and moments over a given list of patches by integrating pressure and viscous forces a...
Definition forces.H:321
forces(const word &name, const Time &runTime, const dictionary &dict, const bool readFields=true)
Construct from name, Time and dictionary.
Definition forces.C:510
Provides several methods to convert an input pressure field into derived forms, including:
Definition pressure.H:337
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Definition readFields.H:146
A class for handling words, derived from Foam::string.
Definition word.H:66
engineTime & runTime
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
auto & name
const dimensionedScalar c1
First radiation constant: default SI units: [W/m2].
const wordList internal
Standard volume internal field types (scalar, vector, tensor, etc).
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
GeometricField< vector, fvPatchField, volMesh > volVectorField
errorManip< error > abort(error &err)
Definition errorManip.H:139
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
const direction noexcept
Definition scalarImpl.H:265
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
Vector< scalar > vector
Definition vector.H:57
static bool initialised_(false)
labelList f(nPoints)
dictionary dict
coeffDesc(const string &description, const word &name, const label c0, const label c1=-1)
Construct from components.
coeffDesc rear() const
Return rear-axle coefficient description.
const word rearName() const noexcept
Return name with rear-name appendix.
coeffDesc front() const
Return front-axle coefficient description.
void print(Ostream &os) const
Print description.
const word frontName() const noexcept
Return name with front-name appendix.
vector value(const forceComponents &f, const forceComponents &m) const
Return force/moment components based on the specified split type.
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68