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) 2011-2015 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::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 "IOdictionary.H"
53 #include "Pair.H"
54 #include "globalIndex.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
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 
82  enum distributionType
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,
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  virtual ~distributedTriSurfaceMesh();
329 
330  //- Clear storage
331  void clearOut();
332 
333 
334  // Member Functions
335 
336  //- Triangle indexing (demand driven)
337  const globalIndex& globalTris() const;
338 
339 
340  // searchableSurface implementation
341 
342  //- Whether supports volume type below. I.e. whether is closed.
343  // Not supported.
344  virtual bool hasVolumeType() const
345  {
346  return false;
347  }
348 
349  //- Range of global indices that can be returned.
350  virtual label globalSize() const
351  {
352  return globalTris().size();
353  }
354 
355  virtual void findNearest
356  (
357  const pointField& sample,
358  const scalarField& nearestDistSqr,
360  ) const;
361 
362  virtual void findLine
363  (
364  const pointField& start,
365  const pointField& end,
367  ) const;
368 
369  virtual void findLineAny
370  (
371  const pointField& start,
372  const pointField& end,
374  ) const;
375 
376  //- Get all intersections in order from start to end.
377  virtual void findLineAll
378  (
379  const pointField& start,
380  const pointField& end,
382  ) const;
383 
384  //- From a set of points and indices get the region
385  virtual void getRegion
386  (
387  const List<pointIndexHit>&,
388  labelList& region
389  ) const;
390 
391  //- From a set of points and indices get the normal
392  virtual void getNormal
393  (
394  const List<pointIndexHit>&,
396  ) const;
397 
398  //- Determine type (inside/outside/mixed) for point. unknown if
399  // cannot be determined (e.g. non-manifold surface)
400  virtual void getVolumeType
401  (
402  const pointField&,
404  ) const;
405 
406  //- Set bounds of surface. Bounds currently set as list of
407  // bounding boxes. Will do redistribution of surface to locally
408  // have all triangles overlapping bounds.
409  // Larger bounds: more triangles (memory), more fully local tests
410  // (quick).
411  // keepNonLocal = true : keep triangles that do not overlap
412  // any processor bounds.
413  // Should really be split into a routine to determine decomposition
414  // and one that does actual distribution but determining
415  // decomposition with duplicate triangle merging requires
416  // same amount as work as actual distribution.
417  virtual void distribute
418  (
419  const List<treeBoundBox>&,
420  const bool keepNonLocal,
422  autoPtr<mapDistribute>& pointMap
423  );
424 
425 
426  // Other
427 
428  //- WIP. From a set of hits (points and
429  // indices) get the specified field. Misses do not get set.
430  virtual void getField(const List<pointIndexHit>&, labelList&) const;
431 
432  //- Subset the part of surface that is overlapping bounds.
434  (
435  const triSurface&,
436  const List<treeBoundBox>&,
437  labelList& subPointMap,
438  labelList& subFaceMap
439  );
440 
441  //- Print some stats. Parallel aware version of
442  // triSurface::writeStats.
443  void writeStats(Ostream& os) const;
444 
445 
446  // regIOobject implementation
447 
448  //- Write using given format, version and compression
449  // Do not use the triSurfaceMesh::writeObject since it
450  // would filter out empty regions. These need to be preserved
451  // in case we want to make decisions based on the number of
452  // regions.
453  virtual bool writeObject
454  (
458  ) const;
459 
460 };
461 
462 
463 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
464 
465 } // End namespace Foam
466 
467 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
468 
469 #ifdef NoRepository
471 #endif
472 
473 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
474 
475 #endif
476 
477 // ************************************************************************* //
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Write using given format, version and compression.
label size() const
Global sum of localSizes.
Definition: globalIndexI.H:66
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject( name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE ))
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Class containing processor-to-processor mapping information.
Triangulated surface description with patch information.
Definition: triSurface.H:57
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 writeStats(Ostream &os) const
Print some stats. Parallel aware version of.
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit > > &) const
Get all intersections in order from start to end.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
Pair< point > segment
virtual label globalSize() const
Range of global indices that can be returned.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
dictionary dict
Triangle with additional region number.
Definition: labelledTri.H:49
bool contiguous< segment >()
virtual void distribute(const List< treeBoundBox > &, const bool keepNonLocal, autoPtr< mapDistribute > &faceMap, autoPtr< mapDistribute > &pointMap)
Set bounds of surface. Bounds currently set as list of.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
Abstract base class for decomposition.
virtual bool hasVolumeType() const
Whether supports volume type below. I.e. whether is closed.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
static triSurface overlappingSurface(const triSurface &, const List< treeBoundBox > &, labelList &subPointMap, labelList &subFaceMap)
Subset the part of surface that is overlapping bounds.
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:421
tmp< pointField > allPoints(const Triangulation &t)
Extract all points in vertex-index order.
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
virtual void getField(const List< pointIndexHit > &, labelList &) const
WIP. From a set of hits (points and.
TypeName("distributedTriSurfaceMesh")
Runtime type information.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
A normal distribution model.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:106
static const NamedEnum< distributionType, 3 > distributionTypeNames_
const globalIndex & globalTris() const
Triangle indexing (demand driven)
IOoject and searching on distributed triSurface. All processor hold (possibly overlapping) part of th...
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
Version number type.
Definition: IOstream.H:96
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
IOoject and searching on triSurface.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point. unknown if.