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-2021 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 Cloud_H
40 #define 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
126 
127  //- Name of cloud properties dictionary
128  static word cloudPropertiesName;
129 
130 
131  // Constructors
132 
133  //- Construct from mesh and a list of particles
134  Cloud
135  (
136  const polyMesh& mesh,
137  const word& cloudName,
138  const IDLList<ParticleType>& particles
139  );
140 
141  //- Construct from mesh by reading from file with given cloud instance
142  // Optionally disable checking of class name for post-processing
143  Cloud
144  (
145  const polyMesh& pMesh,
146  const word& cloudName,
147  const bool checkClass = true
148  );
149 
150 
151  // Member Functions
152 
153  // Access
154 
155  //- Return the polyMesh reference
156  const polyMesh& pMesh() const
157  {
158  return polyMesh_;
159  }
160 
161  //- Return the number of particles in the cloud
163 
164  //- Return the number of particles in the cloud
165  virtual label nParcels() const
166  {
168  };
169 
170  //- Return temporary addressing
171  DynamicList<label>& labels() const
172  {
173  return labels_;
174  }
175 
176 
177  // Iterators
178 
179  using typename IDLList<ParticleType>::iterator;
181 
186 
187 
188  // Edit
189 
190  //- Clear the particle list
192 
193  //- Transfer particle to cloud
194  void addParticle(ParticleType* pPtr);
195 
196  //- Remove particle from cloud and delete
197  void deleteParticle(ParticleType& p);
198 
199  //- Remove lost particles from cloud and delete
200  void deleteLostParticles();
201 
202  //- Reset the particles
203  void cloudReset(const Cloud<ParticleType>& c);
204 
205  //- Move the particles
206  template<class TrackCloudType>
207  void move
208  (
209  TrackCloudType& cloud,
210  typename ParticleType::trackingData& td,
211  const scalar trackTime
212  );
213 
214  //- Remap the cells of particles corresponding to the
215  // mesh topology change
216  void autoMap(const mapPolyMesh&);
217 
218 
219  // Read
220 
221  //- Helper to construct IOobject for field and current time.
223  (
224  const word& fieldName,
225  const IOobject::readOption r
226  ) const;
227 
228  //- Check lagrangian data field
229  template<class DataType>
230  void checkFieldIOobject
231  (
232  const Cloud<ParticleType>& c,
233  const IOField<DataType>& data
234  ) const;
235 
236  //- Check lagrangian data fieldfield
237  template<class DataType>
239  (
240  const Cloud<ParticleType>& c,
241  const CompactIOField<Field<DataType>, DataType>& data
242  ) const;
243 
244  //- Helper function to store a cloud field on its registry
245  template<class Type>
246  bool readStoreFile
247  (
248  const IOobject& io,
249  const IOobject& ioNew
250  ) const;
251 
252  //- Read from files into objectRegistry
253  void readFromFiles
254  (
255  objectRegistry& obr,
256  const wordRes& selectFields
257  ) const;
258 
259 
260  // Write
261 
262  //- Write the field data for the cloud of particles Dummy at
263  // this level.
264  virtual void writeFields() const;
265 
266  //- Write using stream options.
267  // Only writes the cloud file if the Cloud isn't empty
268  virtual bool writeObject
269  (
270  IOstreamOption streamOpt,
271  const bool valid
272  ) const;
273 
274  //- Write positions to <cloudName>_positions.obj file
275  void writePositions() const;
276 
277  //- Call this before a topology change.
278  // Stores the particles global positions in the database
279  // for use during mapping.
280  void storeGlobalPositions() const;
281 };
282 
283 
284 // Ostream Operator
285 
286 template<class ParticleType>
287 Ostream& operator<<(Ostream& os, const Cloud<ParticleType>& c);
288 
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
292 } // End namespace Foam
293 
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 
296 #ifdef NoRepository
297  #include "Cloud.C"
298 #endif
299 
300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 
302 #endif
303 
304 // ************************************************************************* //
Foam::Cloud::addParticle
void addParticle(ParticleType *pPtr)
Transfer particle to cloud.
Definition: Cloud.C:104
wordRes.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::Cloud::writeFields
virtual void writeFields() const
Write the field data for the cloud of particles Dummy at.
Definition: CloudIO.C:322
p
volScalarField & p
Definition: createFieldRefs.H:8
cloudName
const word cloudName(propsDict.get< word >("cloud"))
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::Cloud::TypeName
TypeName("Cloud")
Runtime type information.
Foam::DynamicList< label >
Foam::Cloud::readStoreFile
bool readStoreFile(const IOobject &io, const IOobject &ioNew) const
Helper function to store a cloud field on its registry.
Definition: CloudIO.C:250
Foam::Cloud::writePositions
void writePositions() const
Write positions to <cloudName>_positions.obj file.
Definition: Cloud.C:377
Foam::Cloud::checkFieldIOobject
void checkFieldIOobject(const Cloud< ParticleType > &c, const IOField< DataType > &data) const
Check lagrangian data field.
Definition: CloudIO.C:212
Foam::Cloud::nParcels
virtual label nParcels() const
Return the number of particles in the cloud.
Definition: Cloud.H:164
cloud.H
Foam::CompactIOField
A Field of objects of type <T> with automated input and output using a compact storage....
Definition: CompactIOField.H:53
Foam::Cloud::parcelType
ParticleType parcelType
Parcels are just particles.
Definition: Cloud.H:117
polyMesh.H
bitSet.H
Foam::Cloud::fieldIOobject
IOobject fieldIOobject(const word &fieldName, const IOobject::readOption r) const
Helper to construct IOobject for field and current time.
Definition: CloudIO.C:192
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::Cloud::labels
DynamicList< label > & labels() const
Return temporary addressing.
Definition: Cloud.H:170
Foam::Cloud::storeGlobalPositions
void storeGlobalPositions() const
Call this before a topology change.
Definition: Cloud.C:397
Foam::Cloud::deleteParticle
void deleteParticle(ParticleType &p)
Remove particle from cloud and delete.
Definition: Cloud.C:111
Foam::cloud::geometryType
geometryType
Cloud geometry type (internal or IO representations)
Definition: cloud.H:74
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::Cloud::autoMap
void autoMap(const mapPolyMesh &)
Remap the cells of particles corresponding to the.
Definition: Cloud.C:345
Foam::Cloud::cloudPropertiesName
static word cloudPropertiesName
Name of cloud properties dictionary.
Definition: Cloud.H:127
Foam::IOPosition
Helper IO class to read and write particle coordinates (positions).
Definition: Cloud.H:56
Foam::Cloud::deleteLostParticles
void deleteLostParticles()
Remove lost particles from cloud and delete.
Definition: Cloud.C:118
Foam::Cloud::readFromFiles
void readFromFiles(objectRegistry &obr, const wordRes &selectFields) const
Read from files into objectRegistry.
Definition: CloudIO.C:268
Foam::ILList
Template class for intrusive linked lists.
Definition: ILList.H:52
Foam::Cloud::move
void move(TrackCloudType &cloud, typename ParticleType::trackingData &td, const scalar trackTime)
Move the particles.
Definition: Cloud.C:147
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::Cloud::particleType
ParticleType particleType
Definition: Cloud.H:114
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Cloud::cloudReset
void cloudReset(const Cloud< ParticleType > &c)
Reset the particles.
Definition: Cloud.C:135
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::cloud
A cloud is a registry collection of lagrangian particles.
Definition: cloud.H:57
Foam::Cloud::geometryType_
cloud::geometryType geometryType_
Geometry type.
Definition: Cloud.H:105
Foam::Cloud::pMesh
const polyMesh & pMesh() const
Return the polyMesh reference.
Definition: Cloud.H:155
IOField.H
Foam::particle
Base particle class.
Definition: particle.H:76
Foam::Cloud
Base cloud calls templated on particle type.
Definition: Cloud.H:55
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::Cloud::Cloud
Cloud(const polyMesh &mesh, const word &cloudName, const IDLList< ParticleType > &particles)
Construct from mesh and a list of particles.
Definition: Cloud.C:73
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Cloud.C
Foam::IOobject::readOption
readOption
Enumeration defining the read options.
Definition: IOobject.H:183
CompactIOField.H
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:55
IDLList.H
Intrusive doubly-linked list.
Foam::Cloud::checkFieldFieldIOobject
void checkFieldFieldIOobject(const Cloud< ParticleType > &c, const CompactIOField< Field< DataType >, DataType > &data) const
Check lagrangian data fieldfield.
Definition: CloudIO.C:231
Foam::Cloud::writeObject
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options.
Definition: CloudIO.C:330