OpenFOAM logo
Open Source CFD Toolkit

faceCoupleInfo.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-2005 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00024 
00025 Class
00026     faceCoupleInfo
00027 
00028 Description
00029     Container for information needed to couple to meshes. When constructed from
00030     two meshes and a geometric tolerance finds the corresponding boundary faces.
00031 
00032     The information it keeps is the set of faces&points (cutFaces, cutPoints)
00033     that should replace a set of faces on the master (masterPatch) and
00034     a set of faces on the slave (slavePatch)
00035 
00036 
00037     Uses same tolerance to match faces and points on matched faces since
00038     they both originate from the same points and the tolerance usually
00039     comes from writing these points with limited precision (6 by default)
00040 
00041     Can be constructed from slave being subdivision of master with the
00042     polyPatch constructor:
00043 
00044     Notes on multiple slave faces per master:
00045 
00046     As long as
00047     - all master edges are present in slave
00048     - slave can have extra edges/points
00049     So master:
00050     +-------+
00051     |       |
00052     |       |
00053     |       |
00054     |       |
00055     |       |
00056     |       |
00057     |       |
00058     +-------+
00059 
00060     slave:
00061     +---+---+
00062     |\  |  /|
00063     | \ | / |
00064     |  \|/  |
00065     +---+---+
00066     |  /|\  |
00067     | / | \ |
00068     |/  |  \|
00069     +---+---+
00070 
00071     is ok.
00072 
00073     For this kind of matching the order is:
00074     - match cutpoint to masterpoint
00075     - find those cutEdges that align with a master edge. This gives two sets
00076       of cut edges: those that have a master equivalent ('border edges') and
00077       those that don't ('internal edges'). The border edges now divide the
00078       cutFaces into regions with the same masterFace correspondence.
00079     - find cutFaces that are fully determined by the border edges they use.
00080     - all cutFaces that are connected through an internal edge have the same
00081       master face.
00082 
00083 SourceFiles
00084     faceCoupleInfo.C
00085 
00086 
00087 \*---------------------------------------------------------------------------*/
00088 
00089 #ifndef faceCoupleInfo_H
00090 #define faceCoupleInfo_H
00091 
00092 #include "pointField.H"
00093 #include "indirectPrimitivePatch.H"
00094 #include "primitiveFacePatch.H"
00095 
00096 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00097 
00098 namespace Foam
00099 {
00100 
00101 // Class forward declarations
00102 class face;
00103 class primitiveMesh;
00104 class polyPatch;
00105 class polyMesh;
00106 
00107 /*---------------------------------------------------------------------------*\
00108                            Class faceCoupleInfo Declaration
00109 \*---------------------------------------------------------------------------*/
00110 
00111 class faceCoupleInfo
00112 {
00113     // Private data
00114 
00115         //- Angle matching tolerance.
00116         static const scalar angleTol_;
00117 
00118         //- Master patch
00119         autoPtr<indirectPrimitivePatch> masterPatchPtr_;
00120 
00121         //- Slave patch
00122         autoPtr<indirectPrimitivePatch> slavePatchPtr_;
00123 
00124 
00125         //- Description of cut.
00126         //  Consists of faces and points (note: could be expressed as some
00127         //  kind  of PrimitivePatch which holds points instead of reference to
00128         //  them)
00129         //  Orientation of cutFaces should be same as masterFaces!
00130         pointField cutPoints_;
00131         autoPtr<primitiveFacePatch> cutFacesPtr_;
00132 
00133         //- Additional point coupling information. Is between points on
00134         //  boundary of both meshes.
00135 
00136         // Addressing from cut
00137 
00138             //- map from cutFaces to masterPatch
00139             labelList cutToMasterFaces_;
00140             labelList cutToMasterPoints_;
00141             labelList cutToMasterEdges_;
00142 
00143             //- map from cutFaces to slavePatch
00144             labelList cutToSlaveFaces_;
00145             labelList cutToSlavePoints_;
00146             labelList cutToSlaveEdges_;
00147 
00148             //- map from master to cut (unique points)
00149             labelList masterToCutPoints_;
00150             labelList masterToCutEdges_;
00151             labelList slaveToCutPoints_;
00152             labelList slaveToCutEdges_;
00153 
00154 
00155     // Private Member Functions
00156 
00157         // Debugging
00158 
00159             //- Calculate face centres from (subset of) faces.
00160             static pointField calcFaceCentres
00161             (
00162                 const faceList&,
00163                 const pointField&,
00164                 const label start,
00165                 const label size
00166             );
00167 
00168             //- Write edges
00169             static void writeOBJ
00170             (
00171                 const fileName& fName,
00172                 const edgeList& edges,
00173                 const pointField& points,
00174                 const bool compact = true
00175             );
00176 
00177             //- Write edges
00178             static void writeOBJ
00179             (
00180                 const fileName& fName,
00181                 const pointField& points0,
00182                 const pointField& points1
00183             );
00184 
00185             //- Write connections between corresponding points and faces
00186             //  as .obj files.
00187             void writePointsFaces() const;
00188 
00189             //- Write connections between corresponding edges as .obj files.
00190             void writeEdges() const;
00191 
00192 
00193         // Edge handling/matching
00194 
00195             //- Find corresponding edges on patch when having only a map for
00196             //  the points.
00197             labelList findMappedEdges
00198             (
00199                 const edgeList& edges,
00200                 const labelList& pointMap,
00201                 const indirectPrimitivePatch&
00202             );
00203 
00204             //- Check if edge on slavePatch corresponds to an edge between faces
00205             //  in two different polyPatches on the mesh.
00206             bool regionEdge(const polyMesh&, const label slaveEdgeI) const;
00207 
00208             //- Finds edge connected to point most aligned with master edge.
00209             label mostAlignedCutEdge
00210             (
00211                 const bool report,
00212                 const polyMesh& slaveMesh,
00213                 const bool patchDivision,
00214                 const label pointI,
00215                 const label edgeStart,
00216                 const label edgeEnd
00217             ) const;
00218 
00219 
00220         // Face matching
00221 
00222             //- Returns max distance to masterF of any point on cutF.
00223             static scalar maxDistance
00224             (
00225                 const face& cutF,
00226                 const pointField& cutPoints,
00227                 const face& masterF,
00228                 const pointField& masterPoints
00229             );
00230 
00231             //- Finds matching (boundary)face centres.
00232             //  Since faces identical uses geometric match on face centres.
00233             static void findPerfectMatchingFaces
00234             (
00235                 const primitiveMesh& mesh0,
00236                 const primitiveMesh& mesh1,
00237                 const scalar absTol,
00238 
00239                 labelList& mesh0Faces,
00240                 labelList& mesh1Faces
00241             );
00242 
00243             //- Find matching (boundary)faces. Matching if slave is on top of
00244             //  master face (slaves is subdivision of master)
00245             static void findSlavesCoveringMaster
00246             (
00247                 const primitiveMesh& mesh0,
00248                 const primitiveMesh& mesh1,
00249                 const scalar absTol,
00250 
00251                 labelList& mesh0Faces,
00252                 labelList& mesh1Faces
00253             );
00254 
00255             //- Grow cutToMasterFace across 'internal' edges.
00256             label growCutFaces(Map<labelList>&);
00257 
00258             void checkMatch() const;
00259 
00260             //- Gets a list of cutFaces (that use a master edge) and the
00261             // candidate master faces.
00262             // Checks among these master faces if there is only one remaining
00263             // unmatched one.
00264             label matchEdgeFaces(Map<labelList>& candidates);
00265 
00266             //- Gets a list of cutFaces (that use a master edge) and the
00267             //  candidate master faces.
00268             //  Finds most aligned master face.
00269             label geometricMatchEdgeFaces(Map<labelList>& candidates);
00270 
00271 
00272         //- Find point and edge correspondence for perfect matching faces
00273         void perfectPointMatch(const scalar absTol, const bool);
00274 
00275         //- Find point and edge correspondence for slaves being subdivision of
00276         //  master.
00277         void subDivisionMatch
00278         (
00279             const polyMesh& slaveMesh,
00280             const bool patchDivision,
00281             const scalar absTol
00282         );
00283 
00284 public:
00285 
00286     //- Runtime type information
00287     ClassName("faceCoupleInfo");
00288 
00289 
00290     // Constructors
00291 
00292         //- Construct from two meshes and absolute tolerance.
00293         //  Finds out matches geometrically. No checking for nonsense match.
00294         //  Tolerance is absolute one so use with care.
00295         //  perfectMatch : each point/edge/face has corresponding point on other
00296         //                 side
00297         faceCoupleInfo
00298         (
00299             const polyMesh& mesh0,
00300             const polyMesh& mesh1,
00301             const scalar absTol,
00302             const bool perfectMatch
00303         );
00304 
00305         //- Construct from meshes and subset of mesh faces
00306         //  (i.e. indirectPrimitivePatch addressing)
00307         //  All faces in patch are considered matched (but don't have to be 
00308         //  ordered)
00309         //  perfectMatch : each point/edge/face has corresponding point on other
00310         //                 side
00311         //  orderedFaces : faces in patch are ordered (so masterAddressing[i]
00312         //  matches slaveAddressing[i])
00313         //  patchDivision: faces in slave mesh that originate from the
00314         //  same master face have the same patch. Used by some triangulation
00315         //  methods.
00316         faceCoupleInfo
00317         (
00318             const polyMesh& masterMesh,
00319             const labelList& masterAddressing,
00320             const polyMesh& slaveMesh,
00321             const labelList& slaveAddressing,
00322             const scalar absTol,
00323             const bool perfectMatch,
00324             const bool orderedFaces,
00325             const bool patchDivision
00326         );
00327 
00328 
00329     // Destructor
00330 
00331         ~faceCoupleInfo();
00332 
00333 
00334 
00335     // Member Functions
00336 
00337         //- Utility functions
00338 
00339             //- Get patch face labels
00340             static labelList faceLabels(const polyPatch&);
00341 
00342             //- Create Map from List
00343             static Map<label> makeMap(const labelList&);
00344             static Map<labelList> makeMap(const labelListList&);
00345 
00346 
00347         // Access
00348 
00349             //- Addressing engine for coupled faces on mesh0
00350             const indirectPrimitivePatch& masterPatch() const
00351             {
00352                 return masterPatchPtr_();
00353             }
00354 
00355             //- Addressing engine for coupled faces on mesh1
00356             const indirectPrimitivePatch& slavePatch() const
00357             {
00358                 return slavePatchPtr_();
00359             }
00360 
00361             //- Addressing engine for combined set of faces.
00362             const primitiveFacePatch& cutFaces() const
00363             {
00364                 return cutFacesPtr_();
00365             }
00366 
00367             //- Points for combined set of faces.
00368             const pointField& cutPoints() const
00369             {
00370                 return cutPoints_;
00371             }
00372 
00373 
00374             //- Master face for every face on cut. Will always be at least
00375             //  one but there might be multiple cut faces pointing to the same
00376             //  master
00377             const labelList& cutToMasterFaces() const
00378             {
00379                 return cutToMasterFaces_;
00380             }
00381 
00382             //- Master point for every point on cut. -1 means no equivalent
00383             //  master point. All master points will be present though in cut.
00384             const labelList& cutToMasterPoints() const
00385             {
00386                 return cutToMasterPoints_;
00387             }
00388 
00389             //- Master edge for every edge on cut. -1 means no equivalent
00390             //  master edge. All master edges will be present though in cut.
00391             const labelList& cutToMasterEdges() const
00392             {
00393                 return cutToMasterEdges_;
00394             }
00395 
00396             //- Slave face for every face on cut. Will always be at least
00397             //  one but there might be multiple cut faces pointing to the same
00398             //  master
00399             const labelList& cutToSlaveFaces() const
00400             {
00401                 return cutToSlaveFaces_;
00402             }
00403 
00404             //- Slave point for every point on cut. -1 means no equivalent
00405             //  slave point. All slave points will be present though in cut.
00406             const labelList& cutToSlavePoints() const
00407             {
00408                 return cutToSlavePoints_;
00409             }
00410 
00411             //- Slave edge for every edge on cut. -1 means no equivalent
00412             //  slave edge. All slave edges will be present though in cut.
00413             const labelList& cutToSlaveEdges() const
00414             {
00415                 return cutToSlaveEdges_;
00416             }
00417  
00418 
00419             const labelList& masterToCutPoints() const
00420             {
00421                 return masterToCutPoints_;
00422             }
00423             const labelList& masterToCutEdges() const
00424             {
00425                 return masterToCutEdges_;
00426             }
00427             const labelList& slaveToCutPoints() const
00428             {
00429                 return slaveToCutPoints_;
00430             }
00431             const labelList& slaveToCutEdges() const
00432             {
00433                 return slaveToCutEdges_;
00434             }
00435 
00436 };
00437 
00438 
00439 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00440 
00441 } // End namespace Foam
00442 
00443 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00444 
00445 #endif
00446 
00447 // ************************************************************************* //
For further information go to www.openfoam.org