initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / lagrangian / basic / Cloud / Cloud.H
blob626042e68ac7e1a537daf4229b4fbc650964f802
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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::Cloud
28 Description
30 SourceFiles
31     Cloud.C
32     CloudIO.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef Cloud_H
37 #define Cloud_H
39 #include "cloud.H"
40 #include "IDLList.H"
41 #include "IOField.H"
42 #include "polyMesh.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 namespace Foam
49 // Forward declaration of functions
50 template<class ParticleType>
51 class Cloud;
53 template<class ParticleType>
54 class IOPosition;
56 template<class ParticleType>
57 Ostream& operator<<
59     Ostream&,
60     const Cloud<ParticleType>&
64 /*---------------------------------------------------------------------------*\
65                            Class Cloud Declaration
66 \*---------------------------------------------------------------------------*/
68 template<class ParticleType>
69 class Cloud
71     public cloud,
72     public IDLList<ParticleType>
74     // Private data
76         const polyMesh& polyMesh_;
78         //- Overall count of particles ever created. Never decreases.
79         mutable label particleCount_;
81         //- Temporary storage for addressing. Used in findFaces.
82         mutable DynamicList<label> labels_;
85     // Private member functions
87         //- Initialise cloud on IO constructor
88         void initCloud(const bool checkClass);
91 public:
93     template<class ParticleT>
94     friend class Particle;
95     template<class ParticleT>
96     friend class IOPosition;
98     typedef ParticleType particleType;
100     typedef typename IDLList<ParticleType>::iterator iterator;
101     typedef typename IDLList<ParticleType>::const_iterator const_iterator;
103     //-Runtime type information
104     TypeName("Cloud");
107     // Constructors
109         //- Construct from mesh and a list of particles
110         Cloud
111         (
112             const polyMesh& mesh,
113             const IDLList<ParticleType>& particles
114         );
116         //- Construct from mesh, cloud name, and a list of particles
117         Cloud
118         (
119             const polyMesh& mesh,
120             const word& cloudName,
121             const IDLList<ParticleType>& particles
122         );
124         //- Construct from mesh by reading from file
125         //  Optionally disable checking of class name for post-processing
126         Cloud
127         (
128             const polyMesh& mesh,
129             const bool checkClass = true
130         );
133         //- Construct from mesh by reading from file with given cloud instance
134         //  Optionally disable checking of class name for post-processing
135         Cloud
136         (
137             const polyMesh& pMesh,
138             const word& cloudName,
139             const bool checkClass = true
140         );
143     // Member Functions
145         // Access
147             //- Return the polyMesh reference
148             const polyMesh& pMesh() const
149             {
150                 return polyMesh_;
151             }
153             //- Is this global face an internal face?
154             bool internalFace(const label facei) const
155             {
156                 return polyMesh_.isInternalFace(facei);
157             }
159             //- Is this global face a boundary face?
160             bool boundaryFace(const label facei) const
161             {
162                 return !internalFace(facei);
163             }
165             //- Which patch is this global face on
166             label facePatch(const label facei) const
167             {
168                 return polyMesh_.boundaryMesh().whichPatch(facei);
169             }
171             //- Which face of this patch is this global face
172             label patchFace(const label patchi, const label facei) const
173             {
174                 return polyMesh_.boundaryMesh()[patchi].whichFace(facei);
175             }
177             label size() const
178             {
179                 return IDLList<ParticleType>::size();
180             };
183             // Iterators
185                 const const_iterator begin() const
186                 {
187                     return IDLList<ParticleType>::begin();
188                 };
190                 const const_iterator cbegin() const
191                 {
192                     return IDLList<ParticleType>::cbegin();
193                 };
195                 const const_iterator end() const
196                 {
197                     return IDLList<ParticleType>::end();
198                 };
200                 const const_iterator cend() const
201                 {
202                     return IDLList<ParticleType>::cend();
203                 };
205                 iterator begin()
206                 {
207                     return IDLList<ParticleType>::begin();
208                 };
210                 iterator end()
211                 {
212                     return IDLList<ParticleType>::end();
213                 };
216         // Edit
218             void clear()
219             {
220                 return IDLList<ParticleType>::clear();
221             };
223             //- Get unique particle creation id
224             label getNewParticleID() const;
226             //- Transfer particle to cloud
227             void addParticle(ParticleType* pPtr);
229             //- Remove particle from cloud and delete
230             void deleteParticle(ParticleType&);
232             //- Move the particles
233             //  passing the TrackingData to the track function
234             template<class TrackingData>
235             void move(TrackingData& td);
237             //- Remap the cells of particles corresponding to the
238             //  mesh topology change
239             virtual void autoMap(const mapPolyMesh&);
242         // Read
244             //- Helper to construct IOobject for field and current time.
245             IOobject fieldIOobject
246             (
247                 const word& fieldName,
248                 const IOobject::readOption r
249             ) const;
251             //- Check lagrangian data field
252             template<class DataType>
253             void checkFieldIOobject
254             (
255                 const Cloud<ParticleType>& c,
256                 const IOField<DataType>& data
257             ) const;
259             //- Read the field data for the cloud of particles. Dummy at
260             //  this level.
261             virtual void readFields();
264         // Write
266             //- Write the field data for the cloud of particles Dummy at
267             //  this level.
268             virtual void writeFields() const;
270             //- Write using given format, version and compression.
271             //  Only writes the cloud file if the Cloud isn't empty
272             virtual bool writeObject
273             (
274                 IOstream::streamFormat fmt,
275                 IOstream::versionNumber ver,
276                 IOstream::compressionType cmp
277             ) const;
279             //- Write positions to <cloudName>_positions.obj file
280             void writePositions() const;
283     // Ostream Operator
285         friend Ostream& operator<< <ParticleType>
286         (
287             Ostream&,
288             const Cloud<ParticleType>&
289         );
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 } // End namespace Foam
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299 #ifdef NoRepository
300 #   include "Cloud.C"
301 #endif
303 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
305 #endif
307 // ************************************************************************* //