initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / searchableSurface / distributedTriSurfaceMesh.H
blobdba72d2abf4b1491be861f6e5dc825533d9b1427
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::distributedTriSurfaceMesh
28 Description
29     IOoject and searching on distributed triSurface. All processor hold
30     (possibly overlapping) part of the overall surface. All queries are
31     distributed to the processor that can answer it and the result sent back.
33     Can work in three modes:
34     - follow : makes sure each processor has all the triangles inside the
35     externally provided bounding box (usually the mesh bounding box).
36     Guarantees minimum amount of communication since mesh-local queries
37     should be answerable without any comms.
38     - independent : surface is decomposed according to the triangle centres
39     so the decomposition might be radically different from the mesh
40     decomposition. Guarantees best memory balance but at the expense of
41     more communication.
42     - frozen : no change
44 SourceFiles
45     distributedTriSurfaceMesh.C
47 \*---------------------------------------------------------------------------*/
49 #ifndef distributedTriSurfaceMesh_H
50 #define distributedTriSurfaceMesh_H
52 #include "triSurfaceMesh.H"
53 #include "IOdictionary.H"
54 #include "Pair.H"
55 #include "globalIndex.H"
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 namespace Foam
62 class mapDistribute;
63 class decompositionMethod;
65 // Typedefs
66 typedef Pair<point> segment;
67 template<>
68 inline bool contiguous<segment>() {return contiguous<point>();}
71 /*---------------------------------------------------------------------------*\
72                            Class distributedTriSurfaceMesh Declaration
73 \*---------------------------------------------------------------------------*/
75 class distributedTriSurfaceMesh
77     public triSurfaceMesh
79 public:
81     // Static data
83         enum distributionType
84         {
85             FOLLOW = 0,
86             INDEPENDENT = 1,
87             FROZEN = 2
88         };
90         static const NamedEnum<distributionType, 3> distributionTypeNames_;
92 private:
94     // Private member data
96         //- Merging distance
97         scalar mergeDist_;
99         //- Decomposition used when independently decomposing surface.
100         autoPtr<decompositionMethod> decomposer_;
102         //- Bounding box settings
103         IOdictionary dict_;
105         //- bounding boxes of all processors
106         List<List<treeBoundBox> > procBb_;
108         //- Global triangle numbering
109         mutable autoPtr<globalIndex> globalTris_;
111         //- The distribution type.
112         distributionType distType_;
115     // Private Member Functions
117         // Read
119             //- Read my additional data
120             bool read();
123         // Line intersection
125             static bool isLocal
126             (
127                 const List<treeBoundBox>& myBbs,
128                 const point& start,
129                 const point& end
130             );
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
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,
154                 DynamicList<segment>&,
155                 DynamicList<label>&,
156                 List<DynamicList<label> >&
157             ) const;
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,
166                 List<segment>& allSegments,
167                 List<label>& allSegmentMap
168             ) const;
170             //- Split edges, distribute, test and collect.
171             void findLine
172             (
173                 const bool nearestIntersection,
174                 const pointField& start,
175                 const pointField& end,
176                 List<pointIndexHit>& info
177             ) const;
180         // Triangle index
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;
192         // Nearest
194             label calcOverlappingProcs
195             (
196                 const point& centre,
197                 const scalar radiusSqr,
198                 boolList& overlaps
199             ) const;
201             autoPtr<mapDistribute> calcLocalQueries
202             (
203                 const pointField& centres,
204                 const scalarField& radiusSqr,
206                 pointField& allCentres,
207                 scalarField& allRadiusSqr,
208                 labelList& allSegmentMap
209             ) const;
212         // Surface redistribution
214             //- Finds new bounds based on an indepedent decomposition.
215             List<List<treeBoundBox> > independentlyDistributedBbs
216             (
217                 const triSurface&
218             );
220             //- Calculate surface bounding box
221             void calcBounds(boundBox& bb, label& nPoints) const;
223             //- Does any part of triangle overlap bb.
224             static bool overlaps
225             (
226                 const List<treeBoundBox>& bb,
227                 const point& p0,
228                 const point& p1,
229                 const point& p2
230             );
232             //- Find points used in subset
233             static void subsetMeshMap
234             (
235                 const triSurface& s,
236                 const boolList& include,
237                 const label nIncluded,
238                 labelList& newToOldPoints,
239                 labelList& oldToNewPoints,
240                 labelList& newToOldFaces
241             );
243             //- Construct subsetted surface
244             static triSurface subsetMesh
245             (
246                 const triSurface& s,
247                 const labelList& newToOldPoints,
248                 const labelList& oldToNewPoints,
249                 const labelList& newToOldFaces
250             );
252             //- Subset given marked faces
253             static triSurface subsetMesh
254             (
255                 const triSurface& s,
256                 const boolList& include,
257                 labelList& newToOldPoints,
258                 labelList& newToOldFaces
259             );
261             //- Subset given marked faces
262             static triSurface subsetMesh
263             (
264                 const triSurface& s,
265                 const labelList& newToOldFaces,
266                 labelList& newToOldPoints
267             );
269             //- Find triangle otherF in allFaces.
270             static label findTriangle
271             (
272                 const List<labelledTri>& allFaces,
273                 const labelListList& allPointFaces,
274                 const labelledTri& otherF
275             );
277             //- Merge triSurface (subTris, subPoints) into allTris, allPoints.
278             static void merge
279             (
280                 const scalar mergeDist,
281                 const List<labelledTri>& subTris,
282                 const pointField& subPoints,
284                 List<labelledTri>& allTris,
285                 pointField& allPoints,
287                 labelList& faceConstructMap,
288                 labelList& pointConstructMap
289             );
291             //- Distribute stored fields
292             template<class Type>
293             void distributeFields(const mapDistribute& map);
296         //- Disallow default bitwise copy construct
297         distributedTriSurfaceMesh(const distributedTriSurfaceMesh&);
299         //- Disallow default bitwise assignment
300         void operator=(const distributedTriSurfaceMesh&);
303 public:
305     //- Runtime type information
306     TypeName("distributedTriSurfaceMesh");
309     // Constructors
311         //- Construct from triSurface
312         distributedTriSurfaceMesh
313         (
314             const IOobject&,
315             const triSurface&,
316             const dictionary& dict
317         );
319         //- Construct read. Does findInstance to find io.local().
320         distributedTriSurfaceMesh(const IOobject& io);
322         //- Construct from dictionary (used by searchableSurface).
323         //  Does read. Does findInstance to find io.local().
324         distributedTriSurfaceMesh
325         (
326             const IOobject& io,
327             const dictionary& dict
328         );
331     // Destructor
333         virtual ~distributedTriSurfaceMesh();
335         //- Clear storage
336         void clearOut();
339     // Member Functions
341         //- Triangle indexing (demand driven)
342         const globalIndex& globalTris() const;
345         // searchableSurface implementation
347             //- Whether supports volume type below. I.e. whether is closed.
348             //  Not supported.
349             virtual bool hasVolumeType() const
350             {
351                 return false;
352             }
354             //- Range of global indices that can be returned.
355             virtual label globalSize() const
356             {
357                 return globalTris().size();
358             }
360             virtual void findNearest
361             (
362                 const pointField& sample,
363                 const scalarField& nearestDistSqr,
364                 List<pointIndexHit>&
365             ) const;
367             virtual void findLine
368             (
369                 const pointField& start,
370                 const pointField& end,
371                 List<pointIndexHit>&
372             ) const;
374             virtual void findLineAny
375             (
376                 const pointField& start,
377                 const pointField& end,
378                 List<pointIndexHit>&
379             ) const;
381             //- Get all intersections in order from start to end.
382             virtual void findLineAll
383             (
384                 const pointField& start,
385                 const pointField& end,
386                 List<List<pointIndexHit> >&
387             ) const;
389             //- From a set of points and indices get the region
390             virtual void getRegion
391             (
392                 const List<pointIndexHit>&,
393                 labelList& region
394             ) const;
396             //- From a set of points and indices get the normal
397             virtual void getNormal
398             (
399                 const List<pointIndexHit>&,
400                 vectorField& normal
401             ) const;
403             //- Determine type (inside/outside/mixed) for point. unknown if
404             //  cannot be determined (e.g. non-manifold surface)
405             virtual void getVolumeType
406             (
407                 const pointField&,
408                 List<volumeType>&
409             ) const;
411             //- Set bounds of surface. Bounds currently set as list of
412             //  bounding boxes. Will do redistribution of surface to locally
413             //  have all triangles overlapping bounds.
414             //  Larger bounds: more triangles (memory), more fully local tests
415             //  (quick).
416             //  keepNonLocal = true : keep triangles that do not overlap
417             //  any processor bounds.
418             //  Should really be split into a routine to determine decomposition
419             //  and one that does actual distribution but determining
420             //  decomposition with duplicate triangle merging requires
421             //  same amoun as work as actual distribution.
422             virtual void distribute
423             (
424                 const List<treeBoundBox>&,
425                 const bool keepNonLocal,
426                 autoPtr<mapDistribute>& faceMap,
427                 autoPtr<mapDistribute>& pointMap
428             );
431         // Other
433             //- Specific to triSurfaceMesh: from a set of hits (points and
434             //  indices) get the specified field. Misses do not get set.
435             virtual void getField
436             (
437                 const word& fieldName,
438                 const List<pointIndexHit>&,
439                 labelList& values
440             ) const;
442             //- Subset the part of surface that is overlapping bounds.
443             static triSurface overlappingSurface
444             (
445                 const triSurface&,
446                 const List<treeBoundBox>&,
447                 labelList& subPointMap,
448                 labelList& subFaceMap
449             );
451             //- Print some stats. Parallel aware version of
452             //  triSurface::writeStats.
453             void writeStats(Ostream& os) const;
456         // regIOobject implementation
458             //- Write using given format, version and compression
459             virtual bool writeObject
460             (
461                 IOstream::streamFormat fmt,
462                 IOstream::versionNumber ver,
463                 IOstream::compressionType cmp
464             ) const;
469 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
471 } // End namespace Foam
473 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
475 #ifdef NoRepository
476 #   include "distributedTriSurfaceMeshTemplates.C"
477 #endif
479 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
481 #endif
483 // ************************************************************************* //