regionSplit.H 7.5 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 9
    Copyright (C) 2011-2013 OpenFOAM Foundation
    Copyright (C) 2018 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 31

Class
    Foam::regionSplit

Description
    This class separates the mesh into distinct unconnected regions,
32 33 34 35 36
    each of which is then given a label according to globalNumbering().


    Say 6 cells, 3 processors, with single baffle on proc1.

37
    \verbatim
38 39 40 41 42 43 44
              baffle
                |
    +---+---+---+---+---+---+
    |   |   |   |   |   |   |
    +---+---+---+---+---+---+
      proc0 | proc1 | proc2

45
    \endverbatim
46 47


48 49
    \verbatim

50 51 52 53 54 55 56
    1: determine local regions (uncoupled)

    +---+---+---+---+---+---+
    | 0 | 0 | 0 | 1 | 0 | 0 |
    +---+---+---+---+---+---+
      proc0 | proc1 | proc2

57
    \endverbatim
58 59 60 61


    2: make global

62 63
    \verbatim

64 65 66 67 68
    +---+---+---+---+---+---+
    | 0 | 0 | 1 | 2 | 3 | 3 |
    +---+---+---+---+---+---+
      proc0 | proc1 | proc2

69
    \endverbatim
70 71 72 73


    3: merge connected across procs

74 75
    \verbatim

76 77 78 79 80
    +---+---+---+---+---+---+
    | 0 | 0 | 0 | 2 | 2 | 2 |
    +---+---+---+---+---+---+
      proc0 | proc1 | proc2

81
    \endverbatim
82 83


84
    4. determine locally owner regions.
85

86 87 88 89 90 91 92 93 94 95
    Determine compact numbering for the local regions and send these to
    all processors that need them:

    - proc0 uses regions:
      - 0 which is local to it.
    - proc1 uses regions
      - 0 which originates from proc0
      - 2 which is local to it
    - proc2 uses regions
      - 2 which originates from proc1
96 97 98 99

    So proc1 needs to get the compact number for region 0 from proc0 and proc2
    needs to get the compact number for region 2 from proc1:

100 101
    \verbatim

102 103 104 105 106
    +---+---+---+---+---+---+
    | 0 | 0 | 0 | 1 | 1 | 1 |
    +---+---+---+---+---+---+
      proc0 | proc1 | proc2

107 108
    \endverbatim

109 110
    Can optionally keep all regions local to the processor.

111 112 113
Note
    does not walk across cyclicAMI/cyclicACMI - since these are not
    \c coupled() at the patch level.
114

115 116 117 118 119 120 121 122
SourceFiles
    regionSplit.C

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

#ifndef regionSplit_H
#define regionSplit_H

123 124 125
#include "globalIndex.H"
#include "labelPair.H"
#include "boolList.H"
mattijs's avatar
mattijs committed
126
#include "MeshObject.H"
127 128 129 130 131 132

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

namespace Foam
{

133 134
// Forward declarations

135 136
class polyMesh;

137
/*---------------------------------------------------------------------------*\
138
                         Class regionSplit Declaration
139 140 141 142
\*---------------------------------------------------------------------------*/

class regionSplit
:
143
    public MeshObject<polyMesh, TopologicalMeshObject, regionSplit>,
144 145 146 147
    public labelList
{
    // Private data

148 149 150 151 152 153 154
        autoPtr<globalIndex> globalNumberingPtr_;

        //- Temporary list of cells that have changed
        mutable DynamicList<label> changedCells_;

        //- Temporary list of faces that have changed
        mutable DynamicList<label> changedFaces_;
155 156 157 158


    // Private Member Functions

159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
        //- Update faceRegion data between (non-processor) coupled faces.
        void updateFacePair
        (
            const label face0,
            const label face1,
            labelList& faceRegion,
            DynamicList<label>& facesChanged
        ) const;

        //- Given a seed cell label, fill cellRegion/faceRegion with markValue
        //- for contiguous region around it
        void fillSeedMask
        (
            const List<labelPair>& explicitConnections,
            const label seedCellID,
            const label markValue,
            labelList& cellRegion,
            labelList& faceRegion
        ) const;


        //- Calculate the local region split.
        //  \return number of processor-local regions,
        //      without consolidation between procesors
        label calcLocalRegionSplit
184 185 186 187 188 189
        (
            const boolList& blockedFace,
            const List<labelPair>& explicitConnections,
            labelList& cellRegion
        ) const;

190 191 192 193

        //- Calculate the local region split.
        //  \return number of processor-local regions,
        //      without consolidation between procesors
194
        autoPtr<globalIndex> calcRegionSplit
195
        (
196
            const bool doGlobalRegions,
197
            const boolList& blockedFace,
mattijs's avatar
mattijs committed
198
            const List<labelPair>& explicitConnections,
199 200 201
            labelList& cellRegion
        ) const;

mattijs's avatar
mattijs committed
202

203 204 205 206 207
public:

    //- Runtime type information
    ClassName("regionSplit");

mattijs's avatar
mattijs committed
208

209 210 211
    // Constructors

        //- Construct from mesh
212 213
        regionSplit
        (
214
            const polyMesh& mesh,
215 216
            const bool doGlobalRegions = Pstream::parRun()
        );
217 218

        //- Construct from mesh and whether face is blocked
219
        //  \note blockedFace must be consistent across coupled faces!
220 221
        regionSplit
        (
222
            const polyMesh& mesh,
223 224 225
            const boolList& blockedFace,
            const bool doGlobalRegions = Pstream::parRun()
        );
226

227 228 229
        //- Construct from mesh and whether face is blocked, with additional
        //- explicit connections between normal boundary faces.
        //  \note blockedFace must be consistent across coupled faces!
mattijs's avatar
mattijs committed
230 231
        regionSplit
        (
232
            const polyMesh& mesh,
mattijs's avatar
mattijs committed
233
            const boolList& blockedFace,
234
            const List<labelPair>& explicitConnections,
235
            const bool doGlobalRegions = Pstream::parRun()
mattijs's avatar
mattijs committed
236 237
        );

mattijs's avatar
mattijs committed
238

239 240
    // Member Functions

241 242 243
        //- Return global region numbering
        const globalIndex& globalNumbering() const
        {
244
            return *globalNumberingPtr_;
245 246
        }

247 248 249 250 251 252
        //- Return local number of regions
        label nLocalRegions() const
        {
            return globalNumbering().localSize(Pstream::myProcNo());
        }

253
        //- Return total number of regions
254 255
        label nRegions() const
        {
256
            return globalNumbering().size();
257
        }
258 259 260 261 262 263 264 265 266 267 268 269 270


        //- Manually consolidate the regions globally by swapping information
        //  between processor domains and reducing the regions accordingly.
        //
        //  \return number of local regions after reduction.
        autoPtr<globalIndex> reduceRegions
        (
            const label numLocalRegions,
            const boolList& blockedFace,
            labelList& cellRegion
        ) const;

271 272 273 274 275 276 277 278 279 280 281 282
};


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

} // End namespace Foam

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

#endif

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