1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "forceCoeffs.H"
28 #include "dictionary.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(forceCoeffs, 0);
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 Foam::forceCoeffs::forceCoeffs
45 const objectRegistry& obr,
46 const dictionary& dict,
47 const bool loadFromFiles
50 forces(name, obr, dict, loadFromFiles),
51 liftDir_(vector::zero),
52 dragDir_(vector::zero),
53 pitchAxis_(vector::zero),
62 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
64 Foam::forceCoeffs::~forceCoeffs()
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
70 void Foam::forceCoeffs::read(const dictionary& dict)
76 // Directions for lift and drag forces, and pitch moment
77 dict.lookup("liftDir") >> liftDir_;
78 dict.lookup("dragDir") >> dragDir_;
79 dict.lookup("pitchAxis") >> pitchAxis_;
81 // Free stream velocity magnitude
82 dict.lookup("magUInf") >> magUInf_;
84 // Reference length and area scales
85 dict.lookup("lRef") >> lRef_;
86 dict.lookup("Aref") >> Aref_;
91 void Foam::forceCoeffs::writeFileHeader()
93 if (forcesFilePtr_.valid())
96 << "# Time" << tab << "Cd" << tab << "Cl" << tab << "Cm" << endl;
101 void Foam::forceCoeffs::execute()
103 // Do nothing - only valid on write
107 void Foam::forceCoeffs::end()
109 // Do nothing - only valid on write
113 void Foam::forceCoeffs::write()
117 // Create the forces file if not already created
120 forcesMoments fm = forces::calcForcesMoment();
122 scalar pDyn = 0.5*rhoRef_*magUInf_*magUInf_;
124 vector totForce = fm.first().first() + fm.first().second();
125 vector totMoment = fm.second().first() + fm.second().second();
127 scalar liftForce = totForce & liftDir_;
128 scalar dragForce = totForce & dragDir_;
129 scalar pitchMoment = totMoment & pitchAxis_;
131 scalar Cl = liftForce/(Aref_*pDyn);
132 scalar Cd = dragForce/(Aref_*pDyn);
133 scalar Cm = pitchMoment/(Aref_*lRef_*pDyn);
135 if (Pstream::master())
138 << obr_.time().value() << tab
139 << Cd << tab << Cl << tab << Cm << endl;
143 Info<< "forceCoeffs output:" << nl
144 << " Cd = " << Cd << nl
145 << " Cl = " << Cl << nl
146 << " Cm = " << Cm << nl
154 // ************************************************************************* //