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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "attachDetach.H"
30#include "polyMesh.H"
31#include "primitiveMesh.H"
32#include "primitivePatch.H"
33#include "polyTopoChanger.H"
34
35// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36
38Foam::attachDetach::pointMatchMap() const
39{
40 if (!pointMatchMapPtr_)
41 {
42 calcPointMatchMap();
43 }
44
45 return *pointMatchMapPtr_;
46}
47
48
49void Foam::attachDetach::calcPointMatchMap() const
50{
51 if (debug)
52 {
53 Pout<< "void attachDetach::calcPointMatchMap() const "
54 << " for object " << name() << " : "
55 << "Calculating point matching" << endl;
56 }
57
58 if (pointMatchMapPtr_)
59 {
61 << "Point match map already calculated for object " << name()
62 << abort(FatalError);
63 }
64
65 const polyMesh& mesh = topoChanger().mesh();
66 const faceList& faces = mesh.faces();
67
68 const polyPatch& masterPatch = mesh.boundaryMesh()[masterPatchID_.index()];
69 const polyPatch& slavePatch = mesh.boundaryMesh()[slavePatchID_.index()];
70
71 // Create the reverse patch out of the slave patch
72 primitiveFacePatch reverseSlavePatch
73 (
74 faceList(slavePatch.size()),
75 mesh.points()
76 );
77
78 const label slavePatchStart = slavePatch.start();
79
80 forAll(reverseSlavePatch, facei)
81 {
82 reverseSlavePatch[facei] =
83 faces[slavePatchStart + facei].reverseFace();
84 }
85
86 // Create point merge list and remove merged points
87 const labelList& masterMeshPoints = masterPatch.meshPoints();
88 const labelList& slaveMeshPoints = reverseSlavePatch.meshPoints();
89
90 const faceList& masterLocalFaces = masterPatch.localFaces();
91 const faceList& slaveLocalFaces = reverseSlavePatch.localFaces();
92
93 pointMatchMapPtr_.reset(new Map<label>(2*slaveMeshPoints.size()));
94 auto& removedPointMap = *pointMatchMapPtr_;
95
96 forAll(masterLocalFaces, facei)
97 {
98 const face& curMasterPoints = masterLocalFaces[facei];
99 const face& curSlavePoints = slaveLocalFaces[facei];
100
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 "
113 // << slaveMeshPoints[curSlavePoints[pointi]]
114 // << " with "
115 // << masterMeshPoints[curMasterPoints[pointi]]
116 // << endl;
117
118 // Grab the addressing
119 removedPointMap.insert
120 (
121 slaveMeshPoints[curSlavePoints[pointi]],
122 masterMeshPoints[curMasterPoints[pointi]]
123 );
124 }
125 }
126 }
127
128 if (debug)
129 {
130 Pout<< "void attachDetach::calcPointMatchMap() const "
131 << " for object " << name() << " : "
132 << "Finished calculating point matching" << endl;
133 }
134}
135
136
137// ************************************************************************* //
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1108
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:456
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1083
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
List< label > labelList
A List of labels.
Definition: List.H:66
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
PrimitivePatch< List< face >, const pointField & > primitiveFacePatch
A PrimitivePatch with List storage for the faces, const reference for the point field.
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333