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-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::functionObjects::forceCoeffs
29 
30 Group
31  grpForcesFunctionObjects
32 
33 Description
34  Extends the \c forces functionObject by providing coefficients for:
35  - drag, side and lift forces (Cd, Cs, and Cl)
36  - roll, pitch and yaw moments (CmRoll, CmPitch, and CmYaw)
37  - front and rear axle force contributions (C(f) and C(r)) wherein
38 
39  \verbatim
40  Cd(f/r) = 0.5*Cd \pm CmRoll
41  Cs(f/r) = 0.5*Cs \pm CmYaw
42  Cl(f/r) = 0.5*Cl \pm CmPitch
43  \endverbatim
44 
45  The data can optionally be output into bins, defined in a given direction.
46 
47  The binned data provides the total and consitituent components per bin:
48  - total coefficient
49  - pressure coefficient contribution
50  - viscous coefficient contribution
51  - porous coefficient contribution
52 
53  Data is written into multiple files in the
54  postProcessing/<functionObjectName> directory:
55  - coefficient.dat : integrated coefficients over all geometries
56  - CdBin.dat : drag coefficient bins
57  - CsBin.dat : side coefficient bins
58  - ClBin.dat : lift coefficient bins
59  - CmRollBin.dat : roll moment coefficient bins
60  - CmPitchBin.dat : pitch moment coefficient bins
61  - CmYawBin.dat : yaw moment coefficient bins
62 
63 Usage
64  Example of function object specification:
65  \verbatim
66  forceCoeffs1
67  {
68  type forceCoeffs;
69  libs (forces);
70  ...
71  log yes;
72  writeFields yes;
73  patches (walls);
74 
75  // input keywords for directions of force/moment coefficients
76  // refer below for options, and relations
77 
78  magUInf 100;
79  lRef 3.5;
80  Aref 2.2;
81  porosity no;
82 
83  binData
84  {
85  nBin 20;
86  direction (1 0 0);
87  cumulative yes;
88  }
89  }
90  \endverbatim
91 
92  Where the entries comprise:
93  \table
94  Property | Description | Required | Default
95  type | Type name: forceCoeffs | yes |
96  log | Write force data to standard output | no | no
97  writeFields | Write force,moment coefficient fields | no | no
98  patches | Patches included in the forces calculation | yes |
99  magUInf | Free stream velocity magnitude | yes |
100  rhoInf | Free stream density | for compressible cases |
101  lRef | Reference length scale for moment calculations | yes |
102  Aref | Reference area | yes |
103  porosity | Include porosity contributions | no | false
104  \endtable
105 
106  Bin data is optional, but if the dictionary is present, the entries must
107  be defined according to following:
108  \table
109  nBin | Number of data bins | yes |
110  direction | Direction along which bins are defined | yes |
111  cumulative | Bin data accumulated with incresing distance | yes |
112  \endtable
113 
114  Input of force/moment coefficient directions:
115  - require an origin, and two orthogonal directions; the remaining orthogonal
116  direction is determined accordingly.
117  - can be added by the three options below.
118 
119  \verbatim
120  CofR (0 0 0); // Centre of rotation
121  dragDir (1 0 0);
122  liftDir (0 0 1);
123  \endverbatim
124 
125  \verbatim
126  origin (0 0 0);
127  e1 (1 0 0);
128  e3 (0 0 1); // combinations: (e1, e2) or (e2, e3) or (e3, e1)
129  \endverbatim
130 
131  \verbatim
132  coordinateSystem
133  {
134  origin (0 0 0);
135  rotation
136  {
137  type axes;
138  e1 (1 0 0);
139  e3 (0 0 1); // combinations: (e1, e2) or (e2, e3) or (e3, e1)
140  }
141  }
142  \endverbatim
143 
144  The default direction relations are shown below:
145 
146  \table
147  Property | Description | Alias | Direction
148  dragDir | Drag direction | e1 | (1 0 0)
149  sideDir | Side force direction | e2 | (0 1 0)
150  liftDir | Lift direction | e3 | (0 0 1)
151  rollAxis | Roll axis | e1 | (1 0 0)
152  pitchAxis | Pitch axis | e2 | (0 1 0)
153  yawAxis | Yaw axis | e3 | (0 0 1)
154  \endtable
155 
156 See also
157  Foam::functionObject
158  Foam::functionObjects::timeControl
159  Foam::functionObjects::forces
160 
161 SourceFiles
162  forceCoeffs.C
163 
164 \*---------------------------------------------------------------------------*/
165 
166 #ifndef functionObjects_forceCoeffs_H
167 #define functionObjects_forceCoeffs_H
168 
169 #include "forces.H"
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 namespace Foam
174 {
175 namespace functionObjects
176 {
177 
178 /*---------------------------------------------------------------------------*\
179  Class forceCoeffs Declaration
180 \*---------------------------------------------------------------------------*/
181 
182 class forceCoeffs
183 :
184  public forces
185 {
186  // Private data
187 
188  // Free-stream conditions
189 
190  //- Free-stream velocity magnitude
191  scalar magUInf_;
192 
193 
194  // Reference scales
195 
196  //- Reference length [m]
197  scalar lRef_;
198 
199  //- Reference area [m^2]
200  scalar Aref_;
201 
202 
203  // File streams
204 
205  //- Integrated coefficients
206  autoPtr<OFstream> coeffFilePtr_;
207 
208  //- Drag coefficient
209  autoPtr<OFstream> CdBinFilePtr_;
210 
211  //- Side coefficient
212  autoPtr<OFstream> CsBinFilePtr_;
213 
214  //- Lift coefficient
215  autoPtr<OFstream> ClBinFilePtr_;
216 
217  //- Roll moment coefficient
218  autoPtr<OFstream> CmRollBinFilePtr_;
219 
220  //- Pitch moment coefficient
221  autoPtr<OFstream> CmPitchBinFilePtr_;
222 
223  //- Yaw moment coefficient
224  autoPtr<OFstream> CmYawBinFilePtr_;
225 
226 
227  // Private Member Functions
228 
229  //- No copy construct
230  forceCoeffs(const forceCoeffs&) = delete;
231 
232  //- No copy assignment
233  void operator=(const forceCoeffs&) = delete;
234 
235 
236 protected:
237 
238  // Protected Member Functions
239 
240  //- Create the output files
241  void createFiles();
242 
243  //- Write header for integrated data
244  void writeIntegratedHeader(const word& header, Ostream& os) const;
245 
246  //- Write header for binned data
247  void writeBinHeader(const word& header, Ostream& os) const;
248 
249  //- Write integrated data
251  (
252  const word& title,
253  const List<Field<scalar>>& coeff
254  ) const;
255 
256  //- Write binned data
257  void writeBinData(const List<Field<scalar>> coeffs, Ostream& os) const;
258 
259 
260 public:
261 
262  //- Runtime type information
263  TypeName("forceCoeffs");
264 
265 
266  // Constructors
267 
268  //- Construct from Time and dictionary
269  forceCoeffs
270  (
271  const word& name,
272  const Time& runTime,
273  const dictionary&,
274  const bool readFields = true
275  );
276 
277 
278  //- Destructor
279  virtual ~forceCoeffs() = default;
280 
281 
282  // Member Functions
283 
284  //- Read the forces data
285  virtual bool read(const dictionary&);
286 
287  //- Execute
288  virtual bool execute();
289 
290  //- Write the forces
291  virtual bool write();
292 };
293 
294 
295 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
296 
297 } // End namespace functionObjects
298 } // End namespace Foam
299 
300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 
302 #endif
303 
304 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObjects::forces
Calculates the forces and moments by integrating the pressure and skin-friction forces over a given l...
Definition: forces.H:236
Foam::functionObjects::forceCoeffs::TypeName
TypeName("forceCoeffs")
Runtime type information.
Foam::functionObjects::forceCoeffs::writeBinData
void writeBinData(const List< Field< scalar >> coeffs, Ostream &os) const
Write binned data.
Definition: forceCoeffs.C:208
Foam::functionObjects::forceCoeffs::read
virtual bool read(const dictionary &)
Read the forces data.
Definition: forceCoeffs.C:264
Foam::functionObjects::forceCoeffs::writeBinHeader
void writeBinHeader(const word &header, Ostream &os) const
Write header for binned data.
Definition: forceCoeffs.C:123
Foam::functionObjects::forceCoeffs::~forceCoeffs
virtual ~forceCoeffs()=default
Destructor.
Foam::functionObjects::forceCoeffs::writeIntegratedHeader
void writeIntegratedHeader(const word &header, Ostream &os) const
Write header for integrated data.
Definition: forceCoeffs.C:87
Foam::Field< scalar >
Foam::functionObjects::forceCoeffs::writeIntegratedData
void writeIntegratedData(const word &title, const List< Field< scalar >> &coeff) const
Write integrated data.
Definition: forceCoeffs.C:178
Foam::functionObjects::forceCoeffs
Extends the forces functionObject by providing coefficients for:
Definition: forceCoeffs.H:281
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::functionObjects::forceCoeffs::write
virtual bool write()
Write the forces.
Definition: forceCoeffs.C:495
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::forceCoeffs::execute
virtual bool execute()
Execute.
Definition: forceCoeffs.C:328
Foam::readFields
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.
Definition: ReadFieldsTemplates.C:312
Foam::functionObjects::forceCoeffs::createFiles
void createFiles()
Create the output files.
Definition: forceCoeffs.C:53
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
forces.H
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::functionObjects::readFields
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Definition: readFields.H:155
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56