Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / dynamicMesh / attachDetach / attachDetachPointMatchMap.C
blob025166749969b9d2c1f3542b2013d23d61659a82
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "attachDetach.H"
27 #include "polyMesh.H"
28 #include "primitiveMesh.H"
29 #include "primitiveFacePatch.H"
30 #include "polyTopoChanger.H"
32 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
34 const Foam::Map<Foam::label>&
35 Foam::attachDetach::pointMatchMap() const
37     if (!pointMatchMapPtr_)
38     {
39         calcPointMatchMap();
40     }
42     return *pointMatchMapPtr_;
46 void Foam::attachDetach::calcPointMatchMap() const
48     if (debug)
49     {
50         Pout<< "void attachDetach::calcPointMatchMap() const "
51             << " for object " << name() << " : "
52             << "Calculating point matching" << endl;
53     }
55     if (pointMatchMapPtr_)
56     {
57         FatalErrorIn
58         (
59             "void attachDetach::calcPointMatchMap() const"
60         )   << "Point match map already calculated for object " << name()
61             << abort(FatalError);
62     }
64     const polyMesh& mesh = topoChanger().mesh();
65     const faceList& faces = mesh.faces();
67     const polyPatch& masterPatch = mesh.boundaryMesh()[masterPatchID_.index()];
68     const polyPatch& slavePatch = mesh.boundaryMesh()[slavePatchID_.index()];
70     // Create the reverse patch out of the slave patch
71     primitiveFacePatch reverseSlavePatch
72     (
73         faceList(slavePatch.size()),
74         mesh.points()
75     );
77     const label slavePatchStart = slavePatch.start();
79     forAll(reverseSlavePatch, faceI)
80     {
81         reverseSlavePatch[faceI] =
82             faces[slavePatchStart + faceI].reverseFace();
83     }
85     // Create point merge list and remove merged points
86     const labelList& masterMeshPoints = masterPatch.meshPoints();
87     const labelList& slaveMeshPoints = reverseSlavePatch.meshPoints();
89     const faceList& masterLocalFaces = masterPatch.localFaces();
90     const faceList& slaveLocalFaces = reverseSlavePatch.localFaces();
92     pointMatchMapPtr_ = new Map<label>(2*slaveMeshPoints.size());
93     Map<label>& removedPointMap = *pointMatchMapPtr_;
95     forAll(masterLocalFaces, faceI)
96     {
97         const face& curMasterPoints = masterLocalFaces[faceI];
98         const face& curSlavePoints = slaveLocalFaces[faceI];
100         forAll(curMasterPoints, pointI)
101         {
102             // If the master and slave point labels are the same, the
103             // point remains.  Otherwise, the slave point is removed and
104             // replaced by the master
105             if
106             (
107                 masterMeshPoints[curMasterPoints[pointI]]
108              != slaveMeshPoints[curSlavePoints[pointI]]
109             )
110             {
111                 // Pout<< "Matching slave point "
112                 //     << slaveMeshPoints[curSlavePoints[pointI]]
113                 //     << " with "
114                 //     << masterMeshPoints[curMasterPoints[pointI]]
115                 //     << endl;
117                 // Grab the addressing
118                 removedPointMap.insert
119                 (
120                     slaveMeshPoints[curSlavePoints[pointI]],
121                     masterMeshPoints[curMasterPoints[pointI]]
122                 );
123             }
124         }
125     }
127     if (debug)
128     {
129         Pout<< "void attachDetach::calcPointMatchMap() const "
130             << " for object " << name() << " : "
131             << "Finished calculating point matching" << endl;
132     }
136 // ************************************************************************* //