Loading...
Searching...
No Matches
regionSplit.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-2013 OpenFOAM Foundation
9 Copyright (C) 2018-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::regionSplit
29
30Description
31 This class separates the mesh into distinct unconnected regions,
32 each of which is then given a label according to globalNumbering().
33
34
35 Say 6 cells, 3 processors, with single baffle on proc1.
36
37 \verbatim
38 baffle
39 |
40 +---+---+---+---+---+---+
41 | | | | | | |
42 +---+---+---+---+---+---+
43 proc0 | proc1 | proc2
44
45 \endverbatim
46
47
48 \verbatim
49
50 1: determine local regions (uncoupled)
51
52 +---+---+---+---+---+---+
53 | 0 | 0 | 0 | 1 | 0 | 0 |
54 +---+---+---+---+---+---+
55 proc0 | proc1 | proc2
56
57 \endverbatim
58
59
60 2: make global
61
62 \verbatim
63
64 +---+---+---+---+---+---+
65 | 0 | 0 | 1 | 2 | 3 | 3 |
66 +---+---+---+---+---+---+
67 proc0 | proc1 | proc2
68
69 \endverbatim
70
71
72 3: merge connected across procs
73
74 \verbatim
75
76 +---+---+---+---+---+---+
77 | 0 | 0 | 0 | 2 | 2 | 2 |
78 +---+---+---+---+---+---+
79 proc0 | proc1 | proc2
80
81 \endverbatim
82
83
84 4. determine locally owner regions.
85
86 Determine compact numbering for the local regions and send these to
87 all processors that need them:
88
89 - proc0 uses regions:
90 - 0 which is local to it.
91 - proc1 uses regions
92 - 0 which originates from proc0
93 - 2 which is local to it
94 - proc2 uses regions
95 - 2 which originates from proc1
96
97 So proc1 needs to get the compact number for region 0 from proc0 and proc2
98 needs to get the compact number for region 2 from proc1:
99
100 \verbatim
101
102 +---+---+---+---+---+---+
103 | 0 | 0 | 0 | 1 | 1 | 1 |
104 +---+---+---+---+---+---+
105 proc0 | proc1 | proc2
106
107 \endverbatim
108
109 Can optionally keep all regions local to the processor.
110
111Note
112 does not walk across cyclicAMI/cyclicACMI - since these are not
113 \c coupled() at the patch level.
114
115SourceFiles
116 regionSplit.C
117
118\*---------------------------------------------------------------------------*/
119
120#ifndef regionSplit_H
121#define regionSplit_H
122
123#include "globalIndex.H"
124#include "labelPair.H"
125#include "bitSet.H"
126#include "boolList.H"
127#include "MeshObject.H"
128
129// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
130
131namespace Foam
132{
133
134// Forward Declarations
135class polyMesh;
137/*---------------------------------------------------------------------------*\
138 Class regionSplit Declaration
139\*---------------------------------------------------------------------------*/
140
141class regionSplit
142:
143 public MeshObject<polyMesh, TopologicalMeshObject, regionSplit>,
144 public labelList
145{
146 // Private Typedefs
147
148 typedef MeshObject
149 <
150 polyMesh,
153 > MeshObject_type;
154
155
156 // Private Data
157
158 //- Indexing into the regions
159 globalIndex globalNumbering_;
160
161 //- Temporary list of cells that have changed
162 mutable DynamicList<label> changedCells_;
163
164 //- Temporary list of faces that have changed
165 mutable DynamicList<label> changedFaces_;
166
167
168 // Private Class
169
170 //- Simple wrapper for handling test() on bitSet or boolList
171 //- without a templating layer or lambda expresssion.
172 class bitSetOrBoolList
173 {
174 const bitSet& a_;
175 const boolList& b_;
176
177 public:
178
179 explicit bitSetOrBoolList(const bitSet& select)
180 :
181 a_(select),
182 b_(boolList::null())
183 {}
184
185 explicit bitSetOrBoolList(const boolList& select)
186 :
187 a_(bitSet::null()),
188 b_(select)
189 {}
190
191 //- Test function
192 bool test(const label i) const
193 {
194 return a_.test(i) || b_.test(i);
195 }
196 };
197
198
199 // Private Member Functions
200
201 //- Check that boundary faces are synchronised, or Fatal
202 void checkBoundaryFaceSync(const boolList& blockedFace) const;
203
204 //- Update faceRegion data between (non-processor) coupled faces.
205 void updateFacePair
206 (
207 const label face0,
208 const label face1,
209 labelList& faceRegion,
210 DynamicList<label>& facesChanged
211 ) const;
212
213 //- Given a seed cell label, fill cellRegion/faceRegion with markValue
214 //- for contiguous region around it
215 void fillSeedMask
216 (
217 const UList<labelPair>& explicitConnections,
218 const label seedCellID,
219 const label markValue,
220 labelList& cellRegion,
221 labelList& faceRegion
222 ) const;
223
224
225 //- Calculate the local region split.
226 // \return number of processor-local regions,
227 // without consolidation between procesors
228 label localRegionSplit
229 (
230 const UList<labelPair>& explicitConnections,
231 labelList& cellRegion,
232 labelList& faceRegion
233 ) const;
234
235 //- Manually consolidate regions globally by swapping information
236 // between processor domains and reducing the regions accordingly.
237 //
238 // \return globalIndex into the local regions after reduction.
239 globalIndex reduceRegionsImpl
240 (
241 const label numLocalRegions,
242 const bitSetOrBoolList& blockedFace,
243 labelList& cellRegion
244 ) const;
245
246
247public:
248
249 //- Runtime type information
250 ClassName("regionSplit");
251
252
253 // Constructors
254
255 //- Construct from mesh
257 (
258 const polyMesh& mesh,
259 const bool doGlobalRegions = Pstream::parRun()
260 );
261
262 //- Construct from mesh and whether face is blocked, optionally
263 //- with additional explicit connections between
264 //- normal boundary faces.
265 //
266 // \note blockedFace must be consistent across coupled faces!
268 (
270 const bitSet& blockedFace,
271 const List<labelPair>& explicitConnections = List<labelPair>(),
272 const bool doGlobalRegions = Pstream::parRun()
273 );
274
275 //- Construct from mesh and whether face is blocked, optionally
276 //- with additional explicit connections between
277 //- normal boundary faces.
278 //
279 // \note blockedFace must be consistent across coupled faces!
281 (
282 const polyMesh& mesh,
283 const boolList& blockedFace,
284 const List<labelPair>& explicitConnections = List<labelPair>(),
285 const bool doGlobalRegions = Pstream::parRun()
286 );
287
288
289 // Member Functions
290
291 //- Return global region numbering
293 {
294 return globalNumbering_;
295 }
296
297 //- Return local number of regions
298 label nLocalRegions() const
299 {
301 }
302
303 //- Return total number of regions
304 label nRegions() const
305 {
306 return globalNumbering().totalSize();
307 }
308
309 //- Manually consolidate regions globally by swapping information
310 // between processor domains and reducing the regions accordingly.
311 //
312 // \return globalIndex into the local regions after reduction.
313 globalIndex reduceRegions
314 (
315 const label numLocalRegions,
316 const bitSet& blockedFace,
317 labelList& cellRegion
318 ) const;
319};
320
322// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323
324} // End namespace Foam
325
326// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
327
328#endif
330// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
static const List< bool > & null() noexcept
Definition List.H:138
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
bool test(const label i) const
Definition UList.H:852
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
Definition UPstream.H:1706
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
Definition UPstream.H:1669
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
bool test(const label pos) const
Test for True value at specified position, never auto-vivify entries.
Definition bitSet.H:334
static const bitSet & null() noexcept
Return a null bitSet (reference to a nullObject).
Definition bitSet.H:138
Calculates a non-overlapping list of offsets based on an input size (eg, number of cells) from differ...
Definition globalIndex.H:77
label totalSize() const noexcept
The total addressed size, which corresponds to the end offset and also the sum of all localSizes.
label localSize(const label proci) const
Size of proci data.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
ClassName("regionSplit")
Runtime type information.
label nLocalRegions() const
Return local number of regions.
globalIndex reduceRegions(const label numLocalRegions, const bitSet &blockedFace, labelList &cellRegion) const
Manually consolidate regions globally by swapping information.
const globalIndex & globalNumbering() const noexcept
Return global region numbering.
regionSplit(const polyMesh &mesh, const bool doGlobalRegions=Pstream::parRun())
Construct from mesh.
label nRegions() const
Return total number of regions.
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition className.H:74
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
List< bool > boolList
A List of bools.
Definition List.H:60
const direction noexcept
Definition scalarImpl.H:265