globalMeshData.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-2016 OpenFOAM Foundation
9 Copyright (C) 2018-2022 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::globalMeshData
29
30Description
31 Various mesh related information for a parallel run. Upon construction,
32 constructs all info using parallel communication.
33
34 Requires:
35 - all processor patches to have correct ordering.
36 - all processorPatches to have their transforms set.
37
38 The shared point and edge addressing calculates addressing for points
39 and edges on coupled patches. In the 'old' way a distinction was made
40 between points/edges that are only on two processors and those that are
41 on multiple processors. The problem is that those on multiple processors
42 do not allow any transformations and require a global reduction on the
43 master processor.
44
45 The alternative is to have an exchange schedule (through a 'mapDistribute')
46 which sends all point/edge data (no distinction is made between
47 those on two and those on more than two coupled patches) to the local
48 'master'. This master then does any calculation and sends
49 the result back to the 'slave' points/edges. This only needs to be done
50 on points on coupled faces. Any transformation is done using a
51 predetermined set of transformations - since transformations have to be
52 space filling only a certain number of transformation is supported.
53
54 The exchange needs
55 - a field of data
56 - a mapDistribute which does all parallel exchange and transformations
57 This appends remote data to the end of the field.
58 - a set of indices which indicate where to get untransformed data in the
59 field
60 - a set of indices which indicate where to get transformed data in the
61 field
62
63Note
64 - compared to 17x nTotalFaces, nTotalPoints do not compensate for
65 shared points since this would trigger full connectivity analysis
66 - most calculation is demand driven and uses parallel communication
67 so make sure to invoke on all processors at the same time
68 - old sharedEdge calculation: currently an edge is considered shared
69 if it uses two shared points and is used more than once. This is not
70 correct on processor patches but it only slightly overestimates the number
71 of shared edges. Doing full analysis of how many patches use the edge
72 would be too complicated
73
74See also
75 mapDistribute
76 globalIndexAndTransform
77
78SourceFiles
79 globalMeshData.C
80 globalMeshDataTemplates.C
81
82\*---------------------------------------------------------------------------*/
83
84#ifndef Foam_globalMeshData_H
85#define Foam_globalMeshData_H
86
87#include "processorTopology.H"
88#include "labelPair.H"
90
91// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92
93namespace Foam
94{
95
96// Forward Declarations
97class polyMesh;
98class mapDistribute;
99template<class T> class EdgeMap;
100class globalIndex;
101class globalIndexAndTransform;
102class bitSet;
103
104/*---------------------------------------------------------------------------*\
105 Class globalMeshData Declaration
106\*---------------------------------------------------------------------------*/
108class globalMeshData
109{
110 // Private Data
111
112 //- Reference to mesh
113 const polyMesh& mesh_;
114
115
116 // Data related to the complete mesh
117
118 //- Total number of points in the complete mesh
119 label nTotalPoints_;
120
121 //- Total number of faces in the complete mesh
122 label nTotalFaces_;
123
124 //- Total number of cells in the complete mesh
125 label nTotalCells_;
126
127
128 // Processor patch addressing (be careful if not running in parallel!)
129
130 //- The processor/processor topology
131 processorTopology processorTopology_;
132
133 //- List of processor patch labels
134 // (size of list = number of processor patches)
135 labelList processorPatches_;
136
137 //- List of indices into processorPatches_ for each patch.
138 // Index = -1 for non-processor patches.
139 // (size of list = number of patches)
140 labelList processorPatchIndices_;
141
142 //- processorPatchIndices_ of the neighbours processor patches
143 labelList processorPatchNeighbours_;
144
145
146 // Coupled point addressing
147 // This is addressing from coupled point to coupled points/faces/cells.
148 // This is a full schedule so includes points used by only two
149 // coupled patches.
150
151 //- Patch of coupled faces. Additional patch edge to mesh edges
152 // correspondence:
153 // points: meshPoints(), meshPointMap()
154 // edges : meshEdges(), meshEdgeMap()
155 mutable autoPtr<indirectPrimitivePatch> coupledPatchPtr_;
156 mutable autoPtr<labelList> coupledPatchMeshEdgesPtr_;
157 mutable autoPtr<Map<label>> coupledPatchMeshEdgeMapPtr_;
158
159 //- Global numbering for coupledPatch points
160 mutable autoPtr<globalIndex> globalPointNumberingPtr_;
161
162 //- Global numbering for transforms
163 mutable autoPtr<globalIndexAndTransform> globalTransformsPtr_;
164
165 // Coupled point to coupled points
166
167 mutable autoPtr<labelListList> globalPointSlavesPtr_;
168 mutable autoPtr<labelListList> globalPointTransformedSlavesPtr_;
169 mutable autoPtr<mapDistribute> globalPointSlavesMapPtr_;
170
171 // Coupled edge to coupled edges
172
173 mutable autoPtr<globalIndex> globalEdgeNumberingPtr_;
174 mutable autoPtr<labelListList> globalEdgeSlavesPtr_;
175 mutable autoPtr<labelListList> globalEdgeTransformedSlavesPtr_;
176 mutable autoPtr<bitSet> globalEdgeOrientationPtr_;
177 mutable autoPtr<mapDistribute> globalEdgeSlavesMapPtr_;
178
179
180 // Coupled point to boundary faces
181
182 mutable autoPtr<globalIndex> globalBoundaryFaceNumberingPtr_;
183 mutable autoPtr<labelListList> globalPointBoundaryFacesPtr_;
185 globalPointTransformedBoundaryFacesPtr_;
186 mutable autoPtr<mapDistribute> globalPointBoundaryFacesMapPtr_;
187
188 // Coupled point to boundary cells
189
190 mutable autoPtr<labelList> boundaryCellsPtr_;
191 mutable autoPtr<globalIndex> globalBoundaryCellNumberingPtr_;
192 mutable autoPtr<labelListList> globalPointBoundaryCellsPtr_;
194 globalPointTransformedBoundaryCellsPtr_;
195 mutable autoPtr<mapDistribute> globalPointBoundaryCellsMapPtr_;
196
197
198 // Other: coupled point to coupled COLLOCATED points
199 mutable autoPtr<labelListList> globalCoPointSlavesPtr_;
200 mutable autoPtr<mapDistribute> globalCoPointSlavesMapPtr_;
201
202
203
204 // Globally shared point addressing
205
206 //- Total number of global points
207 mutable label nGlobalPoints_;
208
209 //- Indices of local points that are globally shared
210 mutable autoPtr<labelList> sharedPointLabelsPtr_;
211
212 //- Indices of globally shared points in the master list
213 // This list contains all the shared points in the mesh
214 mutable autoPtr<labelList> sharedPointAddrPtr_;
215
216 //- Shared point global labels.
217 // Global point index for every local shared point.
218 // Only valid if constructed with this information or if
219 // pointProcAddressing read.
220 mutable autoPtr<labelList> sharedPointGlobalLabelsPtr_;
221
222
223 // Globally shared edge addressing. Derived from shared points.
224 // All demand driven since don't want to construct edges always.
225
226 //- Total number of global edges
227 mutable label nGlobalEdges_;
228
229 //- Indices of local edges that are globally shared
230 mutable autoPtr<labelList> sharedEdgeLabelsPtr_;
231
232 //- Indices of globally shared edge in the master list
233 // This list contains all the shared edges in the mesh
234 mutable autoPtr<labelList> sharedEdgeAddrPtr_;
235
236
237 // Private Member Functions
238
239 //- Set up processor patch addressing
240 void initProcAddr();
241
242 //- Helper function for shared edge addressing
243 static void countSharedEdges
244 (
245 const EdgeMap<labelList>&,
247 label&
248 );
249
250 //- Calculate shared point addressing
251 void calcSharedPoints() const;
252
253 //- Calculate shared edge addressing
254 void calcSharedEdges() const;
255
256 //- Calculate global point addressing.
257 void calcGlobalPointSlaves() const;
258
259 // Global edge addressing
260
261 //- Calculate connected points
262 void calcPointConnectivity(List<labelPairList>&) const;
263
264 //- Calculate pointEdges and pointPoints addressing
265 void calcGlobalPointEdges
266 (
267 labelListList& globalPointEdges,
268 List<labelPairList>& globalPointPoints
269 ) const;
270
271 //- Look up remote and local point and find using info the
272 // transforms to go from remotePoint to localPoint
273 label findTransform
274 (
275 const labelPairList& info,
276 const labelPair& remotePoint,
277 const label localPoint
278 ) const;
279
280 //- Calculate global edge addressing.
281 void calcGlobalEdgeSlaves() const;
282
283 //- Calculate orientation w.r.t. edge master.
284 void calcGlobalEdgeOrientation() const;
285
286
287 // Global boundary face/cell addressing
288
289 //- Calculate coupled point to uncoupled boundary faces. Local only.
290 void calcPointBoundaryFaces(labelListList&) const;
291
292 //- Calculate global point to global boundary face addressing.
293 void calcGlobalPointBoundaryFaces() const;
294
295 //- Calculate global point to global boundary cell addressing.
296 void calcGlobalPointBoundaryCells() const;
297
298 // Other
299
300 // Point to collocated points. Note that not all points on
301 // coupled patches now have a master! (since points on either
302 // side of a cyclic are not connected). So check whether the map
303 // reaches all points and decide who is master, slave and who is
304 // its own master. Maybe store as well?
305
306 void calcGlobalCoPointSlaves() const;
307
308
309 //- No copy construct
310 globalMeshData(const globalMeshData&) = delete;
311
312 //- No copy assignment
313 void operator=(const globalMeshData&) = delete;
314
315
316public:
317
318 //- Runtime type information
319 ClassName("globalMeshData");
320
321
322 // Static data members
323
324 //- Geometric tolerance (fraction of bounding box)
325 static const Foam::scalar matchTol_;
326
327
328 // Constructors
329
330 //- Construct from mesh, derive rest (does parallel communication!)
332
333
334 //- Destructor
336
337 //- Remove all demand driven data
338 void clearOut();
339
340
341 // Member Functions
342
343 // Access
344
345 //- Return the mesh reference
346 const polyMesh& mesh() const noexcept
347 {
348 return mesh_;
349 }
350
351 //- Does the mesh contain processor patches? (also valid when
352 // not running parallel)
353 bool parallel() const
354 {
355 return !processorPatches_.empty();
356 }
357
358 //- Return total number of points in decomposed mesh. Not
359 // compensated for duplicate points!
360 label nTotalPoints() const noexcept
361 {
362 return nTotalPoints_;
363 }
364
365 //- Return total number of faces in decomposed mesh. Not
366 // compensated for duplicate faces!
367 label nTotalFaces() const noexcept
368 {
369 return nTotalFaces_;
370 }
371
372 //- Return total number of cells in decomposed mesh.
373 label nTotalCells() const noexcept
374 {
375 return nTotalCells_;
376 }
377
378
379 // Processor patch addressing (be careful when not running in parallel)
380
381 //- The processor to processor topology.
382 const processorTopology& topology() const noexcept
383 {
384 return processorTopology_;
385 }
386
387 //- Order in which the patches should be initialised/evaluated
388 //- corresponding to the schedule
389 const lduSchedule& patchSchedule() const noexcept
390 {
391 return processorTopology_.patchSchedule();
392 }
393
394 //- Return list of processor patch labels
395 // (size of list = number of processor patches)
396 const labelList& processorPatches() const noexcept
397 {
398 return processorPatches_;
399 }
400
401 //- Return list of indices into processorPatches_ for each patch.
402 // Index = -1 for non-processor parches.
403 // (size of list = number of patches)
405 {
406 return processorPatchIndices_;
407 }
408
409 //- Return processorPatchIndices of the neighbours
410 //- processor patches. -1 if not running parallel.
412 {
413 return processorPatchNeighbours_;
414 }
415
416
417 // Globally shared point addressing
418
419 //- Return number of globally shared points
420 label nGlobalPoints() const;
421
422 //- Return indices of local points that are globally shared
423 const labelList& sharedPointLabels() const;
424
425 //- Return addressing into the complete globally shared points
426 // list
427 // Note: It is assumed that a (never constructed) complete
428 // list of globally shared points exists. The set of shared
429 // points on the current processor is a subset of all shared
430 // points. Shared point addressing gives the index in the
431 // list of all globally shared points for each of the locally
432 // shared points.
433 const labelList& sharedPointAddr() const;
434
435 //- Return shared point global labels. Tries to read
436 // 'pointProcAddressing' and returns list or -1 if none
437 // available.
438 const labelList& sharedPointGlobalLabels() const;
439
440 //- Collect coordinates of shared points on all processors.
441 // (does parallel communication!)
442 // Note: not valid for cyclicParallel since shared cyclic points
443 // are merged into single global point. (use geometricSharedPoints
444 // instead)
445 pointField sharedPoints() const;
446
447 //- Like sharedPoints but keeps cyclic points separate.
448 // (does geometric merging; uses matchTol_*bb as merging tolerance)
449 // Use sharedPoints() instead.
451
452
453
454 // Globally shared edge addressing
455
456 //- Return number of globally shared edges. Demand-driven
457 // calculation so call needs to be synchronous among processors!
458 label nGlobalEdges() const;
459
460 //- Return indices of local edges that are globally shared.
461 // Demand-driven
462 // calculation so call needs to be synchronous among processors!
463 const labelList& sharedEdgeLabels() const;
464
465 //- Return addressing into the complete globally shared edge
466 // list. The set of shared
467 // edges on the current processor is a subset of all shared
468 // edges. Shared edge addressing gives the index in the
469 // list of all globally shared edges for each of the locally
470 // shared edges.
471 // Demand-driven
472 // calculation so call needs to be synchronous among processors!
473 const labelList& sharedEdgeAddr() const;
474
475
476
477 // Global master - slave point communication
478
479 //- Return patch of all coupled faces
481
482 //- Return map from coupledPatch edges to mesh edges
483 const labelList& coupledPatchMeshEdges() const;
484
485 //- Return map from mesh edges to coupledPatch edges
486 const Map<label>& coupledPatchMeshEdgeMap() const;
487
488 //- Global transforms numbering
490
491 //- Helper: synchronise data with transforms
492 template<class Type, class CombineOp, class TransformOp>
493 static void syncData
494 (
495 List<Type>& elems,
496 const labelListList& slaves,
497 const labelListList& transformedSlaves,
498 const mapDistribute& slavesMap,
500 const CombineOp& cop,
501 const TransformOp& top
502 );
503
504 //- Helper: synchronise data without transforms
505 template<class Type, class CombineOp>
506 static void syncData
507 (
508 List<Type>& elems,
509 const labelListList& slaves,
510 const labelListList& transformedSlaves,
511 const mapDistribute& slavesMap,
512 const CombineOp& cop
513 );
514
515
516 // Coupled point to coupled points. Coupled points are
517 // points on any coupled patch.
518
519 //- Numbering of coupled points is according to coupledPatch.
520 const globalIndex& globalPointNumbering() const;
521 const labelListList& globalPointSlaves() const;
523 const mapDistribute& globalPointSlavesMap() const;
524 //- Helper to synchronise coupled patch point data
525 template<class Type, class CombineOp, class TransformOp>
526 void syncPointData
527 (
528 List<Type>& pointData,
529 const CombineOp& cop,
530 const TransformOp& top
531 ) const;
532
533 // Coupled edge to coupled edges.
534
535 const globalIndex& globalEdgeNumbering() const;
536 const labelListList& globalEdgeSlaves() const;
538 const mapDistribute& globalEdgeSlavesMap() const;
539 //- Is my edge same orientation as master edge
540 const bitSet& globalEdgeOrientation() const;
541
542 // Collocated point to collocated point
543
544 const labelListList& globalCoPointSlaves() const;
546
547 // Coupled point to boundary faces. These are uncoupled boundary
548 // faces only but include empty patches.
549
550 //- Numbering of boundary faces is face-mesh.nInternalFaces()
554 const;
556
557 // Coupled point to boundary cell
558
559 //- From boundary cell to mesh cell
560 const labelList& boundaryCells() const;
561
562 //- Numbering of boundary cells is according to boundaryCells()
566 const;
568
569
570 // Other
571
572 //- Helper for merging (collocated!) mesh point data.
573 // Determines:
574 // - my unique indices
575 // - global numbering over all unique indices
576 // - the global number for all local points (so this will
577 // be local for my unique points)
579 (
580 labelList& pointToGlobal,
581 labelList& uniquePoints
582 ) const;
583
584 //- Helper for merging (collocated!) patch point data.
585 // Takes maps from:
586 // local points to/from mesh. Determines
587 // - my unique points. These are mesh point indices, not patch
588 // point indices.
589 // - global numbering over all unique indices.
590 // - the global number for all local points.
592 (
593 const labelUList& meshPoints,
594 const Map<label>& meshPointMap,
595 labelList& pointToGlobal,
596 labelList& uniqueMeshPoints
597 ) const;
598
599
600 // Edit
601
602 //- Update for moving points.
603 void movePoints(const pointField& newPoints);
604
605 //- Change global mesh data given a topological change. Does a
606 // full parallel analysis to determine shared points and
607 // boundaries.
608 void updateMesh();
609
610
611 // Housekeeping
612
613 //- Deprecated(2020-09) use ListOps::appendEqOp
614 // Uses a different template parameter
615 // \code
616 // globalMeshData::ListPlusEqOp<labelList>()
617 // ListOps::appendEqOp<label>()
618 // \endcode
619 //
620 // \deprecated(2020-09) - use ListOps::appendEqOp
621 template<class T>
622 struct ListPlusEqOp
623 {
624 FOAM_DEPRECATED_FOR(2020-09, "ListOps::appendEqOp")
625 void operator()(T& x, const T& y) const
626 {
627 label n = x.size();
628
629 x.setSize(x.size() + y.size());
630
631 forAll(y, i)
632 {
633 x[n++] = y[i];
634 }
635 }
636 };
637};
638
639
640// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
641
642} // End namespace Foam
643
644// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
645
646#ifdef NoRepository
648#endif
649
650
651// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
652
653#endif
654
655// ************************************************************************* //
scalar y
label n
Map from edge (expressed as its endpoints) to value. For easier forward declaration it is currently i...
Definition: EdgeMap.H:54
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
A list of faces which address into the list of points.
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
Determination and storage of the possible independent transforms introduced by coupledPolyPatches,...
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
const mapDistribute & globalCoPointSlavesMap() const
void movePoints(const pointField &newPoints)
Update for moving points.
const labelList & sharedPointAddr() const
Return addressing into the complete globally shared points.
const bitSet & globalEdgeOrientation() const
Is my edge same orientation as master edge.
const labelListList & globalPointTransformedBoundaryCells() const
const labelListList & globalEdgeTransformedSlaves() const
const Map< label > & coupledPatchMeshEdgeMap() const
Return map from mesh edges to coupledPatch edges.
const labelList & sharedEdgeAddr() const
Return addressing into the complete globally shared edge.
pointField geometricSharedPoints() const
Like sharedPoints but keeps cyclic points separate.
bool parallel() const
Does the mesh contain processor patches? (also valid when.
const labelList & processorPatches() const noexcept
Return list of processor patch labels.
static const Foam::scalar matchTol_
Geometric tolerance (fraction of bounding box)
const labelList & processorPatchIndices() const noexcept
Return list of indices into processorPatches_ for each patch.
label nGlobalPoints() const
Return number of globally shared points.
const mapDistribute & globalPointBoundaryCellsMap() const
const lduSchedule & patchSchedule() const noexcept
const mapDistribute & globalPointBoundaryFacesMap() const
const mapDistribute & globalPointSlavesMap() const
const labelList & processorPatchNeighbours() const noexcept
const labelList & sharedPointLabels() const
Return indices of local points that are globally shared.
const labelListList & globalPointTransformedBoundaryFaces() const
const labelList & boundaryCells() const
From boundary cell to mesh cell.
const labelListList & globalPointBoundaryFaces() const
const mapDistribute & globalEdgeSlavesMap() const
const globalIndex & globalBoundaryFaceNumbering() const
Numbering of boundary faces is face-mesh.nInternalFaces()
static void syncData(List< Type > &elems, const labelListList &slaves, const labelListList &transformedSlaves, const mapDistribute &slavesMap, const globalIndexAndTransform &, const CombineOp &cop, const TransformOp &top)
Helper: synchronise data with transforms.
ClassName("globalMeshData")
Runtime type information.
label nGlobalEdges() const
Return number of globally shared edges. Demand-driven.
const labelList & coupledPatchMeshEdges() const
Return map from coupledPatch edges to mesh edges.
~globalMeshData()
Destructor.
autoPtr< globalIndex > mergePoints(labelList &pointToGlobal, labelList &uniquePoints) const
Helper for merging (collocated!) mesh point data.
const labelList & sharedPointGlobalLabels() const
Return shared point global labels. Tries to read.
const labelListList & globalCoPointSlaves() const
void syncPointData(List< Type > &pointData, const CombineOp &cop, const TransformOp &top) const
Helper to synchronise coupled patch point data.
pointField sharedPoints() const
Collect coordinates of shared points on all processors.
label nTotalFaces() const noexcept
Return total number of faces in decomposed mesh. Not.
const globalIndex & globalBoundaryCellNumbering() const
Numbering of boundary cells is according to boundaryCells()
const labelListList & globalPointSlaves() const
const globalIndex & globalEdgeNumbering() const
const polyMesh & mesh() const noexcept
Return the mesh reference.
const globalIndexAndTransform & globalTransforms() const
Global transforms numbering.
const labelList & sharedEdgeLabels() const
Return indices of local edges that are globally shared.
label nTotalPoints() const noexcept
Return total number of points in decomposed mesh. Not.
const labelListList & globalPointTransformedSlaves() const
const indirectPrimitivePatch & coupledPatch() const
Return patch of all coupled faces.
label nTotalCells() const noexcept
Return total number of cells in decomposed mesh.
void updateMesh()
Change global mesh data given a topological change. Does a.
const labelListList & globalPointBoundaryCells() const
void clearOut()
Remove all demand driven data.
const labelListList & globalEdgeSlaves() const
const processorTopology & topology() const noexcept
The processor to processor topology.
const globalIndex & globalPointNumbering() const
Numbering of coupled points is according to coupledPatch.
Class containing processor-to-processor mapping information.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
Determines/represents processor-processor connection. After instantiation contains the processor-proc...
const lduSchedule & patchSchedule() const noexcept
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition: className.H:67
const volScalarField & T
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
const direction noexcept
Definition: Scalar.H:223
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition: stdFoam.H:52
Deprecated(2020-09) use ListOps::appendEqOp.