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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2017-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::Cloud
29 
30 Description
31  Base cloud calls templated on particle type
32 
33 SourceFiles
34  Cloud.C
35  CloudIO.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Foam_Cloud_H
40 #define Foam_Cloud_H
41 
42 #include "cloud.H"
43 #include "IDLList.H"
44 #include "IOField.H"
45 #include "CompactIOField.H"
46 #include "polyMesh.H"
47 #include "bitSet.H"
48 #include "wordRes.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward Declarations
56 template<class ParticleType> class Cloud;
57 template<class ParticleType> class IOPosition;
58 
59 
60 /*---------------------------------------------------------------------------*\
61  Class Cloud Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 template<class ParticleType>
65 class Cloud
66 :
67  public cloud,
68  public IDLList<ParticleType>
69 {
70  // Private Data
71 
72  //- Reference to the mesh database
73  const polyMesh& polyMesh_;
74 
75  //- Temporary storage for addressing. Used in findTris.
76  mutable DynamicList<label> labels_;
77 
78  //- Does the cell have wall faces
79  mutable autoPtr<bitSet> cellWallFacesPtr_;
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  //- Find all cells which have wall faces
94  void calcCellWallFaces() const;
95 
96  //- Read cloud properties dictionary
97  void readCloudUniformProperties();
98 
99  //- Write cloud properties dictionary
100  void writeCloudUniformProperties() const;
101 
102 
103 protected:
104 
105  //- Geometry type
107 
108 
109 public:
110 
111  friend class particle;
112  template<class ParticleT>
113  friend class IOPosition;
114 
115  typedef ParticleType particleType;
116 
117  //- Parcels are just particles
118  typedef ParticleType parcelType;
119 
120 
121  //- Runtime type information
122  TypeName("Cloud");
123 
124 
125  // Static Data
127  //- Name of cloud properties dictionary
129 
131  // Constructors
132 
133  //- Construct without particles
134  Cloud
135  (
136  const polyMesh& mesh,
137  const Foam::zero,
138  const word& cloudName
139  );
140 
141  //- Construct from mesh and a list of particles
142  Cloud
143  (
144  const polyMesh& mesh,
145  const word& cloudName,
146  const IDLList<ParticleType>& particles
147  );
148 
149  //- Read construct from file(s) with given cloud instance.
150  Cloud
151  (
152  const polyMesh& pMesh,
153  const word& cloudName,
155  const bool checkClass = true
156  );
157 
158 
159  // Member Functions
160 
161  // Access
162 
163  //- Return the polyMesh reference
164  const polyMesh& pMesh() const noexcept
165  {
166  return polyMesh_;
167  }
168 
169  //- Return the number of particles in the cloud
171 
172  //- Return the number of particles in the cloud
173  virtual label nParcels() const
174  {
176  };
177 
178  //- Return temporary addressing
179  DynamicList<label>& labels() const
180  {
181  return labels_;
182  }
183 
184 
185  // Iterators
186 
187  using typename IDLList<ParticleType>::iterator;
188  using typename IDLList<ParticleType>::const_iterator;
189 
194 
195 
196  // Edit
197 
198  //- Clear the particle list
200 
201  //- Transfer particle to cloud
202  void addParticle(ParticleType* pPtr);
203 
204  //- Remove particle from cloud and delete
205  void deleteParticle(ParticleType& p);
207  //- Remove lost particles from cloud and delete
208  void deleteLostParticles();
209 
210  //- Reset the particles
211  void cloudReset(const Cloud<ParticleType>& c);
212 
213  //- Move the particles
214  template<class TrackCloudType>
215  void move
216  (
217  TrackCloudType& cloud,
218  typename ParticleType::trackingData& td,
219  const scalar trackTime
220  );
221 
222  //- Remap the cells of particles corresponding to the
223  // mesh topology change
224  void autoMap(const mapPolyMesh&);
225 
226 
227  // Read
228 
229  //- Helper to construct IOobject for field and current time.
231  (
232  const word& fieldName,
234  ) const;
235 
236  //- Check lagrangian data field
237  template<class DataType>
238  void checkFieldIOobject
239  (
240  const Cloud<ParticleType>& c,
241  const IOField<DataType>& data
242  ) const;
243 
244  //- Check lagrangian data fieldfield
245  template<class DataType>
247  (
248  const Cloud<ParticleType>& c,
249  const CompactIOField<Field<DataType>, DataType>& data
250  ) const;
251 
252  //- Helper function to store a cloud field on its registry
253  template<class Type>
254  bool readStoreFile
255  (
256  const IOobject& io,
257  const IOobject& ioNew
258  ) const;
259 
260  //- Read from files into objectRegistry
261  void readFromFiles
262  (
263  objectRegistry& obr,
264  const wordRes& selectFields,
266  ) const;
267 
268 
269  // Write
270 
271  //- Write the field data for the cloud of particles Dummy at
272  // this level.
273  virtual void writeFields() const;
274 
275  //- Write using stream options.
276  // Only writes the cloud file if the Cloud isn't empty
277  virtual bool writeObject
278  (
279  IOstreamOption streamOpt,
280  const bool writeOnProc
281  ) const;
282 
283  //- Write positions to <cloudName>_positions.obj file
284  void writePositions() const;
285 
286  //- Call this before a topology change.
287  // Stores the particles global positions in the database
288  // for use during mapping.
289  void storeGlobalPositions() const;
290 };
291 
292 
293 // Ostream Operator
294 
295 template<class ParticleType>
296 Ostream& operator<<(Ostream& os, const Cloud<ParticleType>& c);
297 
298 
299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
300 
301 } // End namespace Foam
302 
303 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
304 
305 #ifdef NoRepository
306  #include "Cloud.C"
307 #endif
308 
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
310 
311 #endif
312 
313 // ************************************************************************* //
void readFromFiles(objectRegistry &obr, const wordRes &selectFields, const wordRes &excludeFields=wordRes::null()) const
Read from files into objectRegistry.
Definition: CloudIO.C:251
ParticleType particleType
Definition: Cloud.H:130
Template class for intrusive linked lists.
Definition: ILList.H:45
virtual label nParcels() const
Return the number of particles in the cloud.
Definition: Cloud.H:206
void cloudReset(const Cloud< ParticleType > &c)
Reset the particles.
Definition: Cloud.C:125
cloud::geometryType geometryType_
Geometry type.
Definition: Cloud.H:121
DynamicList< label > & labels() const
Return temporary addressing.
Definition: Cloud.H:214
geometryType
Cloud geometry type (internal or IO representations)
Definition: cloud.H:62
void checkFieldFieldIOobject(const Cloud< ParticleType > &c, const CompactIOField< Field< DataType >, DataType > &data) const
Check lagrangian data fieldfield.
Definition: CloudIO.C:214
A simple container for options an IOstream can normally have.
void autoMap(const mapPolyMesh &)
Remap the cells of particles corresponding to the.
Definition: Cloud.C:297
bool readStoreFile(const IOobject &io, const IOobject &ioNew) const
Helper function to store a cloud field on its registry.
Definition: CloudIO.C:233
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
static word cloudPropertiesName
Name of cloud properties dictionary.
Definition: Cloud.H:149
Base particle class.
Definition: particle.H:69
const polyMesh & pMesh() const noexcept
Return the polyMesh reference.
Definition: Cloud.H:193
const_iterator cbegin() const
Iterator to first item in list with const access.
Definition: UILList.H:448
wordRes excludeFields
void addParticle(ParticleType *pPtr)
Transfer particle to cloud.
Definition: Cloud.C:94
dynamicFvMesh & mesh
Generic templated field type.
Definition: Field.H:62
void storeGlobalPositions() const
Call this before a topology change.
Definition: Cloud.C:348
const word cloudName(propsDict.get< word >("cloud"))
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
Definition: CloudIO.C:314
Intrusive doubly-linked list.
A class for handling words, derived from Foam::string.
Definition: word.H:63
A cloud is a registry collection of lagrangian particles.
Definition: cloud.H:53
static const wordRes & null()
Return a null wordRes - a reference to the NullObject.
Definition: wordResI.H:23
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
Cloud(const polyMesh &mesh, const Foam::zero, const word &cloudName)
Construct without particles.
Definition: Cloud.C:57
const iterator & end()
End of list for forward iterators.
Definition: UILList.H:489
Base cloud calls templated on particle type.
Definition: Cloud.H:51
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
void deleteLostParticles()
Remove lost particles from cloud and delete.
Definition: Cloud.C:108
virtual void writeFields() const
Write the field data for the cloud of particles Dummy at.
Definition: CloudIO.C:306
TypeName("Cloud")
Runtime type information.
void move(TrackCloudType &cloud, typename ParticleType::trackingData &td, const scalar trackTime)
Move the particles.
Definition: Cloud.C:137
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.
Nothing to be read.
IOobject fieldIOobject(const word &fieldName, IOobjectOption::readOption rOpt=IOobjectOption::NO_READ) const
Helper to construct IOobject for field and current time.
Definition: CloudIO.C:175
void checkFieldIOobject(const Cloud< ParticleType > &c, const IOField< DataType > &data) const
Check lagrangian data field.
Definition: CloudIO.C:195
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
ParticleType parcelType
Parcels are just particles.
Definition: Cloud.H:135
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
void deleteParticle(ParticleType &p)
Remove particle from cloud and delete.
Definition: Cloud.C:101
volScalarField & p
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Helper IO class to read and write particle coordinates (positions).
Definition: Cloud.H:52
Registry of regIOobjects.
iterator begin()
Iterator to first item in list with non-const access.
Definition: UILList.H:440
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
A primitive field of type <T> with automated input and output.
void writePositions() const
Write positions to <cloudName>_positions.obj file.
Definition: Cloud.C:329
Namespace for OpenFOAM.
readOption
Enumeration defining read preferences.