forceCoeffs.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 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 \*---------------------------------------------------------------------------*/
25 
26 #include "forceCoeffs.H"
27 #include "dictionary.H"
28 #include "Time.H"
29 #include "Pstream.H"
30 #include "IOmanip.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(forceCoeffs, 0);
37 }
38 
39 
40 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
41 
43 {
44  if (i == 0)
45  {
46  // force coeff data
47 
48  writeHeader(file(i), "Force coefficients");
49  writeHeaderValue(file(i), "liftDir", liftDir_);
50  writeHeaderValue(file(i), "dragDir", dragDir_);
51  writeHeaderValue(file(i), "pitchAxis", pitchAxis_);
52  writeHeaderValue(file(i), "magUInf", magUInf_);
53  writeHeaderValue(file(i), "lRef", lRef_);
54  writeHeaderValue(file(i), "Aref", Aref_);
55  writeHeaderValue(file(i), "CofR", coordSys_.origin());
56  writeCommented(file(i), "Time");
57  writeTabbed(file(i), "Cm");
58  writeTabbed(file(i), "Cd");
59  writeTabbed(file(i), "Cl");
60  writeTabbed(file(i), "Cl(f)");
61  writeTabbed(file(i), "Cl(r)");
62  file(i)
63  << tab << "Cm" << tab << "Cd" << tab << "Cl" << tab << "Cl(f)"
64  << tab << "Cl(r)";
65  }
66  else if (i == 1)
67  {
68  // bin coeff data
69 
70  writeHeader(file(i), "Force coefficient bins");
71  writeHeaderValue(file(i), "bins", nBin_);
72  writeHeaderValue(file(i), "start", binMin_);
73  writeHeaderValue(file(i), "delta", binDx_);
74  writeHeaderValue(file(i), "direction", binDir_);
75 
76  vectorField binPoints(nBin_);
77  writeCommented(file(i), "x co-ords :");
78  forAll(binPoints, pointI)
79  {
80  binPoints[pointI] = (binMin_ + (pointI + 1)*binDx_)*binDir_;
81  file(i) << tab << binPoints[pointI].x();
82  }
83  file(i) << nl;
84 
85  writeCommented(file(i), "y co-ords :");
86  forAll(binPoints, pointI)
87  {
88  file(i) << tab << binPoints[pointI].y();
89  }
90  file(i) << nl;
91 
92  writeCommented(file(i), "z co-ords :");
93  forAll(binPoints, pointI)
94  {
95  file(i) << tab << binPoints[pointI].z();
96  }
97  file(i) << nl;
98 
99  writeCommented(file(i), "Time");
100 
101  for (label j = 0; j < nBin_; j++)
102  {
103  const word jn('(' + Foam::name(j) + ')');
104  writeTabbed(file(i), "Cm" + jn);
105  writeTabbed(file(i), "Cd" + jn);
106  writeTabbed(file(i), "Cl" + jn);
107  }
108  }
109  else
110  {
111  FatalErrorIn("void Foam::forces::writeFileHeader(const label)")
112  << "Unhandled file index: " << i
113  << abort(FatalError);
114  }
115 
116  file(i)<< endl;
117 }
118 
119 
120 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
121 
122 Foam::forceCoeffs::forceCoeffs
123 (
124  const word& name,
125  const objectRegistry& obr,
126  const dictionary& dict,
127  const bool loadFromFiles
128 )
129 :
130  forces(name, obr, dict, loadFromFiles, false),
131  liftDir_(vector::zero),
132  dragDir_(vector::zero),
133  pitchAxis_(vector::zero),
134  magUInf_(0.0),
135  lRef_(0.0),
136  Aref_(0.0)
137 {
138  read(dict);
139 
140  Info<< endl;
141 }
142 
143 
144 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
145 
147 {}
148 
149 
150 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
151 
153 {
154  if (active_)
155  {
156  forces::read(dict);
157 
158  // Directions for lift and drag forces, and pitch moment
159  dict.lookup("liftDir") >> liftDir_;
160  dict.lookup("dragDir") >> dragDir_;
161  dict.lookup("pitchAxis") >> pitchAxis_;
162 
163  // Free stream velocity magnitude
164  dict.lookup("magUInf") >> magUInf_;
165 
166  // Reference length and area scales
167  dict.lookup("lRef") >> lRef_;
168  dict.lookup("Aref") >> Aref_;
169  }
170 }
171 
172 
174 {
175  // Do nothing - only valid on write
176 }
177 
178 
180 {
181  // Do nothing - only valid on write
182 }
183 
184 
186 {
187  // Do nothing - only valid on write
188 }
189 
190 
192 {
194 
195  if (!active_)
196  {
197  return;
198  }
199 
200  if (Pstream::master())
201  {
203 
204  scalar pDyn = 0.5*rhoRef_*magUInf_*magUInf_;
205 
206  Field<vector> totForce(force_[0] + force_[1] + force_[2]);
207  Field<vector> totMoment(moment_[0] + moment_[1] + moment_[2]);
208 
209  List<Field<scalar> > coeffs(3);
210  coeffs[0].setSize(nBin_);
211  coeffs[1].setSize(nBin_);
212  coeffs[2].setSize(nBin_);
213 
214  // lift, drag and moment
215  coeffs[0] = (totForce & liftDir_)/(Aref_*pDyn);
216  coeffs[1] = (totForce & dragDir_)/(Aref_*pDyn);
217  coeffs[2] = (totMoment & pitchAxis_)/(Aref_*lRef_*pDyn);
218 
219  scalar Cl = sum(coeffs[0]);
220  scalar Cd = sum(coeffs[1]);
221  scalar Cm = sum(coeffs[2]);
222 
223  scalar Clf = Cl/2.0 + Cm;
224  scalar Clr = Cl/2.0 - Cm;
225 
226  file(0)
227  << obr_.time().value() << tab << Cm << tab << Cd
228  << tab << Cl << tab << Clf << tab << Clr << endl;
229 
230  if (log_) Info<< type() << " " << name_ << " output:" << nl
231  << " Cm = " << Cm << nl
232  << " Cd = " << Cd << nl
233  << " Cl = " << Cl << nl
234  << " Cl(f) = " << Clf << nl
235  << " Cl(r) = " << Clr << endl;
236 
237  if (nBin_ > 1)
238  {
239  if (binCumulative_)
240  {
241  for (label i = 1; i < coeffs[0].size(); i++)
242  {
243  coeffs[0][i] += coeffs[0][i-1];
244  coeffs[1][i] += coeffs[1][i-1];
245  coeffs[2][i] += coeffs[2][i-1];
246  }
247  }
248 
249  file(1)<< obr_.time().value();
250 
251  forAll(coeffs[0], i)
252  {
253  file(1)
254  << tab << coeffs[2][i]
255  << tab << coeffs[1][i]
256  << tab << coeffs[0][i];
257  }
258 
259  file(1) << endl;
260  }
261 
262  if (log_) Info<< endl;
263  }
264 }
265 
266 
267 // ************************************************************************* //
virtual void calcForcesMoment()
Calculate the forces and moments.
Definition: forces.C:809
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
virtual ~forceCoeffs()
Destructor.
Definition: forceCoeffs.C:146
dimensionedScalar jn(const int n, const dimensionedScalar &ds)
volScalarField pDyn(IOobject( "pDyn", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedScalar("zero", dimPressure, 0.0))
This function object calculates the forces and moments by integrating the pressure and skin-friction ...
Definition: forces.H:206
A class for handling words, derived from string.
Definition: word.H:59
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
messageStream Info
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
static const char nl
Definition: Ostream.H:260
void setSize(const label)
Reset size of List.
Definition: List.C:318
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define forAll(list, i)
Definition: UList.H:421
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: forceCoeffs.C:185
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
errorManip< error > abort(error &err)
Definition: errorManip.H:131
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
Istream and Ostream manipulators taking arguments.
virtual void write()
Write the forces.
Definition: forceCoeffs.C:191
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
virtual void write()
Write function.
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: forceCoeffs.C:179
static const char tab
Definition: Ostream.H:259
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
virtual void read(const dictionary &)
Read the forces data.
Definition: forces.C:634
virtual void read(const dictionary &)
Read the forces data.
Definition: forceCoeffs.C:152
Registry of regIOobjects.
static const Vector zero
Definition: Vector.H:80
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:398
virtual void execute()
Execute, currently does nothing.
Definition: forceCoeffs.C:173
bool read(const char *, int32_t &)
Definition: int32IO.C:87
virtual void writeFileHeader(const label i)
Output file header information.
Definition: forceCoeffs.C:42
defineTypeNameAndDebug(combustionModel, 0)