OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

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-2007 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 class wedgePolyPatch;
00052 class symmetryPolyPatch;
00053 class cyclicPolyPatch;
00054 class processorPolyPatch;
00055 class wallPolyPatch;
00056 class polyPatch;
00057 
00058 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
00059 
00060 template<class particleType>
00061 class particle;
00062 
00063 template<class particleType>
00064 Ostream& operator<<
00065 (
00066     Ostream&,
00067     const particle<particleType>&
00068 );
00069 
00070 
00071 /*---------------------------------------------------------------------------*\
00072                            Class particle Declaration
00073 \*---------------------------------------------------------------------------*/
00074 
00075 template<class particleType>
00076 class particle
00077 :
00078     public IDLList<particleType>::link
00079 {
00080     // Private data
00081 
00082         //- Reference to the particle cloud
00083         const Cloud<particleType>& cloud_;
00084 
00085         //- Position of particle
00086         vector position_;
00087 
00088         //- Index of the cell it is in
00089         label celli_;
00090 
00091         //- Face index if the particle is on a face otherwise -1
00092         label facei_;
00093 
00094         //- Fraction of time-step completed
00095         scalar stepFraction_;
00096 
00097 
00098     // Private member functions
00099 
00100         //- Return the 'lambda' value for the position, p, on the face,
00101         // where, p = from + lamda*(to - from)
00102         // for non-static meshes
00103         inline scalar lambda
00104         (
00105             const vector& from,
00106             const vector& to,
00107             const label facei,
00108             const scalar stepFraction
00109         );
00110 
00111         //- Return the 'lambda' value for the position, p, on the face,
00112         // where, p = from + lamda*(to - from) 
00113         // for static meshes
00114         inline scalar lambda
00115         (
00116             const vector& from,
00117             const vector& to,
00118             const label facei
00119         );
00120 
00121         //- Return the faces between position and cell centre
00122         labelList findFaces
00123         (
00124             const vector& position
00125         );
00126 
00127         //- Return the faces between position and cell centre
00128         labelList findFaces
00129         (
00130             const vector& position,
00131             const label celli,
00132             const scalar stepFraction
00133         );
00134 
00135 
00136 protected:
00137 
00138         //- Overridable function to handle the particle hitting a wedgePatch
00139         template<class TrackingData>
00140         void hitWedgePatch
00141         (
00142             const wedgePolyPatch&,
00143             TrackingData& td
00144         );
00145 
00146         //- Overridable function to handle the particle hitting a symmetryPatch
00147         template<class TrackingData>
00148         void hitSymmetryPatch
00149         (
00150             const symmetryPolyPatch&,
00151             TrackingData& td
00152         );
00153 
00154         //- Overridable function to handle the particle hitting a cyclicPatch
00155         template<class TrackingData>
00156         void hitCyclicPatch
00157         (
00158             const cyclicPolyPatch&,
00159             TrackingData& td
00160         );
00161 
00162         //- Overridable function to handle the particle hitting a processorPatch
00163         template<class TrackingData>
00164         void hitProcessorPatch
00165         (
00166             const processorPolyPatch&,
00167             TrackingData& td
00168         );
00169 
00170         //- Overridable function to handle the particle hitting a wallPatch
00171         template<class TrackingData>
00172         void hitWallPatch
00173         (
00174             const wallPolyPatch&,
00175             TrackingData& td
00176         );
00177 
00178         //- Overridable function to handle the particle hitting a general patch
00179         template<class TrackingData>
00180         void hitPatch
00181         (
00182             const polyPatch&,
00183             TrackingData& td
00184         );
00185 
00186         //- Transform the position the particle
00187         //  according to the given transformation tensor
00188         void transformPosition(const tensor& T);
00189 
00190         //- Transform the physical properties of the particle
00191         //  according to the given transformation tensor
00192         void transformProperties(const tensor& T);
00193 
00194         //- Transform the physical properties of the particle
00195         //  according to the given separation vector
00196         void transformProperties(const vector& separation);
00197 
00198         //- Convert global addressing to the processor patch
00199         //  local equivalents
00200         template<class TrackingData>
00201         void prepareForParallelTransfer(const label patchi, TrackingData& td);
00202 
00203         //- Convert processor patch addressing to the global equivalents
00204         //  and set the celli to the face-neighbour
00205         template<class TrackingData>
00206         void correctAfterParallelTransfer(const label patchi, TrackingData& td);
00207 
00208 
00209 public:
00210 
00211     friend class Cloud<particleType>;
00212 
00213 
00214     //- Runtime type information
00215     TypeName("particle");
00216 
00217 
00218     // Constructors
00219 
00220         //- Construct from components
00221         particle
00222         (
00223             const Cloud<particleType>&,
00224             const vector& position,
00225             const label celli
00226         );
00227 
00228         //- Construct from Istream
00229         particle
00230         (
00231             const Cloud<particleType>&,
00232             Istream&,
00233             bool readFields = true
00234         );
00235 
00236         //- Factory class to read-construct particles used for parallel transfer
00237         class iNew
00238         {
00239             const Cloud<particleType>& cloud_;
00240 
00241         public:
00242 
00243             iNew(const Cloud<particleType>& cloud)
00244             :
00245                 cloud_(cloud)
00246             {}
00247 
00248             autoPtr<particleType> operator()(Istream& is) const
00249             {
00250                 return autoPtr<particleType>(new particleType(cloud_, is));
00251             }
00252         };
00253 
00254 
00255     // Destructor
00256 
00257         virtual ~particle()
00258         {}
00259 
00260 
00261     // Member Functions
00262 
00263         // Access
00264 
00265             //- Return true if particle is in cell
00266             inline bool inCell();
00267 
00268             //- Return true if position is in cell i
00269             inline bool inCell
00270             (
00271                 const vector& position,
00272                 const label celli,
00273                 const scalar stepFraction
00274             );
00275 
00276             //- Return current particle position
00277             inline const vector& position() const;
00278 
00279             //- Return current cell particle is in
00280             inline label cell() const;
00281 
00282             //- Return current face particle is on otherwise -1
00283             inline label face() const;
00284 
00285             //- Return reference to the particle cloud
00286             inline const Cloud<particleType>& cloud() const;
00287 
00288             //- Return the impact model to be used, soft or hard (default).
00289             inline bool softImpact() const;
00290 
00291 
00292         // Check
00293 
00294             //- Is the particle on the boundary/( or outside the domain)?
00295             inline bool onBoundary() const;
00296 
00297             //- Which patch is particle on
00298             inline label patch(const label facei) const;
00299 
00300             //- Which face of this patch is this particle on
00301             inline label patchFace(const label patchi, const label facei) const;
00302     
00303             //- The nearest distance to a wall that 
00304             //  the particle can be in the n direction
00305             inline scalar wallImpactDistance(const vector& n) const;
00306 
00307             //- Return the fraction of time-step completed
00308             inline scalar& stepFraction();
00309 
00310             //-  Return the fraction of time-step completed
00311             inline scalar stepFraction() const;
00312 
00313 
00314         // Track
00315 
00316             //- Track particle to end of trajectory
00317             //  or until it hits the boundary.
00318             //  On entry 'stepFraction()' should be set to the fraction of the
00319             //  time-step at which the tracking starts and on exit it contains
00320             //  the fraction of the time-step completed.
00321             //  Returns the boundary face index if the track stops at the
00322             //  boundary, -1 otherwise.
00323             template<class TrackingData>
00324             label track
00325             (
00326                 const vector& endPosition,
00327                 TrackingData& td
00328             );
00329 
00330             //- Calls the templated track with dummy TrackingData
00331             label track(const vector& endPosition);
00332 
00333             //- Track particle to a given position and returns 1.0 if the 
00334             //  trajectory is completed without hitting a face otherwise
00335             //  stops at the face and returns the fraction of the trajectory
00336             //  completed.
00337             //  on entry 'stepFraction()' should be set to the fraction of the
00338             //  time-step at which the tracking starts.
00339             template<class TrackingData>
00340             scalar trackToFace
00341             (
00342                 const vector& endPosition,
00343                 TrackingData& td
00344             );
00345 
00346             //- calls the templated trackToFace with dummy TrackingData
00347             scalar trackToFace(const vector& endPosition);
00348 
00349 
00350     // Ostream Operator
00351 
00352         friend Ostream& operator<< <particleType>
00353         (
00354             Ostream&,
00355             const particle<particleType>&
00356         );
00357 };
00358 
00359 
00360 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00361 
00362 } // End namespace Foam
00363 
00364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00365 
00366 #include "particleI.H"
00367 
00368 #define defineParticleTypeNameAndDebug(Type, DebugSwitch)                     \
00369     template<>                                                                \
00370     const Foam::word particle<Type>::typeName(#Type);                         \
00371     template<>                                                                \
00372     int particle<Type>::debug(Foam::debug::debugSwitch(#Type, DebugSwitch));
00373 
00374 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00375 
00376 #ifdef NoRepository
00377 #   include "particle.C"
00378 #endif
00379 
00380 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00381 
00382 #endif
00383 
00384 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd