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) 2011-2015 OpenFOAM Foundation
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 "polyMesh.H"
28 #include "primitiveMesh.H"
29 #include "primitiveFacePatch.H"
30 #include "polyTopoChanger.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
36 {
37  if (!pointMatchMapPtr_)
38  {
40  }
41 
42  return *pointMatchMapPtr_;
43 }
44 
45 
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  << "Point match map already calculated for object " << name()
59  << abort(FatalError);
60  }
61 
62  const polyMesh& mesh = topoChanger().mesh();
63  const faceList& faces = mesh.faces();
64 
65  const polyPatch& masterPatch = mesh.boundaryMesh()[masterPatchID_.index()];
66  const polyPatch& slavePatch = mesh.boundaryMesh()[slavePatchID_.index()];
67 
68  // Create the reverse patch out of the slave patch
69  primitiveFacePatch reverseSlavePatch
70  (
71  faceList(slavePatch.size()),
72  mesh.points()
73  );
74 
75  const label slavePatchStart = slavePatch.start();
76 
77  forAll(reverseSlavePatch, faceI)
78  {
79  reverseSlavePatch[faceI] =
80  faces[slavePatchStart + faceI].reverseFace();
81  }
82 
83  // Create point merge list and remove merged points
84  const labelList& masterMeshPoints = masterPatch.meshPoints();
85  const labelList& slaveMeshPoints = reverseSlavePatch.meshPoints();
86 
87  const faceList& masterLocalFaces = masterPatch.localFaces();
88  const faceList& slaveLocalFaces = reverseSlavePatch.localFaces();
89 
90  pointMatchMapPtr_ = new Map<label>(2*slaveMeshPoints.size());
91  Map<label>& removedPointMap = *pointMatchMapPtr_;
92 
93  forAll(masterLocalFaces, faceI)
94  {
95  const face& curMasterPoints = masterLocalFaces[faceI];
96  const face& curSlavePoints = slaveLocalFaces[faceI];
97 
98  forAll(curMasterPoints, pointI)
99  {
100  // If the master and slave point labels are the same, the
101  // point remains. Otherwise, the slave point is removed and
102  // replaced by the master
103  if
104  (
105  masterMeshPoints[curMasterPoints[pointI]]
106  != slaveMeshPoints[curSlavePoints[pointI]]
107  )
108  {
109  // Pout<< "Matching slave point "
110  // << slaveMeshPoints[curSlavePoints[pointI]]
111  // << " with "
112  // << masterMeshPoints[curMasterPoints[pointI]]
113  // << endl;
114 
115  // Grab the addressing
116  removedPointMap.insert
117  (
118  slaveMeshPoints[curSlavePoints[pointI]],
119  masterMeshPoints[curMasterPoints[pointI]]
120  );
121  }
122  }
123  }
124 
125  if (debug)
126  {
127  Pout<< "void attachDetach::calcPointMatchMap() const "
128  << " for object " << name() << " : "
129  << "Finished calculating point matching" << endl;
130  }
131 }
132 
133 
134 // ************************************************************************* //
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
Foam::attachDetach::pointMatchMapPtr_
Map< label > * pointMatchMapPtr_
Map of matching points.
Definition: attachDetach.H:104
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::attachDetach::calcPointMatchMap
void calcPointMatchMap() const
Calculate point match addressing.
Definition: attachDetachPointMatchMap.C:46
polyTopoChanger.H
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: PrimitivePatchTemplate.H:68
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:312
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::faceList
List< face > faceList
Definition: faceListFwd.H:43
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
attachDetach.H
Foam::PrimitivePatch::localFaces
const List< Face > & localFaces() const
Return patch faces addressing into local point list.
Definition: PrimitivePatchTemplate.C:372
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::attachDetach::pointMatchMap
const Map< label > & pointMatchMap() const
Return point match map.
Definition: attachDetachPointMatchMap.C:35
Foam::PrimitivePatch::meshPoints
const labelList & meshPoints() const
Return labelList of mesh points in patch.
Definition: PrimitivePatchTemplate.C:392
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88