BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / postProcessing / functionObjects / forces / forceCoeffs / forceCoeffs.C
blob3ce1fd2f11846f96ad10c616fcc11fc1ddc9053f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
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
19     for more details.
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"
28 #include "Time.H"
29 #include "Pstream.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 defineTypeNameAndDebug(Foam::forceCoeffs, 0);
36 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
38 Foam::forceCoeffs::forceCoeffs
40     const word& name,
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),
50     magUInf_(0.0),
51     lRef_(0.0),
52     Aref_(0.0)
54     read(dict);
58 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
60 Foam::forceCoeffs::~forceCoeffs()
64 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
66 void Foam::forceCoeffs::read(const dictionary& dict)
68     if (active_)
69     {
70         forces::read(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_;
83     }
87 void Foam::forceCoeffs::writeFileHeader()
89     if (forcesFilePtr_.valid())
90     {
91         forcesFilePtr_()
92             << "# Time" << tab << "Cd" << tab << "Cl" << tab << "Cm" << endl;
93     }
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()
111     if (active_)
112     {
113         // Create the forces file if not already created
114         makeFile();
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())
132         {
133             forcesFilePtr_()
134                 << obr_.time().value() << tab
135                 << Cd << tab << Cl << tab << Cm << endl;
137             if (log_)
138             {
139                 Info<< "forceCoeffs output:" << nl
140                     << "    Cd = " << Cd << nl
141                     << "    Cl = " << Cl << nl
142                     << "    Cm = " << Cm << nl
143                     << endl;
144             }
145         }
146     }
150 // ************************************************************************* //