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-2022 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  //- Map from patch index to the neighbouring processor index
82  const labelList patchNbrProc_;
83 
84  //- Map from patch index to the corresponding patch index on the
85  // neighbouring processor
86  const labelList patchNbrProcPatch_;
87 
88  //- Map from patch index to connected non-conformal cyclics
89  const labelListList patchNonConformalCyclicPatches_;
90 
91  //- Temporary storage for the global particle positions
92  mutable autoPtr<vectorField> globalPositionsPtr_;
93 
94 
95  // Private Member Functions
96 
97  //- Check patches
98  void checkPatches() const;
99 
100  //- Initialise cloud on IO constructor
101  void initCloud(const bool checkClass);
102 
103  //- Read cloud properties dictionary
104  void readCloudUniformProperties();
105 
106  //- Write cloud properties dictionary
107  void writeCloudUniformProperties() const;
108 
109  //- Map from patch index to the neighbouring processor index
110  static labelList patchNbrProc(const polyMesh&);
111 
112  //- Map from patch index to the corresponding patch index on the
113  // neighbouring processor
114  static labelList patchNbrProcPatch(const polyMesh&);
115 
116  //- Map from patch index to connected non-conformal cyclics
118 
119  //- Store rays necessary for non conformal cyclic transfer
120  void storeRays() const;
121 
122 
123 public:
125  friend class particle;
126  template<class ParticleT>
127  friend class IOPosition;
129  typedef ParticleType particleType;
133 
134 
135  // Static data
136 
137  //- Name of cloud properties dictionary
138  static word cloudPropertiesName;
139 
140 
141  // Constructors
142 
143  //- Construct from mesh and a list of particles
144  Cloud
145  (
146  const polyMesh& mesh,
147  const word& cloudName,
148  const IDLList<ParticleType>& particles
149  );
150 
151  //- Construct from mesh by reading from file with given cloud instance
152  // Optionally disable checking of class name for post-processing
153  Cloud
154  (
155  const polyMesh& pMesh,
156  const word& cloudName,
157  const bool checkClass = true
158  );
159 
160 
161  // Member Functions
162 
163  // Access
164 
165  //- Return the polyMesh reference
166  const polyMesh& pMesh() const
167  {
168  return polyMesh_;
169  }
170 
171  //- Map from patch index to the neighbouring processor index
172  const labelList& patchNbrProc() const
173  {
174  return patchNbrProc_;
175  }
176 
177  //- Map from patch index to the corresponding patch index on the
178  // neighbouring processor
179  const labelList& patchNbrProcPatch() const
180  {
181  return patchNbrProcPatch_;
182  }
183 
184  //- Return map from patch index to connected non-conformal cyclics
186  {
187  return patchNonConformalCyclicPatches_;
188  }
189 
190  //- Return the number of particles in the cloud
191  label size() const
192  {
194  };
195 
196 
197  // Iterators
199  const const_iterator begin() const
200  {
202  };
204  const const_iterator cbegin() const
205  {
207  };
209  const const_iterator end() const
210  {
212  };
214  const const_iterator cend() const
215  {
217  };
219  iterator begin()
220  {
222  };
224  iterator end()
225  {
227  };
228 
229 
230  // Edit
232  void clear()
233  {
235  };
236 
237  //- Transfer particle to cloud
238  void addParticle(ParticleType* pPtr);
239 
240  //- Remove particle from cloud and delete
241  void deleteParticle(ParticleType&);
242 
243  //- Remove lost particles from cloud and delete
244  void deleteLostParticles();
245 
246  //- Reset the particles
247  void cloudReset(const Cloud<ParticleType>& c);
248 
249  //- Move the particles
250  template<class TrackCloudType>
251  void move
252  (
253  TrackCloudType& cloud,
254  typename ParticleType::trackingData& td,
255  const scalar trackTime
256  );
257 
258  //- Remap the cells of particles corresponding to the
259  // mesh topology change
260  void autoMap(const polyTopoChangeMap&);
261 
262 
263  // Read
264 
265  //- Helper to construct IOobject for field and current time.
267  (
268  const word& fieldName,
269  const IOobject::readOption r
270  ) const;
271 
272  //- Check lagrangian data field
273  template<class DataType>
274  void checkFieldIOobject
275  (
276  const Cloud<ParticleType>& c,
277  const IOField<DataType>& data
278  ) const;
279 
280  //- Check lagrangian data fieldfield
281  template<class DataType>
283  (
284  const Cloud<ParticleType>& c,
285  const CompactIOField<Field<DataType>, DataType>& data
286  ) const;
287 
288 
289  // Write
290 
291  //- Write the field data for the cloud of particles Dummy at
292  // this level.
293  virtual void writeFields() const;
294 
295  //- Write using given format, version and compression.
296  // Only writes the cloud file if the Cloud isn't empty
297  virtual bool writeObject
298  (
302  const bool write = true
303  ) const;
304 
305  //- Write positions to <cloudName>_positions.obj file
306  void writePositions() const;
307 
308  //- Call this before a topology change. Stores the particles global
309  // positions in the database for use during mapping.
310  void storeGlobalPositions() const;
311 
312 
313  // Ostream Operator
314 
315  friend Ostream& operator<< <ParticleType>
316  (
317  Ostream&,
318  const Cloud<ParticleType>&
319  );
320 };
321 
322 
323 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
324 
325 } // End namespace Foam
326 
327 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
328 
329 #ifdef NoRepository
330  #include "Cloud.C"
331 #endif
332 
333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334 
335 #endif
336 
337 // ************************************************************************* //
ParticleType particleType
Definition: Cloud.H:128
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:253
void deleteParticle(ParticleType &)
Remove particle from cloud and delete.
Definition: Cloud.C:227
const labelList & patchNbrProcPatch() const
Map from patch index to the corresponding patch index on the.
Definition: Cloud.H:178
const labelList & patchNbrProc() const
Map from patch index to the neighbouring processor index.
Definition: Cloud.H:171
void checkFieldFieldIOobject(const Cloud< ParticleType > &c, const CompactIOField< Field< DataType >, DataType > &data) const
Check lagrangian data fieldfield.
Definition: CloudIO.C:209
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:234
Cloud(const polyMesh &mesh, const word &cloudName, const IDLList< ParticleType > &particles)
Construct from mesh and a list of particles.
Definition: Cloud.C:188
void autoMap(const polyTopoChangeMap &)
Remap the cells of particles corresponding to the.
Definition: Cloud.C:414
label size() const
Return the number of particles in the cloud.
Definition: Cloud.H:190
fvMesh & mesh
readOption
Enumeration defining the read options.
Definition: IOobject.H:116
const const_iterator end() const
Definition: Cloud.H:208
const dimensionedScalar c
Speed of light in a vacuum.
An STL-conforming const_iterator.
Definition: UILList.H:234
static word cloudPropertiesName
Name of cloud properties dictionary.
Definition: Cloud.H:137
Base particle class.
Definition: particle.H:81
const const_iterator cbegin() const
Definition: Cloud.H:203
IDLList< ParticleType >::iterator iterator
Definition: Cloud.H:130
const_iterator cbegin() const
Definition: UILList.H:275
void addParticle(ParticleType *pPtr)
Transfer particle to cloud.
Definition: Cloud.C:220
const labelListList & patchNonConformalCyclicPatches() const
Return map from patch index to connected non-conformal cyclics.
Definition: Cloud.H:184
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:461
Intrusive doubly-linked list.
A class for handling words, derived from string.
Definition: word.H:59
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
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:213
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:231
Database for solution and other reduced data.
Definition: data.H:51
const const_iterator begin() const
Definition: Cloud.H:198
void deleteLostParticles()
Remove lost particles from cloud and delete.
Definition: Cloud.C:234
virtual void writeFields() const
Write the field data for the cloud of particles Dummy at.
Definition: CloudIO.C:226
IDLList< ParticleType >::const_iterator const_iterator
Definition: Cloud.H:131
void move(TrackCloudType &cloud, typename ParticleType::trackingData &td, const scalar trackTime)
Move the particles.
Definition: Cloud.C:265
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:190
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:76
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:165
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
IOobject fieldIOobject(const word &fieldName, const IOobject::readOption r) const
Helper to construct IOobject for field and current time.
Definition: CloudIO.C:170
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:442
Namespace for OpenFOAM.