distributedTriSurfaceMesh.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-2020 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 
92 private:
93 
94  // Private Data
95 
96  //- Merging distance
97  scalar mergeDist_;
98 
99  //- Decomposition used when independently decomposing surface.
100  autoPtr<decompositionMethod> decomposer_;
101 
102  //- Bounding box settings
103  IOdictionary dict_;
104 
105  //- Bounding boxes of all processors
106  List<List<treeBoundBox>> procBb_;
107 
108  //- Global triangle numbering
109  mutable autoPtr<globalIndex> globalTris_;
110 
111  //- The distribution type.
112  distributionType distType_;
113 
114 
115  // Private Member Functions
116 
117  // Read
118 
119  //- Read my additional data
120  bool read();
121 
122 
123  // Line intersection
124 
125  static bool isLocal
126  (
127  const List<treeBoundBox>& myBbs,
128  const point& start,
129  const point& end
130  );
131 
132  //- Split segment into subsegments overlapping the processor
133  // bounding box.
134  // void Foam::distributedTriSurfaceMesh::splitSegment
135  //(
136  // const label segmentI,
137  // const point& start,
138  // const point& end,
139  // const treeBoundBox& bb,
140  //
141  // DynamicList<segment>& allSegments,
142  // DynamicList<label>& allSegmentMap,
143  // DynamicList<label> sendMap
144  //) const
145 
146  //- Distribute segments into overlapping processor
147  // bounding boxes. Sort per processor.
148  void distributeSegment
149  (
150  const label,
151  const point& start,
152  const point& end,
153 
157  ) const;
158 
159  //- Divide edges into local and remote segments. Construct map to
160  // distribute and collect data.
161  autoPtr<mapDistribute> distributeSegments
162  (
163  const pointField& start,
164  const pointField& end,
165 
166  List<segment>& allSegments,
167  List<label>& allSegmentMap
168  ) const;
169 
170  //- Split edges, distribute, test and collect.
171  void findLine
172  (
173  const bool nearestIntersection,
174  const pointField& start,
175  const pointField& end,
177  ) const;
178 
179 
180  // Triangle index
181 
182  //- Obtains global indices from pointIndexHit and swaps them back
183  // to their original processor. Used to calculate local region
184  // and normal.
185  autoPtr<mapDistribute> calcLocalQueries
186  (
187  const List<pointIndexHit>&,
188  labelList& triangleIndex
189  ) const;
190 
191 
192  // Nearest
193 
194  label calcOverlappingProcs
195  (
196  const point& centre,
197  const scalar radiusSqr,
198  boolList& overlaps
199  ) const;
200 
201  autoPtr<mapDistribute> calcLocalQueries
202  (
203  const pointField& centres,
204  const scalarField& radiusSqr,
205 
206  pointField& allCentres,
207  scalarField& allRadiusSqr,
208  labelList& allSegmentMap
209  ) const;
210 
211 
212  // Surface redistribution
213 
214  //- Finds new bounds based on an independent decomposition.
215  List<List<treeBoundBox>> independentlyDistributedBbs
216  (
217  const triSurface&
218  );
219 
220  //- Does any part of triangle overlap bb.
221  static bool overlaps
222  (
223  const List<treeBoundBox>& bb,
224  const point& p0,
225  const point& p1,
226  const point& p2
227  );
228 
229  //- Find points used in subset
230  static void subsetMeshMap
231  (
232  const triSurface& s,
233  const boolList& include,
234  const label nIncluded,
235  labelList& newToOldPoints,
236  labelList& oldToNewPoints,
237  labelList& newToOldFaces
238  );
239 
240  //- Construct subsetted surface
241  static triSurface subsetMesh
242  (
243  const triSurface& s,
244  const labelList& newToOldPoints,
245  const labelList& oldToNewPoints,
246  const labelList& newToOldFaces
247  );
248 
249  //- Subset given marked faces
250  static triSurface subsetMesh
251  (
252  const triSurface& s,
253  const boolList& include,
254  labelList& newToOldPoints,
255  labelList& newToOldFaces
256  );
257 
258  //- Subset given marked faces
259  static triSurface subsetMesh
260  (
261  const triSurface& s,
262  const labelList& newToOldFaces,
263  labelList& newToOldPoints
264  );
265 
266  //- Find triangle otherF in allFaces.
267  static label findTriangle
268  (
269  const List<labelledTri>& allFaces,
270  const labelListList& allPointFaces,
271  const labelledTri& otherF
272  );
273 
274  //- Merge triSurface (subTris, subPoints) into allTris, allPoints.
275  static void merge
276  (
277  const scalar mergeDist,
278  const List<labelledTri>& subTris,
279  const pointField& subPoints,
280 
281  List<labelledTri>& allTris,
283 
284  labelList& faceConstructMap,
285  labelList& pointConstructMap
286  );
287 
288  //- Distribute stored fields
289  template<class Type>
290  void distributeFields(const mapDistribute& map);
291 
292 
293 public:
294 
295  //- Runtime type information
296  TypeName("distributedTriSurfaceMesh");
297 
298 
299  // Constructors
300 
301  //- Construct from triSurface
303  (
304  const IOobject&,
305  const triSurface&,
306  const dictionary& dict
307  );
308 
309  //- Construct read. Does findInstance to find io.local().
311 
312  //- Construct from dictionary (used by searchableSurface).
313  // Does read. Does findInstance to find io.local().
315  (
316  const IOobject& io,
317  const dictionary& dict
318  );
319 
320  //- Disallow default bitwise copy construction
322 
323 
324  //- Destructor
325  virtual ~distributedTriSurfaceMesh();
326 
327  //- Clear storage
328  void clearOut();
329 
330 
331  // Member Functions
332 
333  //- Triangle indexing (demand driven)
334  const globalIndex& globalTris() const;
335 
336 
337  // searchableSurface implementation
338 
339  //- Whether supports volume type below. I.e. whether is closed.
340  // Not supported.
341  virtual bool hasVolumeType() const
342  {
343  return false;
344  }
345 
346  //- Range of global indices that can be returned.
347  virtual label globalSize() const
348  {
349  return globalTris().size();
350  }
351 
352  virtual void findNearest
353  (
354  const pointField& sample,
355  const scalarField& nearestDistSqr,
357  ) const;
358 
359  virtual void findLine
360  (
361  const pointField& start,
362  const pointField& end,
364  ) const;
365 
366  virtual void findLineAny
367  (
368  const pointField& start,
369  const pointField& end,
371  ) const;
372 
373  //- Get all intersections in order from start to end.
374  virtual void findLineAll
375  (
376  const pointField& start,
377  const pointField& end,
379  ) const;
380 
381  //- From a set of points and indices get the region
382  virtual void getRegion
383  (
384  const List<pointIndexHit>&,
385  labelList& region
386  ) const;
387 
388  //- From a set of points and indices get the normal
389  virtual void getNormal
390  (
391  const List<pointIndexHit>&,
392  vectorField& normal
393  ) const;
394 
395  //- Determine type (inside/outside/mixed) for point. unknown if
396  // cannot be determined (e.g. non-manifold surface)
397  virtual void getVolumeType
398  (
399  const pointField&,
401  ) const;
402 
403  //- Set bounds of surface. Bounds currently set as list of
404  // bounding boxes. Will do redistribution of surface to locally
405  // have all triangles overlapping bounds.
406  // Larger bounds: more triangles (memory), more fully local tests
407  // (quick).
408  // keepNonLocal = true : keep triangles that do not overlap
409  // any processor bounds.
410  // Should really be split into a routine to determine decomposition
411  // and one that does actual distribution but determining
412  // decomposition with duplicate triangle merging requires
413  // same amount as work as actual distribution.
414  virtual void distribute
415  (
416  const List<treeBoundBox>&,
417  const bool keepNonLocal,
419  autoPtr<mapDistribute>& pointMap
420  );
421 
422 
423  // Other
424 
425  //- WIP. From a set of hits (points and
426  // indices) get the specified field. Misses do not get set.
427  virtual void getField(const List<pointIndexHit>&, labelList&) const;
428 
429  //- Subset the part of surface that is overlapping bounds.
431  (
432  const triSurface&,
433  const List<treeBoundBox>&,
434  labelList& subPointMap,
435  labelList& subFaceMap
436  );
437 
438  //- Print some stats. Parallel aware version of
439  // triSurface::writeStats.
440  void writeStats(Ostream& os) const;
441 
442 
443  // regIOobject implementation
444 
445  //- Write using given format, version and compression
446  // Do not use the triSurfaceMesh::writeObject since it
447  // would filter out empty regions. These need to be preserved
448  // in case we want to make decisions based on the number of
449  // regions.
450  virtual bool writeObject
451  (
455  const bool write = true
456  ) const;
457 
458  //- Is object global
459  virtual bool global() const
460  {
461  return false;
462  }
463 
464  //- Return complete path + object name if the file exists
465  // either in the case/processor or case otherwise null
466  virtual fileName filePath() const
467  {
469  }
470 
471 
472  // Member Operators
473 
474  //- Disallow default bitwise assignment
475  void operator=(const distributedTriSurfaceMesh&) = delete;
476 };
477 
478 
479 //- Template function for obtaining global status
480 template<>
482 {
483  return false;
484 }
485 
486 
487 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
488 
489 } // End namespace Foam
490 
491 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
492 
493 #ifdef NoRepository
495 #endif
496 
497 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
498 
499 #endif
500 
501 // ************************************************************************* //
virtual void getField(const List< pointIndexHit > &, labelList &) const
WIP. From a set of hits (points and.
dictionary dict
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
A class for handling file names.
Definition: fileName.H:79
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112
void operator=(const distributedTriSurfaceMesh &)=delete
Disallow default bitwise assignment.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
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
const globalIndex & globalTris() const
Triangle indexing (demand driven)
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.
Pair< point > segment
static const NamedEnum< distributionType, 3 > distributionTypeNames_
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point. unknown if.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
IOoject and searching on triSurface.
fileName localFilePath(const word &typeName) const
Helper for filePath that searches locally.
Definition: IOobject.C:385
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
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))
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
virtual bool hasVolumeType() const
Whether supports volume type below. I.e. whether is closed.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
virtual fileName filePath() const
Return complete path + object name if the file exists.
label size() const
Global sum of localSizes.
Definition: globalIndexI.H:66
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
Abstract base class for decomposition.
Triangle with additional region number.
Definition: labelledTri.H:57
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
IOoject and searching on distributed triSurface. All processor hold (possibly overlapping) part of th...
void write(Ostream &) const
Write to Ostream in simple FOAM format.
Definition: triSurface.C:1328
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
static triSurface overlappingSurface(const triSurface &, const List< treeBoundBox > &, labelList &subPointMap, labelList &subFaceMap)
Subset the part of surface that is overlapping bounds.
Class containing processor-to-processor mapping information.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
Version number type.
Definition: IOstream.H:96
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write=true) const
Write using given format, version and compression.
tmp< pointField > allPoints(const Triangulation &t)
Extract all points in vertex-index order.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
TypeName("distributedTriSurfaceMesh")
Runtime type information.
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:490
Triangulated surface description with patch information.
Definition: triSurface.H:66
virtual label globalSize() const
Range of global indices that can be returned.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
bool typeGlobal< distributedTriSurfaceMesh >()
Template function for obtaining global status.
distributedTriSurfaceMesh(const IOobject &, const triSurface &, const dictionary &dict)
Construct from triSurface.
Namespace for OpenFOAM.
void writeStats(Ostream &os) const
Print some stats. Parallel aware version of.
virtual bool global() const
Is object global.