1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
26 Foam::distributedTriSurfaceMesh
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
45 distributedTriSurfaceMesh.C
47 \*---------------------------------------------------------------------------*/
49 #ifndef distributedTriSurfaceMesh_H
50 #define distributedTriSurfaceMesh_H
52 #include "triSurfaceMesh.H"
53 #include "IOdictionary.H"
55 #include "globalIndex.H"
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 class decompositionMethod;
66 typedef Pair<point> segment;
68 inline bool contiguous<segment>() {return contiguous<point>();}
71 /*---------------------------------------------------------------------------*\
72 Class distributedTriSurfaceMesh Declaration
73 \*---------------------------------------------------------------------------*/
75 class distributedTriSurfaceMesh
90 static const NamedEnum<distributionType, 3> distributionTypeNames_;
94 // Private member data
99 //- Decomposition used when independently decomposing surface.
100 autoPtr<decompositionMethod> decomposer_;
102 //- Bounding box settings
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
119 //- Read my additional data
127 const List<treeBoundBox>& myBbs,
132 //- Split segment into subsegments overlapping the processor
134 //void Foam::distributedTriSurfaceMesh::splitSegment
136 // const label segmentI,
137 // const point& start,
139 // const treeBoundBox& bb,
141 // DynamicList<segment>& allSegments,
142 // DynamicList<label>& allSegmentMap,
143 // DynamicList<label> sendMap
146 //- Distribute segments into overlapping processor
147 // bounding boxes. Sort per processor.
148 void distributeSegment
154 DynamicList<segment>&,
156 List<DynamicList<label> >&
159 //- Divide edges into local and remote segments. Construct map to
160 // distribute and collect data.
161 autoPtr<mapDistribute> distributeSegments
163 const pointField& start,
164 const pointField& end,
166 List<segment>& allSegments,
167 List<label>& allSegmentMap
170 //- Split edges, distribute, test and collect.
173 const bool nearestIntersection,
174 const pointField& start,
175 const pointField& end,
176 List<pointIndexHit>& info
182 //- Obtains global indices from pointIndexHit and swaps them back
183 // to their original processor. Used to calculate local region
185 autoPtr<mapDistribute> calcLocalQueries
187 const List<pointIndexHit>&,
188 labelList& triangleIndex
194 label calcOverlappingProcs
197 const scalar radiusSqr,
201 autoPtr<mapDistribute> calcLocalQueries
203 const pointField& centres,
204 const scalarField& radiusSqr,
206 pointField& allCentres,
207 scalarField& allRadiusSqr,
208 labelList& allSegmentMap
212 // Surface redistribution
214 //- Finds new bounds based on an indepedent decomposition.
215 List<List<treeBoundBox> > independentlyDistributedBbs
220 //- Calculate surface bounding box
221 void calcBounds(boundBox& bb, label& nPoints) const;
223 //- Does any part of triangle overlap bb.
226 const List<treeBoundBox>& bb,
232 //- Find points used in subset
233 static void subsetMeshMap
236 const boolList& include,
237 const label nIncluded,
238 labelList& newToOldPoints,
239 labelList& oldToNewPoints,
240 labelList& newToOldFaces
243 //- Construct subsetted surface
244 static triSurface subsetMesh
247 const labelList& newToOldPoints,
248 const labelList& oldToNewPoints,
249 const labelList& newToOldFaces
252 //- Subset given marked faces
253 static triSurface subsetMesh
256 const boolList& include,
257 labelList& newToOldPoints,
258 labelList& newToOldFaces
261 //- Subset given marked faces
262 static triSurface subsetMesh
265 const labelList& newToOldFaces,
266 labelList& newToOldPoints
269 //- Find triangle otherF in allFaces.
270 static label findTriangle
272 const List<labelledTri>& allFaces,
273 const labelListList& allPointFaces,
274 const labelledTri& otherF
277 //- Merge triSurface (subTris, subPoints) into allTris, allPoints.
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
291 //- Distribute stored fields
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&);
305 //- Runtime type information
306 TypeName("distributedTriSurfaceMesh");
311 //- Construct from triSurface
312 distributedTriSurfaceMesh
316 const dictionary& dict
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
327 const dictionary& dict
333 virtual ~distributedTriSurfaceMesh();
341 //- Triangle indexing (demand driven)
342 const globalIndex& globalTris() const;
345 // searchableSurface implementation
347 //- Whether supports volume type below. I.e. whether is closed.
349 virtual bool hasVolumeType() const
354 //- Range of global indices that can be returned.
355 virtual label globalSize() const
357 return globalTris().size();
360 virtual void findNearest
362 const pointField& sample,
363 const scalarField& nearestDistSqr,
367 virtual void findLine
369 const pointField& start,
370 const pointField& end,
374 virtual void findLineAny
376 const pointField& start,
377 const pointField& end,
381 //- Get all intersections in order from start to end.
382 virtual void findLineAll
384 const pointField& start,
385 const pointField& end,
386 List<List<pointIndexHit> >&
389 //- From a set of points and indices get the region
390 virtual void getRegion
392 const List<pointIndexHit>&,
396 //- From a set of points and indices get the normal
397 virtual void getNormal
399 const List<pointIndexHit>&,
403 //- Determine type (inside/outside/mixed) for point. unknown if
404 // cannot be determined (e.g. non-manifold surface)
405 virtual void getVolumeType
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
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
424 const List<treeBoundBox>&,
425 const bool keepNonLocal,
426 autoPtr<mapDistribute>& faceMap,
427 autoPtr<mapDistribute>& pointMap
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
437 const word& fieldName,
438 const List<pointIndexHit>&,
442 //- Subset the part of surface that is overlapping bounds.
443 static triSurface overlappingSurface
446 const List<treeBoundBox>&,
447 labelList& subPointMap,
448 labelList& subFaceMap
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
461 IOstream::streamFormat fmt,
462 IOstream::versionNumber ver,
463 IOstream::compressionType cmp
469 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
471 } // End namespace Foam
473 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
476 # include "distributedTriSurfaceMeshTemplates.C"
479 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
483 // ************************************************************************* //