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

attachInterface.C

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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "attachDetach.H"
00028 #include "polyMesh.H"
00029 #include "primitiveMesh.H"
00030 #include "polyTopoChange.H"
00031 #include "polyTopoChanger.H"
00032 #include "polyRemovePoint.H"
00033 #include "polyRemoveFace.H"
00034 #include "polyModifyFace.H"
00035 
00036 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00037 
00038 const Foam::scalar Foam::attachDetach::positionDifference_ = 1e-8;
00039 
00040 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00041 
00042 void Foam::attachDetach::attachInterface
00043 (
00044     polyTopoChange& ref
00045 ) const
00046 {
00047     // Algorithm:
00048     // 1. Create the reverse patch out of the slave faces.
00049     // 2. Go through all the mesh points from the master and slave patch.
00050     //    If the point labels are different, insert them into the point
00051     //    renumbering list and remove them from the mesh.
00052     // 3. Remove all faces from the slave patch
00053     // 4. Modify all the faces from the master patch by making them internal
00054     //    between the faceCell cells for the two patches.  If the master owner
00055     //    is higher than the slave owner, turn the face around
00056     // 5. Get all the faces attached to the slave patch points.
00057     //    If they have not been removed, renumber them using the
00058     //    point renumbering list.
00059 
00060     if (debug)
00061     {
00062         Pout<< "void attachDetach::attachInterface("
00063             << "polyTopoChange& ref) const "
00064             << " for object " << name() << " : "
00065             << "Attaching interface" << endl;
00066     }
00067 
00068     const polyMesh& mesh = topoChanger().mesh();
00069     const faceList& faces = mesh.faces();
00070     const labelList& own = mesh.faceOwner();
00071     const labelList& nei = mesh.faceNeighbour();
00072 
00073     const polyPatch& masterPatch = mesh.boundaryMesh()[masterPatchID_.index()];
00074     const polyPatch& slavePatch = mesh.boundaryMesh()[slavePatchID_.index()];
00075 
00076     const label masterPatchStart = masterPatch.start();
00077     const label slavePatchStart = slavePatch.start();
00078 
00079     const labelList& slaveMeshPoints = slavePatch.meshPoints();
00080 
00081     const Map<label>& removedPointMap = pointMatchMap();
00082 
00083     const labelList removedPoints = removedPointMap.toc();
00084 
00085     forAll (removedPoints, pointI)
00086     {
00087         ref.setAction(polyRemovePoint(removedPoints[pointI]));
00088     }
00089 
00090 // Pout << "Points to be mapped: " << removedPoints << endl;
00091     // Remove all faces from the slave patch
00092     for (label i = 0; i < slavePatch.size(); i++)
00093     {
00094         ref.setAction(polyRemoveFace(i + slavePatchStart));
00095 // Pout << "Removing face " << i + slavePatchStart << endl;
00096     }
00097 
00098     // Modify the faces from the master patch
00099     const labelList& masterFaceCells = masterPatch.faceCells();
00100     const labelList& slaveFaceCells = slavePatch.faceCells();
00101 
00102     const boolList& mfFlip = mesh.faceZones()[faceZoneID_.index()].flipMap();
00103 
00104     forAll (masterFaceCells, faceI)
00105     {
00106         // If slave neighbour is greater than master, face does not need
00107         // turning.  Modify it to become internal
00108         if (masterFaceCells[faceI] < slaveFaceCells[faceI])
00109         {
00110             ref.setAction
00111             (
00112                 polyModifyFace
00113                 (
00114                     faces[masterPatchStart + faceI], // modified face
00115                     masterPatchStart + faceI,    // label of face being modified
00116                     masterFaceCells[faceI],          // owner
00117                     slaveFaceCells[faceI],           // neighbour
00118                     false,                           // face flip
00119                     -1,                              // patch for face
00120                     false,                           // remove from zone
00121                     faceZoneID_.index(),             // zone for face
00122                     mfFlip[faceI]                    // face flip in zone
00123                 )
00124             );
00125         }
00126         else
00127         {
00128             // Flip required
00129             ref.setAction
00130             (
00131                 polyModifyFace
00132                 (
00133                     faces[masterPatchStart + faceI].reverseFace(), // mod face
00134                     masterPatchStart + faceI,    // label of face being modified
00135                     slaveFaceCells[faceI],        // owner
00136                     masterFaceCells[faceI],       // neighbour
00137                     true,                         // face flip
00138                     -1,                           // patch for face
00139                     false,                        // remove from zone
00140                     faceZoneID_.index(),          // zone for face
00141                     !mfFlip[faceI]                // face flip in zone
00142                 )
00143             );
00144         }
00145     }
00146 
00147     // Renumber faces affected by point removal
00148 // Pout << "slaveMeshPoints: " << slaveMeshPoints << endl;
00149     // Make a map of faces that need to be renumbered
00150     labelHashSet facesToModifyMap
00151     (
00152         slaveMeshPoints.size()*primitiveMesh::facesPerPoint_
00153     );
00154 
00155     const labelListList& pf = mesh.pointFaces();
00156 
00157     // Grab all the faces off the points in the slave patch.  If the face has
00158     //  not been removed, add it to the map of faces to renumber
00159     forAll (slaveMeshPoints, pointI)
00160     {
00161         const labelList& curFaces = pf[slaveMeshPoints[pointI]];
00162 
00163         forAll (curFaces, faceI)
00164         {
00165             if (!ref.faceRemoved(curFaces[faceI]))
00166             {
00167                 facesToModifyMap.insert(curFaces[faceI]);
00168             }
00169         }
00170     }
00171 
00172     // Grab the faces to be renumbered
00173     const labelList ftm = facesToModifyMap.toc();
00174 
00175     forAll (ftm, faceI)
00176     {
00177         // For every face to modify, copy the face and re-map the vertices.
00178         // It is known all the faces will be changed since they hang off
00179         // re-mapped vertices
00180         label curFaceID = ftm[faceI];
00181 
00182         face newFace(faces[curFaceID]);
00183 
00184         forAll (newFace, pointI)
00185         {
00186             Map<label>::const_iterator rpmIter =
00187                 removedPointMap.find(newFace[pointI]);
00188 
00189             if (rpmIter != removedPointMap.end())
00190             {
00191                 // Point mapped. Replace it
00192                 newFace[pointI] = rpmIter();
00193             }
00194         }
00195 
00196 // Pout<< "face label: " << curFaceID << " old face: " << faces[curFaceID] << " new face: " << newFace << endl;
00197 
00198         // Get face zone and its flip
00199         label modifiedFaceZone = mesh.faceZones().whichZone(curFaceID);
00200         bool modifiedFaceZoneFlip = false;
00201 
00202         if (modifiedFaceZone >= 0)
00203         {
00204             modifiedFaceZoneFlip =
00205                 mesh.faceZones()[modifiedFaceZone].flipMap()
00206                 [
00207                     mesh.faceZones()[modifiedFaceZone].whichFace(curFaceID)
00208                 ];
00209         }
00210 
00211 
00212         label patchID = mesh.boundaryMesh().whichPatch(curFaceID);
00213         label neiCell;
00214         if (patchID == -1)
00215         {
00216             neiCell = nei[curFaceID];
00217         }
00218         else
00219         {
00220             neiCell = -1;
00221         }
00222 
00223 
00224         // Modify the face
00225         ref.setAction
00226         (
00227             polyModifyFace
00228             (
00229                 newFace,                // modified face
00230                 curFaceID,              // label of face being modified
00231                 own[curFaceID],         // owner
00232                 neiCell,                // neighbour
00233                 false,                  // face flip
00234                 patchID,                // patch for face
00235                 false,                  // remove from zone
00236                 modifiedFaceZone,       // zone for face
00237                 modifiedFaceZoneFlip    // face flip in zone
00238             )
00239         );
00240     }
00241 
00242     if (debug)
00243     {
00244         Pout<< "void attachDetach::attachInterface("
00245             << "polyTopoChange& ref) const "
00246             << " for object " << name() << " : "
00247             << "Finished attaching interface" << endl;
00248     }
00249 }
00250 
00251 
00252 void Foam::attachDetach::modifyMotionPoints
00253 (
00254     pointField& motionPoints
00255 ) const
00256 {
00257     const Map<label>& removedPointMap = pointMatchMap();
00258 
00259     const labelList removedPoints = removedPointMap.toc();
00260 
00261     if (debug)
00262     {
00263         Pout<< "void attachDetach::modifyMotionPoints(" 
00264             << "pointField& motionPoints) const "
00265             << " for object " << name() << " : "
00266             << "Adjusting motion points." << endl;
00267 
00268         // Calculate the difference in motion point positions
00269         scalar pointDiff = 0;
00270 
00271         forAll (removedPoints, pointI)
00272         {
00273             pointDiff +=
00274                 mag
00275                 (
00276                     motionPoints[removedPoints[pointI]]
00277                   - motionPoints[removedPointMap.find(removedPoints[pointI])()]
00278                 );
00279         }
00280 
00281         if (pointDiff > removedPoints.size()*positionDifference_)
00282         {
00283             Pout<< "Point motion difference = " << pointDiff << endl;
00284         }
00285     }
00286 
00287     // Put the slave point on top of the master point
00288     forAll (removedPoints, pointI)
00289     {
00290         motionPoints[removedPoints[pointI]] =
00291             motionPoints[removedPointMap.find(removedPoints[pointI])()];
00292     }
00293 
00294 }
00295 
00296 
00297 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd