All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
attachDetachPointMatchMap.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 
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  << "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 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
label index() const
Return index of first matching zone.
Definition: DynamicID.H:107
PrimitivePatch< List< face >, const pointField & > primitiveFacePatch
Foam::primitiveFacePatch.
const polyTopoChanger & topoChanger() const
Return reference to morph engine.
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
const word & name() const
Return name of this modifier.
const polyMesh & mesh() const
Return the mesh reference.
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49