Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / meshTools / searchableSurface / distributedTriSurfaceMesh.H
blob521dd8ced1f814edf3115aad2ebf3a6150867206
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::distributedTriSurfaceMesh
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.
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
43 SourceFiles
44     distributedTriSurfaceMesh.C
46 \*---------------------------------------------------------------------------*/
48 #ifndef distributedTriSurfaceMesh_H
49 #define distributedTriSurfaceMesh_H
51 #include "triSurfaceMesh.H"
52 #include "IOdictionary.H"
53 #include "Pair.H"
54 #include "globalIndex.H"
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 namespace Foam
61 class mapDistribute;
62 class decompositionMethod;
64 // Typedefs
65 typedef Pair<point> segment;
66 template<>
67 inline bool contiguous<segment>() {return contiguous<point>();}
70 /*---------------------------------------------------------------------------*\
71                            Class distributedTriSurfaceMesh Declaration
72 \*---------------------------------------------------------------------------*/
74 class distributedTriSurfaceMesh
76     public triSurfaceMesh
78 public:
80     // Static data
82         enum distributionType
83         {
84             FOLLOW = 0,
85             INDEPENDENT = 1,
86             FROZEN = 2
87         };
89         static const NamedEnum<distributionType, 3> distributionTypeNames_;
91 private:
93     // Private member data
95         //- Merging distance
96         scalar mergeDist_;
98         //- Decomposition used when independently decomposing surface.
99         autoPtr<decompositionMethod> decomposer_;
101         //- Bounding box settings
102         IOdictionary dict_;
104         //- bounding boxes of all processors
105         List<List<treeBoundBox> > procBb_;
107         //- Global triangle numbering
108         mutable autoPtr<globalIndex> globalTris_;
110         //- The distribution type.
111         distributionType distType_;
114     // Private Member Functions
116         // Read
118             //- Read my additional data
119             bool read();
122         // Line intersection
124             static bool isLocal
125             (
126                 const List<treeBoundBox>& myBbs,
127                 const point& start,
128                 const point& end
129             );
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             //    dynamicLabelList& allSegmentMap,
142             //    dynamicLabelList sendMap
143             //) const
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,
153                 DynamicList<segment>&,
154                 dynamicLabelList&,
155                 List<dynamicLabelList >&
156             ) const;
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,
165                 List<segment>& allSegments,
166                 List<label>& allSegmentMap
167             ) const;
169             //- Split edges, distribute, test and collect.
170             void findLine
171             (
172                 const bool nearestIntersection,
173                 const pointField& start,
174                 const pointField& end,
175                 List<pointIndexHit>& info
176             ) const;
179         // Triangle index
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;
191         // Nearest
193             label calcOverlappingProcs
194             (
195                 const point& centre,
196                 const scalar radiusSqr,
197                 boolList& overlaps
198             ) const;
200             autoPtr<mapDistribute> calcLocalQueries
201             (
202                 const pointField& centres,
203                 const scalarField& radiusSqr,
205                 pointField& allCentres,
206                 scalarField& allRadiusSqr,
207                 labelList& allSegmentMap
208             ) const;
211         // Surface redistribution
213             //- Finds new bounds based on an indepedent decomposition.
214             List<List<treeBoundBox> > independentlyDistributedBbs
215             (
216                 const triSurface&
217             );
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             );
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             );
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             );
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             );
257             //- Subset given marked faces
258             static triSurface subsetMesh
259             (
260                 const triSurface& s,
261                 const labelList& newToOldFaces,
262                 labelList& newToOldPoints
263             );
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             );
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,
280                 List<labelledTri>& allTris,
281                 pointField& allPoints,
283                 labelList& faceConstructMap,
284                 labelList& pointConstructMap
285             );
287             //- Distribute stored fields
288             template<class Type>
289             void distributeFields(const mapDistribute& map);
292         //- Disallow default bitwise copy construct
293         distributedTriSurfaceMesh(const distributedTriSurfaceMesh&);
295         //- Disallow default bitwise assignment
296         void operator=(const distributedTriSurfaceMesh&);
299 public:
301     //- Runtime type information
302     TypeName("distributedTriSurfaceMesh");
305     // Constructors
307         //- Construct from triSurface
308         distributedTriSurfaceMesh
309         (
310             const IOobject&,
311             const triSurface&,
312             const dictionary& dict
313         );
315         //- Construct read. Does findInstance to find io.local().
316         distributedTriSurfaceMesh(const IOobject& io);
318         //- Construct from dictionary (used by searchableSurface).
319         //  Does read. Does findInstance to find io.local().
320         distributedTriSurfaceMesh
321         (
322             const IOobject& io,
323             const dictionary& dict
324         );
327     // Destructor
329         virtual ~distributedTriSurfaceMesh();
331         //- Clear storage
332         void clearOut();
335     // Member Functions
337         //- Triangle indexing (demand driven)
338         const globalIndex& globalTris() const;
341         // searchableSurface implementation
343             //- Whether supports volume type below. I.e. whether is closed.
344             //  Not supported.
345             virtual bool hasVolumeType() const
346             {
347                 return false;
348             }
350             //- Range of global indices that can be returned.
351             virtual label globalSize() const
352             {
353                 return globalTris().size();
354             }
356             virtual void findNearest
357             (
358                 const pointField& sample,
359                 const scalarField& nearestDistSqr,
360                 List<pointIndexHit>&
361             ) const;
363             virtual void findLine
364             (
365                 const pointField& start,
366                 const pointField& end,
367                 List<pointIndexHit>&
368             ) const;
370             virtual void findLineAny
371             (
372                 const pointField& start,
373                 const pointField& end,
374                 List<pointIndexHit>&
375             ) const;
377             //- Get all intersections in order from start to end.
378             virtual void findLineAll
379             (
380                 const pointField& start,
381                 const pointField& end,
382                 List<List<pointIndexHit> >&
383             ) const;
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;
392             //- From a set of points and indices get the normal
393             virtual void getNormal
394             (
395                 const List<pointIndexHit>&,
396                 vectorField& normal
397             ) const;
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&,
404                 List<volumeType>&
405             ) const;
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             );
427         // Other
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;
433             //- Subset the part of surface that is overlapping bounds.
434             static triSurface overlappingSurface
435             (
436                 const triSurface&,
437                 const List<treeBoundBox>&,
438                 labelList& subPointMap,
439                 labelList& subFaceMap
440             );
442             //- Print some stats. Parallel aware version of
443             //  triSurface::writeStats.
444             void writeStats(Ostream& os) const;
447         // regIOobject implementation
449             //- Write using given format, version and compression
450             virtual bool writeObject
451             (
452                 IOstream::streamFormat fmt,
453                 IOstream::versionNumber ver,
454                 IOstream::compressionType cmp
455             ) const;
460 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
462 } // End namespace Foam
464 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
466 #ifdef NoRepository
467 #   include "distributedTriSurfaceMeshTemplates.C"
468 #endif
470 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
472 #endif
474 // ************************************************************************* //