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-2016 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 
91  // Private Member Functions
92 
93  //- Check patches
94  void checkPatches() const;
95 
96  //- Initialise cloud on IO constructor
97  void initCloud(const bool checkClass);
98 
99  //- Find all cells which have wall faces
100  void calcCellWallFaces() const;
101 
102  //- Read cloud properties dictionary
103  void readCloudUniformProperties();
104 
105  //- Write cloud properties dictionary
106  void writeCloudUniformProperties() const;
107 
108 
109 public:
111  friend class particle;
112  template<class ParticleT>
113  friend class IOPosition;
115  typedef ParticleType particleType;
119 
120  //-Runtime type information
121  TypeName("Cloud");
122 
123 
124  // Static data
125 
126  //- Name of cloud properties dictionary
127  static word cloudPropertiesName;
128 
129 
130  // Constructors
131 
132  //- Construct from mesh and a list of particles
133  Cloud
134  (
135  const polyMesh& mesh,
136  const IDLList<ParticleType>& particles
137  );
138 
139  //- Construct from mesh, cloud name, and a list of particles
140  Cloud
141  (
142  const polyMesh& mesh,
143  const word& cloudName,
144  const IDLList<ParticleType>& particles
145  );
146 
147  //- Construct from mesh by reading from file
148  // Optionally disable checking of class name for post-processing
149  Cloud
150  (
151  const polyMesh& mesh,
152  const bool checkClass = true
153  );
154 
155 
156  //- Construct from mesh by reading from file with given cloud instance
157  // Optionally disable checking of class name for post-processing
158  Cloud
159  (
160  const polyMesh& pMesh,
161  const word& cloudName,
162  const bool checkClass = true
163  );
164 
165 
166  // Member Functions
167 
168  // Access
169 
170  //- Return the polyMesh reference
171  const polyMesh& pMesh() const
172  {
173  return polyMesh_;
174  }
176  label size() const
177  {
179  };
182  {
183  return labels_;
184  }
185 
186  //- Return nTrackingRescues
187  label nTrackingRescues() const
188  {
189  return nTrackingRescues_;
190  }
191 
192  //- Increment the nTrackingRescues counter
193  void trackingRescue() const
194  {
195  nTrackingRescues_++;
196  if (cloud::debug && size() && (nTrackingRescues_ % size() == 0))
197  {
198  Pout<< " " << nTrackingRescues_
199  << " tracking rescues " << endl;
200  }
201  }
202 
203  //- Whether each cell has any wall faces (demand driven data)
204  const PackedBoolList& cellHasWallFaces() const;
205 
206  //- Switch to specify if particles of the cloud can return
207  // non-zero wall distance values. By default, assume
208  // that they can't (default for wallImpactDistance in
209  // particle is 0.0).
210  virtual bool hasWallImpactDistance() const
211  {
212  return false;
213  }
214 
215 
216  // Iterators
218  const const_iterator begin() const
219  {
221  };
223  const const_iterator cbegin() const
224  {
226  };
228  const const_iterator end() const
229  {
231  };
233  const const_iterator cend() const
234  {
236  };
238  iterator begin()
239  {
241  };
243  iterator end()
244  {
246  };
247 
248 
249  // Edit
251  void clear()
252  {
254  };
255 
256  //- Transfer particle to cloud
257  void addParticle(ParticleType* pPtr);
258 
259  //- Remove particle from cloud and delete
260  void deleteParticle(ParticleType&);
261 
262  //- Reset the particles
263  void cloudReset(const Cloud<ParticleType>& c);
264 
265  //- Move the particles
266  // passing the TrackingData to the track function
267  template<class TrackData>
268  void move(TrackData& td, const scalar trackTime);
269 
270  //- Remap the cells of particles corresponding to the
271  // mesh topology change
272  template<class TrackData>
273  void autoMap(TrackData& td, const mapPolyMesh&);
274 
275 
276  // Read
277 
278  //- Helper to construct IOobject for field and current time.
280  (
281  const word& fieldName,
282  const IOobject::readOption r
283  ) const;
284 
285  //- Check lagrangian data field
286  template<class DataType>
287  void checkFieldIOobject
288  (
289  const Cloud<ParticleType>& c,
290  const IOField<DataType>& data
291  ) const;
292 
293  //- Check lagrangian data fieldfield
294  template<class DataType>
296  (
297  const Cloud<ParticleType>& c,
298  const CompactIOField<Field<DataType>, DataType>& data
299  ) const;
300 
301  //- Read the field data for the cloud of particles. Dummy at
302  // this level.
303  virtual void readFields();
304 
305 
306  // Write
307 
308  //- Write the field data for the cloud of particles Dummy at
309  // this level.
310  virtual void writeFields() const;
311 
312  //- Write using given format, version and compression.
313  // Only writes the cloud file if the Cloud isn't empty
314  virtual bool writeObject
315  (
319  ) const;
320 
321  //- Write positions to <cloudName>_positions.obj file
322  void writePositions() const;
323 
324 
325  // Ostream Operator
326 
327  friend Ostream& operator<< <ParticleType>
328  (
329  Ostream&,
330  const Cloud<ParticleType>&
331  );
332 };
333 
334 
335 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
336 
337 } // End namespace Foam
338 
339 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
340 
341 #ifdef NoRepository
342  #include "Cloud.C"
343 #endif
344 
345 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
346 
347 #endif
348 
349 // ************************************************************************* //
ParticleType particleType
Definition: Cloud.H:114
void cloudReset(const Cloud< ParticleType > &c)
Reset the particles.
Definition: Cloud.C:176
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
void checkFieldIOobject(const Cloud< ParticleType > &c, const IOField< DataType > &data) const
Check lagrangian data field.
Definition: CloudIO.C:215
void deleteParticle(ParticleType &)
Remove particle from cloud and delete.
Definition: Cloud.C:169
DynamicList< label > & labels()
Definition: Cloud.H:180
void checkFieldFieldIOobject(const Cloud< ParticleType > &c, const CompactIOField< Field< DataType >, DataType > &data) const
Check lagrangian data fieldfield.
Definition: CloudIO.C:234
const_iterator cbegin() const
Definition: UILList.H:268
const const_iterator & cend() const
Definition: UILList.H:273
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
const word cloudName(propsDict.lookup("cloudName"))
label nTrackingRescues() const
Return nTrackingRescues.
Definition: Cloud.H:186
label size() const
Return number of elements in list.
Definition: DLListBaseI.H:77
readOption
Enumeration defining the read options.
Definition: IOobject.H:106
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:126
const const_iterator end() const
Definition: Cloud.H:227
Base particle class.
Definition: particle.H:78
const const_iterator cend() const
Definition: Cloud.H:232
IDLList< ParticleType >::iterator iterator
Definition: Cloud.H:116
void addParticle(ParticleType *pPtr)
Transfer particle to cloud.
Definition: Cloud.C:162
dynamicFvMesh & mesh
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Write using given format, version and compression.
Definition: CloudIO.C:267
Cloud(const polyMesh &mesh, const IDLList< ParticleType > &particles)
Construct from mesh and a list of particles.
Definition: Cloud.C:97
void autoMap(TrackData &td, const mapPolyMesh &)
Remap the cells of particles corresponding to the.
Definition: Cloud.C:396
Pre-declare SubField and related Field type.
Definition: Field.H:57
A class for handling words, derived from string.
Definition: word.H:59
void clear()
Clear the contents of the list.
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
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:187
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
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53
void clear()
Definition: Cloud.H:250
const const_iterator cbegin() const
Definition: Cloud.H:222
const const_iterator begin() const
Definition: Cloud.H:217
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
label size() const
Definition: Cloud.H:175
virtual void writeFields() const
Write the field data for the cloud of particles Dummy at.
Definition: CloudIO.C:256
Intrusive doubly-linked list.
Definition: IDLList.H:47
virtual void readFields()
Read the field data for the cloud of particles. Dummy at.
Definition: CloudIO.C:251
IDLList< ParticleType >::const_iterator const_iterator
Definition: Cloud.H:117
TypeName("Cloud")
Runtime type information.
A bit-packed bool list.
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
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
IOobject fieldIOobject(const word &fieldName, const IOobject::readOption r) const
Helper to construct IOobject for field and current time.
Definition: CloudIO.C:195
virtual bool hasWallImpactDistance() const
Switch to specify if particles of the cloud can return.
Definition: Cloud.H:209
const PackedBoolList & cellHasWallFaces() const
Whether each cell has any wall faces (demand driven data)
Definition: Cloud.C:149
Helper IO class to read and write particle positions.
Definition: Cloud.H:55
void trackingRescue() const
Increment the nTrackingRescues counter.
Definition: Cloud.H:192
const polyMesh & pMesh() const
Return the polyMesh reference.
Definition: Cloud.H:170
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
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:468
Namespace for OpenFOAM.