FreeFOAM The Cross-Platform CFD Toolkit
distributedTriSurfaceMesh.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::distributedTriSurfaceMesh
26 
27 Description
28  IOoject and searching on distributed triSurface. All processor hold
29  (possibly overlapping) part of the overall surface. All queries are
30  distributed to the processor that can answer it and the result sent back.
31 
32  Can work in three modes:
33  - follow : makes sure each processor has all the triangles inside the
34  externally provided bounding box (usually the mesh bounding box).
35  Guarantees minimum amount of communication since mesh-local queries
36  should be answerable without any comms.
37  - independent : surface is decomposed according to the triangle centres
38  so the decomposition might be radically different from the mesh
39  decomposition. Guarantees best memory balance but at the expense of
40  more communication.
41  - frozen : no change
42 
43 SourceFiles
44  distributedTriSurfaceMesh.C
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef distributedTriSurfaceMesh_H
49 #define distributedTriSurfaceMesh_H
50 
51 #include "triSurfaceMesh.H"
52 #include <OpenFOAM/IOdictionary.H>
53 #include <OpenFOAM/Pair.H>
54 #include <OpenFOAM/globalIndex.H>
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 class mapDistribute;
63 
64 // Typedefs
65 typedef Pair<point> segment;
66 template<>
67 inline bool contiguous<segment>() {return contiguous<point>();}
68 
69 
70 /*---------------------------------------------------------------------------*\
71  Class distributedTriSurfaceMesh Declaration
72 \*---------------------------------------------------------------------------*/
73 
75 :
76  public triSurfaceMesh
77 {
78 public:
79 
80  // Static data
81 
83  {
84  FOLLOW = 0,
86  FROZEN = 2
87  };
88 
90 
91 private:
92 
93  // Private member data
94 
95  //- Merging distance
96  scalar mergeDist_;
97 
98  //- Decomposition used when independently decomposing surface.
99  autoPtr<decompositionMethod> decomposer_;
100 
101  //- Bounding box settings
102  IOdictionary dict_;
103 
104  //- bounding boxes of all processors
105  List<List<treeBoundBox> > procBb_;
106 
107  //- Global triangle numbering
108  mutable autoPtr<globalIndex> globalTris_;
109 
110  //- The distribution type.
111  distributionType distType_;
112 
113 
114  // Private Member Functions
115 
116  // Read
117 
118  //- Read my additional data
119  bool read();
120 
121 
122  // Line intersection
123 
124  static bool isLocal
125  (
126  const List<treeBoundBox>& myBbs,
127  const point& start,
128  const point& end
129  );
130 
131  //- Split segment into subsegments overlapping the processor
132  // bounding box.
133  //void Foam::distributedTriSurfaceMesh::splitSegment
134  //(
135  // const label segmentI,
136  // const point& start,
137  // const point& end,
138  // const treeBoundBox& bb,
139  //
140  // DynamicList<segment>& allSegments,
141  // DynamicList<label>& allSegmentMap,
142  // DynamicList<label> sendMap
143  //) const
144 
145  //- Distribute segments into overlapping processor
146  // bounding boxes. Sort per processor.
147  void distributeSegment
148  (
149  const label,
150  const point& start,
151  const point& end,
152 
156  ) const;
157 
158  //- Divide edges into local and remote segments. Construct map to
159  // distribute and collect data.
160  autoPtr<mapDistribute> distributeSegments
161  (
162  const pointField& start,
163  const pointField& end,
164 
165  List<segment>& allSegments,
166  List<label>& allSegmentMap
167  ) const;
168 
169  //- Split edges, distribute, test and collect.
170  void findLine
171  (
172  const bool nearestIntersection,
173  const pointField& start,
174  const pointField& end,
176  ) const;
177 
178 
179  // Triangle index
180 
181  //- Obtains global indices from pointIndexHit and swaps them back
182  // to their original processor. Used to calculate local region
183  // and normal.
184  autoPtr<mapDistribute> calcLocalQueries
185  (
186  const List<pointIndexHit>&,
187  labelList& triangleIndex
188  ) const;
189 
190 
191  // Nearest
192 
193  label calcOverlappingProcs
194  (
195  const point& centre,
196  const scalar radiusSqr,
197  boolList& overlaps
198  ) const;
199 
200  autoPtr<mapDistribute> calcLocalQueries
201  (
202  const pointField& centres,
203  const scalarField& radiusSqr,
204 
205  pointField& allCentres,
206  scalarField& allRadiusSqr,
207  labelList& allSegmentMap
208  ) const;
209 
210 
211  // Surface redistribution
212 
213  //- Finds new bounds based on an indepedent decomposition.
214  List<List<treeBoundBox> > independentlyDistributedBbs
215  (
216  const triSurface&
217  );
218 
219  //- Does any part of triangle overlap bb.
220  static bool overlaps
221  (
222  const List<treeBoundBox>& bb,
223  const point& p0,
224  const point& p1,
225  const point& p2
226  );
227 
228  //- Find points used in subset
229  static void subsetMeshMap
230  (
231  const triSurface& s,
232  const boolList& include,
233  const label nIncluded,
234  labelList& newToOldPoints,
235  labelList& oldToNewPoints,
236  labelList& newToOldFaces
237  );
238 
239  //- Construct subsetted surface
240  static triSurface subsetMesh
241  (
242  const triSurface& s,
243  const labelList& newToOldPoints,
244  const labelList& oldToNewPoints,
245  const labelList& newToOldFaces
246  );
247 
248  //- Subset given marked faces
249  static triSurface subsetMesh
250  (
251  const triSurface& s,
252  const boolList& include,
253  labelList& newToOldPoints,
254  labelList& newToOldFaces
255  );
256 
257  //- Subset given marked faces
258  static triSurface subsetMesh
259  (
260  const triSurface& s,
261  const labelList& newToOldFaces,
262  labelList& newToOldPoints
263  );
264 
265  //- Find triangle otherF in allFaces.
266  static label findTriangle
267  (
268  const List<labelledTri>& allFaces,
269  const labelListList& allPointFaces,
270  const labelledTri& otherF
271  );
272 
273  //- Merge triSurface (subTris, subPoints) into allTris, allPoints.
274  static void merge
275  (
276  const scalar mergeDist,
277  const List<labelledTri>& subTris,
278  const pointField& subPoints,
279 
280  List<labelledTri>& allTris,
281  pointField& allPoints,
282 
283  labelList& faceConstructMap,
284  labelList& pointConstructMap
285  );
286 
287  //- Distribute stored fields
288  template<class Type>
289  void distributeFields(const mapDistribute& map);
290 
291 
292  //- Disallow default bitwise copy construct
294 
295  //- Disallow default bitwise assignment
296  void operator=(const distributedTriSurfaceMesh&);
297 
298 
299 public:
300 
301  //- Runtime type information
302  TypeName("distributedTriSurfaceMesh");
303 
304 
305  // Constructors
306 
307  //- Construct from triSurface
309  (
310  const IOobject&,
311  const triSurface&,
312  const dictionary& dict
313  );
314 
315  //- Construct read. Does findInstance to find io.local().
317 
318  //- Construct from dictionary (used by searchableSurface).
319  // Does read. Does findInstance to find io.local().
321  (
322  const IOobject& io,
323  const dictionary& dict
324  );
325 
326 
327  // Destructor
328 
329  virtual ~distributedTriSurfaceMesh();
330 
331  //- Clear storage
332  void clearOut();
333 
334 
335  // Member Functions
336 
337  //- Triangle indexing (demand driven)
338  const globalIndex& globalTris() const;
339 
340 
341  // searchableSurface implementation
342 
343  //- Whether supports volume type below. I.e. whether is closed.
344  // Not supported.
345  virtual bool hasVolumeType() const
346  {
347  return false;
348  }
349 
350  //- Range of global indices that can be returned.
351  virtual label globalSize() const
352  {
353  return globalTris().size();
354  }
355 
356  virtual void findNearest
357  (
358  const pointField& sample,
359  const scalarField& nearestDistSqr,
361  ) const;
362 
363  virtual void findLine
364  (
365  const pointField& start,
366  const pointField& end,
368  ) const;
369 
370  virtual void findLineAny
371  (
372  const pointField& start,
373  const pointField& end,
375  ) const;
376 
377  //- Get all intersections in order from start to end.
378  virtual void findLineAll
379  (
380  const pointField& start,
381  const pointField& end,
383  ) const;
384 
385  //- From a set of points and indices get the region
386  virtual void getRegion
387  (
388  const List<pointIndexHit>&,
389  labelList& region
390  ) const;
391 
392  //- From a set of points and indices get the normal
393  virtual void getNormal
394  (
395  const List<pointIndexHit>&,
397  ) const;
398 
399  //- Determine type (inside/outside/mixed) for point. unknown if
400  // cannot be determined (e.g. non-manifold surface)
401  virtual void getVolumeType
402  (
403  const pointField&,
405  ) const;
406 
407  //- Set bounds of surface. Bounds currently set as list of
408  // bounding boxes. Will do redistribution of surface to locally
409  // have all triangles overlapping bounds.
410  // Larger bounds: more triangles (memory), more fully local tests
411  // (quick).
412  // keepNonLocal = true : keep triangles that do not overlap
413  // any processor bounds.
414  // Should really be split into a routine to determine decomposition
415  // and one that does actual distribution but determining
416  // decomposition with duplicate triangle merging requires
417  // same amount as work as actual distribution.
418  virtual void distribute
419  (
420  const List<treeBoundBox>&,
421  const bool keepNonLocal,
422  autoPtr<mapDistribute>& faceMap,
423  autoPtr<mapDistribute>& pointMap
424  );
425 
426 
427  // Other
428 
429  //- WIP. From a set of hits (points and
430  // indices) get the specified field. Misses do not get set.
431  virtual void getField(const List<pointIndexHit>&, labelList&) const;
432 
433  //- Subset the part of surface that is overlapping bounds.
435  (
436  const triSurface&,
437  const List<treeBoundBox>&,
438  labelList& subPointMap,
439  labelList& subFaceMap
440  );
441 
442  //- Print some stats. Parallel aware version of
443  // triSurface::writeStats.
444  void writeStats(Ostream& os) const;
445 
446 
447  // regIOobject implementation
448 
449  //- Write using given format, version and compression
450  virtual bool writeObject
451  (
455  ) const;
456 
457 };
458 
459 
460 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
461 
462 } // End namespace Foam
463 
464 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
465 
466 #ifdef NoRepository
468 #endif
469 
470 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
471 
472 #endif
473 
474 // ************************ vim: set sw=4 sts=4 et: ************************ //