FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 by using parallel communication.
30 
31  Requires:
32  - all processor patches to have correct ordering.
33  - all processorPatches to have their transforms set ('makeTransforms')
34 
35  The shared point addressing is quite interesting. It gives on each processor
36  the vertices that cannot be set using a normal swap on processor patches.
37  These are the vertices that are shared between more than 2 processors.
38 
39  There is an issue with these shared vertices if they originate from
40  cyclics (i.e. are now separated processor patches). They will all be
41  mapped to the same global point (so even though the processor points are
42  not on the same location) since topologically they are one and the same.
43 
44  So if you ask for sharedPoints() you get only one of the coordinates of
45  the topologically shared points.
46 
47  All the hard work of these shared points is done by the globalPoints class.
48 
49  Shared edges: similar to shared points gives on all processors the edges
50  that are shared between more than two patches (i.e. the edges on which
51  data cannot be synchronized by a straightforward edge data swap). Note
52  that shared edges will use shared points but not all edges between shared
53  points need to be shared edges (e.g. there might be an edge connecting
54  two disconnected regions of shared points).
55 
56  Currently an edge is considered shared
57  if it uses two shared points and is used more than once. This is not
58  correct on processor patches but it only slightly overestimates the number
59  of shared edges. Doing full analysis of how many patches use the edge
60  would be too complicated.
61 
62  Shared edge calculation is demand driven so always make sure to have
63  your first call to one of the access functions synchronous amongst all
64  processors!
65 
66 
67 SourceFiles
68  globalMeshData.C
69  globalMeshDataMorph.C
70 
71 \*---------------------------------------------------------------------------*/
72 
73 #ifndef globalMeshData_H
74 #define globalMeshData_H
75 
76 #include <OpenFOAM/polyMesh.H>
77 #include <OpenFOAM/Switch.H>
78 #include "processorTopology.H"
79 #include <OpenFOAM/labelPair.H>
80 
81 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
82 
83 namespace Foam
84 {
85 
86 // Forward declaration of friend functions and operators
87 
88 class globalMeshData;
89 Ostream& operator<<(Ostream&, const globalMeshData&);
90 
91 
92 /*---------------------------------------------------------------------------*\
93  Class globalMeshData Declaration
94 \*---------------------------------------------------------------------------*/
95 
97 :
98  public processorTopology
99 {
100 
101  // Private class
102 
103  // To combineReduce a pointField. Just appends all lists.
104  template <class T>
105  class plusEqOp
106  {
107 
108  public:
109 
110  void operator()(T& x, const T& y) const
111  {
112  label n = x.size();
113 
114  x.setSize(x.size() + y.size());
115 
116  forAll(y, i)
117  {
118  x[n++] = y[i];
119  }
120  }
121  };
122 
123 
125 
126 
127  // Private data
128 
129  //- Reference to mesh
130  const polyMesh& mesh_;
131 
132 
133  // Data related to the complete mesh
134 
135  //- Bounding box of complete mesh
136  boundBox bb_;
137 
138  //- Total number of points in the complete mesh
139  label nTotalPoints_;
140 
141  //- Total number of faces in the complete mesh
142  label nTotalFaces_;
143 
144  //- Total number of cells in the complete mesh
145  label nTotalCells_;
146 
147 
148  // Processor patch addressing (be careful if not running in parallel!)
149 
150  //- List of processor patch labels
151  // (size of list = number of processor patches)
152  labelList processorPatches_;
153 
154  //- List of indices into processorPatches_ for each patch.
155  // Index = -1 for non-processor patches.
156  // (size of list = number of patches)
157  labelList processorPatchIndices_;
158 
159  //- processorPatchIndices_ of the neighbours processor patches
160  labelList processorPatchNeighbours_;
161 
162 
163  // Globally shared point addressing
164 
165  //- Total number of global points
166  label nGlobalPoints_;
167 
168  //- Indices of local points that are globally shared
169  labelList sharedPointLabels_;
170 
171  //- Indices of globally shared points in the master list
172  // This list contains all the shared points in the mesh
173  labelList sharedPointAddr_;
174 
175  //- Shared point global labels.
176  // Global point index for every local shared point.
177  // Only valid if constructed with this information or if
178  // pointProcAddressing read.
179  mutable labelList* sharedPointGlobalLabelsPtr_;
180 
181 
182  // Globally shared edge addressing. Derived from shared points.
183  // All demand driven since don't want to construct edges always.
184 
185  //- Total number of global edges
186  mutable label nGlobalEdges_;
187 
188  //- Indices of local edges that are globally shared
189  mutable labelList* sharedEdgeLabelsPtr_;
190 
191  //- Indices of globally shared edge in the master list
192  // This list contains all the shared edges in the mesh
193  mutable labelList* sharedEdgeAddrPtr_;
194 
195 
196  // Private Member Functions
197 
198  //- Set up processor patch addressing
199  void initProcAddr();
200 
201  //- Helper function for shared edge addressing
202  static void countSharedEdges
203  (
204  const HashTable<labelList, edge, Hash<edge> >& procSharedEdges,
205  HashTable<label, edge, Hash<edge> >&,
206  label&
207  );
208 
209  //- Calculate shared edge addressing
210  void calcSharedEdges() const;
211 
212  //- Count coincident faces.
213  static label countCoincidentFaces
214  (
215  const scalar tolDim,
216  const vectorField& separationDist
217  );
218 
219  //- Disallow default bitwise copy construct
221 
222  //- Disallow default bitwise assignment
223  void operator=(const globalMeshData&);
224 
225 
226 public:
227 
228  //- Runtime type information
229  ClassName("globalMeshData");
230 
231 
232  // Static data members
233 
234  //- Geomtric tolerance (fraction of bounding box)
235  static const Foam::scalar matchTol_;
236 
237 
238  // Constructors
239 
240  //- Construct from mesh, derive rest (does parallel communication!)
241  globalMeshData(const polyMesh& mesh);
242 
243  //- Old behaviour: read constructor given IOobject and a polyMesh
244  // reference. Only use this for testing!
245  globalMeshData(const IOobject& io, const polyMesh& mesh);
246 
247 
248  // Destructor
249 
250  ~globalMeshData();
251 
252  //- Remove all demand driven data
253  void clearOut();
254 
255 
256  // Member Functions
257 
258  // Access
259 
260  //- Return the mesh reference
261  const polyMesh& mesh() const
262  {
263  return mesh_;
264  }
265 
266  //- Does the mesh contain processor patches? (also valid when
267  // not running parallel)
268  bool parallel() const
269  {
270  return processorPatches_.size() > 0;
271  }
272 
273  const boundBox& bb() const
274  {
275  return bb_;
276  }
277 
278  //- Return total number of points in decomposed mesh
279  label nTotalPoints() const
280  {
281  return nTotalPoints_;
282  }
283 
284  //- Return total number of faces in decomposed mesh
285  label nTotalFaces() const
286  {
287  return nTotalFaces_;
288  }
289 
290  //- Return total number of cells in decomposed mesh
291  label nTotalCells() const
292  {
293  return nTotalCells_;
294  }
295 
296 
297  // Processor patch addressing (be careful when not running in parallel)
298 
299  //- Return list of processor patch labels
300  // (size of list = number of processor patches)
302  {
303  return processorPatches_;
304  }
305 
306  //- Return list of indices into processorPatches_ for each patch.
307  // Index = -1 for non-processor parches.
308  // (size of list = number of patches)
310  {
311  return processorPatchIndices_;
312  }
313 
314  //- Return processorPatchIndices of the neighbours
315  // processor patches. -1 if not running parallel.
317  {
318  return processorPatchNeighbours_;
319  }
320 
321 
322  // Globally shared point addressing
323 
324  //- Return number of globally shared points
325  label nGlobalPoints() const
326  {
327  return nGlobalPoints_;
328  }
329 
330  //- Return indices of local points that are globally shared
332  {
333  return sharedPointLabels_;
334  }
335 
336  //- Return addressing into the complete globally shared points
337  // list
338  // Note: It is assumed that a (never constructed) complete
339  // list of globally shared points exists. The set of shared
340  // points on the current processor is a subset of all shared
341  // points. Shared point addressing gives the index in the
342  // list of all globally shared points for each of the locally
343  // shared points.
344  const labelList& sharedPointAddr() const
345  {
346  return sharedPointAddr_;
347  }
348 
349  //- Return shared point global labels. Tries to read
350  // 'pointProcAddressing' and returns list or -1 if none
351  // available.
352  const labelList& sharedPointGlobalLabels() const;
353 
354  //- Collect coordinates of shared points on all processors.
355  // (does parallel communication!)
356  // Note: not valid for cyclicParallel since shared cyclic points
357  // are merged into single global point. (use geometricSharedPoints
358  // instead)
359  pointField sharedPoints() const;
360 
361  //- Like sharedPoints but keeps cyclic points separate.
362  // (does geometric merging; uses matchTol_*bb as merging tolerance)
363  // Use sharedPoints() instead.
365 
366 
367 
368  // Globally shared edge addressing
369 
370  //- Return number of globally shared edges. Demand-driven
371  // calculation so call needs to be synchronous among processors!
372  label nGlobalEdges() const;
373 
374  //- Return indices of local edges that are globally shared.
375  // Demand-driven
376  // calculation so call needs to be synchronous among processors!
377  const labelList& sharedEdgeLabels() const;
378 
379  //- Return addressing into the complete globally shared edge
380  // list. The set of shared
381  // edges on the current processor is a subset of all shared
382  // edges. Shared edge addressing gives the index in the
383  // list of all globally shared edges for each of the locally
384  // shared edges.
385  // Demand-driven
386  // calculation so call needs to be synchronous among processors!
387  const labelList& sharedEdgeAddr() const;
388 
389 
390  // Edit
391 
392  //- Update for moving points.
393  void movePoints(const pointField& newPoints);
394 
395  //- Change global mesh data given a topological change. Does a
396  // full parallel analysis to determine shared points and
397  // boundaries.
398  void updateMesh();
399 
400 
401  // Write
402 
403  bool write() const;
404 
405 
406  // Ostream Operator
407 
408  friend Ostream& operator<<(Ostream&, const globalMeshData&);
409 };
410 
411 
412 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
413 
414 } // End namespace Foam
415 
416 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
417 
418 #endif
419 
420 // ************************ vim: set sw=4 sts=4 et: ************************ //