1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "forceCoeffs.H"
27 #include "dictionary.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 defineTypeNameAndDebug(Foam::forceCoeffs, 0);
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 Foam::forceCoeffs::forceCoeffs
41 const objectRegistry& obr,
42 const dictionary& dict,
43 const bool loadFromFiles
46 forces(name, obr, dict, loadFromFiles),
47 liftDir_(vector::zero),
48 dragDir_(vector::zero),
49 pitchAxis_(vector::zero),
58 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
60 Foam::forceCoeffs::~forceCoeffs()
64 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
66 void Foam::forceCoeffs::read(const dictionary& dict)
72 // Directions for lift and drag forces, and pitch moment
73 dict.lookup("liftDir") >> liftDir_;
74 dict.lookup("dragDir") >> dragDir_;
75 dict.lookup("pitchAxis") >> pitchAxis_;
77 // Free stream velocity magnitude
78 dict.lookup("magUInf") >> magUInf_;
80 // Reference length and area scales
81 dict.lookup("lRef") >> lRef_;
82 dict.lookup("Aref") >> Aref_;
87 void Foam::forceCoeffs::writeFileHeader()
89 if (forcesFilePtr_.valid())
92 << "# Time" << tab << "Cd" << tab << "Cl" << tab << "Cm" << endl;
97 void Foam::forceCoeffs::execute()
99 // Do nothing - only valid on write
103 void Foam::forceCoeffs::end()
105 // Do nothing - only valid on write
109 void Foam::forceCoeffs::write()
113 // Create the forces file if not already created
116 forcesMoments fm = forces::calcForcesMoment();
118 scalar pDyn = 0.5*rhoRef_*magUInf_*magUInf_;
120 vector totForce = fm.first().first() + fm.first().second();
121 vector totMoment = fm.second().first() + fm.second().second();
123 scalar liftForce = totForce & liftDir_;
124 scalar dragForce = totForce & dragDir_;
125 scalar pitchMoment = totMoment & pitchAxis_;
127 scalar Cl = liftForce/(Aref_*pDyn);
128 scalar Cd = dragForce/(Aref_*pDyn);
129 scalar Cm = pitchMoment/(Aref_*lRef_*pDyn);
131 if (Pstream::master())
134 << obr_.time().value() << tab
135 << Cd << tab << Cl << tab << Cm << endl;
139 Info<< "forceCoeffs output:" << nl
140 << " Cd = " << Cd << nl
141 << " Cl = " << Cl << nl
142 << " Cm = " << Cm << nl
150 // ************************************************************************* //