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