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