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