Cloud.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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  //- Reference to the mesh
79  const polyMesh& polyMesh_;
80 
81  //- Temporary storage for the global particle positions
82  mutable autoPtr<vectorField> globalPositionsPtr_;
83 
84 
85  // Private Member Functions
86 
87  //- Check patches
88  void checkPatches() const;
89 
90  //- Initialise cloud on IO constructor
91  void initCloud(const bool checkClass);
92 
93  //- Read cloud properties dictionary
94  void readCloudUniformProperties();
95 
96  //- Write cloud properties dictionary
97  void writeCloudUniformProperties() const;
98 
99 
100 public:
102  friend class particle;
103  template<class ParticleT>
104  friend class IOPosition;
106  typedef ParticleType particleType;
110 
111 
112  // Static data
113 
114  //- Name of cloud properties dictionary
115  static word cloudPropertiesName;
116 
117 
118  // Constructors
119 
120  //- Construct from mesh and a list of particles
121  Cloud
122  (
123  const polyMesh& mesh,
124  const word& cloudName,
125  const IDLList<ParticleType>& particles
126  );
127 
128  //- Construct from mesh by reading from file with given cloud instance
129  // Optionally disable checking of class name for post-processing
130  Cloud
131  (
132  const polyMesh& pMesh,
133  const word& cloudName,
134  const bool checkClass = true
135  );
136 
137 
138  // Member Functions
139 
140  // Access
141 
142  //- Return the polyMesh reference
143  const polyMesh& pMesh() const
144  {
145  return polyMesh_;
146  }
147 
148  //- Return the number of particles in the cloud
149  label size() const
150  {
152  };
153 
154 
155  // Iterators
157  const const_iterator begin() const
158  {
160  };
162  const const_iterator cbegin() const
163  {
165  };
167  const const_iterator end() const
168  {
170  };
172  const const_iterator cend() const
173  {
175  };
177  iterator begin()
178  {
180  };
182  iterator end()
183  {
185  };
186 
187 
188  // Edit
190  void clear()
191  {
193  };
194 
195  //- Transfer particle to cloud
196  void addParticle(ParticleType* pPtr);
197 
198  //- Remove particle from cloud and delete
199  void deleteParticle(ParticleType&);
200 
201  //- Remove lost particles from cloud and delete
202  void deleteLostParticles();
203 
204  //- Reset the particles
205  void cloudReset(const Cloud<ParticleType>& c);
206 
207  //- Move the particles
208  template<class TrackCloudType>
209  void move
210  (
211  TrackCloudType& cloud,
212  typename ParticleType::trackingData& td,
213  const scalar trackTime
214  );
215 
216  //- Remap the cells of particles corresponding to the
217  // mesh topology change
218  void autoMap(const mapPolyMesh&);
219 
220 
221  // Read
222 
223  //- Helper to construct IOobject for field and current time.
225  (
226  const word& fieldName,
227  const IOobject::readOption r
228  ) const;
229 
230  //- Check lagrangian data field
231  template<class DataType>
232  void checkFieldIOobject
233  (
234  const Cloud<ParticleType>& c,
235  const IOField<DataType>& data
236  ) const;
237 
238  //- Check lagrangian data fieldfield
239  template<class DataType>
241  (
242  const Cloud<ParticleType>& c,
243  const CompactIOField<Field<DataType>, DataType>& data
244  ) const;
245 
246 
247  // Write
248 
249  //- Write the field data for the cloud of particles Dummy at
250  // this level.
251  virtual void writeFields() const;
252 
253  //- Write using given format, version and compression.
254  // Only writes the cloud file if the Cloud isn't empty
255  virtual bool writeObject
256  (
260  const bool write = true
261  ) const;
262 
263  //- Write positions to <cloudName>_positions.obj file
264  void writePositions() const;
265 
266  //- Call this before a topology change. Stores the particles global
267  // positions in the database for use during mapping.
268  void storeGlobalPositions() const;
269 
270 
271  // Ostream Operator
272 
273  friend Ostream& operator<< <ParticleType>
274  (
275  Ostream&,
276  const Cloud<ParticleType>&
277  );
278 };
279 
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
283 } // End namespace Foam
284 
285 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
286 
287 #ifdef NoRepository
288  #include "Cloud.C"
289 #endif
290 
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 
293 #endif
294 
295 // ************************************************************************* //
ParticleType particleType
Definition: Cloud.H:105
Template class for intrusive linked lists.
Definition: ILList.H:50
const const_iterator & cend() const
Definition: UILList.H:280
void cloudReset(const Cloud< ParticleType > &c)
Reset the particles.
Definition: Cloud.C:130
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 deleteParticle(ParticleType &)
Remove particle from cloud and delete.
Definition: Cloud.C:104
void checkFieldFieldIOobject(const Cloud< ParticleType > &c, const CompactIOField< Field< DataType >, DataType > &data) const
Check lagrangian data fieldfield.
Definition: CloudIO.C:206
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write=true) const
Write using given format, version and compression.
Definition: CloudIO.C:231
Cloud(const polyMesh &mesh, const word &cloudName, const IDLList< ParticleType > &particles)
Construct from mesh and a list of particles.
Definition: Cloud.C:68
label size() const
Return the number of particles in the cloud.
Definition: Cloud.H:148
readOption
Enumeration defining the read options.
Definition: IOobject.H:110
const const_iterator end() const
Definition: Cloud.H:166
const dimensionedScalar c
Speed of light in a vacuum.
void autoMap(const mapPolyMesh &)
Remap the cells of particles corresponding to the.
Definition: Cloud.C:341
An STL-conforming const_iterator.
Definition: UILList.H:234
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:114
Base particle class.
Definition: particle.H:83
const const_iterator cbegin() const
Definition: Cloud.H:161
IDLList< ParticleType >::iterator iterator
Definition: Cloud.H:107
const_iterator cbegin() const
Definition: UILList.H:275
void addParticle(ParticleType *pPtr)
Transfer particle to cloud.
Definition: Cloud.C:97
dynamicFvMesh & mesh
Pre-declare SubField and related Field type.
Definition: Field.H:56
void storeGlobalPositions() const
Call this before a topology change. Stores the particles global.
Definition: Cloud.C:388
Intrusive doubly-linked list.
A class for handling words, derived from string.
Definition: word.H:59
void clear()
Clear the contents of the list.
Definition: ILList.C:121
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:185
const const_iterator cend() const
Definition: Cloud.H:171
const iterator & end()
Definition: UILList.H:223
Base cloud calls templated on particle type.
Definition: Cloud.H:52
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:54
void clear()
Definition: Cloud.H:189
Database for solution and other reduced data.
Definition: data.H:51
const const_iterator begin() const
Definition: Cloud.H:156
void deleteLostParticles()
Remove lost particles from cloud and delete.
Definition: Cloud.C:111
virtual void writeFields() const
Write the field data for the cloud of particles Dummy at.
Definition: CloudIO.C:223
IDLList< ParticleType >::const_iterator const_iterator
Definition: Cloud.H:108
void move(TrackCloudType &cloud, typename ParticleType::trackingData &td, const scalar trackTime)
Move the particles.
Definition: Cloud.C:142
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.
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:187
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"))
virtual bool write(const bool write=true) const
Write using setting from DB.
Helper IO class to read and write particle positions.
Definition: Cloud.H:55
iterator begin()
Definition: UILList.H:218
const polyMesh & pMesh() const
Return the polyMesh reference.
Definition: Cloud.H:142
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:167
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:369
Namespace for OpenFOAM.