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& 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 
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 pMesh_;
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
198 
199  const const_iterator begin() const
200  {
202  };
203 
204  const const_iterator cbegin() const
205  {
207  };
208 
209  const const_iterator end() const
210  {
212  };
213 
214  const const_iterator cend() const
215  {
217  };
218 
219  iterator begin()
220  {
222  };
223 
224  iterator end()
225  {
227  };
228 
229 
230  // Edit
231 
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  //- Change the particles' state from the end of the previous time
250  // step to the start of the next time step
251  void changeTimeStep();
252 
253  //- Move the particles
254  template<class TrackCloudType>
255  void move
256  (
257  TrackCloudType& cloud,
258  typename ParticleType::trackingData& td
259  );
260 
261 
262  // Mapping
263 
264  //- Update topology using the given map
265  virtual void topoChange(const polyTopoChangeMap&);
266 
267  //- Update from another mesh using the given map
268  virtual void mapMesh(const polyMeshMap&);
269 
270  //- Redistribute or update using the given distribution map
271  virtual void distribute(const polyDistributionMap&);
272 
273 
274  // Read
275 
276  //- Helper to construct IOobject for field and current time.
278  (
279  const word& fieldName,
280  const IOobject::readOption r
281  ) const;
282 
283  //- Check lagrangian data field
284  template<class DataType>
285  void checkFieldIOobject
286  (
287  const Cloud<ParticleType>& c,
288  const IOField<DataType>& data
289  ) const;
290 
291  //- Check lagrangian data fieldfield
292  template<class DataType>
294  (
295  const Cloud<ParticleType>& c,
297  ) const;
298 
299 
300  // Write
301 
302  //- Write the field data for the cloud of particles Dummy at
303  // this level.
304  virtual void writeFields() const;
305 
306  //- Write using given format, version and compression.
307  // Only writes the cloud file if the Cloud isn't empty
308  virtual bool writeObject
309  (
313  const bool write = true
314  ) const;
315 
316  //- Write positions to <cloudName>_positions.obj file
317  void writePositions() const;
318 
319  //- Call this before a topology change. Stores the particles global
320  // positions in the database for use during mapping.
321  void storeGlobalPositions() const;
322 
323 
324  // Ostream Operator
325 
326  friend Ostream& operator<< <ParticleType>
327  (
328  Ostream&,
329  const Cloud<ParticleType>&
330  );
331 };
332 
333 
334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 
336 } // End namespace Foam
337 
338 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
339 
340 #ifdef NoRepository
341  #include "Cloud.C"
342 #endif
343 
344 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345 
346 #endif
347 
348 // ************************************************************************* //
Intrusive doubly-linked list.
Base cloud calls templated on particle type.
Definition: Cloud.H:74
IDLList< ParticleType >::const_iterator const_iterator
Definition: Cloud.H:131
void changeTimeStep()
Change the particles' state from the end of the previous time.
Definition: Cloud.C:261
static word cloudPropertiesName
Name of cloud properties dictionary.
Definition: Cloud.H:137
void deleteParticle(ParticleType &)
Remove particle from cloud and delete.
Definition: Cloud.C:225
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:658
const labelListList & patchNonConformalCyclicPatches() const
Return map from patch index to connected non-conformal cyclics.
Definition: Cloud.H:184
const polyMesh & pMesh() const
Return the polyMesh reference.
Definition: Cloud.H:165
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
Definition: Cloud.C:419
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: Cloud.C:558
const labelList & patchNbrProcPatch() const
Map from patch index to the corresponding patch index on the.
Definition: Cloud.H:178
void deleteLostParticles()
Remove lost particles from cloud and delete.
Definition: Cloud.C:232
const const_iterator cend() const
Definition: Cloud.H:213
IDLList< ParticleType >::iterator iterator
Definition: Cloud.H:130
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:449
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:251
label size() const
Return the number of particles in the cloud.
Definition: Cloud.H:190
const const_iterator end() const
Definition: Cloud.H:208
Cloud(const polyMesh &mesh, const word &cloudName, const IDLList< ParticleType > &particles)
Construct from mesh and a list of particles.
Definition: Cloud.C:187
const labelList & patchNbrProc() const
Map from patch index to the neighbouring processor index.
Definition: Cloud.H:171
const const_iterator begin() const
Definition: Cloud.H:198
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:231
void storeGlobalPositions() const
Call this before a topology change. Stores the particles global.
Definition: Cloud.C:677
void addParticle(ParticleType *pPtr)
Transfer particle to cloud.
Definition: Cloud.C:218
void move(TrackCloudType &cloud, typename ParticleType::trackingData &td)
Move the particles.
Definition: Cloud.C:275
const const_iterator cbegin() const
Definition: Cloud.H:203
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:82
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
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
Database for solution and other reduced data.
Definition: data.H:54
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"))