FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "forceCoeffs.H"
00027 #include <OpenFOAM/dictionary.H>
00028 #include <OpenFOAM/Time.H>
00029 #include <OpenFOAM/Pstream.H>
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035     defineTypeNameAndDebug(forceCoeffs, 0);
00036 }
00037 
00038 
00039 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00040 
00041 Foam::forceCoeffs::forceCoeffs
00042 (
00043     const word& name,
00044     const objectRegistry& obr,
00045     const dictionary& dict,
00046     const bool loadFromFiles
00047 )
00048 :
00049     forces(name, obr, dict, loadFromFiles),
00050     liftDir_(vector::zero),
00051     dragDir_(vector::zero),
00052     pitchAxis_(vector::zero),
00053     magUInf_(0.0),
00054     lRef_(0.0),
00055     Aref_(0.0)
00056 {
00057     read(dict);
00058 }
00059 
00060 
00061 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00062 
00063 Foam::forceCoeffs::~forceCoeffs()
00064 {}
00065 
00066 
00067 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00068 
00069 void Foam::forceCoeffs::read(const dictionary& dict)
00070 {
00071     if (active_)
00072     {
00073         forces::read(dict);
00074 
00075         // Directions for lift and drag forces, and pitch moment
00076         dict.lookup("liftDir") >> liftDir_;
00077         dict.lookup("dragDir") >> dragDir_;
00078         dict.lookup("pitchAxis") >> pitchAxis_;
00079 
00080         // Free stream velocity magnitude
00081         dict.lookup("magUInf") >> magUInf_;
00082 
00083         // Reference length and area scales
00084         dict.lookup("lRef") >> lRef_;
00085         dict.lookup("Aref") >> Aref_;
00086     }
00087 }
00088 
00089 
00090 void Foam::forceCoeffs::writeFileHeader()
00091 {
00092     if (forcesFilePtr_.valid())
00093     {
00094         forcesFilePtr_()
00095             << "# Time" << tab << "Cd" << tab << "Cl" << tab << "Cm" << endl;
00096     }
00097 }
00098 
00099 
00100 void Foam::forceCoeffs::execute()
00101 {
00102     // Do nothing - only valid on write
00103 }
00104 
00105 
00106 void Foam::forceCoeffs::end()
00107 {
00108     // Do nothing - only valid on write
00109 }
00110 
00111 
00112 void Foam::forceCoeffs::write()
00113 {
00114     if (active_)
00115     {
00116         // Create the forces file if not already created
00117         makeFile();
00118 
00119         forcesMoments fm = forces::calcForcesMoment();
00120 
00121         scalar pDyn = 0.5*rhoRef_*magUInf_*magUInf_;
00122 
00123         vector totForce = fm.first().first() + fm.first().second();
00124         vector totMoment = fm.second().first() + fm.second().second();
00125 
00126         scalar liftForce = totForce & liftDir_;
00127         scalar dragForce = totForce & dragDir_;
00128         scalar pitchMoment = totMoment & pitchAxis_;
00129 
00130         scalar Cl = liftForce/(Aref_*pDyn);
00131         scalar Cd = dragForce/(Aref_*pDyn);
00132         scalar Cm = pitchMoment/(Aref_*lRef_*pDyn);
00133 
00134         if (Pstream::master())
00135         {
00136             forcesFilePtr_()
00137                 << obr_.time().value() << tab
00138                 << Cd << tab << Cl << tab << Cm << endl;
00139 
00140             if (log_)
00141             {
00142                 Info<< "forceCoeffs output:" << nl
00143                     << "    Cd = " << Cd << nl
00144                     << "    Cl = " << Cl << nl
00145                     << "    Cm = " << Cm << nl
00146                     << endl;
00147             }
00148         }
00149     }
00150 }
00151 
00152 
00153 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines