OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

forceCoeffs.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "forceCoeffs.H"
00028 #include "dictionary.H"
00029 #include "Time.H"
00030 #include "Pstream.H"
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036     defineTypeNameAndDebug(forceCoeffs, 0);
00037 }
00038 
00039 
00040 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00041 
00042 Foam::forceCoeffs::forceCoeffs
00043 (
00044     const word& name,
00045     const objectRegistry& obr,
00046     const dictionary& dict,
00047     const bool loadFromFiles
00048 )
00049 :
00050     forces(name, obr, dict, loadFromFiles),
00051     liftDir_(vector::zero),
00052     dragDir_(vector::zero),
00053     pitchAxis_(vector::zero),
00054     magUInf_(0.0),
00055     lRef_(0.0),
00056     Aref_(0.0)
00057 {
00058     read(dict);
00059 }
00060 
00061 
00062 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00063 
00064 Foam::forceCoeffs::~forceCoeffs()
00065 {}
00066 
00067 
00068 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00069 
00070 void Foam::forceCoeffs::read(const dictionary& dict)
00071 {
00072     if (active_)
00073     {
00074         forces::read(dict);
00075 
00076         // Directions for lift and drag forces, and pitch moment
00077         dict.lookup("liftDir") >> liftDir_;
00078         dict.lookup("dragDir") >> dragDir_;
00079         dict.lookup("pitchAxis") >> pitchAxis_;
00080 
00081         // Free stream velocity magnitude
00082         dict.lookup("magUInf") >> magUInf_;
00083 
00084         // Reference length and area scales
00085         dict.lookup("lRef") >> lRef_;
00086         dict.lookup("Aref") >> Aref_;
00087     }
00088 }
00089 
00090 
00091 void Foam::forceCoeffs::writeFileHeader()
00092 {
00093     if (forcesFilePtr_.valid())
00094     {
00095         forcesFilePtr_()
00096             << "# Time" << tab << "Cd" << tab << "Cl" << tab << "Cm" << endl;
00097     }
00098 }
00099 
00100 
00101 void Foam::forceCoeffs::execute()
00102 {
00103     // Do nothing - only valid on write
00104 }
00105 
00106 
00107 void Foam::forceCoeffs::end()
00108 {
00109     // Do nothing - only valid on write
00110 }
00111 
00112 
00113 void Foam::forceCoeffs::write()
00114 {
00115     if (active_)
00116     {
00117         // Create the forces file if not already created
00118         makeFile();
00119 
00120         forcesMoments fm = forces::calcForcesMoment();
00121 
00122         scalar pDyn = 0.5*rhoRef_*magUInf_*magUInf_;
00123 
00124         vector totForce = fm.first().first() + fm.first().second();
00125         vector totMoment = fm.second().first() + fm.second().second();
00126 
00127         scalar liftForce = totForce & liftDir_;
00128         scalar dragForce = totForce & dragDir_;
00129         scalar pitchMoment = totMoment & pitchAxis_;
00130 
00131         scalar Cl = liftForce/(Aref_*pDyn);
00132         scalar Cd = dragForce/(Aref_*pDyn);
00133         scalar Cm = pitchMoment/(Aref_*lRef_*pDyn);
00134 
00135         if (Pstream::master())
00136         {
00137             forcesFilePtr_()
00138                 << obr_.time().value() << tab
00139                 << Cd << tab << Cl << tab << Cm << endl;
00140 
00141             if (log_)
00142             {
00143                 Info<< "forceCoeffs output:" << nl
00144                     << "    Cd = " << Cd << nl
00145                     << "    Cl = " << Cl << nl
00146                     << "    Cm = " << Cm << nl
00147                     << endl;
00148             }
00149         }
00150     }
00151 }
00152 
00153 
00154 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd