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-2024 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& pMesh_;
80 
81  //- Map from patch index to the neighbouring processor index
82  labelList patchNbrProc_;
83 
84  //- Map from patch index to the corresponding patch index on the
85  // neighbouring processor
86  labelList patchNbrProcPatch_;
87 
88  //- Map from patch index to connected non-conformal cyclics
89  labelListList patchNonConformalCyclicPatches_;
90 
91  //- Temporary storage for the global particle positions
92  mutable autoPtr<vectorField> globalPositionsPtr_;
93 
94  //- Time index
95  mutable label timeIndex_;
96 
97 
98  // Private Member Functions
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:
124 
125  friend class particle;
126  template<class ParticleT>
127  friend class IOPosition;
128 
129  typedef ParticleType particleType;
130 
134 
135 
136  // Static data
137 
138  //- Name of cloud properties dictionary
139  static word cloudPropertiesName;
140 
141 
142  // Constructors
143 
144  //- Construct from mesh and a list of particles
145  Cloud
146  (
147  const polyMesh& mesh,
148  const word& cloudName,
149  const IDLList<ParticleType>& particles
150  );
151 
152  //- Construct from mesh by reading from file with given cloud instance
153  // Optionally disable checking of class name for post-processing
154  Cloud
155  (
156  const polyMesh& pMesh,
157  const word& cloudName,
158  const bool checkClass = true
159  );
160 
161 
162  // Member Functions
163 
164  // Access
165 
166  //- Return the polyMesh reference
167  const polyMesh& pMesh() const
168  {
169  return pMesh_;
170  }
171 
172  //- Map from patch index to the neighbouring processor index
173  const labelList& patchNbrProc() const
174  {
175  return patchNbrProc_;
176  }
177 
178  //- Map from patch index to the corresponding patch index on the
179  // neighbouring processor
180  const labelList& patchNbrProcPatch() const
181  {
182  return patchNbrProcPatch_;
183  }
184 
185  //- Return map from patch index to connected non-conformal cyclics
187  {
188  return patchNonConformalCyclicPatches_;
189  }
190 
191  //- Return the number of particles in the cloud
192  label size() const
193  {
195  };
196 
197  //- Return true to cache per-cell CPU load
198  // Overridden in derived clouds, defaults to false
199  bool cpuLoad() const
200  {
201  return false;
202  }
203 
204 
205  // Iterators
206 
207  const const_iterator begin() const
208  {
210  };
211 
212  const const_iterator cbegin() const
213  {
215  };
216 
217  const const_iterator end() const
218  {
220  };
221 
222  const const_iterator cend() const
223  {
225  };
226 
227  iterator begin()
228  {
230  };
231 
232  iterator end()
233  {
235  };
236 
237 
238  // Edit
239 
240  void clear()
241  {
243  };
244 
245  //- Transfer particle to cloud
246  void addParticle(ParticleType* pPtr);
247 
248  //- Remove particle from cloud and delete
249  void deleteParticle(ParticleType&);
250 
251  //- Remove lost particles from cloud and delete
252  void deleteLostParticles();
253 
254  //- Reset the particles
255  void cloudReset(const Cloud<ParticleType>& c);
256 
257  //- Change the particles' state from the end of the previous time
258  // step to the start of the next time step
259  void changeTimeStep();
260 
261  //- Move the particles
262  template<class TrackCloudType>
263  void move
264  (
265  TrackCloudType& cloud,
266  typename ParticleType::trackingData& td
267  );
268 
269 
270  // Mapping
271 
272  //- Update topology using the given map
273  virtual void topoChange(const polyTopoChangeMap&);
274 
275  //- Update from another mesh using the given map
276  virtual void mapMesh(const polyMeshMap&);
277 
278  //- Redistribute or update using the given distribution map
279  virtual void distribute(const polyDistributionMap&);
280 
281 
282  // Read
283 
284  //- Helper to construct IOobject for field and current time.
286  (
287  const word& fieldName,
288  const IOobject::readOption r
289  ) const;
290 
291  //- Check lagrangian data field
292  template<class DataType>
293  void checkFieldIOobject
294  (
295  const Cloud<ParticleType>& c,
296  const IOField<DataType>& data
297  ) const;
298 
299  //- Check lagrangian data fieldfield
300  template<class DataType>
302  (
303  const Cloud<ParticleType>& c,
304  const CompactIOField<Field<DataType>>& data
305  ) const;
306 
307 
308  // Write
309 
310  //- Write the field data for the cloud of particles Dummy at
311  // this level.
312  virtual void writeFields() const;
313 
314  //- Write using given format, version and compression.
315  // Only writes the cloud file if the Cloud isn't empty
316  virtual bool writeObject
317  (
321  const bool write = true
322  ) const;
323 
324  //- Write positions to <cloudName>_positions.obj file
325  void writePositions() const;
326 
327  //- Call this before a topology change. Stores the particles global
328  // positions in the database for use during mapping.
329  void storeGlobalPositions() const;
330 
331 
332  // Ostream Operator
333 
334  friend Ostream& operator<< <ParticleType>
335  (
336  Ostream&,
337  const Cloud<ParticleType>&
338  );
339 };
340 
341 
342 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
343 
344 } // End namespace Foam
345 
346 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
347 
348 #ifdef NoRepository
349  #include "Cloud.C"
350 #endif
351 
352 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
353 
354 #endif
355 
356 // ************************************************************************* //
Intrusive doubly-linked list.
Base cloud calls templated on particle type.
Definition: Cloud.H:74
IDLList< ParticleType >::const_iterator const_iterator
Definition: Cloud.H:132
void changeTimeStep()
Change the particles' state from the end of the previous time.
Definition: Cloud.C:267
static word cloudPropertiesName
Name of cloud properties dictionary.
Definition: Cloud.H:138
void deleteParticle(ParticleType &)
Remove particle from cloud and delete.
Definition: Cloud.C:226
bool cpuLoad() const
Return true to cache per-cell CPU load.
Definition: Cloud.H:198
void checkFieldIOobject(const Cloud< ParticleType > &c, const IOField< DataType > &data) const
Check lagrangian data field.
Definition: CloudIO.C:188
void writePositions() const
Write positions to <cloudName>_positions.obj file.
Definition: Cloud.C:750
const labelListList & patchNonConformalCyclicPatches() const
Return map from patch index to connected non-conformal cyclics.
Definition: Cloud.H:185
const polyMesh & pMesh() const
Return the polyMesh reference.
Definition: Cloud.H:166
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
Definition: Cloud.C:457
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: Cloud.C:634
const labelList & patchNbrProcPatch() const
Map from patch index to the corresponding patch index on the.
Definition: Cloud.H:179
void deleteLostParticles()
Remove lost particles from cloud and delete.
Definition: Cloud.C:233
const const_iterator cend() const
Definition: Cloud.H:221
IDLList< ParticleType >::value_type value_type
Definition: Cloud.H:130
IDLList< ParticleType >::iterator iterator
Definition: Cloud.H:131
virtual void writeFields() const
Write the field data for the cloud of particles Dummy at.
Definition: CloudIO.C:224
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:232
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: Cloud.C:504
IOobject fieldIOobject(const word &fieldName, const IOobject::readOption r) const
Helper to construct IOobject for field and current time.
Definition: CloudIO.C:168
void cloudReset(const Cloud< ParticleType > &c)
Reset the particles.
Definition: Cloud.C:257
label size() const
Return the number of particles in the cloud.
Definition: Cloud.H:191
const const_iterator end() const
Definition: Cloud.H:216
Cloud(const polyMesh &mesh, const word &cloudName, const IDLList< ParticleType > &particles)
Construct from mesh and a list of particles.
Definition: Cloud.C:188
const labelList & patchNbrProc() const
Map from patch index to the neighbouring processor index.
Definition: Cloud.H:172
const const_iterator begin() const
Definition: Cloud.H:206
void checkFieldFieldIOobject(const Cloud< ParticleType > &c, const CompactIOField< Field< DataType >> &data) const
Check lagrangian data fieldfield.
Definition: CloudIO.C:207
void clear()
Definition: Cloud.H:239
void storeGlobalPositions() const
Call this before a topology change. Stores the particles global.
Definition: Cloud.C:769
void addParticle(ParticleType *pPtr)
Transfer particle to cloud.
Definition: Cloud.C:219
void move(TrackCloudType &cloud, typename ParticleType::trackingData &td)
Move the particles.
Definition: Cloud.C:281
const const_iterator cbegin() const
Definition: Cloud.H:211
ParticleType particleType
Definition: Cloud.H:128
A Field of objects of type <Type> with automated input and output using a compact storage....
Pre-declare SubField and related Field type.
Definition: Field.H:83
Template class for intrusive linked lists.
Definition: ILList.H:67
void clear()
Clear the contents of the list.
Definition: ILList.C:121
A primitive field of type <Type> with automated input and output.
Definition: IOField.H:53
Helper IO class to read and write particle positions.
Definition: IOPosition.H:60
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
readOption
Enumeration defining the read options.
Definition: IOobject.H:117
Version number type.
Definition: IOstream.H:97
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An STL-conforming const_iterator.
Definition: UILList.H:237
An STL-conforming iterator.
Definition: UILList.H:188
T value_type
Type of values the DLList contains.
Definition: UILList.H:166
const_iterator cbegin() const
Definition: UILList.H:275
const iterator & end()
Definition: UILList.H:223
const const_iterator & cend() const
Definition: UILList.H:280
iterator begin()
Definition: UILList.H:218
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A cloud is a collection of lagrangian particles.
Definition: cloud.H:55
Base particle class.
Definition: particle.H:83
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
virtual bool write(const bool write=true) const
Write using setting from DB.
A class for handling words, derived from string.
Definition: word.H:62
const dimensionedScalar c
Speed of light in a vacuum.
Namespace for OpenFOAM.
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
const word cloudName(propsDict.lookup("cloudName"))