1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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
30 \*---------------------------------------------------------------------------*/
37 #include "labelList.H"
38 #include "pointField.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 template<class Particle>
52 class symmetryPolyPatch;
53 class cyclicPolyPatch;
54 class processorPolyPatch;
58 // Forward declaration of friend functions and operators
60 template<class ParticleType>
63 template<class ParticleType>
67 const Particle<ParticleType>&
71 /*---------------------------------------------------------------------------*\
72 Class Particle Declaration
73 \*---------------------------------------------------------------------------*/
75 template<class ParticleType>
78 public IDLList<ParticleType>::link
83 //- Class used to pass tracking data to the trackToFace function
89 //- Reference to the cloud containing this particle
90 Cloud<ParticleType>& cloud_;
101 inline trackData(Cloud<ParticleType>& cloud);
106 //- Return a reference to the cloud
107 inline Cloud<ParticleType>& cloud();
115 //- Reference to the particle cloud
116 const Cloud<ParticleType>& cloud_;
118 //- Position of particle
121 //- Index of the cell it is in
124 //- Face index if the particle is on a face otherwise -1
127 //- Fraction of time-step completed
128 scalar stepFraction_;
130 //- Originating processor id
133 //- Local particle id on originating processor
137 // Private member functions
139 //- Return the 'lambda' value for the position, p, on the face,
140 // where, p = from + lamda*(to - from)
141 // for non-static meshes
147 const scalar stepFraction
150 //- Return the 'lambda' value for the position, p, on the face,
151 // where, p = from + lamda*(to - from)
160 //- Find the faces between position and cell centre
163 const vector& position,
164 DynamicList<label>& faceList
167 //- Find the faces between position and cell centre
170 const vector& position,
172 const scalar stepFraction,
173 DynamicList<label>& faceList
177 // Patch interactions
179 //- Overridable function to handle the particle hitting a patch
180 // Executed before other patch-hitting functions
181 template<class TrackData>
189 //- Overridable function to handle the particle hitting a wedgePatch
190 template<class TrackData>
193 const wedgePolyPatch&,
197 //- Overridable function to handle the particle hitting a
199 template<class TrackData>
200 void hitSymmetryPatch
202 const symmetryPolyPatch&,
206 //- Overridable function to handle the particle hitting a cyclicPatch
207 template<class TrackData>
210 const cyclicPolyPatch&,
214 //- Overridable function to handle the particle hitting a
216 template<class TrackData>
217 void hitProcessorPatch
219 const processorPolyPatch&,
223 //- Overridable function to handle the particle hitting a wallPatch
224 template<class TrackData>
227 const wallPolyPatch&,
231 //- Overridable function to handle the particle hitting a
233 template<class TrackData>
243 //- Transform the position the particle
244 // according to the given transformation tensor
245 virtual void transformPosition(const tensor& T);
247 //- Transform the physical properties of the particle
248 // according to the given transformation tensor
249 virtual void transformProperties(const tensor& T);
251 //- Transform the physical properties of the particle
252 // according to the given separation vector
253 virtual void transformProperties(const vector& separation);
258 //- Convert global addressing to the processor patch
260 template<class TrackData>
261 void prepareForParallelTransfer(const label patchi, TrackData& td);
263 //- Convert processor patch addressing to the global equivalents
264 // and set the celli to the face-neighbour
265 template<class TrackData>
266 void correctAfterParallelTransfer(const label patchi, TrackData& td);
271 friend class Cloud<ParticleType>;
274 // Static data members
276 //- Runtime type information
277 TypeName("Particle");
279 //- String representation of properties
280 static string propHeader;
285 //- Construct from components
288 const Cloud<ParticleType>&,
289 const vector& position,
293 //- Construct from Istream
296 const Cloud<ParticleType>&,
298 bool readFields = true
301 //- Construct as a copy
302 Particle(const Particle& p);
304 //- Construct a clone
305 autoPtr<ParticleType> clone() const
307 return autoPtr<Particle>(new Particle(*this));
311 //- Factory class to read-construct particles used for
317 //- Reference to the cloud
318 const Cloud<ParticleType>& cloud_;
323 iNew(const Cloud<ParticleType>& cloud)
328 autoPtr<ParticleType> operator()(Istream& is) const
330 return autoPtr<ParticleType>
352 //- Return true if particle is in cell
353 inline bool inCell() const;
355 //- Return true if position is in cell i
358 const vector& position,
360 const scalar stepFraction
363 //- Return current particle position
364 inline const vector& position() const;
366 //- Return current particle position
367 inline vector& position();
369 //- Return current cell particle is in
370 inline label& cell();
372 //- Return current cell particle is in
373 inline label cell() const;
375 //- Return current face particle is on otherwise -1
376 inline label face() const;
378 //- Return reference to the particle cloud
379 inline const Cloud<ParticleType>& cloud() const;
381 //- Return the impact model to be used, soft or hard (default).
382 inline bool softImpact() const;
384 //- Return the particle current time
385 inline scalar currentTime() const;
390 //- Is the particle on the boundary/(or outside the domain)?
391 inline bool onBoundary() const;
393 //- Which patch is particle on
394 inline label patch(const label facei) const;
396 //- Which face of this patch is this particle on
397 inline label patchFace
403 //- The nearest distance to a wall that
404 // the particle can be in the n direction
405 inline scalar wallImpactDistance(const vector& n) const;
407 //- Return the fraction of time-step completed
408 inline scalar& stepFraction();
410 //- Return the fraction of time-step completed
411 inline scalar stepFraction() const;
413 //- Return the originating processor id
414 inline label origProc() const;
416 //- Return the particle id on originating processor
417 inline label origId() const;
422 //- Track particle to end of trajectory
423 // or until it hits the boundary.
424 // On entry 'stepFraction()' should be set to the fraction of the
425 // time-step at which the tracking starts and on exit it contains
426 // the fraction of the time-step completed.
427 // Returns the boundary face index if the track stops at the
428 // boundary, -1 otherwise.
429 template<class TrackData>
432 const vector& endPosition,
436 //- Calls the templated track with dummy TrackData
437 label track(const vector& endPosition);
439 //- Track particle to a given position and returns 1.0 if the
440 // trajectory is completed without hitting a face otherwise
441 // stops at the face and returns the fraction of the trajectory
443 // on entry 'stepFraction()' should be set to the fraction of the
444 // time-step at which the tracking starts.
445 template<class TrackData>
448 const vector& endPosition,
452 //- Calls the templated trackToFace with dummy TrackData
453 scalar trackToFace(const vector& endPosition);
455 //- Return the index of the face to be used in the interpolation
457 inline label faceInterpolation() const;
462 //- Read the fields associated with the owner cloud
463 static void readFields(Cloud<ParticleType>& c);
465 //- Write the fields associated with the owner cloud
466 static void writeFields(const Cloud<ParticleType>& c);
468 //- Write the particle data
469 void write(Ostream& os, bool writeFields) const;
473 friend Ostream& operator<< <ParticleType>
476 const Particle<ParticleType>&
481 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
483 } // End namespace Foam
485 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
487 #include "ParticleI.H"
489 #define defineParticleTypeNameAndDebug(Type, DebugSwitch) \
491 const Foam::word Particle<Type>::typeName(#Type); \
493 int Particle<Type>::debug(Foam::debug::debugSwitch(#Type, DebugSwitch));
495 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
498 # include "Particle.C"
501 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
505 // ************************************************************************* //