polyBoundaryMesh.H 9.68 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) 2018-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::polyBoundaryMesh

Description
31 32
    A polyBoundaryMesh is a polyPatch list with additional search methods
    and registered IO.
33 34 35 36 37 38 39 40 41 42 43 44

SourceFiles
    polyBoundaryMesh.C

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

#ifndef polyBoundaryMesh_H
#define polyBoundaryMesh_H

#include "polyPatchList.H"
#include "regIOobject.H"
#include "labelPair.H"
45
#include "HashSet.H"
46 47 48 49 50 51

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

namespace Foam
{

52
// Forward declarations
53
class polyMesh;
54
class wordRe;
55

56
Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
57 58 59 60 61 62 63 64 65 66 67


/*---------------------------------------------------------------------------*\
                      Class polyBoundaryMesh Declaration
\*---------------------------------------------------------------------------*/

class polyBoundaryMesh
:
    public polyPatchList,
    public regIOobject
{
68
    // Private Data
69 70 71 72

        //- Reference to mesh
        const polyMesh& mesh_;

73
        //- Demand-driven: list of patch ids per face.
mattijs's avatar
mattijs committed
74 75
        mutable autoPtr<labelList> patchIDPtr_;

76
        //- Demand-driven:
77
        mutable autoPtr<HashTable<labelList>> groupPatchIDsPtr_;
78

79
        //- Demand-driven: edges of neighbouring patches
80
        mutable autoPtr<List<labelPairList>> neighbourEdgesPtr_;
81 82 83 84


    // Private Member Functions

85
        //- Calculate geometry for the patches (transformation tensors etc.)
86 87
        void calcGeometry();

88
        //- No copy construct
89
        polyBoundaryMesh(const polyBoundaryMesh&) = delete;
90

91
        //- No copy assignment
92
        void operator=(const polyBoundaryMesh&) = delete;
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110


public:

    //- Declare friendship with polyMesh
    friend class polyMesh;


    //- Runtime type information
    TypeName("polyBoundaryMesh");


    // Constructors

        //- Read constructor given IOobject and a polyMesh reference
        //  Note point pointers are unset, only used in copying meshes
        polyBoundaryMesh
        (
111 112
            const IOobject& io,
            const polyMesh& mesh
113 114 115 116 117
        );

        //- Construct given size
        polyBoundaryMesh
        (
118 119
            const IOobject& io,
            const polyMesh& mesh,
120 121 122
            const label size
        );

123 124 125
        //- Construct given polyPatchList
        polyBoundaryMesh
        (
126 127 128
            const IOobject& io,
            const polyMesh& mesh,
            const polyPatchList& ppl
129 130
        );

131

132
    //- Destructor
133
    ~polyBoundaryMesh() = default;
134 135 136 137 138 139 140 141

        //- Clear geometry at this level and at patches
        void clearGeom();

        //- Clear addressing at this level and at patches
        void clearAddressing();


142
    // Member Functions
143 144 145 146 147 148 149

        //- Return the mesh reference
        const polyMesh& mesh() const
        {
            return mesh_;
        }

150 151 152 153 154 155 156
        //- Per patch the edges on the neighbouring patch.
        //  Is for every external edge the neighbouring patch and
        //  neighbouring (external) patch edge label. Note that edge indices
        //  are offset by nInternalEdges to keep it as much as possible
        //  consistent with coupled patch addressing (where coupling is by
        //  local patch face index). Only valid for singly connected
        //  polyBoundaryMesh and not parallel
157 158
        const List<labelPairList>& neighbourEdges() const;

159
        //- The number of patches before the first processor patch.
160 161
        label nNonProcessor() const;

162 163 164 165 166 167 168 169 170
        //- Return a list of patch names
        wordList names() const;

        //- Return a list of patch types
        wordList types() const;

        //- Return a list of physical types
        wordList physicalTypes() const;

171 172 173 174 175 176
        //- Return a list of patch start face indices
        labelList patchStarts() const;

        //- Return a list of patch sizes
        labelList patchSizes() const;

177 178 179 180 181 182 183 184 185 186
        //- The start label of the boundary faces in the polyMesh face list
        //  Same as mesh.nInternalFaces()
        label start() const;

        //- The number of boundary faces in the underlying mesh
        //  Same as mesh.nBoundaryFaces()
        label nFaces() const;

        //- The face range for all boundary faces
        //  Spans [nInternalFaces, nFaces) of the underlying mesh
187 188 189 190 191 192 193 194
        labelRange range() const;

        //- Return the range used for boundary faces on patchi.
        //  Always returns an empty range for negative values of patchi,
        //  which allows safe use with findIndex or findPatchID.
        labelRange range(const label patchi) const;


195 196 197
        //- Return patch indices for all matches.
        //  Optionally matches patchGroups
        labelList indices
198
        (
199
            const keyType& key,
200
            const bool useGroups = true
201
        ) const;
202

203

204
        //- Return patch index for the first match, return -1 if not found
205
        label findIndex(const keyType& key) const;
206

207
        //- Find patch index given a name, return -1 if not found
208 209 210 211 212
        label findPatchID
        (
            const word& patchName,
            const bool allowNotFound = true
        ) const;
213

214 215 216 217
        //- Find patch indices for a given polyPatch type
        template<class Type>
        labelHashSet findPatchIDs() const;

218 219 220
        //- Return patch index for a given face label
        label whichPatch(const label faceIndex) const;

mattijs's avatar
mattijs committed
221 222 223
        //- Per boundary face label the patch index
        const labelList& patchID() const;

224 225
        //- The patch indices per patch group
        const HashTable<labelList>& groupPatchIDs() const;
226

227
        //- Set/add group with patches
228
        void setGroup(const word& groupName, const labelUList& patchIDs);
229

230
        //- Return the set of patch IDs corresponding to the given names
231 232
        //  By default warns if given names are not found.
        //  Optionally matches to patchGroups as well as patchNames.
233 234
        labelHashSet patchSet
        (
235
            const UList<wordRe>& patchNames,
236
            const bool warnNotFound = true,
237
            const bool useGroups = true
238
        ) const;
239

240 241 242
        //- Match the patches to groups.
        //  Returns all the (fully matched) groups and any remaining
        //  unmatched patches.
243 244 245 246 247 248 249
        void matchGroups
        (
            const labelUList& patchIDs,
            wordList& groups,
            labelHashSet& nonGroupPatches
        ) const;

250 251 252 253 254 255 256 257
        //- Check whether all procs have all patches and in same order. Return
        //  true if in error.
        bool checkParallelSync(const bool report = false) const;

        //- Check boundary definition. Return true if in error.
        bool checkDefinition(const bool report = false) const;

        //- Correct polyBoundaryMesh after moving points
258
        void movePoints(const pointField& p);
259 260 261 262 263 264

        //- Correct polyBoundaryMesh after topology update
        void updateMesh();

        //- Reorders patches. Ordering does not have to be done in
        //  ascending or descending order. Reordering has to be unique.
265 266 267
        //  (is shuffle) If validBoundary calls updateMesh()
        //  after reordering to recalculate data (so call needs to be parallel
        //  sync in that case)
268
        void reorder(const labelUList& oldToNew, const bool validBoundary);
269 270

        //- writeData member function required by regIOobject
271
        virtual bool writeData(Ostream& os) const;
272

273
        //- Write using stream options
274
        virtual bool writeObject
275
        (
276
            IOstreamOption streamOpt,
277
            const bool valid
278 279
        ) const;

280

281 282 283 284 285 286
    // Member Operators

        //- Return const and non-const reference to polyPatch by index.
        using polyPatchList::operator[];

        //- Return const reference to polyPatch by name.
287
        const polyPatch& operator[](const word& patchName) const;
288 289

        //- Return reference to polyPatch by name.
290
        polyPatch& operator[](const word& patchName);
291

292 293 294

    // Ostream operator

295
        friend Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
296 297 298 299 300 301 302 303 304 305 306 307 308


    // Housekeeping

        //- Identical to the indices() method (AUG-2018)
        labelList findIndices
        (
            const keyType& key,
            const bool useGroups = true
        ) const
        {
            return this->indices(key, useGroups);
        }
309 310 311 312 313 314 315 316 317
};


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

} // End namespace Foam

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

318 319 320 321 322 323
#ifdef NoRepository
    #include "polyBoundaryMeshTemplates.C"
#endif

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

324 325 326
#endif

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