OpenFOAM logo
Open Source CFD Toolkit

particle.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-2005 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 Class
00026     particle
00027 
00028 Description
00029 
00030 \*---------------------------------------------------------------------------*/
00031 
00032 #ifndef particle_H
00033 #define particle_H
00034 
00035 #include "vector.H"
00036 #include "IDLList.H"
00037 #include "labelList.H"
00038 #include "pointField.H"
00039 #include "faceList.H"
00040 #include "typeInfo.H"
00041 #include "OFstream.H"
00042 
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00044 
00045 namespace Foam
00046 {
00047 
00048 template<class particle>
00049 class Cloud;
00050 
00051 
00052 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
00053 
00054 template<class particleType>
00055 class particle;
00056 
00057 template<class particleType>
00058 Ostream& operator<<
00059 (
00060     Ostream&,
00061     const particle<particleType>&
00062 );
00063 
00064 
00065 /*---------------------------------------------------------------------------*\
00066                            Class particle Declaration
00067 \*---------------------------------------------------------------------------*/
00068 
00069 template<class particleType>
00070 class particle
00071 :
00072     public IDLList<particleType>::link
00073 {
00074     // Private data
00075 
00076         //- Reference to the particle cloud
00077         const Cloud<particleType>& cloud_;
00078 
00079         //- Position of particle
00080         vector position_;
00081 
00082         //- Index of the cell it is
00083         label celli_;
00084 
00085         //- is particle on boundary/outside domain
00086         bool onBoundary_;
00087 
00088 
00089     // Private member functions
00090 
00091         //- Return the 'lambda' value for the position, p, on the face,
00092         // where, p = from + lamda*(to - from)
00093         // for non-static meshes
00094         inline scalar lambda
00095         (
00096             const vector& from,
00097             const vector& to,
00098             const label facei,
00099             const scalar fraction
00100         );
00101 
00102         //- Return the 'lambda' value for the position, p, on the face,
00103         // where, p = from + lamda*(to - from) 
00104         // for static meshes
00105         inline scalar lambda
00106         (
00107             const vector& from,
00108             const vector& to,
00109             const label facei
00110         );
00111 
00112         //- Return the faces between position and cell centre
00113         labelList findFaces
00114         (
00115             const vector& position
00116         );
00117 
00118         //- Return the faces between position and cell centre
00119         labelList findFaces
00120         (
00121             const vector& position,
00122             const label celli,
00123             const scalar fraction
00124         );
00125 
00126 protected:
00127 
00128         //- Convert global addressing to the processor patch
00129         //  local equivalents
00130         void prepareForParallelTransfer
00131         (
00132             const label patchi,
00133             const label facei
00134         );
00135 
00136         //- Convert processor patch addressing to the global equivalents
00137         //  and set the celli to the face-neighbour
00138         void correctAfterParallelTransfer
00139         (
00140             const label patchi,
00141             const label facei
00142         );
00143 
00144 
00145 public:
00146 
00147     friend class Cloud<particleType>;
00148 
00149 
00150     //- Runtime type information
00151     TypeName("particle");
00152 
00153 
00154     // Constructors
00155 
00156         //- Construct from components
00157         particle
00158         (
00159             const Cloud<particleType>&,
00160             const vector& position,
00161             const label celli
00162         );
00163 
00164         //- Construct from Istream
00165         particle
00166         (
00167             const Cloud<particleType>&,
00168             Istream&
00169         );
00170 
00171 
00172     // Destructor
00173 
00174         virtual ~particle()
00175         {}
00176 
00177 
00178     // Member Functions
00179 
00180         // Access
00181 
00182             //- Return true if particle is in cell
00183             inline bool inCell();
00184 
00185             //- Return true if position is in cell i
00186             inline bool inCell
00187             (
00188                 const vector& position,
00189                 const label celli,
00190                 const scalar fraction
00191             );
00192 
00193             //- Return current particle position
00194             inline const vector& position() const;
00195 
00196             //- Return current cell particle is in
00197             inline label cell() const;
00198 
00199             //- Return reference to the particle cloud
00200             inline const Cloud<particleType>& cloud() const;
00201 
00202 
00203         // Check
00204 
00205             //- Is the particle on the boundary/( or outside the domain)?
00206             inline bool onBoundary() const;
00207 
00208             //- Which patch is particle on
00209             inline label patch(const label facei) const;
00210 
00211             //- Which face of this patch is this particle on
00212             inline label patchFace(const label patchi, const label facei) const;
00213     
00214             //- The nearest distance to a wall that 
00215             // the particle can be in the n direction
00216             virtual scalar wallImpactDistance(const vector& n) const;
00217 
00218 
00219         // Track
00220 
00221             //- Track particle to end of trajectory
00222             //  or until it hits the boundary,
00223             // on entry 'fraction' is the fraction of the integration step
00224             // at which the tracking starts (only used for moving meshes)
00225             // and on exit it contains the fraction of the traveled trajectory
00226             label track
00227             (
00228                 const vector& endPosition,
00229                 scalar& fraction,
00230                 const bool softAlgorithm = false
00231             );
00232 
00233             //- Track particle to a given position
00234             // If particle reaches that position without hitting a face
00235             // we return -1, otherwise track to face and return face index
00236             // on entry 'fraction' is the fraction of the integration step
00237             // at which the tracking starts (only used for moving meshes)
00238             // upon exit fraction contains the fraction of the actual
00239             // distance moved
00240             label trackToFace
00241             (
00242                 const vector& endPosition,
00243                 scalar& fraction,
00244                 const bool softAlgorithm = false
00245             );
00246 
00247 
00248         // Particle operations
00249 
00250             //- Transform the position the particle
00251             //  according to the given transformation tensor
00252             void transformPosition(const tensor& T);
00253 
00254             //- Transform the physical properties of the particle
00255             //  according to the given transformation tensor
00256             virtual void transformProperties(const tensor& T);
00257 
00258 
00259     // Ostream Operator
00260 
00261         friend Ostream& operator<< <particleType>
00262         (
00263             Ostream&,
00264             const particle<particleType>&
00265         );
00266 };
00267 
00268 
00269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00270 
00271 } // End namespace Foam
00272 
00273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00274 
00275 #include "particleI.H"
00276 
00277 #define defineParticleTypeNameAndDebug(Type, DebugSwitch)                     \
00278     template<>                                                                \
00279     const Foam::word particle<Type>::typeName(#Type);                         \
00280     template<>                                                                \
00281     int particle<Type>::debug(Foam::debug::debugSwitch(#Type, DebugSwitch));
00282 
00283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00284 
00285 #ifdef NoRepository
00286 #   include "particle.C"
00287 #endif
00288 
00289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00290 
00291 #endif
00292 
00293 // ************************************************************************* //
For further information go to www.openfoam.org