FreeFOAM The Cross-Platform CFD Toolkit
attachDetachPointMatchMap.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "attachDetach.H"
27 #include <OpenFOAM/polyMesh.H>
28 #include <OpenFOAM/primitiveMesh.H>
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
35 Foam::attachDetach::pointMatchMap() const
36 {
37  if (!pointMatchMapPtr_)
38  {
39  calcPointMatchMap();
40  }
41 
42  return *pointMatchMapPtr_;
43 }
44 
45 
46 void Foam::attachDetach::calcPointMatchMap() const
47 {
48  if (debug)
49  {
50  Pout<< "void attachDetach::calcPointMatchMap() const "
51  << " for object " << name() << " : "
52  << "Calculating point matching" << endl;
53  }
54 
55  if (pointMatchMapPtr_)
56  {
58  (
59  "void attachDetach::calcPointMatchMap() const"
60  ) << "Point match map already calculated for object " << name()
61  << abort(FatalError);
62  }
63 
64  const polyMesh& mesh = topoChanger().mesh();
65  const faceList& faces = mesh.faces();
66 
67  const polyPatch& masterPatch = mesh.boundaryMesh()[masterPatchID_.index()];
68  const polyPatch& slavePatch = mesh.boundaryMesh()[slavePatchID_.index()];
69 
70  // Create the reverse patch out of the slave patch
71  primitiveFacePatch reverseSlavePatch
72  (
73  faceList(slavePatch.size()),
74  mesh.points()
75  );
76 
77  const label slavePatchStart = slavePatch.start();
78 
79  forAll (reverseSlavePatch, faceI)
80  {
81  reverseSlavePatch[faceI] =
82  faces[slavePatchStart + faceI].reverseFace();
83  }
84 
85  // Create point merge list and remove merged points
86  const labelList& masterMeshPoints = masterPatch.meshPoints();
87  const labelList& slaveMeshPoints = reverseSlavePatch.meshPoints();
88 
89  const faceList& masterLocalFaces = masterPatch.localFaces();
90  const faceList& slaveLocalFaces = reverseSlavePatch.localFaces();
91 
92  pointMatchMapPtr_ = new Map<label>(2*slaveMeshPoints.size());
93  Map<label>& removedPointMap = *pointMatchMapPtr_;
94 
95  forAll (masterLocalFaces, faceI)
96  {
97  const face& curMasterPoints = masterLocalFaces[faceI];
98  const face& curSlavePoints = slaveLocalFaces[faceI];
99 
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 " << slaveMeshPoints[curSlavePoints[pointI]] << " with " << masterMeshPoints[curMasterPoints[pointI]] << endl;
112 
113  // Grab the addressing
114  removedPointMap.insert
115  (
116  slaveMeshPoints[curSlavePoints[pointI]],
117  masterMeshPoints[curMasterPoints[pointI]]
118  );
119  }
120  }
121  }
122 
123  if (debug)
124  {
125  Pout<< "void attachDetach::calcPointMatchMap() const "
126  << " for object " << name() << " : "
127  << "Finished calculating point matching" << endl;
128  }
129 }
130 
131 
132 // ************************ vim: set sw=4 sts=4 et: ************************ //