OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

distributedTriSurfaceMesh.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::distributedTriSurfaceMesh
00027 
00028 Description
00029     IOoject and searching on distributed triSurface. All processor hold
00030     (possibly overlapping) part of the overall surface. All queries are
00031     distributed to the processor that can answer it and the result sent back.
00032 
00033     Can work in three modes:
00034     - follow : makes sure each processor has all the triangles inside the
00035     externally provided bounding box (usually the mesh bounding box).
00036     Guarantees minimum amount of communication since mesh-local queries
00037     should be answerable without any comms.
00038     - independent : surface is decomposed according to the triangle centres
00039     so the decomposition might be radically different from the mesh
00040     decomposition. Guarantees best memory balance but at the expense of
00041     more communication.
00042     - frozen : no change
00043 
00044 SourceFiles
00045     distributedTriSurfaceMesh.C
00046 
00047 \*---------------------------------------------------------------------------*/
00048 
00049 #ifndef distributedTriSurfaceMesh_H
00050 #define distributedTriSurfaceMesh_H
00051 
00052 #include "triSurfaceMesh.H"
00053 #include "IOdictionary.H"
00054 #include "Pair.H"
00055 #include "globalIndex.H"
00056 
00057 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00058 
00059 namespace Foam
00060 {
00061 
00062 class mapDistribute;
00063 class decompositionMethod;
00064 
00065 // Typedefs
00066 typedef Pair<point> segment;
00067 template<>
00068 inline bool contiguous<segment>() {return contiguous<point>();}
00069 
00070 
00071 /*---------------------------------------------------------------------------*\
00072                            Class distributedTriSurfaceMesh Declaration
00073 \*---------------------------------------------------------------------------*/
00074 
00075 class distributedTriSurfaceMesh
00076 :
00077     public triSurfaceMesh
00078 {
00079 public:
00080 
00081     // Static data
00082 
00083         enum distributionType
00084         {
00085             FOLLOW = 0,
00086             INDEPENDENT = 1,
00087             FROZEN = 2
00088         };
00089 
00090         static const NamedEnum<distributionType, 3> distributionTypeNames_;
00091 
00092 private:
00093 
00094     // Private member data
00095 
00096         //- Merging distance
00097         scalar mergeDist_;
00098 
00099         //- Decomposition used when independently decomposing surface.
00100         autoPtr<decompositionMethod> decomposer_;
00101 
00102         //- Bounding box settings
00103         IOdictionary dict_;
00104 
00105         //- bounding boxes of all processors
00106         List<List<treeBoundBox> > procBb_;
00107 
00108         //- Global triangle numbering
00109         mutable autoPtr<globalIndex> globalTris_;
00110 
00111         //- The distribution type.
00112         distributionType distType_;
00113 
00114 
00115     // Private Member Functions
00116 
00117         // Read
00118 
00119             //- Read my additional data
00120             bool read();
00121 
00122 
00123         // Line intersection
00124 
00125             static bool isLocal
00126             (
00127                 const List<treeBoundBox>& myBbs,
00128                 const point& start,
00129                 const point& end
00130             );
00131 
00132             //- Split segment into subsegments overlapping the processor
00133             //  bounding box.
00134             //void Foam::distributedTriSurfaceMesh::splitSegment
00135             //(
00136             //    const label segmentI,
00137             //    const point& start,
00138             //    const point& end,
00139             //    const treeBoundBox& bb,
00140             //
00141             //    DynamicList<segment>& allSegments,
00142             //    DynamicList<label>& allSegmentMap,
00143             //    DynamicList<label> sendMap
00144             //) const
00145 
00146             //- Distribute segments into overlapping processor
00147             //  bounding boxes. Sort per processor.
00148             void distributeSegment
00149             (
00150                 const label,
00151                 const point& start,
00152                 const point& end,
00153 
00154                 DynamicList<segment>&,
00155                 DynamicList<label>&,
00156                 List<DynamicList<label> >&
00157             ) const;
00158 
00159             //- Divide edges into local and remote segments. Construct map to
00160             //  distribute and collect data.
00161             autoPtr<mapDistribute> distributeSegments
00162             (
00163                 const pointField& start,
00164                 const pointField& end,
00165 
00166                 List<segment>& allSegments,
00167                 List<label>& allSegmentMap
00168             ) const;
00169 
00170             //- Split edges, distribute, test and collect.
00171             void findLine
00172             (
00173                 const bool nearestIntersection,
00174                 const pointField& start,
00175                 const pointField& end,
00176                 List<pointIndexHit>& info
00177             ) const;
00178 
00179 
00180         // Triangle index
00181 
00182             //- Obtains global indices from pointIndexHit and swaps them back
00183             //  to their original processor. Used to calculate local region
00184             //  and normal.
00185             autoPtr<mapDistribute> calcLocalQueries
00186             (
00187                 const List<pointIndexHit>&,
00188                 labelList& triangleIndex
00189             ) const;
00190 
00191 
00192         // Nearest
00193 
00194             label calcOverlappingProcs
00195             (
00196                 const point& centre,
00197                 const scalar radiusSqr,
00198                 boolList& overlaps
00199             ) const;
00200 
00201             autoPtr<mapDistribute> calcLocalQueries
00202             (
00203                 const pointField& centres,
00204                 const scalarField& radiusSqr,
00205 
00206                 pointField& allCentres,
00207                 scalarField& allRadiusSqr,
00208                 labelList& allSegmentMap
00209             ) const;
00210 
00211 
00212         // Surface redistribution
00213 
00214             //- Finds new bounds based on an indepedent decomposition.
00215             List<List<treeBoundBox> > independentlyDistributedBbs
00216             (
00217                 const triSurface&
00218             );
00219 
00220             //- Calculate surface bounding box
00221             void calcBounds(boundBox& bb, label& nPoints) const;
00222 
00223             //- Does any part of triangle overlap bb.
00224             static bool overlaps
00225             (
00226                 const List<treeBoundBox>& bb,
00227                 const point& p0,
00228                 const point& p1,
00229                 const point& p2
00230             );
00231 
00232             //- Find points used in subset
00233             static void subsetMeshMap
00234             (
00235                 const triSurface& s,
00236                 const boolList& include,
00237                 const label nIncluded,
00238                 labelList& newToOldPoints,
00239                 labelList& oldToNewPoints,
00240                 labelList& newToOldFaces
00241             );
00242 
00243             //- Construct subsetted surface
00244             static triSurface subsetMesh
00245             (
00246                 const triSurface& s,
00247                 const labelList& newToOldPoints,
00248                 const labelList& oldToNewPoints,
00249                 const labelList& newToOldFaces
00250             );
00251 
00252             //- Subset given marked faces
00253             static triSurface subsetMesh
00254             (
00255                 const triSurface& s,
00256                 const boolList& include,
00257                 labelList& newToOldPoints,
00258                 labelList& newToOldFaces
00259             );
00260 
00261             //- Subset given marked faces
00262             static triSurface subsetMesh
00263             (
00264                 const triSurface& s,
00265                 const labelList& newToOldFaces,
00266                 labelList& newToOldPoints
00267             );
00268 
00269             //- Find triangle otherF in allFaces.
00270             static label findTriangle
00271             (
00272                 const List<labelledTri>& allFaces,
00273                 const labelListList& allPointFaces,
00274                 const labelledTri& otherF
00275             );
00276 
00277             //- Merge triSurface (subTris, subPoints) into allTris, allPoints.
00278             static void merge
00279             (
00280                 const scalar mergeDist,
00281                 const List<labelledTri>& subTris,
00282                 const pointField& subPoints,
00283 
00284                 List<labelledTri>& allTris,
00285                 pointField& allPoints,
00286 
00287                 labelList& faceConstructMap,
00288                 labelList& pointConstructMap
00289             );
00290 
00291             //- Distribute stored fields
00292             template<class Type>
00293             void distributeFields(const mapDistribute& map);
00294 
00295 
00296         //- Disallow default bitwise copy construct
00297         distributedTriSurfaceMesh(const distributedTriSurfaceMesh&);
00298 
00299         //- Disallow default bitwise assignment
00300         void operator=(const distributedTriSurfaceMesh&);
00301 
00302 
00303 public:
00304 
00305     //- Runtime type information
00306     TypeName("distributedTriSurfaceMesh");
00307 
00308 
00309     // Constructors
00310 
00311         //- Construct from triSurface
00312         distributedTriSurfaceMesh
00313         (
00314             const IOobject&,
00315             const triSurface&,
00316             const dictionary& dict
00317         );
00318 
00319         //- Construct read. Does findInstance to find io.local().
00320         distributedTriSurfaceMesh(const IOobject& io);
00321 
00322         //- Construct from dictionary (used by searchableSurface).
00323         //  Does read. Does findInstance to find io.local().
00324         distributedTriSurfaceMesh
00325         (
00326             const IOobject& io,
00327             const dictionary& dict
00328         );
00329 
00330 
00331     // Destructor
00332 
00333         virtual ~distributedTriSurfaceMesh();
00334 
00335         //- Clear storage
00336         void clearOut();
00337 
00338 
00339     // Member Functions
00340 
00341         //- Triangle indexing (demand driven)
00342         const globalIndex& globalTris() const;
00343 
00344 
00345         // searchableSurface implementation
00346 
00347             //- Whether supports volume type below. I.e. whether is closed.
00348             //  Not supported.
00349             virtual bool hasVolumeType() const
00350             {
00351                 return false;
00352             }
00353 
00354             //- Range of global indices that can be returned.
00355             virtual label globalSize() const
00356             {
00357                 return globalTris().size();
00358             }
00359 
00360             virtual void findNearest
00361             (
00362                 const pointField& sample,
00363                 const scalarField& nearestDistSqr,
00364                 List<pointIndexHit>&
00365             ) const;
00366 
00367             virtual void findLine
00368             (
00369                 const pointField& start,
00370                 const pointField& end,
00371                 List<pointIndexHit>&
00372             ) const;
00373 
00374             virtual void findLineAny
00375             (
00376                 const pointField& start,
00377                 const pointField& end,
00378                 List<pointIndexHit>&
00379             ) const;
00380 
00381             //- Get all intersections in order from start to end.
00382             virtual void findLineAll
00383             (
00384                 const pointField& start,
00385                 const pointField& end,
00386                 List<List<pointIndexHit> >&
00387             ) const;
00388 
00389             //- From a set of points and indices get the region
00390             virtual void getRegion
00391             (
00392                 const List<pointIndexHit>&,
00393                 labelList& region
00394             ) const;
00395 
00396             //- From a set of points and indices get the normal
00397             virtual void getNormal
00398             (
00399                 const List<pointIndexHit>&,
00400                 vectorField& normal
00401             ) const;
00402 
00403             //- Determine type (inside/outside/mixed) for point. unknown if
00404             //  cannot be determined (e.g. non-manifold surface)
00405             virtual void getVolumeType
00406             (
00407                 const pointField&,
00408                 List<volumeType>&
00409             ) const;
00410 
00411             //- Set bounds of surface. Bounds currently set as list of
00412             //  bounding boxes. Will do redistribution of surface to locally
00413             //  have all triangles overlapping bounds.
00414             //  Larger bounds: more triangles (memory), more fully local tests
00415             //  (quick).
00416             //  keepNonLocal = true : keep triangles that do not overlap
00417             //  any processor bounds.
00418             //  Should really be split into a routine to determine decomposition
00419             //  and one that does actual distribution but determining
00420             //  decomposition with duplicate triangle merging requires
00421             //  same amoun as work as actual distribution.
00422             virtual void distribute
00423             (
00424                 const List<treeBoundBox>&,
00425                 const bool keepNonLocal,
00426                 autoPtr<mapDistribute>& faceMap,
00427                 autoPtr<mapDistribute>& pointMap
00428             );
00429 
00430 
00431         // Other
00432 
00433             //- Specific to triSurfaceMesh: from a set of hits (points and
00434             //  indices) get the specified field. Misses do not get set.
00435             virtual void getField
00436             (
00437                 const word& fieldName,
00438                 const List<pointIndexHit>&,
00439                 labelList& values
00440             ) const;
00441 
00442             //- Subset the part of surface that is overlapping bounds.
00443             static triSurface overlappingSurface
00444             (
00445                 const triSurface&,
00446                 const List<treeBoundBox>&,
00447                 labelList& subPointMap,
00448                 labelList& subFaceMap
00449             );
00450 
00451             //- Print some stats. Parallel aware version of
00452             //  triSurface::writeStats.
00453             void writeStats(Ostream& os) const;
00454 
00455 
00456         // regIOobject implementation
00457 
00458             //- Write using given format, version and compression
00459             virtual bool writeObject
00460             (
00461                 IOstream::streamFormat fmt,
00462                 IOstream::versionNumber ver,
00463                 IOstream::compressionType cmp
00464             ) const;
00465 
00466 };
00467 
00468 
00469 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00470 
00471 } // End namespace Foam
00472 
00473 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00474 
00475 #ifdef NoRepository
00476 #   include "distributedTriSurfaceMeshTemplates.C"
00477 #endif
00478 
00479 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00480 
00481 #endif
00482 
00483 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd