FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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