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-2020 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 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 template<class ParticleType> class Cloud;
56 template<class ParticleType> class IOPosition;
57 
58 
59 /*---------------------------------------------------------------------------*\
60  Class Cloud Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 template<class ParticleType>
64 class Cloud
65 :
66  public cloud,
67  public IDLList<ParticleType>
68 {
69  // Private data
70 
71  //- Reference to the mesh database
72  const polyMesh& polyMesh_;
73 
74  //- Temporary storage for addressing. Used in findTris.
75  mutable DynamicList<label> labels_;
76 
77  //- Does the cell have wall faces
78  mutable autoPtr<bitSet> cellWallFacesPtr_;
79 
80  //- Temporary storage for the global particle positions
81  mutable autoPtr<vectorField> globalPositionsPtr_;
82 
83 
84  // Private Member Functions
85 
86  //- Check patches
87  void checkPatches() const;
88 
89  //- Initialise cloud on IO constructor
90  void initCloud(const bool checkClass);
91 
92  //- Find all cells which have wall faces
93  void calcCellWallFaces() const;
94 
95  //- Read cloud properties dictionary
96  void readCloudUniformProperties();
97 
98  //- Write cloud properties dictionary
99  void writeCloudUniformProperties() const;
100 
101 
102 protected:
103 
104  //- Geometry type
106 
107 
108 public:
109 
110  friend class particle;
111  template<class ParticleT>
112  friend class IOPosition;
113 
114  typedef ParticleType particleType;
115 
116  //- Parcels are just particles
117  typedef ParticleType parcelType;
118 
119 
120  //- Runtime type information
121  TypeName("Cloud");
122 
123 
124  // Static Data
125 
126  //- Name of cloud properties dictionary
127  static word cloudPropertiesName;
128 
129 
130  // Constructors
131 
132  //- Construct from mesh and a list of particles
133  Cloud
134  (
135  const polyMesh& mesh,
136  const word& cloudName,
137  const IDLList<ParticleType>& particles
138  );
139 
140  //- Construct from mesh by reading from file with given cloud instance
141  // Optionally disable checking of class name for post-processing
142  Cloud
143  (
144  const polyMesh& pMesh,
145  const word& cloudName,
146  const bool checkClass = true
147  );
148 
149 
150  // Member Functions
151 
152  // Access
153 
154  //- Return the polyMesh reference
155  const polyMesh& pMesh() const
156  {
157  return polyMesh_;
158  }
159 
160  //- Return the number of particles in the cloud
162 
163  //- Return the number of particles in the cloud
164  virtual label nParcels() const
165  {
167  };
168 
169  //- Return temporary addressing
170  DynamicList<label>& labels() const
171  {
172  return labels_;
173  }
174 
175 
176  // Iterators
177 
178  using typename IDLList<ParticleType>::iterator;
180 
185 
186 
187  // Edit
188 
189  //- Clear the particle list
191 
192  //- Transfer particle to cloud
193  void addParticle(ParticleType* pPtr);
194 
195  //- Remove particle from cloud and delete
196  void deleteParticle(ParticleType& p);
197 
198  //- Remove lost particles from cloud and delete
199  void deleteLostParticles();
200 
201  //- Reset the particles
202  void cloudReset(const Cloud<ParticleType>& c);
203 
204  //- Move the particles
205  template<class TrackCloudType>
206  void move
207  (
208  TrackCloudType& cloud,
209  typename ParticleType::trackingData& td,
210  const scalar trackTime
211  );
212 
213  //- Remap the cells of particles corresponding to the
214  // mesh topology change
215  void autoMap(const mapPolyMesh&);
216 
217 
218  // Read
219 
220  //- Helper to construct IOobject for field and current time.
222  (
223  const word& fieldName,
224  const IOobject::readOption r
225  ) const;
226 
227  //- Check lagrangian data field
228  template<class DataType>
229  void checkFieldIOobject
230  (
231  const Cloud<ParticleType>& c,
232  const IOField<DataType>& data
233  ) const;
234 
235  //- Check lagrangian data fieldfield
236  template<class DataType>
238  (
239  const Cloud<ParticleType>& c,
240  const CompactIOField<Field<DataType>, DataType>& data
241  ) const;
242 
243 
244  // Write
245 
246  //- Write the field data for the cloud of particles Dummy at
247  // this level.
248  virtual void writeFields() const;
249 
250  //- Write using stream options.
251  // Only writes the cloud file if the Cloud isn't empty
252  virtual bool writeObject
253  (
254  IOstreamOption streamOpt,
255  const bool valid
256  ) const;
257 
258  //- Write positions to <cloudName>_positions.obj file
259  void writePositions() const;
260 
261  //- Call this before a topology change.
262  // Stores the particles global positions in the database
263  // for use during mapping.
264  void storeGlobalPositions() const;
265 };
266 
267 
268 // Ostream Operator
269 
270 template<class ParticleType>
271 Ostream& operator<<(Ostream& os, const Cloud<ParticleType>& c);
272 
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 } // End namespace Foam
277 
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 
280 #ifdef NoRepository
281  #include "Cloud.C"
282 #endif
283 
284 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 
286 #endif
287 
288 // ************************************************************************* //
Foam::Cloud::addParticle
void addParticle(ParticleType *pPtr)
Transfer particle to cloud.
Definition: Cloud.C:103
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::Cloud::writeFields
virtual void writeFields() const
Write the field data for the cloud of particles Dummy at.
Definition: CloudIO.C:244
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:62
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::writePositions
void writePositions() const
Write positions to <cloudName>_positions.obj file.
Definition: Cloud.C:375
Foam::Cloud::checkFieldIOobject
void checkFieldIOobject(const Cloud< ParticleType > &c, const IOField< DataType > &data) const
Check lagrangian data field.
Definition: CloudIO.C:208
Foam::Cloud::nParcels
virtual label nParcels() const
Return the number of particles in the cloud.
Definition: Cloud.H:163
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:116
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:188
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
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:169
Foam::Cloud::storeGlobalPositions
void storeGlobalPositions() const
Call this before a topology change.
Definition: Cloud.C:395
Foam::Cloud::deleteParticle
void deleteParticle(ParticleType &p)
Remove particle from cloud and delete.
Definition: Cloud.C:110
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:344
Foam::Cloud::cloudPropertiesName
static word cloudPropertiesName
Name of cloud properties dictionary.
Definition: Cloud.H:126
Foam::IOPosition
Helper IO class to read and write particle coordinates (positions).
Definition: Cloud.H:55
Foam::Cloud::deleteLostParticles
void deleteLostParticles()
Remove lost particles from cloud and delete.
Definition: Cloud.C:117
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:146
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::Cloud::particleType
ParticleType particleType
Definition: Cloud.H:113
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Cloud::cloudReset
void cloudReset(const Cloud< ParticleType > &c)
Reset the particles.
Definition: Cloud.C:134
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:104
Foam::Cloud::pMesh
const polyMesh & pMesh() const
Return the polyMesh reference.
Definition: Cloud.H:154
IOField.H
Foam::particle
Base particle class.
Definition: particle.H:76
Foam::Cloud
Base cloud calls templated on particle type.
Definition: Cloud.H:54
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:160
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:118
CompactIOField.H
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:54
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:227
Foam::Cloud::writeObject
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options.
Definition: CloudIO.C:252