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

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-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::Particle
00026 
00027 Description
00028 
00029 \*---------------------------------------------------------------------------*/
00030 
00031 #ifndef Particle_H
00032 #define Particle_H
00033 
00034 #include <OpenFOAM/vector.H>
00035 #include <OpenFOAM/IDLList.H>
00036 #include <OpenFOAM/labelList.H>
00037 #include <OpenFOAM/pointField.H>
00038 #include <OpenFOAM/faceList.H>
00039 #include <OpenFOAM/typeInfo.H>
00040 #include <OpenFOAM/OFstream.H>
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 namespace Foam
00045 {
00046 
00047 template<class Particle>
00048 class Cloud;
00049 
00050 class wedgePolyPatch;
00051 class symmetryPolyPatch;
00052 class cyclicPolyPatch;
00053 class processorPolyPatch;
00054 class wallPolyPatch;
00055 class polyPatch;
00056 
00057 // Forward declaration of friend functions and operators
00058 
00059 template<class ParticleType>
00060 class Particle;
00061 
00062 template<class ParticleType>
00063 Ostream& operator<<
00064 (
00065     Ostream&,
00066     const Particle<ParticleType>&
00067 );
00068 
00069 
00070 /*---------------------------------------------------------------------------*\
00071                            Class Particle Declaration
00072 \*---------------------------------------------------------------------------*/
00073 
00074 template<class ParticleType>
00075 class Particle
00076 :
00077     public IDLList<ParticleType>::link
00078 {
00079 
00080 public:
00081 
00082     //- Class used to pass tracking data to the trackToFace function
00083     class trackData
00084     {
00085 
00086         // Private data
00087 
00088             //- Reference to the cloud containing this particle
00089             Cloud<ParticleType>& cloud_;
00090 
00091 
00092     public:
00093 
00094         bool switchProcessor;
00095         bool keepParticle;
00096 
00097 
00098         // Constructors
00099 
00100             inline trackData(Cloud<ParticleType>& cloud);
00101 
00102 
00103         // Member functions
00104 
00105             //- Return a reference to the cloud
00106             inline Cloud<ParticleType>& cloud();
00107     };
00108 
00109 
00110 protected:
00111 
00112     // Private data
00113 
00114         //- Reference to the particle cloud
00115         const Cloud<ParticleType>& cloud_;
00116 
00117         //- Position of particle
00118         vector position_;
00119 
00120         //- Index of the cell it is in
00121         label celli_;
00122 
00123         //- Face index if the particle is on a face otherwise -1
00124         label facei_;
00125 
00126         //- Fraction of time-step completed
00127         scalar stepFraction_;
00128 
00129         //- Originating processor id
00130         label origProc_;
00131 
00132         //- Local particle id on originating processor
00133         label origId_;
00134 
00135 
00136     // Private member functions
00137 
00138         //- Return the 'lambda' value for the position, p, on the face,
00139         // where, p = from + lamda*(to - from)
00140         // for non-static meshes
00141         inline scalar lambda
00142         (
00143             const vector& from,
00144             const vector& to,
00145             const label facei,
00146             const scalar stepFraction
00147         ) const;
00148 
00149         //- Return the 'lambda' value for the position, p, on the face,
00150         // where, p = from + lamda*(to - from)
00151         // for static meshes
00152         inline scalar lambda
00153         (
00154             const vector& from,
00155             const vector& to,
00156             const label facei
00157         ) const;
00158 
00159         //- Find the faces between position and cell centre
00160         void findFaces
00161         (
00162             const vector& position,
00163             DynamicList<label>& faceList
00164         ) const;
00165 
00166         //- Find the faces between position and cell centre
00167         void findFaces
00168         (
00169             const vector& position,
00170             const label celli,
00171             const scalar stepFraction,
00172             DynamicList<label>& faceList
00173         ) const;
00174 
00175 
00176     // Patch interactions
00177 
00178         //- Overridable function to handle the particle hitting a patch
00179         //  Executed before other patch-hitting functions
00180         template<class TrackData>
00181         bool hitPatch
00182         (
00183             const polyPatch&,
00184             TrackData& td,
00185             const label patchI
00186         );
00187 
00188         //- Overridable function to handle the particle hitting a wedgePatch
00189         template<class TrackData>
00190         void hitWedgePatch
00191         (
00192             const wedgePolyPatch&,
00193             TrackData& td
00194         );
00195 
00196         //- Overridable function to handle the particle hitting a
00197         //  symmetryPatch
00198         template<class TrackData>
00199         void hitSymmetryPatch
00200         (
00201             const symmetryPolyPatch&,
00202             TrackData& td
00203         );
00204 
00205         //- Overridable function to handle the particle hitting a cyclicPatch
00206         template<class TrackData>
00207         void hitCyclicPatch
00208         (
00209             const cyclicPolyPatch&,
00210             TrackData& td
00211         );
00212 
00213         //- Overridable function to handle the particle hitting a
00214         //  processorPatch
00215         template<class TrackData>
00216         void hitProcessorPatch
00217         (
00218             const processorPolyPatch&,
00219             TrackData& td
00220         );
00221 
00222         //- Overridable function to handle the particle hitting a wallPatch
00223         template<class TrackData>
00224         void hitWallPatch
00225         (
00226             const wallPolyPatch&,
00227             TrackData& td
00228         );
00229 
00230         //- Overridable function to handle the particle hitting a
00231         //  general patch
00232         template<class TrackData>
00233         void hitPatch
00234         (
00235             const polyPatch&,
00236             TrackData& td
00237         );
00238 
00239 
00240     // Transformations
00241 
00242         //- Transform the position the particle
00243         //  according to the given transformation tensor
00244         virtual void transformPosition(const tensor& T);
00245 
00246         //- Transform the physical properties of the particle
00247         //  according to the given transformation tensor
00248         virtual void transformProperties(const tensor& T);
00249 
00250         //- Transform the physical properties of the particle
00251         //  according to the given separation vector
00252         virtual void transformProperties(const vector& separation);
00253 
00254 
00255     // Parallel transfer
00256 
00257         //- Convert global addressing to the processor patch
00258         //  local equivalents
00259         template<class TrackData>
00260         void prepareForParallelTransfer(const label patchi, TrackData& td);
00261 
00262         //- Convert processor patch addressing to the global equivalents
00263         //  and set the celli to the face-neighbour
00264         template<class TrackData>
00265         void correctAfterParallelTransfer(const label patchi, TrackData& td);
00266 
00267 
00268 public:
00269 
00270     friend class Cloud<ParticleType>;
00271 
00272 
00273     // Static data members
00274 
00275         //- Runtime type information
00276         TypeName("Particle");
00277 
00278         //- String representation of properties
00279         static string propHeader;
00280 
00281 
00282     // Constructors
00283 
00284         //- Construct from components
00285         Particle
00286         (
00287             const Cloud<ParticleType>&,
00288             const vector& position,
00289             const label celli
00290         );
00291 
00292         //- Construct from Istream
00293         Particle
00294         (
00295             const Cloud<ParticleType>&,
00296             Istream&,
00297             bool readFields = true
00298         );
00299 
00300         //- Construct as a copy
00301         Particle(const Particle& p);
00302 
00303         //- Construct a clone
00304         autoPtr<ParticleType> clone() const
00305         {
00306             return autoPtr<Particle>(new Particle(*this));
00307         }
00308 
00309 
00310         //- Factory class to read-construct particles used for
00311         //  parallel transfer
00312         class iNew
00313         {
00314             // Private data
00315 
00316                 //- Reference to the cloud
00317                 const Cloud<ParticleType>& cloud_;
00318 
00319 
00320         public:
00321 
00322             iNew(const Cloud<ParticleType>& cloud)
00323             :
00324                 cloud_(cloud)
00325             {}
00326 
00327             autoPtr<ParticleType> operator()(Istream& is) const
00328             {
00329                 return autoPtr<ParticleType>
00330                 (
00331                     new ParticleType
00332                     (
00333                         cloud_,
00334                         is,
00335                         true
00336                     )
00337                 );
00338             }
00339         };
00340 
00341 
00342     //- Destructor
00343     virtual ~Particle()
00344     {}
00345 
00346 
00347     // Member Functions
00348 
00349         // Access
00350 
00351             //- Return true if particle is in cell
00352             inline bool inCell() const;
00353 
00354             //- Return true if position is in cell i
00355             inline bool inCell
00356             (
00357                 const vector& position,
00358                 const label celli,
00359                 const scalar stepFraction
00360             ) const;
00361 
00362             //- Return current particle position
00363             inline const vector& position() const;
00364 
00365             //- Return current particle position
00366             inline vector& position();
00367 
00368             //- Return current cell particle is in
00369             inline label& cell();
00370 
00371             //- Return current cell particle is in
00372             inline label cell() const;
00373 
00374             //- Return current face particle is on otherwise -1
00375             inline label face() const;
00376 
00377             //- Return reference to the particle cloud
00378             inline const Cloud<ParticleType>& cloud() const;
00379 
00380             //- Return the impact model to be used, soft or hard (default).
00381             inline bool softImpact() const;
00382 
00383             //- Return the particle current time
00384             inline scalar currentTime() const;
00385 
00386 
00387         // Check
00388 
00389             //- Is the particle on the boundary/(or outside the domain)?
00390             inline bool onBoundary() const;
00391 
00392             //- Which patch is particle on
00393             inline label patch(const label facei) const;
00394 
00395             //- Which face of this patch is this particle on
00396             inline label patchFace
00397             (
00398                 const label patchi,
00399                 const label facei
00400             ) const;
00401 
00402             //- The nearest distance to a wall that
00403             //  the particle can be in the n direction
00404             inline scalar wallImpactDistance(const vector& n) const;
00405 
00406             //- Return the fraction of time-step completed
00407             inline scalar& stepFraction();
00408 
00409             //-  Return the fraction of time-step completed
00410             inline scalar stepFraction() const;
00411 
00412             //- Return the originating processor id
00413             inline label origProc() const;
00414 
00415             //- Return the particle id on originating processor
00416             inline label origId() const;
00417 
00418 
00419         // Track
00420 
00421             //- Track particle to end of trajectory
00422             //  or until it hits the boundary.
00423             //  On entry 'stepFraction()' should be set to the fraction of the
00424             //  time-step at which the tracking starts and on exit it contains
00425             //  the fraction of the time-step completed.
00426             //  Returns the boundary face index if the track stops at the
00427             //  boundary, -1 otherwise.
00428             template<class TrackData>
00429             label track
00430             (
00431                 const vector& endPosition,
00432                 TrackData& td
00433             );
00434 
00435             //- Calls the templated track with dummy TrackData
00436             label track(const vector& endPosition);
00437 
00438             //- Track particle to a given position and returns 1.0 if the
00439             //  trajectory is completed without hitting a face otherwise
00440             //  stops at the face and returns the fraction of the trajectory
00441             //  completed.
00442             //  on entry 'stepFraction()' should be set to the fraction of the
00443             //  time-step at which the tracking starts.
00444             template<class TrackData>
00445             scalar trackToFace
00446             (
00447                 const vector& endPosition,
00448                 TrackData& td
00449             );
00450 
00451             //- Calls the templated trackToFace with dummy TrackData
00452             scalar trackToFace(const vector& endPosition);
00453 
00454             //- Return the index of the face to be used in the interpolation
00455             //  routine
00456             inline label faceInterpolation() const;
00457 
00458 
00459     // I-O
00460 
00461         //- Read the fields associated with the owner cloud
00462         static void readFields(Cloud<ParticleType>& c);
00463 
00464         //- Write the fields associated with the owner cloud
00465         static void writeFields(const Cloud<ParticleType>& c);
00466 
00467         //- Write the particle data
00468         void write(Ostream& os, bool writeFields) const;
00469 
00470     // Ostream Operator
00471 
00472         friend Ostream& operator<< <ParticleType>
00473         (
00474             Ostream&,
00475             const Particle<ParticleType>&
00476         );
00477 };
00478 
00479 
00480 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00481 
00482 } // End namespace Foam
00483 
00484 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00485 
00486 #include <lagrangian/ParticleI.H>
00487 
00488 #define defineParticleTypeNameAndDebug(Type, DebugSwitch)                     \
00489     template<>                                                                \
00490     const Foam::word Particle<Type>::typeName(#Type);                         \
00491     template<>                                                                \
00492     int Particle<Type>::debug(Foam::debug::debugSwitch(#Type, DebugSwitch));
00493 
00494 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00495 
00496 #ifdef NoRepository
00497 #   include <lagrangian/Particle.C>
00498 #endif
00499 
00500 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00501 
00502 #endif
00503 
00504 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines