intersection with triangle plane for miss
[OpenFOAM-1.5.x.git] / src / lagrangian / basic / Particle / Particle.H
blob914f2a99df2fd86e1b7fee35a82958e05fe2b819
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::Particle
28 Description
30 \*---------------------------------------------------------------------------*/
32 #ifndef Particle_H
33 #define Particle_H
35 #include "vector.H"
36 #include "IDLList.H"
37 #include "labelList.H"
38 #include "pointField.H"
39 #include "faceList.H"
40 #include "typeInfo.H"
41 #include "OFstream.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 namespace Foam
48 template<class Particle>
49 class Cloud;
51 class wedgePolyPatch;
52 class symmetryPolyPatch;
53 class cyclicPolyPatch;
54 class processorPolyPatch;
55 class wallPolyPatch;
56 class polyPatch;
58 // Forward declaration of friend functions and operators
60 template<class ParticleType>
61 class Particle;
63 template<class ParticleType>
64 Ostream& operator<<
66     Ostream&,
67     const Particle<ParticleType>&
71 /*---------------------------------------------------------------------------*\
72                            Class Particle Declaration
73 \*---------------------------------------------------------------------------*/
75 template<class ParticleType>
76 class Particle
78     public IDLList<ParticleType>::link
81 public:
83     //- Class used to pass tracking data to the trackToFace function
84     class trackData
85     {
87         // Private data
89             //- Reference to the cloud containing this particle
90             Cloud<ParticleType>& cloud_;
93     public:
95         bool switchProcessor;
96         bool keepParticle;
99         // Constructors
101             inline trackData
102             (
103                 Cloud<ParticleType>& cloud
104             );
107         // Member functions
109             //- Return a reference to the cloud
110             inline Cloud<ParticleType>& cloud();
111     };
114 protected:
116     // Private data
118         //- Reference to the particle cloud
119         const Cloud<ParticleType>& cloud_;
121         //- Position of particle
122         vector position_;
124         //- Index of the cell it is in
125         label celli_;
127         //- Face index if the particle is on a face otherwise -1
128         label facei_;
130         //- Fraction of time-step completed
131         scalar stepFraction_;
134     // Private member functions
136         //- Return the 'lambda' value for the position, p, on the face,
137         // where, p = from + lamda*(to - from)
138         // for non-static meshes
139         inline scalar lambda
140         (
141             const vector& from,
142             const vector& to,
143             const label facei,
144             const scalar stepFraction
145         ) const;
147         //- Return the 'lambda' value for the position, p, on the face,
148         // where, p = from + lamda*(to - from)
149         // for static meshes
150         inline scalar lambda
151         (
152             const vector& from,
153             const vector& to,
154             const label facei
155         ) const;
157         //- Return the faces between position and cell centre
158         labelList findFaces
159         (
160             const vector& position
161         ) const;
163         //- Return the faces between position and cell centre
164         labelList findFaces
165         (
166             const vector& position,
167             const label celli,
168             const scalar stepFraction
169         ) const;
172     // Patch interactions
174         //- Overridable function to handle the particle hitting a wedgePatch
175         template<class TrackData>
176         void hitWedgePatch
177         (
178             const wedgePolyPatch&,
179             TrackData& td
180         );
182         //- Overridable function to handle the particle hitting a
183         //  symmetryPatch
184         template<class TrackData>
185         void hitSymmetryPatch
186         (
187             const symmetryPolyPatch&,
188             TrackData& td
189         );
191         //- Overridable function to handle the particle hitting a cyclicPatch
192         template<class TrackData>
193         void hitCyclicPatch
194         (
195             const cyclicPolyPatch&,
196             TrackData& td
197         );
199         //- Overridable function to handle the particle hitting a
200         //  processorPatch
201         template<class TrackData>
202         void hitProcessorPatch
203         (
204             const processorPolyPatch&,
205             TrackData& td
206         );
208         //- Overridable function to handle the particle hitting a wallPatch
209         template<class TrackData>
210         void hitWallPatch
211         (
212             const wallPolyPatch&,
213             TrackData& td
214         );
216         //- Overridable function to handle the particle hitting a
217         //  general patch
218         template<class TrackData>
219         void hitPatch
220         (
221             const polyPatch&,
222             TrackData& td
223         );
226     // Transformations
228         //- Transform the position the particle
229         //  according to the given transformation tensor
230         virtual void transformPosition(const tensor& T);
232         //- Transform the physical properties of the particle
233         //  according to the given transformation tensor
234         virtual void transformProperties(const tensor& T);
236         //- Transform the physical properties of the particle
237         //  according to the given separation vector
238         virtual void transformProperties(const vector& separation);
241     // Parallel transfer
243         //- Convert global addressing to the processor patch
244         //  local equivalents
245         template<class TrackData>
246         void prepareForParallelTransfer(const label patchi, TrackData& td);
248         //- Convert processor patch addressing to the global equivalents
249         //  and set the celli to the face-neighbour
250         template<class TrackData>
251         void correctAfterParallelTransfer(const label patchi, TrackData& td);
254 public:
256     friend class Cloud<ParticleType>;
259     //- Runtime type information
260     TypeName("Particle");
263     // Constructors
265         //- Construct from components
266         Particle
267         (
268             const Cloud<ParticleType>&,
269             const vector& position,
270             const label celli
271         );
273         //- Construct from Istream
274         Particle
275         (
276             const Cloud<ParticleType>&,
277             Istream&,
278             bool readFields = true
279         );
281         //- Factory class to read-construct particles used for
282         //  parallel transfer
283         class iNew
284         {
286             // Private data
288             const Cloud<ParticleType>& cloud_;
291         public:
293             iNew(const Cloud<ParticleType>& cloud)
294             :
295                 cloud_(cloud)
296             {}
298             autoPtr<ParticleType> operator()(Istream& is) const
299             {
300                 return autoPtr<ParticleType>(new ParticleType(cloud_, is));
301             }
302         };
305     //- Destructor
307         virtual ~Particle()
308         {}
311     // Member Functions
313         // Access
315             //- Return true if particle is in cell
316             inline bool inCell() const;
318             //- Return true if position is in cell i
319             inline bool inCell
320             (
321                 const vector& position,
322                 const label celli,
323                 const scalar stepFraction
324             ) const;
326             //- Return current particle position
327             inline const vector& position() const;
329             //- Return current particle position
330             inline vector& position();
332             //- Return current cell particle is in
333             inline label& cell();
335             //- Return current cell particle is in
336             inline label cell() const;
338             //- Return current face particle is on otherwise -1
339             inline label face() const;
341             //- Return reference to the particle cloud
342             inline const Cloud<ParticleType>& cloud() const;
344             //- Return the impact model to be used, soft or hard (default).
345             inline bool softImpact() const;
348         // Check
350             //- Is the particle on the boundary/(or outside the domain)?
351             inline bool onBoundary() const;
353             //- Which patch is particle on
354             inline label patch(const label facei) const;
356             //- Which face of this patch is this particle on
357             inline label patchFace
358             (
359                 const label patchi,
360                 const label facei
361             ) const;
363             //- The nearest distance to a wall that
364             //  the particle can be in the n direction
365             inline scalar wallImpactDistance(const vector& n) const;
367             //- Return the fraction of time-step completed
368             inline scalar& stepFraction();
370             //-  Return the fraction of time-step completed
371             inline scalar stepFraction() const;
374         // Track
376             //- Track particle to end of trajectory
377             //  or until it hits the boundary.
378             //  On entry 'stepFraction()' should be set to the fraction of the
379             //  time-step at which the tracking starts and on exit it contains
380             //  the fraction of the time-step completed.
381             //  Returns the boundary face index if the track stops at the
382             //  boundary, -1 otherwise.
383             template<class TrackData>
384             label track
385             (
386                 const vector& endPosition,
387                 TrackData& td
388             );
390             //- Calls the templated track with dummy TrackData
391             label track(const vector& endPosition);
393             //- Track particle to a given position and returns 1.0 if the
394             //  trajectory is completed without hitting a face otherwise
395             //  stops at the face and returns the fraction of the trajectory
396             //  completed.
397             //  on entry 'stepFraction()' should be set to the fraction of the
398             //  time-step at which the tracking starts.
399             template<class TrackData>
400             scalar trackToFace
401             (
402                 const vector& endPosition,
403                 TrackData& td
404             );
406             //- Calls the templated trackToFace with dummy TrackData
407             scalar trackToFace(const vector& endPosition);
409             //- Return the index of the face to be used in the interpolation
410             //  routine
411             inline label faceInterpolation() const;
414     // I-O
416         //- Write the fields associated with the owner cloud
417         static void writeFields
418         (
419             const Cloud<ParticleType>& c
420         );
423     // Ostream Operator
425         friend Ostream& operator<< <ParticleType>
426         (
427             Ostream&,
428             const Particle<ParticleType>&
429         );
433 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
435 } // End namespace Foam
437 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
439 #include "ParticleI.H"
441 #define defineParticleTypeNameAndDebug(Type, DebugSwitch)                     \
442     template<>                                                                \
443     const Foam::word Particle<Type>::typeName(#Type);                         \
444     template<>                                                                \
445     int Particle<Type>::debug(Foam::debug::debugSwitch(#Type, DebugSwitch));
447 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
449 #ifdef NoRepository
450 #   include "Particle.C"
451 #endif
453 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
455 #endif
457 // ************************************************************************* //