Cloud.H 7.73 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
OpenFOAM bot's avatar
OpenFOAM bot committed
6 7
     \\/     M anipulation  |
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2011-2017 OpenFOAM Foundation
9
    Copyright (C) 2017-2020 OpenCFD Ltd.
10 11 12 13
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

14 15 16 17
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
18 19 20 21 22 23 24

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    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 28 29 30

Class
    Foam::Cloud

Description
andy's avatar
andy committed
31
    Base cloud calls templated on particle type
32 33 34 35 36 37 38 39 40 41 42 43 44

SourceFiles
    Cloud.C
    CloudIO.C

\*---------------------------------------------------------------------------*/

#ifndef Cloud_H
#define Cloud_H

#include "cloud.H"
#include "IDLList.H"
#include "IOField.H"
45
#include "CompactIOField.H"
46
#include "polyMesh.H"
47
#include "bitSet.H"
48 49 50 51 52 53

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

54 55 56
// Forward Declarations
template<class ParticleType> class Cloud;
template<class ParticleType> class IOPosition;
57 58 59 60 61 62 63 64 65 66 67 68 69 70


/*---------------------------------------------------------------------------*\
                           Class Cloud Declaration
\*---------------------------------------------------------------------------*/

template<class ParticleType>
class Cloud
:
    public cloud,
    public IDLList<ParticleType>
{
    // Private data

71
        //- Reference to the mesh database
72
        const polyMesh& polyMesh_;
mattijs's avatar
mattijs committed
73

74
        //- Temporary storage for addressing. Used in findTris.
mattijs's avatar
mattijs committed
75 76
        mutable DynamicList<label> labels_;

77
        //- Does the cell have wall faces
78
        mutable autoPtr<bitSet> cellWallFacesPtr_;
79

80 81 82
        //- Temporary storage for the global particle positions
        mutable autoPtr<vectorField> globalPositionsPtr_;

83

84
    // Private Member Functions
85

86 87 88
        //- Check patches
        void checkPatches() const;

89 90 91
        //- Initialise cloud on IO constructor
        void initCloud(const bool checkClass);

92 93 94
        //- Find all cells which have wall faces
        void calcCellWallFaces() const;

95 96 97 98 99 100
        //- Read cloud properties dictionary
        void readCloudUniformProperties();

        //- Write cloud properties dictionary
        void writeCloudUniformProperties() const;

101

102 103 104
protected:

        //- Geometry type
105
        cloud::geometryType geometryType_;
106 107


108 109
public:

andy's avatar
andy committed
110
    friend class particle;
mattijs's avatar
mattijs committed
111 112
    template<class ParticleT>
    friend class IOPosition;
113 114 115

    typedef ParticleType particleType;

116 117
    //- Parcels are just particles
    typedef ParticleType parcelType;
118

119 120

    //- Runtime type information
121 122 123
    TypeName("Cloud");


124
    // Static Data
125

126 127 128
        //- Name of cloud properties dictionary
        static word cloudPropertiesName;

129

130 131 132 133 134 135 136
    // Constructors

        //- Construct from mesh and a list of particles
        Cloud
        (
            const polyMesh& mesh,
            const word& cloudName,
137
            const IDLList<ParticleType>& particles
138 139 140 141 142 143 144 145
        );

        //- Construct from mesh by reading from file with given cloud instance
        //  Optionally disable checking of class name for post-processing
        Cloud
        (
            const polyMesh& pMesh,
            const word& cloudName,
146
            const bool checkClass = true
147 148 149 150 151 152 153 154 155 156 157 158 159
        );


    // Member Functions

        // Access

            //- Return the polyMesh reference
            const polyMesh& pMesh() const
            {
                return polyMesh_;
            }

160
            //- Return the number of particles in the cloud
161 162 163 164
            using IDLList<ParticleType>::size;

            //- Return the number of particles in the cloud
            virtual label nParcels() const
165 166 167 168
            {
                return IDLList<ParticleType>::size();
            };

169
            //- Return temporary addressing
170
            DynamicList<label>& labels() const
andy's avatar
andy committed
171 172 173
            {
                return labels_;
            }
174

175

176
    // Iterators
177

178 179
        using typename IDLList<ParticleType>::iterator;
        using typename IDLList<ParticleType>::const_iterator;
180

181 182 183 184
        using IDLList<ParticleType>::begin;
        using IDLList<ParticleType>::cbegin;
        using IDLList<ParticleType>::end;
        using IDLList<ParticleType>::cend;
Andrew Heather's avatar
Andrew Heather committed
185 186 187


        // Edit
188

189 190
            //- Clear the particle list
            using IDLList<ParticleType>::clear;
191

192 193 194 195
            //- Transfer particle to cloud
            void addParticle(ParticleType* pPtr);

            //- Remove particle from cloud and delete
196
            void deleteParticle(ParticleType& p);
197

198 199 200
            //- Remove lost particles from cloud and delete
            void deleteLostParticles();

201 202 203
            //- Reset the particles
            void cloudReset(const Cloud<ParticleType>& c);

204
            //- Move the particles
205 206 207 208 209 210 211
            template<class TrackCloudType>
            void move
            (
                TrackCloudType& cloud,
                typename ParticleType::trackingData& td,
                const scalar trackTime
            );
212 213 214

            //- Remap the cells of particles corresponding to the
            //  mesh topology change
215
            void autoMap(const mapPolyMesh&);
216 217 218 219


        // Read

220 221 222 223 224 225 226 227
            //- Helper to construct IOobject for field and current time.
            IOobject fieldIOobject
            (
                const word& fieldName,
                const IOobject::readOption r
            ) const;

            //- Check lagrangian data field
228 229 230 231 232 233 234
            template<class DataType>
            void checkFieldIOobject
            (
                const Cloud<ParticleType>& c,
                const IOField<DataType>& data
            ) const;

235 236 237 238 239
            //- Check lagrangian data fieldfield
            template<class DataType>
            void checkFieldFieldIOobject
            (
                const Cloud<ParticleType>& c,
240
                const CompactIOField<Field<DataType>, DataType>& data
241 242
            ) const;

243 244 245

        // Write

mattijs's avatar
mattijs committed
246 247
            //- Write the field data for the cloud of particles Dummy at
            //  this level.
248 249
            virtual void writeFields() const;

250
            //- Write using stream options.
251 252 253
            //  Only writes the cloud file if the Cloud isn't empty
            virtual bool writeObject
            (
254
                IOstreamOption streamOpt,
255
                const bool valid
256 257
            ) const;

258
            //- Write positions to \<cloudName\>_positions.obj file
Andrew Heather's avatar
Andrew Heather committed
259 260
            void writePositions() const;

261 262 263
            //- Call this before a topology change.
            //  Stores the particles global positions in the database
            //  for use during mapping.
264
            void storeGlobalPositions() const;
265
};
266

267

268
// Ostream Operator
269

270 271
template<class ParticleType>
Ostream& operator<<(Ostream& os, const Cloud<ParticleType>& c);
272 273 274 275 276 277 278 279 280


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#ifdef NoRepository
281
    #include "Cloud.C"
282 283 284 285 286 287 288
#endif

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //