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