Fix tutorials: coupled/conjugateHeatFoam/conjugateCavity: fix Allrun file
[OpenFOAM-1.6-ext.git] / src / meshTools / searchableSurface / distributedTriSurfaceMesh.H
blobdba695de01633212d4c501029af1510f78783405
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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             //- 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             );
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             );
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             );
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             );
258             //- Subset given marked faces
259             static triSurface subsetMesh
260             (
261                 const triSurface& s,
262                 const labelList& newToOldFaces,
263                 labelList& newToOldPoints
264             );
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             );
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,
281                 List<labelledTri>& allTris,
282                 pointField& allPoints,
284                 labelList& faceConstructMap,
285                 labelList& pointConstructMap
286             );
288             //- Distribute stored fields
289             template<class Type>
290             void distributeFields(const mapDistribute& map);
293         //- Disallow default bitwise copy construct
294         distributedTriSurfaceMesh(const distributedTriSurfaceMesh&);
296         //- Disallow default bitwise assignment
297         void operator=(const distributedTriSurfaceMesh&);
300 public:
302     //- Runtime type information
303     TypeName("distributedTriSurfaceMesh");
306     // Constructors
308         //- Construct from triSurface
309         distributedTriSurfaceMesh
310         (
311             const IOobject&,
312             const triSurface&,
313             const dictionary& dict
314         );
316         //- Construct read. Does findInstance to find io.local().
317         distributedTriSurfaceMesh(const IOobject& io);
319         //- Construct from dictionary (used by searchableSurface).
320         //  Does read. Does findInstance to find io.local().
321         distributedTriSurfaceMesh
322         (
323             const IOobject& io,
324             const dictionary& dict
325         );
328     // Destructor
330         virtual ~distributedTriSurfaceMesh();
332         //- Clear storage
333         void clearOut();
336     // Member Functions
338         //- Triangle indexing (demand driven)
339         const globalIndex& globalTris() const;
342         // searchableSurface implementation
344             //- Whether supports volume type below. I.e. whether is closed.
345             //  Not supported.
346             virtual bool hasVolumeType() const
347             {
348                 return false;
349             }
351             //- Range of global indices that can be returned.
352             virtual label globalSize() const
353             {
354                 return globalTris().size();
355             }
357             virtual void findNearest
358             (
359                 const pointField& sample,
360                 const scalarField& nearestDistSqr,
361                 List<pointIndexHit>&
362             ) const;
364             virtual void findLine
365             (
366                 const pointField& start,
367                 const pointField& end,
368                 List<pointIndexHit>&
369             ) const;
371             virtual void findLineAny
372             (
373                 const pointField& start,
374                 const pointField& end,
375                 List<pointIndexHit>&
376             ) const;
378             //- Get all intersections in order from start to end.
379             virtual void findLineAll
380             (
381                 const pointField& start,
382                 const pointField& end,
383                 List<List<pointIndexHit> >&
384             ) const;
386             //- From a set of points and indices get the region
387             virtual void getRegion
388             (
389                 const List<pointIndexHit>&,
390                 labelList& region
391             ) const;
393             //- From a set of points and indices get the normal
394             virtual void getNormal
395             (
396                 const List<pointIndexHit>&,
397                 vectorField& normal
398             ) const;
400             //- Determine type (inside/outside/mixed) for point. unknown if
401             //  cannot be determined (e.g. non-manifold surface)
402             virtual void getVolumeType
403             (
404                 const pointField&,
405                 List<volumeType>&
406             ) const;
408             //- Set bounds of surface. Bounds currently set as list of
409             //  bounding boxes. Will do redistribution of surface to locally
410             //  have all triangles overlapping bounds.
411             //  Larger bounds: more triangles (memory), more fully local tests
412             //  (quick).
413             //  keepNonLocal = true : keep triangles that do not overlap
414             //  any processor bounds.
415             //  Should really be split into a routine to determine decomposition
416             //  and one that does actual distribution but determining
417             //  decomposition with duplicate triangle merging requires
418             //  same amount as work as actual distribution.
419             virtual void distribute
420             (
421                 const List<treeBoundBox>&,
422                 const bool keepNonLocal,
423                 autoPtr<mapDistribute>& faceMap,
424                 autoPtr<mapDistribute>& pointMap
425             );
428         // Other
430             //- WIP. From a set of hits (points and
431             //  indices) get the specified field. Misses do not get set.
432             virtual void getField(const List<pointIndexHit>&, labelList&) const;
434             //- Subset the part of surface that is overlapping bounds.
435             static triSurface overlappingSurface
436             (
437                 const triSurface&,
438                 const List<treeBoundBox>&,
439                 labelList& subPointMap,
440                 labelList& subFaceMap
441             );
443             //- Print some stats. Parallel aware version of
444             //  triSurface::writeStats.
445             void writeStats(Ostream& os) const;
448         // regIOobject implementation
450             //- Write using given format, version and compression
451             virtual bool writeObject
452             (
453                 IOstream::streamFormat fmt,
454                 IOstream::versionNumber ver,
455                 IOstream::compressionType cmp
456             ) const;
461 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
463 } // End namespace Foam
465 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
467 #ifdef NoRepository
468 #   include "distributedTriSurfaceMeshTemplates.C"
469 #endif
471 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
473 #endif
475 // ************************************************************************* //