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

attachDetachPointMatchMap.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 "primitiveFacePatch.H"
00031 #include "polyTopoChanger.H"
00032 
00033 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00034 
00035 const Foam::Map<Foam::label>&
00036 Foam::attachDetach::pointMatchMap() const
00037 {
00038     if (!pointMatchMapPtr_)
00039     {
00040         calcPointMatchMap();
00041     }
00042 
00043     return *pointMatchMapPtr_;
00044 }
00045 
00046 
00047 void Foam::attachDetach::calcPointMatchMap() const
00048 {
00049     if (debug)
00050     {
00051         Pout<< "void attachDetach::calcPointMatchMap() const "
00052             << " for object " << name() << " : "
00053             << "Calculating point matching" << endl;
00054     }
00055 
00056     if (pointMatchMapPtr_)
00057     {
00058         FatalErrorIn
00059         (
00060             "void attachDetach::calcPointMatchMap() const"
00061         )   << "Point match map already calculated for object " << name()
00062             << abort(FatalError);
00063     }
00064 
00065     const polyMesh& mesh = topoChanger().mesh();
00066     const faceList& faces = mesh.faces();
00067 
00068     const polyPatch& masterPatch = mesh.boundaryMesh()[masterPatchID_.index()];
00069     const polyPatch& slavePatch = mesh.boundaryMesh()[slavePatchID_.index()];
00070 
00071     // Create the reverse patch out of the slave patch
00072     primitiveFacePatch reverseSlavePatch
00073     (
00074         faceList(slavePatch.size()),
00075         mesh.points()
00076     );
00077 
00078     const label slavePatchStart = slavePatch.start();
00079 
00080     forAll (reverseSlavePatch, faceI)
00081     {
00082         reverseSlavePatch[faceI] =
00083             faces[slavePatchStart + faceI].reverseFace();
00084     }
00085 
00086     // Create point merge list and remove merged points
00087     const labelList& masterMeshPoints = masterPatch.meshPoints();
00088     const labelList& slaveMeshPoints = reverseSlavePatch.meshPoints();
00089 
00090     const faceList& masterLocalFaces = masterPatch.localFaces();
00091     const faceList& slaveLocalFaces = reverseSlavePatch.localFaces();
00092 
00093     pointMatchMapPtr_ = new Map<label>(2*slaveMeshPoints.size());
00094     Map<label>& removedPointMap = *pointMatchMapPtr_;
00095 
00096     forAll (masterLocalFaces, faceI)
00097     {
00098         const face& curMasterPoints = masterLocalFaces[faceI];
00099         const face& curSlavePoints = slaveLocalFaces[faceI];
00100 
00101         forAll (curMasterPoints, pointI)
00102         {
00103             // If the master and slave point labels are the same, the
00104             // point remains.  Otherwise, the slave point is removed and
00105             // replaced by the master
00106             if
00107             (
00108                 masterMeshPoints[curMasterPoints[pointI]]
00109              != slaveMeshPoints[curSlavePoints[pointI]]
00110             )
00111             {
00112 // Pout << "Matching slave point " << slaveMeshPoints[curSlavePoints[pointI]] << " with " << masterMeshPoints[curMasterPoints[pointI]] << endl;
00113 
00114                 // Grab the addressing
00115                 removedPointMap.insert
00116                 (
00117                     slaveMeshPoints[curSlavePoints[pointI]],
00118                     masterMeshPoints[curMasterPoints[pointI]]
00119                 );
00120             }
00121         }
00122     }
00123 
00124     if (debug)
00125     {
00126         Pout<< "void attachDetach::calcPointMatchMap() const "
00127             << " for object " << name() << " : "
00128             << "Finished calculating point matching" << endl;
00129     }
00130 }
00131 
00132 
00133 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd