initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / postProcessing / functionObjects / forces / forceCoeffs / forceCoeffs.C
blob5fe1b846707dcd266b5fc67b536c34a3ac8b9dc8
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
29 #include "Time.H"
30 #include "Pstream.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace Foam
36     defineTypeNameAndDebug(forceCoeffs, 0);
40 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
42 Foam::forceCoeffs::forceCoeffs
44     const word& name,
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),
54     magUInf_(0.0),
55     lRef_(0.0),
56     Aref_(0.0)
58     read(dict);
62 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
64 Foam::forceCoeffs::~forceCoeffs()
68 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
70 void Foam::forceCoeffs::read(const dictionary& dict)
72     if (active_)
73     {
74         forces::read(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_;
87     }
91 void Foam::forceCoeffs::writeFileHeader()
93     if (forcesFilePtr_.valid())
94     {
95         forcesFilePtr_()
96             << "# Time" << tab << "Cd" << tab << "Cl" << tab << "Cm" << endl;
97     }
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()
115     if (active_)
116     {
117         // Create the forces file if not already created
118         makeFile();
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())
136         {
137             forcesFilePtr_()
138                 << obr_.time().value() << tab
139                 << Cd << tab << Cl << tab << Cm << endl;
141             if (log_)
142             {
143                 Info<< "forceCoeffs output:" << nl
144                     << "    Cd = " << Cd << nl
145                     << "    Cl = " << Cl << nl
146                     << "    Cm = " << Cm << nl
147                     << endl;
148             }
149         }
150     }
154 // ************************************************************************* //