Cloud.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::Cloud
26 
27 Description
28  Base cloud calls templated on particle type
29 
30 SourceFiles
31  Cloud.C
32  CloudIO.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef Cloud_H
37 #define Cloud_H
38 
39 #include "cloud.H"
40 #include "IDLList.H"
41 #include "IOField.H"
42 #include "CompactIOField.H"
43 #include "polyMesh.H"
44 #include "PackedBoolList.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Forward declaration of functions
52 template<class ParticleType>
53 class Cloud;
54 
55 template<class ParticleType>
56 class IOPosition;
57 
58 template<class ParticleType>
59 Ostream& operator<<
60 (
61  Ostream&,
62  const Cloud<ParticleType>&
63 );
64 
65 
66 /*---------------------------------------------------------------------------*\
67  Class Cloud Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 template<class ParticleType>
71 class Cloud
72 :
73  public cloud,
74  public IDLList<ParticleType>
75 {
76  // Private data
77 
78  const polyMesh& polyMesh_;
79 
80  //- Temporary storage for addressing. Used in findTris.
81  mutable DynamicList<label> labels_;
82 
83  //- Count of how many tracking rescue corrections have been
84  // applied
85  mutable label nTrackingRescues_;
86 
87  //- Does the cell have wall faces
88  mutable autoPtr<PackedBoolList> cellWallFacesPtr_;
89 
90  //- Temporary storage for the global particle positions
91  mutable autoPtr<vectorField> globalPositionsPtr_;
92 
93 
94  // Private Member Functions
95 
96  //- Check patches
97  void checkPatches() const;
98 
99  //- Initialise cloud on IO constructor
100  void initCloud(const bool checkClass);
101 
102  //- Find all cells which have wall faces
103  void calcCellWallFaces() const;
104 
105  //- Read cloud properties dictionary
106  void readCloudUniformProperties();
107 
108  //- Write cloud properties dictionary
109  void writeCloudUniformProperties() const;
110 
111 
112 public:
114  friend class particle;
115  template<class ParticleT>
116  friend class IOPosition;
118  typedef ParticleType particleType;
122 
123  //-Runtime type information
124  TypeName("Cloud");
125 
126 
127  // Static data
128 
129  //- Name of cloud properties dictionary
130  static word cloudPropertiesName;
131 
132 
133  // Constructors
134 
135  //- Construct from mesh and a list of particles
136  Cloud
137  (
138  const polyMesh& mesh,
139  const word& cloudName,
140  const IDLList<ParticleType>& particles
141  );
142 
143  //- Construct from mesh by reading from file with given cloud instance
144  // Optionally disable checking of class name for post-processing
145  Cloud
146  (
147  const polyMesh& pMesh,
148  const word& cloudName,
149  const bool checkClass = true
150  );
151 
152 
153  // Member Functions
154 
155  // Access
156 
157  //- Return the polyMesh reference
158  const polyMesh& pMesh() const
159  {
160  return polyMesh_;
161  }
163  label size() const
164  {
166  };
168  DynamicList<label>& labels() const
169  {
170  return labels_;
171  }
172 
173  //- Return nTrackingRescues
174  label nTrackingRescues() const
175  {
176  return nTrackingRescues_;
177  }
178 
179  //- Increment the nTrackingRescues counter
180  void trackingRescue() const
181  {
182  nTrackingRescues_++;
183  if (cloud::debug && size() && (nTrackingRescues_ % size() == 0))
184  {
185  Pout<< " " << nTrackingRescues_
186  << " tracking rescues " << endl;
187  }
188  }
189 
190  //- Whether each cell has any wall faces (demand driven data)
191  const PackedBoolList& cellHasWallFaces() const;
192 
193  //- Switch to specify if particles of the cloud can return
194  // non-zero wall distance values. By default, assume
195  // that they can't (default for wallImpactDistance in
196  // particle is 0.0).
197  bool hasWallImpactDistance() const
198  {
199  return false;
200  }
201 
202 
203  // Iterators
205  const const_iterator begin() const
206  {
208  };
210  const const_iterator cbegin() const
211  {
213  };
215  const const_iterator end() const
216  {
218  };
220  const const_iterator cend() const
221  {
223  };
225  iterator begin()
226  {
228  };
230  iterator end()
231  {
233  };
234 
235 
236  // Edit
238  void clear()
239  {
241  };
242 
243  //- Transfer particle to cloud
244  void addParticle(ParticleType* pPtr);
245 
246  //- Remove particle from cloud and delete
247  void deleteParticle(ParticleType&);
248 
249  //- Remove lost particles from cloud and delete
250  void deleteLostParticles();
251 
252  //- Reset the particles
253  void cloudReset(const Cloud<ParticleType>& c);
254 
255  //- Move the particles
256  // passing the TrackingData to the track function
257  template<class TrackData>
258  void move(TrackData& td, const scalar trackTime);
259 
260  //- Remap the cells of particles corresponding to the
261  // mesh topology change
262  void autoMap(const mapPolyMesh&);
263 
264 
265  // Read
266 
267  //- Helper to construct IOobject for field and current time.
269  (
270  const word& fieldName,
271  const IOobject::readOption r
272  ) const;
273 
274  //- Check lagrangian data field
275  template<class DataType>
276  void checkFieldIOobject
277  (
278  const Cloud<ParticleType>& c,
279  const IOField<DataType>& data
280  ) const;
281 
282  //- Check lagrangian data fieldfield
283  template<class DataType>
285  (
286  const Cloud<ParticleType>& c,
287  const CompactIOField<Field<DataType>, DataType>& data
288  ) const;
289 
290 
291  // Write
292 
293  //- Write the field data for the cloud of particles Dummy at
294  // this level.
295  virtual void writeFields() const;
296 
297  //- Write using given format, version and compression.
298  // Only writes the cloud file if the Cloud isn't empty
299  virtual bool writeObject
300  (
304  const bool valid
305  ) const;
306 
307  //- Write positions to <cloudName>_positions.obj file
308  void writePositions() const;
309 
310  //- Call this before a topology change. Stores the particles global
311  // positions in the database for use during mapping.
312  void storeGlobalPositions() const;
313 
314 
315  // Ostream Operator
316 
317  friend Ostream& operator<< <ParticleType>
318  (
319  Ostream&,
320  const Cloud<ParticleType>&
321  );
322 };
323 
324 
325 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
326 
327 } // End namespace Foam
328 
329 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 
331 #ifdef NoRepository
332  #include "Cloud.C"
333 #endif
334 
335 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
336 
337 #endif
338 
339 // ************************************************************************* //
ParticleType particleType
Definition: Cloud.H:117
Template class for intrusive linked lists.
Definition: ILList.H:50
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool valid) const
Write using given format, version and compression.
Definition: CloudIO.C:230
const const_iterator & cend() const
Definition: UILList.H:273
void cloudReset(const Cloud< ParticleType > &c)
Reset the particles.
Definition: Cloud.C:174
bool hasWallImpactDistance() const
Switch to specify if particles of the cloud can return.
Definition: Cloud.H:196
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
DynamicList< label > & labels() const
Definition: Cloud.H:167
void deleteParticle(ParticleType &)
Remove particle from cloud and delete.
Definition: Cloud.C:148
label nTrackingRescues() const
Return nTrackingRescues.
Definition: Cloud.H:173
void checkFieldFieldIOobject(const Cloud< ParticleType > &c, const CompactIOField< Field< DataType >, DataType > &data) const
Check lagrangian data fieldfield.
Definition: CloudIO.C:205
Cloud(const polyMesh &mesh, const word &cloudName, const IDLList< ParticleType > &particles)
Construct from mesh and a list of particles.
Definition: Cloud.C:97
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
label size() const
Definition: Cloud.H:162
readOption
Enumeration defining the read options.
Definition: IOobject.H:107
const const_iterator end() const
Definition: Cloud.H:214
void autoMap(const mapPolyMesh &)
Remap the cells of particles corresponding to the.
Definition: Cloud.C:399
An STL-conforming const_iterator.
Definition: UILList.H:227
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
static word cloudPropertiesName
Name of cloud properties dictionary.
Definition: Cloud.H:129
Base particle class.
Definition: particle.H:81
const const_iterator cbegin() const
Definition: Cloud.H:209
IDLList< ParticleType >::iterator iterator
Definition: Cloud.H:119
const_iterator cbegin() const
Definition: UILList.H:268
void addParticle(ParticleType *pPtr)
Transfer particle to cloud.
Definition: Cloud.C:141
dynamicFvMesh & mesh
Pre-declare SubField and related Field type.
Definition: Field.H:57
void storeGlobalPositions() const
Call this before a topology change. Stores the particles global.
Definition: Cloud.C:449
Intrusive doubly-linked list.
A class for handling words, derived from string.
Definition: word.H:59
void trackingRescue() const
Increment the nTrackingRescues counter.
Definition: Cloud.H:179
void clear()
Clear the contents of the list.
Definition: ILList.C:112
A cloud is a collection of lagrangian particles.
Definition: cloud.H:51
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
An STL-conforming iterator.
Definition: UILList.H:178
const const_iterator cend() const
Definition: Cloud.H:219
const iterator & end()
Definition: UILList.H:216
Base cloud calls templated on particle type.
Definition: Cloud.H:52
void move(TrackData &td, const scalar trackTime)
Move the particles.
Definition: Cloud.C:185
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void clear()
Definition: Cloud.H:237
const PackedBoolList & cellHasWallFaces() const
Whether each cell has any wall faces (demand driven data)
Definition: Cloud.C:128
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
const const_iterator begin() const
Definition: Cloud.H:204
void deleteLostParticles()
Remove lost particles from cloud and delete.
Definition: Cloud.C:155
virtual void writeFields() const
Write the field data for the cloud of particles Dummy at.
Definition: CloudIO.C:222
IDLList< ParticleType >::const_iterator const_iterator
Definition: Cloud.H:120
TypeName("Cloud")
Runtime type information.
A bit-packed bool list.
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
A Field of objects of type <T> with automated input and output using a compact storage. Behaves like IOField except when binary output in case it writes a CompactListList.
const dimensionedScalar c
Speed of light in a vacuum.
Version number type.
Definition: IOstream.H:96
void checkFieldIOobject(const Cloud< ParticleType > &c, const IOField< DataType > &data) const
Check lagrangian data field.
Definition: CloudIO.C:186
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
const word cloudName(propsDict.lookup("cloudName"))
Helper IO class to read and write particle positions.
Definition: Cloud.H:55
iterator begin()
Definition: UILList.H:211
const polyMesh & pMesh() const
Return the polyMesh reference.
Definition: Cloud.H:157
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
IOobject fieldIOobject(const word &fieldName, const IOobject::readOption r) const
Helper to construct IOobject for field and current time.
Definition: CloudIO.C:166
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50
void writePositions() const
Write positions to <cloudName>_positions.obj file.
Definition: Cloud.C:430
Namespace for OpenFOAM.