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

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-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::faceCoupleInfo
00027 
00028 Description
00029     Container for information needed to couple to meshes. When constructed
00030     from two meshes and a geometric tolerance finds the corresponding
00031     boundary faces.
00032 
00033     The information it keeps is the set of faces&points (cutFaces,
00034     cutPoints) that should replace a set of faces on the master
00035     (masterPatch) and a set of faces on the slave (slavePatch)
00036 
00037 
00038     Uses same tolerance to match faces and points on matched faces since
00039     they both originate from the same points and the tolerance usually
00040     comes from writing these points with limited precision (6 by default)
00041 
00042     -# Perfect match:
00043        - one-to-one match for faces and points.
00044        - the cut is always the 'most connected' of the master and slave so
00045          multiple master or slave points might point to the same cut point.
00046 
00047     @verbatim
00048     e.g. master:
00049     
00050         +--+
00051         |  |
00052         |  |
00053         +--+
00054             +--+
00055             |  |
00056             |  |
00057             +--+
00058     slave:
00059             +--+
00060             |  |
00061             |  |
00062             +--+
00063         +--+
00064         |  |
00065         |  |
00066         +--+
00067     @endverbatim
00068     adding both together creates a singly connected 2x2 cavity so suddenly
00069     the duplicate master points and the duplicate slave points all become
00070     a single cut point.
00071 
00072 
00073     -# Subdivision match:
00074        - Can be constructed from slave being subdivision of master with the
00075          polyPatch constructor.
00076        - Does not include above shared-point detection!
00077 
00078     Notes on multiple slave faces per master:
00079 
00080     As long as
00081     - all master edges are present in slave
00082     - slave can have extra edges/points/faces BUT all subfaces have to have
00083       at least one point on a maste face.
00084 
00085     @verbatim
00086     So master:
00087     +-------+
00088     |       |
00089     |       |
00090     |       |
00091     |       |
00092     |       |
00093     |       |
00094     |       |
00095     +-------+
00096 
00097     slave:
00098     +---+---+
00099     |\  |  /|
00100     | \ | / |
00101     |  \|/  |
00102     +---+---+
00103     |  /|\  |
00104     | / | \ |
00105     |/  |  \|
00106     +---+---+
00107     is ok.
00108     @endverbatim
00109 
00110     For this kind of matching the order is:
00111     - match cutpoint to masterpoint
00112     - find those cutEdges that align with a master edge. This gives two sets
00113       of cut edges: those that have a master equivalent ('border edges') and
00114       those that don't ('internal edges'). The border edges now divide the
00115       cutFaces into regions with the same masterFace correspondence.
00116     - find cutFaces that are fully determined by the border edges they use.
00117     - all cutFaces that are connected through an internal edge have the same
00118       master face.
00119 
00120 
00121     Note: matching refined faces onto master is a bit dodgy and will probably
00122     only work for unwarped faces. Also it will fail if e.g. face is split
00123     into 3x3 since then middle face has no point/edge in common with master.
00124     (problem is in face matching (findSlavesCoveringMaster), probably
00125      point/edge matching might just work)
00126 
00127 
00128 SourceFiles
00129     faceCoupleInfo.C
00130 
00131 
00132 \*---------------------------------------------------------------------------*/
00133 
00134 #ifndef faceCoupleInfo_H
00135 #define faceCoupleInfo_H
00136 
00137 #include "pointField.H"
00138 #include "indirectPrimitivePatch.H"
00139 #include "primitiveFacePatch.H"
00140 
00141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00142 
00143 namespace Foam
00144 {
00145 
00146 typedef HashTable<labelList, edge, Hash<edge> > edgeLookup;
00147 
00148 
00149 // Forward declaration of classes
00150 class face;
00151 class primitiveMesh;
00152 class polyPatch;
00153 class polyMesh;
00154 
00155 /*---------------------------------------------------------------------------*\
00156                            Class faceCoupleInfo Declaration
00157 \*---------------------------------------------------------------------------*/
00158 
00159 class faceCoupleInfo
00160 {
00161     // Private data
00162 
00163         //- Angle matching tolerance.
00164         static const scalar angleTol_;
00165 
00166         //- Master patch
00167         autoPtr<indirectPrimitivePatch> masterPatchPtr_;
00168 
00169         //- Slave patch
00170         autoPtr<indirectPrimitivePatch> slavePatchPtr_;
00171 
00172 
00173         //- Description of cut.
00174         //  - Cut is the matching area between the slave
00175         //  and the master.
00176         //  - cut is the finest of master and slave. It can never be
00177         //  coarser than either one of them. (so face addressing we keep is
00178         //  cut-to-master and cut-to-slave)
00179         //  - multiple master or slave points can end up becoming one cut point
00180         //  (so point addressing we keep is master-to-cut and slave-to-cut)
00181 
00182         //  Cut consists of faces and points (note: could be expressed as some
00183         //  kind of PrimitivePatch which holds points instead of reference to
00184         //  them)
00185         //  Orientation of cutFaces should be same as masterFaces!
00186         pointField cutPoints_;
00187         autoPtr<primitiveFacePatch> cutFacesPtr_;
00188 
00189         //- Additional point coupling information. Is between points on
00190         //  boundary of both meshes.
00191 
00192         // Addressing to/from cut
00193 
00194             //- master
00195             labelList cutToMasterFaces_;
00196             labelList masterToCutPoints_;
00197 
00198             //- slave
00199             labelList cutToSlaveFaces_;
00200             labelList slaveToCutPoints_;
00201 
00202             //- For edges originating from splitting of edges:
00203             //  given the two endpoints of the unsplit edge give the list
00204             //  of inbetween vertices
00205             edgeLookup cutEdgeToPoints_;
00206 
00207 
00208     // Private Member Functions
00209 
00210         // Debugging
00211 
00212             //- Calculate face centres from (subset of) faces.
00213             template<template<class> class FaceList>
00214             static pointField calcFaceCentres
00215             (
00216                 const FaceList<face>&,
00217                 const pointField&,
00218                 const label start,
00219                 const label size
00220             );
00221 
00222             //- Write edges
00223             static void writeOBJ
00224             (
00225                 const fileName& fName,
00226                 const edgeList& edges,
00227                 const pointField& points,
00228                 const bool compact = true
00229             );
00230 
00231             //- Write edges
00232             static void writeOBJ
00233             (
00234                 const fileName& fName,
00235                 const pointField& points0,
00236                 const pointField& points1
00237             );
00238 
00239             //- Write connections between corresponding points and faces
00240             //  as .obj files.
00241             void writePointsFaces() const;
00242 
00243             //- Write connections between corresponding edges as .obj files.
00244             void writeEdges(const labelList&, const labelList&) const;
00245 
00246 
00247         // Edge handling/matching
00248 
00249             //- Find corresponding edges on patch when having only a map for
00250             //  the points.
00251             labelList findMappedEdges
00252             (
00253                 const edgeList& edges,
00254                 const labelList& pointMap,
00255                 const indirectPrimitivePatch&
00256             );
00257 
00258             //- Check if edge on slavePatch corresponds to an edge between faces
00259             //  in two different polyPatches on the mesh.
00260             bool regionEdge(const polyMesh&, const label slaveEdgeI) const;
00261 
00262             //- Finds edge connected to point most aligned with master edge.
00263             label mostAlignedCutEdge
00264             (
00265                 const bool report,
00266                 const polyMesh& slaveMesh,
00267                 const bool patchDivision,
00268                 const labelList& cutToMasterEdges,
00269                 const labelList& cutToSlaveEdges,
00270                 const label pointI,
00271                 const label edgeStart,
00272                 const label edgeEnd
00273             ) const;
00274 
00275             //- From (many-to-one) map of cut edges to master edges determine
00276             //  points inbetween. I.e. just string up the edges. Stores this
00277             //  all on cutEdgeToPoints_
00278             void setCutEdgeToPoints(const labelList& cutToMasterEdges);
00279 
00280         // Face matching
00281 
00282             //- Matches two faces.Determines rotation for f1 to match up
00283             // with f0, i.e. the index in f0 of
00284             // the first point of f1.
00285             static label matchFaces
00286             (
00287                 const scalar absTol,
00288                 const pointField& points0,
00289                 const face& f0,
00290                 const pointField& points1,
00291                 const face& f1,
00292                 const bool sameOrientation
00293             );
00294 
00295             //- Matches points on patch to points on cut.
00296             static bool matchPointsThroughFaces
00297             (
00298                 const scalar absTol,
00299                 const pointField& cutPoints,
00300                 const faceList& cutFaces,
00301                 const pointField& patchPoints,
00302                 const faceList& patchFaces,
00303                 const bool sameOrientation,
00304 
00305                 labelList& patchToCutPoints,    // patch to (uncompacted) cut points
00306                 labelList& cutToCompact,        // compaction list
00307                 labelList& compactToCut         // compaction list
00308             );
00309 
00310             //- Returns max distance to masterF of any point on cutF.
00311             static scalar maxDistance
00312             (
00313                 const face& cutF,
00314                 const pointField& cutPoints,
00315                 const face& masterF,
00316                 const pointField& masterPoints
00317             );
00318 
00319             //- Finds matching (boundary)face centres.
00320             //  Since faces identical uses geometric match on face centres.
00321             static void findPerfectMatchingFaces
00322             (
00323                 const primitiveMesh& mesh0,
00324                 const primitiveMesh& mesh1,
00325                 const scalar absTol,
00326 
00327                 labelList& mesh0Faces,
00328                 labelList& mesh1Faces
00329             );
00330 
00331             //- Find matching (boundary)faces. Matching if slave is on top of
00332             //  master face (slaves is subdivision of master)
00333             static void findSlavesCoveringMaster
00334             (
00335                 const primitiveMesh& mesh0,
00336                 const primitiveMesh& mesh1,
00337                 const scalar absTol,
00338 
00339                 labelList& mesh0Faces,
00340                 labelList& mesh1Faces
00341             );
00342 
00343             //- Grow cutToMasterFace across 'internal' edges.
00344             label growCutFaces(const labelList&, Map<labelList>&);
00345 
00346             void checkMatch(const labelList& cutToMasterEdges) const;
00347 
00348             //- Gets a list of cutFaces (that use a master edge) and the
00349             // candidate master faces.
00350             // Checks among these master faces if there is only one remaining
00351             // unmatched one.
00352             label matchEdgeFaces(const labelList&, Map<labelList>& candidates);
00353 
00354             //- Gets a list of cutFaces (that use a master edge) and the
00355             //  candidate master faces.
00356             //  Finds most aligned master face.
00357             label geometricMatchEdgeFaces(Map<labelList>& candidates);
00358 
00359         //- Used by perfectPointMatch. Determine match from cut points to
00360         //  slave points (for perfect matching faces)
00361         void perfectSlavePointMatch(const scalar absTol);
00362 
00363         //- Find point and edge correspondence for perfect matching faces
00364         void perfectPointMatch(const scalar absTol, const bool);
00365 
00366         //- Find point and edge correspondence for slaves being subdivision of
00367         //  master.
00368         void subDivisionMatch
00369         (
00370             const polyMesh& slaveMesh,
00371             const bool patchDivision,
00372             const scalar absTol
00373         );
00374 
00375 public:
00376 
00377     //- Runtime type information
00378     ClassName("faceCoupleInfo");
00379 
00380 
00381     // Constructors
00382 
00383         //- Construct from two meshes and absolute tolerance.
00384         //  Finds out matches geometrically. No checking for nonsense match.
00385         //  Tolerance is absolute one so use with care.
00386         //  perfectMatch : each point/edge/face has corresponding point on other
00387         //                 side
00388         //                 if this is false then assumes slave is subdivision.
00389         //                 Matching then will work only for non-warped faces
00390         //                 since does nearest-to-face comparison with absTol.
00391         faceCoupleInfo
00392         (
00393             const polyMesh& mesh0,
00394             const polyMesh& mesh1,
00395             const scalar absTol,
00396             const bool perfectMatch
00397         );
00398 
00399         //- Construct from meshes and subset of mesh faces
00400         //  (i.e. indirectPrimitivePatch addressing)
00401         //  All faces in patch are considered matched (but don't have to be 
00402         //  ordered)
00403         //  perfectMatch : each point/edge/face has corresponding point on other
00404         //                 side
00405         //  orderedFaces : faces in patch are ordered (so masterAddressing[i]
00406         //  matches slaveAddressing[i])
00407         //  patchDivision: faces in slave mesh that originate from the
00408         //  same master face have the same patch. Used by some triangulation
00409         //  methods.
00410         faceCoupleInfo
00411         (
00412             const polyMesh& masterMesh,
00413             const labelList& masterAddressing,
00414             const polyMesh& slaveMesh,
00415             const labelList& slaveAddressing,
00416             const scalar absTol,
00417             const bool perfectMatch,
00418             const bool orderedFaces,
00419             const bool patchDivision
00420         );
00421 
00422 
00423     // Destructor
00424 
00425         ~faceCoupleInfo();
00426 
00427 
00428 
00429     // Member Functions
00430 
00431         //- Utility functions
00432 
00433             //- Get patch face labels
00434             static labelList faceLabels(const polyPatch&);
00435 
00436             //- Create Map from List
00437             static Map<label> makeMap(const labelList&);
00438             static Map<labelList> makeMap(const labelListList&);
00439 
00440 
00441         // Access
00442 
00443             //- Addressing engine for coupled faces on mesh0
00444             const indirectPrimitivePatch& masterPatch() const
00445             {
00446                 return masterPatchPtr_();
00447             }
00448 
00449             //- Addressing engine for coupled faces on mesh1
00450             const indirectPrimitivePatch& slavePatch() const
00451             {
00452                 return slavePatchPtr_();
00453             }
00454 
00455             //- Addressing engine for combined set of faces.
00456             const primitiveFacePatch& cutFaces() const
00457             {
00458                 return cutFacesPtr_();
00459             }
00460 
00461             //- Points for combined set of faces.
00462             const pointField& cutPoints() const
00463             {
00464                 return cutPoints_;
00465             }
00466 
00467 
00468         // Addressing from meshes to cut and vice versa.
00469 
00470             //- Master face for every face on cut. Will always be at least
00471             //  one but there might be multiple cut faces pointing to the same
00472             //  master
00473             const labelList& cutToMasterFaces() const
00474             {
00475                 return cutToMasterFaces_;
00476             }
00477             const labelList& masterToCutPoints() const
00478             {
00479                 return masterToCutPoints_;
00480             }
00481 
00482             const labelList& cutToSlaveFaces() const
00483             {
00484                 return cutToSlaveFaces_;
00485             }
00486             const labelList& slaveToCutPoints() const
00487             {
00488                 return slaveToCutPoints_;
00489             }
00490 
00491             //- From two cut points (original edge) to list of inserted
00492             //  points
00493             const edgeLookup& cutEdgeToPoints() const
00494             {
00495                 return cutEdgeToPoints_;
00496             }
00497 
00498  };
00499 
00500 
00501 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00502 
00503 } // End namespace Foam
00504 
00505 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00506 
00507 #ifdef NoRepository
00508 #   include "faceCoupleInfoTemplates.C"
00509 #endif
00510 
00511 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00512 
00513 #endif
00514 
00515 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd