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

forces.H

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 Class
00025     Foam::forces
00026 
00027 Description
00028     Calculates the forces and moments by integrating the pressure and
00029     skin-friction forces over a given list of patches.
00030 
00031     Member function calcForcesMoment()calculates and returns the forces and
00032     moments.
00033 
00034     Member function forces::write() calls calcForcesMoment() and writes the
00035     forces and moments into the file <timeDir>/forces.dat
00036 
00037 SourceFiles
00038     forces.C
00039     IOforces.H
00040 
00041 \*---------------------------------------------------------------------------*/
00042 
00043 #ifndef forces_H
00044 #define forces_H
00045 
00046 #include <OpenFOAM/primitiveFieldsFwd.H>
00047 #include <finiteVolume/volFieldsFwd.H>
00048 #include <OpenFOAM/HashSet.H>
00049 #include <OpenFOAM/Tuple2.H>
00050 #include <OpenFOAM/OFstream.H>
00051 #include <OpenFOAM/Switch.H>
00052 #include <OpenFOAM/pointFieldFwd.H>
00053 
00054 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00055 
00056 namespace Foam
00057 {
00058 
00059 // Forward declaration of classes
00060 class objectRegistry;
00061 class dictionary;
00062 class mapPolyMesh;
00063 
00064 /*---------------------------------------------------------------------------*\
00065                            Class forces Declaration
00066 \*---------------------------------------------------------------------------*/
00067 
00068 class forces
00069 {
00070 public:
00071 
00072     // Tuple which holds the pressure (.first()) and viscous (.second) forces
00073     typedef Tuple2<vector, vector> pressureViscous;
00074 
00075     // Tuple which holds the forces (.first()) and moment (.second)
00076     // pressure/viscous forces Tuples.
00077     typedef Tuple2<pressureViscous, pressureViscous> forcesMoments;
00078 
00079     //- Sum operation class to accumulate the pressure, viscous forces and moments
00080     class sumOp
00081     {
00082     public:
00083 
00084         forcesMoments operator()
00085         (
00086             const forcesMoments& fm1,
00087             const forcesMoments& fm2
00088         ) const
00089         {
00090             return forcesMoments
00091             (
00092                 pressureViscous
00093                 (
00094                     fm1.first().first() + fm2.first().first(),
00095                     fm1.first().second() + fm2.first().second()
00096                 ),
00097                 pressureViscous
00098                 (
00099                     fm1.second().first() + fm2.second().first(),
00100                     fm1.second().second() + fm2.second().second()
00101                 )
00102             );
00103         }
00104     };
00105 
00106 
00107 protected:
00108 
00109     // Private data
00110 
00111         //- Name of this set of forces,
00112         //  Also used as the name of the probes directory.
00113         word name_;
00114 
00115         const objectRegistry& obr_;
00116 
00117         //- on/off switch
00118         bool active_;
00119 
00120         //- Switch to send output to Info as well as to file
00121         Switch log_;
00122 
00123         // Read from dictionary
00124 
00125             //- Patches to integrate forces over
00126             labelHashSet patchSet_;
00127 
00128             //- Name of pressure field
00129             word pName_;
00130 
00131             //- Name of velocity field
00132             word UName_;
00133 
00134             //- Name of density field (optional)
00135             word rhoName_;
00136 
00137             //- Is the force density being supplied directly?
00138             Switch directForceDensity_;
00139 
00140             //- The name of the force density (fD) field
00141             word fDName_;
00142 
00143             //- Reference density needed for incompressible calculations
00144             scalar rhoRef_;
00145 
00146             //- Reference pressure
00147             scalar pRef_;
00148 
00149             //- Centre of rotation
00150             vector CofR_;
00151 
00152 
00153         //- Forces/moment file ptr
00154         autoPtr<OFstream> forcesFilePtr_;
00155 
00156 
00157     // Private Member Functions
00158 
00159         //- If the forces file has not been created create it
00160         void makeFile();
00161 
00162         //- Output file header information
00163         virtual void writeFileHeader();
00164 
00165         //- Return the effective viscous stress (laminar + turbulent).
00166         tmp<volSymmTensorField> devRhoReff() const;
00167 
00168         //- Return rho if rhoName is specified otherwise rhoRef
00169         tmp<volScalarField> rho() const;
00170 
00171         //- Return rhoRef if the pressure field is dynamic, i.e. p/rho
00172         //  otherwise return 1
00173         scalar rho(const volScalarField& p) const;
00174 
00175         //- Disallow default bitwise copy construct
00176         forces(const forces&);
00177 
00178         //- Disallow default bitwise assignment
00179         void operator=(const forces&);
00180 
00181 
00182 public:
00183 
00184     //- Runtime type information
00185     TypeName("forces");
00186 
00187 
00188     // Constructors
00189 
00190         //- Construct for given objectRegistry and dictionary.
00191         //  Allow the possibility to load fields from files
00192         forces
00193         (
00194             const word& name,
00195             const objectRegistry&,
00196             const dictionary&,
00197             const bool loadFromFiles = false
00198         );
00199 
00200 
00201     //- Destructor
00202     virtual ~forces();
00203 
00204 
00205     // Member Functions
00206 
00207         //- Return name of the set of forces
00208         virtual const word& name() const
00209         {
00210             return name_;
00211         }
00212 
00213         //- Read the forces data
00214         virtual void read(const dictionary&);
00215 
00216         //- Execute, currently does nothing
00217         virtual void execute();
00218 
00219         //- Execute at the final time-loop, currently does nothing
00220         virtual void end();
00221 
00222         //- Write the forces
00223         virtual void write();
00224 
00225         //- Calculate and return forces and moment
00226         virtual forcesMoments calcForcesMoment() const;
00227 
00228         //- Update for changes of mesh
00229         virtual void updateMesh(const mapPolyMesh&)
00230         {}
00231 
00232         //- Update for changes of mesh
00233         virtual void movePoints(const pointField&)
00234         {}
00235 };
00236 
00237 
00238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00239 
00240 } // End namespace Foam
00241 
00242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00243 
00244 #endif
00245 
00246 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines