FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/dictionary.H>
28 #include <OpenFOAM/Time.H>
29 #include <OpenFOAM/Pstream.H>
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(forceCoeffs, 0);
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
41 Foam::forceCoeffs::forceCoeffs
42 (
43  const word& name,
44  const objectRegistry& obr,
45  const dictionary& dict,
46  const bool loadFromFiles
47 )
48 :
49  forces(name, obr, dict, loadFromFiles),
50  liftDir_(vector::zero),
51  dragDir_(vector::zero),
52  pitchAxis_(vector::zero),
53  magUInf_(0.0),
54  lRef_(0.0),
55  Aref_(0.0)
56 {
57  read(dict);
58 }
59 
60 
61 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
62 
64 {}
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
70 {
71  if (active_)
72  {
73  forces::read(dict);
74 
75  // Directions for lift and drag forces, and pitch moment
76  dict.lookup("liftDir") >> liftDir_;
77  dict.lookup("dragDir") >> dragDir_;
78  dict.lookup("pitchAxis") >> pitchAxis_;
79 
80  // Free stream velocity magnitude
81  dict.lookup("magUInf") >> magUInf_;
82 
83  // Reference length and area scales
84  dict.lookup("lRef") >> lRef_;
85  dict.lookup("Aref") >> Aref_;
86  }
87 }
88 
89 
91 {
92  if (forcesFilePtr_.valid())
93  {
94  forcesFilePtr_()
95  << "# Time" << tab << "Cd" << tab << "Cl" << tab << "Cm" << endl;
96  }
97 }
98 
99 
101 {
102  // Do nothing - only valid on write
103 }
104 
105 
107 {
108  // Do nothing - only valid on write
109 }
110 
111 
113 {
114  if (active_)
115  {
116  // Create the forces file if not already created
117  makeFile();
118 
120 
121  scalar pDyn = 0.5*rhoRef_*magUInf_*magUInf_;
122 
123  vector totForce = fm.first().first() + fm.first().second();
124  vector totMoment = fm.second().first() + fm.second().second();
125 
126  scalar liftForce = totForce & liftDir_;
127  scalar dragForce = totForce & dragDir_;
128  scalar pitchMoment = totMoment & pitchAxis_;
129 
130  scalar Cl = liftForce/(Aref_*pDyn);
131  scalar Cd = dragForce/(Aref_*pDyn);
132  scalar Cm = pitchMoment/(Aref_*lRef_*pDyn);
133 
134  if (Pstream::master())
135  {
136  forcesFilePtr_()
137  << obr_.time().value() << tab
138  << Cd << tab << Cl << tab << Cm << endl;
139 
140  if (log_)
141  {
142  Info<< "forceCoeffs output:" << nl
143  << " Cd = " << Cd << nl
144  << " Cl = " << Cl << nl
145  << " Cm = " << Cm << nl
146  << endl;
147  }
148  }
149  }
150 }
151 
152 
153 // ************************ vim: set sw=4 sts=4 et: ************************ //