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

Cloud.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::Cloud
00026 
00027 Description
00028 
00029 SourceFiles
00030     Cloud.C
00031     CloudIO.C
00032 
00033 \*---------------------------------------------------------------------------*/
00034 
00035 #ifndef Cloud_H
00036 #define Cloud_H
00037 
00038 #include <OpenFOAM/cloud.H>
00039 #include <OpenFOAM/IDLList.H>
00040 #include <OpenFOAM/IOField.H>
00041 #include <OpenFOAM/polyMesh.H>
00042 
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00044 
00045 namespace Foam
00046 {
00047 
00048 // Forward declaration of functions
00049 template<class ParticleType>
00050 class Cloud;
00051 
00052 template<class ParticleType>
00053 class IOPosition;
00054 
00055 template<class ParticleType>
00056 Ostream& operator<<
00057 (
00058     Ostream&,
00059     const Cloud<ParticleType>&
00060 );
00061 
00062 
00063 /*---------------------------------------------------------------------------*\
00064                            Class Cloud Declaration
00065 \*---------------------------------------------------------------------------*/
00066 
00067 template<class ParticleType>
00068 class Cloud
00069 :
00070     public cloud,
00071     public IDLList<ParticleType>
00072 {
00073     // Private data
00074 
00075         const polyMesh& polyMesh_;
00076 
00077         //- Overall count of particles ever created. Never decreases.
00078         mutable label particleCount_;
00079 
00080         //- Temporary storage for addressing. Used in findFaces.
00081         mutable DynamicList<label> labels_;
00082 
00083 
00084     // Private member functions
00085 
00086         //- Initialise cloud on IO constructor
00087         void initCloud(const bool checkClass);
00088 
00089         //- Read cloud properties dictionary
00090         void readCloudUniformProperties();
00091 
00092         //- Write cloud properties dictionary
00093         void writeCloudUniformProperties() const;
00094 
00095 
00096 public:
00097 
00098     template<class ParticleT>
00099     friend class Particle;
00100     template<class ParticleT>
00101     friend class IOPosition;
00102 
00103     typedef ParticleType particleType;
00104 
00105     typedef typename IDLList<ParticleType>::iterator iterator;
00106     typedef typename IDLList<ParticleType>::const_iterator const_iterator;
00107 
00108     //-Runtime type information
00109     TypeName("Cloud");
00110 
00111 
00112     // Static data
00113 
00114         //- Name of cloud properties dictionary
00115         static word cloudPropertiesName;
00116 
00117 
00118     // Constructors
00119 
00120         //- Construct from mesh and a list of particles
00121         Cloud
00122         (
00123             const polyMesh& mesh,
00124             const IDLList<ParticleType>& particles
00125         );
00126 
00127         //- Construct from mesh, cloud name, and a list of particles
00128         Cloud
00129         (
00130             const polyMesh& mesh,
00131             const word& cloudName,
00132             const IDLList<ParticleType>& particles
00133         );
00134 
00135         //- Construct from mesh by reading from file
00136         //  Optionally disable checking of class name for post-processing
00137         Cloud
00138         (
00139             const polyMesh& mesh,
00140             const bool checkClass = true
00141         );
00142 
00143 
00144         //- Construct from mesh by reading from file with given cloud instance
00145         //  Optionally disable checking of class name for post-processing
00146         Cloud
00147         (
00148             const polyMesh& pMesh,
00149             const word& cloudName,
00150             const bool checkClass = true
00151         );
00152 
00153 
00154     // Member Functions
00155 
00156         // Access
00157 
00158             //- Return the polyMesh reference
00159             const polyMesh& pMesh() const
00160             {
00161                 return polyMesh_;
00162             }
00163 
00164             //- Is this global face an internal face?
00165             bool internalFace(const label facei) const
00166             {
00167                 return polyMesh_.isInternalFace(facei);
00168             }
00169 
00170             //- Is this global face a boundary face?
00171             bool boundaryFace(const label facei) const
00172             {
00173                 return !internalFace(facei);
00174             }
00175 
00176             //- Which patch is this global face on
00177             label facePatch(const label facei) const
00178             {
00179                 return polyMesh_.boundaryMesh().whichPatch(facei);
00180             }
00181 
00182             //- Which face of this patch is this global face
00183             label patchFace(const label patchi, const label facei) const
00184             {
00185                 return polyMesh_.boundaryMesh()[patchi].whichFace(facei);
00186             }
00187 
00188             label size() const
00189             {
00190                 return IDLList<ParticleType>::size();
00191             };
00192 
00193 
00194             // Iterators
00195 
00196                 const const_iterator begin() const
00197                 {
00198                     return IDLList<ParticleType>::begin();
00199                 };
00200 
00201                 const const_iterator cbegin() const
00202                 {
00203                     return IDLList<ParticleType>::cbegin();
00204                 };
00205 
00206                 const const_iterator end() const
00207                 {
00208                     return IDLList<ParticleType>::end();
00209                 };
00210 
00211                 const const_iterator cend() const
00212                 {
00213                     return IDLList<ParticleType>::cend();
00214                 };
00215 
00216                 iterator begin()
00217                 {
00218                     return IDLList<ParticleType>::begin();
00219                 };
00220 
00221                 iterator end()
00222                 {
00223                     return IDLList<ParticleType>::end();
00224                 };
00225 
00226 
00227         // Edit
00228 
00229             void clear()
00230             {
00231                 return IDLList<ParticleType>::clear();
00232             };
00233 
00234             //- Get unique particle creation id
00235             label getNewParticleID() const;
00236 
00237             //- Transfer particle to cloud
00238             void addParticle(ParticleType* pPtr);
00239 
00240             //- Remove particle from cloud and delete
00241             void deleteParticle(ParticleType&);
00242 
00243             //- Move the particles
00244             //  passing the TrackingData to the track function
00245             template<class TrackingData>
00246             void move(TrackingData& td);
00247 
00248             //- Remap the cells of particles corresponding to the
00249             //  mesh topology change
00250             virtual void autoMap(const mapPolyMesh&);
00251 
00252 
00253         // Read
00254 
00255             //- Helper to construct IOobject for field and current time.
00256             IOobject fieldIOobject
00257             (
00258                 const word& fieldName,
00259                 const IOobject::readOption r
00260             ) const;
00261 
00262             //- Check lagrangian data field
00263             template<class DataType>
00264             void checkFieldIOobject
00265             (
00266                 const Cloud<ParticleType>& c,
00267                 const IOField<DataType>& data
00268             ) const;
00269 
00270             //- Read the field data for the cloud of particles. Dummy at
00271             //  this level.
00272             virtual void readFields();
00273 
00274 
00275         // Write
00276 
00277             //- Write the field data for the cloud of particles Dummy at
00278             //  this level.
00279             virtual void writeFields() const;
00280 
00281             //- Write using given format, version and compression.
00282             //  Only writes the cloud file if the Cloud isn't empty
00283             virtual bool writeObject
00284             (
00285                 IOstream::streamFormat fmt,
00286                 IOstream::versionNumber ver,
00287                 IOstream::compressionType cmp
00288             ) const;
00289 
00290             //- Write positions to <cloudName>_positions.obj file
00291             void writePositions() const;
00292 
00293 
00294     // Ostream Operator
00295 
00296         friend Ostream& operator<< <ParticleType>
00297         (
00298             Ostream&,
00299             const Cloud<ParticleType>&
00300         );
00301 };
00302 
00303 
00304 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00305 
00306 } // End namespace Foam
00307 
00308 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00309 
00310 #ifdef NoRepository
00311 #   include "Cloud.C"
00312 #endif
00313 
00314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00315 
00316 #endif
00317 
00318 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines