distributedTriSurfaceMesh.H 14.4 KB
Newer Older
mattijs's avatar
mattijs committed
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
Mark Olesen's avatar
Mark Olesen committed
5
    \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
mattijs's avatar
mattijs committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM; if not, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Class
    Foam::distributedTriSurfaceMesh

Description
mattijs's avatar
mattijs committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    IOoject and searching on distributed triSurface. All processor hold
    (possibly overlapping) part of the overall surface. All queries are
    distributed to the processor that can answer it and the result sent back.

    Can work in three modes:
    - follow : makes sure each processor has all the triangles inside the
    externally provided bounding box (usually the mesh bounding box).
    Guarantees minimum amount of communication since mesh-local queries
    should be answerable without any comms.
    - independent : surface is decomposed according to the triangle centres
    so the decomposition might be radically different from the mesh
    decomposition. Guarantees best memory balance but at the expense of
    more communication.
    - frozen : no change
mattijs's avatar
mattijs committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

SourceFiles
    distributedTriSurfaceMesh.C

\*---------------------------------------------------------------------------*/

#ifndef distributedTriSurfaceMesh_H
#define distributedTriSurfaceMesh_H

#include "triSurfaceMesh.H"
#include "IOdictionary.H"
#include "Pair.H"
#include "globalIndex.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

class mapDistribute;
mattijs's avatar
mattijs committed
63
class decompositionMethod;
mattijs's avatar
mattijs committed
64

mattijs's avatar
mattijs committed
65
66
67
68
69
70
// Typedefs
typedef Pair<point> segment;
template<>
inline bool contiguous<segment>() {return contiguous<point>();}


mattijs's avatar
mattijs committed
71
72
73
74
75
76
77
78
/*---------------------------------------------------------------------------*\
                           Class distributedTriSurfaceMesh Declaration
\*---------------------------------------------------------------------------*/

class distributedTriSurfaceMesh
:
    public triSurfaceMesh
{
mattijs's avatar
mattijs committed
79
public:
mattijs's avatar
mattijs committed
80
81
82

    // Static data

mattijs's avatar
mattijs committed
83
84
85
86
87
88
89
90
91
92
93
        enum distributionType
        {
            FOLLOW = 0,
            INDEPENDENT = 1,
            FROZEN = 2
        };

        static const NamedEnum<distributionType, 3> distributionTypeNames_;

private:

mattijs's avatar
mattijs committed
94
95
    // Private member data

mattijs's avatar
mattijs committed
96
        //- Merging distance
mattijs's avatar
mattijs committed
97
98
99
100
        scalar mergeDist_;

        //- Decomposition used when independently decomposing surface.
        autoPtr<decompositionMethod> decomposer_;
mattijs's avatar
mattijs committed
101
102
103
104
105
106
107
108
109
110

        //- Bounding box settings
        IOdictionary dict_;

        //- bounding boxes of all processors
        List<List<treeBoundBox> > procBb_;

        //- Global triangle numbering
        mutable autoPtr<globalIndex> globalTris_;

mattijs's avatar
mattijs committed
111
112
113
        //- The distribution type.
        distributionType distType_;

mattijs's avatar
mattijs committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

    // Private Member Functions

        // Read

            //- Read my additional data
            bool read();


        // Line intersection

            static bool isLocal
            (
                const List<treeBoundBox>& myBbs,
                const point& start,
                const point& end
            );

            //- Split segment into subsegments overlapping the processor
mattijs's avatar
mattijs committed
133
134
135
136
137
138
139
140
141
142
143
144
145
146
            //  bounding box.
            //void Foam::distributedTriSurfaceMesh::splitSegment
            //(
            //    const label segmentI,
            //    const point& start,
            //    const point& end,
            //    const treeBoundBox& bb,
            //
            //    DynamicList<segment>& allSegments,
            //    DynamicList<label>& allSegmentMap,
            //    DynamicList<label> sendMap
            //) const

            //- Distribute segments into overlapping processor
mattijs's avatar
mattijs committed
147
            //  bounding boxes. Sort per processor.
mattijs's avatar
mattijs committed
148
            void distributeSegment
mattijs's avatar
mattijs committed
149
150
151
152
153
            (
                const label,
                const point& start,
                const point& end,

mattijs's avatar
mattijs committed
154
                DynamicList<segment>&,
mattijs's avatar
mattijs committed
155
156
157
158
159
160
                DynamicList<label>&,
                List<DynamicList<label> >&
            ) const;

            //- Divide edges into local and remote segments. Construct map to
            //  distribute and collect data.
mattijs's avatar
mattijs committed
161
            autoPtr<mapDistribute> distributeSegments
mattijs's avatar
mattijs committed
162
163
164
165
            (
                const pointField& start,
                const pointField& end,

mattijs's avatar
mattijs committed
166
                List<segment>& allSegments,
mattijs's avatar
mattijs committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
                List<label>& allSegmentMap
            ) const;

            //- Split edges, distribute, test and collect.
            void findLine
            (
                const bool nearestIntersection,
                const pointField& start,
                const pointField& end,
                List<pointIndexHit>& info
            ) const;


        // Triangle index

            //- Obtains global indices from pointIndexHit and swaps them back
            //  to their original processor. Used to calculate local region
            //  and normal.
            autoPtr<mapDistribute> calcLocalQueries
            (
                const List<pointIndexHit>&,
                labelList& triangleIndex
            ) const;


        // Nearest

            label calcOverlappingProcs
            (
                const point& centre,
                const scalar radiusSqr,
                boolList& overlaps
            ) const;

            autoPtr<mapDistribute> calcLocalQueries
            (
                const pointField& centres,
                const scalarField& radiusSqr,

                pointField& allCentres,
                scalarField& allRadiusSqr,
                labelList& allSegmentMap
            ) const;


        // Surface redistribution

mattijs's avatar
mattijs committed
214
215
216
217
218
219
            //- Finds new bounds based on an indepedent decomposition.
            List<List<treeBoundBox> > independentlyDistributedBbs
            (
                const triSurface&
            );

mattijs's avatar
mattijs committed
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
            //- Calculate surface bounding box
            void calcBounds(boundBox& bb, label& nPoints) const;

            //- Does any part of triangle overlap bb.
            static bool overlaps
            (
                const List<treeBoundBox>& bb,
                const point& p0,
                const point& p1,
                const point& p2
            );

            //- Find points used in subset
            static void subsetMeshMap
            (
                const triSurface& s,
                const boolList& include,
                const label nIncluded,
                labelList& newToOldPoints,
                labelList& oldToNewPoints,
                labelList& newToOldFaces
            );

            //- Construct subsetted surface
            static triSurface subsetMesh
            (
                const triSurface& s,
                const labelList& newToOldPoints,
                const labelList& oldToNewPoints,
                const labelList& newToOldFaces
            );

            //- Subset given marked faces
            static triSurface subsetMesh
            (
                const triSurface& s,
                const boolList& include,
                labelList& newToOldPoints,
                labelList& newToOldFaces
            );

            //- Subset given marked faces
            static triSurface subsetMesh
            (
                const triSurface& s,
                const labelList& newToOldFaces,
                labelList& newToOldPoints
            );

            //- Find triangle otherF in allFaces.
            static label findTriangle
            (
                const List<labelledTri>& allFaces,
                const labelListList& allPointFaces,
                const labelledTri& otherF
            );

            //- Merge triSurface (subTris, subPoints) into allTris, allPoints.
            static void merge
            (
                const scalar mergeDist,
                const List<labelledTri>& subTris,
                const pointField& subPoints,

                List<labelledTri>& allTris,
                pointField& allPoints,

                labelList& faceConstructMap,
                labelList& pointConstructMap
            );

            //- Distribute stored fields
            template<class Type>
            void distributeFields(const mapDistribute& map);


        //- Disallow default bitwise copy construct
        distributedTriSurfaceMesh(const distributedTriSurfaceMesh&);

        //- Disallow default bitwise assignment
        void operator=(const distributedTriSurfaceMesh&);


public:

    //- Runtime type information
    TypeName("distributedTriSurfaceMesh");


    // Constructors

        //- Construct from triSurface
        distributedTriSurfaceMesh
        (
            const IOobject&,
            const triSurface&,
            const dictionary& dict
        );

mattijs's avatar
mattijs committed
319
        //- Construct read. Does findInstance to find io.local().
mattijs's avatar
mattijs committed
320
321
        distributedTriSurfaceMesh(const IOobject& io);

mattijs's avatar
mattijs committed
322
323
        //- Construct from dictionary (used by searchableSurface).
        //  Does read. Does findInstance to find io.local().
mattijs's avatar
mattijs committed
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
        distributedTriSurfaceMesh
        (
            const IOobject& io,
            const dictionary& dict
        );


    // Destructor

        virtual ~distributedTriSurfaceMesh();

        //- Clear storage
        void clearOut();


    // Member Functions

        //- Triangle indexing (demand driven)
        const globalIndex& globalTris() const;


        // searchableSurface implementation

            //- Whether supports volume type below. I.e. whether is closed.
            //  Not supported.
            virtual bool hasVolumeType() const
            {
                return false;
            }

            //- Range of global indices that can be returned.
            virtual label globalSize() const
            {
                const labelList& offsets = globalTris().offsets();
                return offsets[offsets.size()-1];
            }

            virtual void findNearest
            (
                const pointField& sample,
                const scalarField& nearestDistSqr,
                List<pointIndexHit>&
            ) const;

            virtual void findLine
            (
                const pointField& start,
                const pointField& end,
                List<pointIndexHit>&
            ) const;

            virtual void findLineAny
            (
                const pointField& start,
                const pointField& end,
                List<pointIndexHit>&
            ) const;

            //- Get all intersections in order from start to end.
            virtual void findLineAll
            (
                const pointField& start,
                const pointField& end,
                List<List<pointIndexHit> >&
            ) const;

            //- From a set of points and indices get the region
            virtual void getRegion
            (
                const List<pointIndexHit>&,
                labelList& region
            ) const;

            //- From a set of points and indices get the normal
            virtual void getNormal
            (
                const List<pointIndexHit>&,
                vectorField& normal
            ) const;

            //- Determine type (inside/outside/mixed) for point. unknown if
            //  cannot be determined (e.g. non-manifold surface)
            virtual void getVolumeType
            (
                const pointField&,
                List<volumeType>&
            ) const;

            //- Set bounds of surface. Bounds currently set as list of
            //  bounding boxes. Will do redistribution of surface to locally
            //  have all triangles overlapping bounds.
            //  Larger bounds: more triangles (memory), more fully local tests
            //  (quick).
            //  keepNonLocal = true : keep triangles that do not overlap
            //  any processor bounds.
            //  Should really be split into a routine to determine decomposition
            //  and one that does actual distribution but determining
            //  decomposition with duplicate triangle merging requires
            //  same amoun as work as actual distribution.
            virtual void distribute
            (
                const List<treeBoundBox>&,
                const bool keepNonLocal,
                autoPtr<mapDistribute>& faceMap,
                autoPtr<mapDistribute>& pointMap
            );


        // Other

            //- Specific to triSurfaceMesh: from a set of hits (points and
            //  indices) get the specified field. Misses do not get set.
            virtual void getField
            (
                const word& fieldName,
                const List<pointIndexHit>&,
                labelList& values
            ) const;

            //- Subset the part of surface that is overlapping bounds.
            static triSurface overlappingSurface
            (
                const triSurface&,
                const List<treeBoundBox>&,
                labelList& subPointMap,
                labelList& subFaceMap
            );

            //- Print some stats. Parallel aware version of
            //  triSurface::writeStats.
            void writeStats(Ostream& os) const;


        // regIOobject implementation

            //- Write using given format, version and compression
            virtual bool writeObject
            (
                IOstream::streamFormat fmt,
                IOstream::versionNumber ver,
                IOstream::compressionType cmp
            ) const;

};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#ifdef NoRepository
#   include "distributedTriSurfaceMeshTemplates.C"
#endif

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //