initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / dynamicMesh / attachDetach / attachDetachPointMatchMap.C
blobba63ad4b26d12157597e5a369e0fafda57b2c630
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "attachDetach.H"
28 #include "polyMesh.H"
29 #include "primitiveMesh.H"
30 #include "primitiveFacePatch.H"
31 #include "polyTopoChanger.H"
33 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
35 const Foam::Map<Foam::label>&
36 Foam::attachDetach::pointMatchMap() const
38     if (!pointMatchMapPtr_)
39     {
40         calcPointMatchMap();
41     }
43     return *pointMatchMapPtr_;
47 void Foam::attachDetach::calcPointMatchMap() const
49     if (debug)
50     {
51         Pout<< "void attachDetach::calcPointMatchMap() const "
52             << " for object " << name() << " : "
53             << "Calculating point matching" << endl;
54     }
56     if (pointMatchMapPtr_)
57     {
58         FatalErrorIn
59         (
60             "void attachDetach::calcPointMatchMap() const"
61         )   << "Point match map already calculated for object " << name()
62             << abort(FatalError);
63     }
65     const polyMesh& mesh = topoChanger().mesh();
66     const faceList& faces = mesh.faces();
68     const polyPatch& masterPatch = mesh.boundaryMesh()[masterPatchID_.index()];
69     const polyPatch& slavePatch = mesh.boundaryMesh()[slavePatchID_.index()];
71     // Create the reverse patch out of the slave patch
72     primitiveFacePatch reverseSlavePatch
73     (
74         faceList(slavePatch.size()),
75         mesh.points()
76     );
78     const label slavePatchStart = slavePatch.start();
80     forAll (reverseSlavePatch, faceI)
81     {
82         reverseSlavePatch[faceI] =
83             faces[slavePatchStart + faceI].reverseFace();
84     }
86     // Create point merge list and remove merged points
87     const labelList& masterMeshPoints = masterPatch.meshPoints();
88     const labelList& slaveMeshPoints = reverseSlavePatch.meshPoints();
90     const faceList& masterLocalFaces = masterPatch.localFaces();
91     const faceList& slaveLocalFaces = reverseSlavePatch.localFaces();
93     pointMatchMapPtr_ = new Map<label>(2*slaveMeshPoints.size());
94     Map<label>& removedPointMap = *pointMatchMapPtr_;
96     forAll (masterLocalFaces, faceI)
97     {
98         const face& curMasterPoints = masterLocalFaces[faceI];
99         const face& curSlavePoints = slaveLocalFaces[faceI];
101         forAll (curMasterPoints, pointI)
102         {
103             // If the master and slave point labels are the same, the
104             // point remains.  Otherwise, the slave point is removed and
105             // replaced by the master
106             if
107             (
108                 masterMeshPoints[curMasterPoints[pointI]]
109              != slaveMeshPoints[curSlavePoints[pointI]]
110             )
111             {
112 // Pout << "Matching slave point " << slaveMeshPoints[curSlavePoints[pointI]] << " with " << masterMeshPoints[curMasterPoints[pointI]] << endl;
114                 // Grab the addressing
115                 removedPointMap.insert
116                 (
117                     slaveMeshPoints[curSlavePoints[pointI]],
118                     masterMeshPoints[curMasterPoints[pointI]]
119                 );
120             }
121         }
122     }
124     if (debug)
125     {
126         Pout<< "void attachDetach::calcPointMatchMap() const "
127             << " for object " << name() << " : "
128             << "Finished calculating point matching" << endl;
129     }
133 // ************************************************************************* //