PatchToolsGatherAndMerge.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) 2012-2013 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 "PatchTools.H"
27 #include "ListListOps.H"
28 #include "mergePoints.H"
29 #include "face.H"
30 #include "triFace.H"
31 #include "ListListOps.H"
32 
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 
35 template
36 <
37  class Face,
38  template<class> class FaceList,
39  class PointField,
40  class PointType
41 >
43 (
44  const scalar mergeDist,
46  Field<PointType>& mergedPoints,
47  List<Face>& mergedFaces,
48  labelList& pointMergeMap
49 )
50 {
51  // Collect points from all processors
52  labelList pointSizes;
53  {
54  List<Field<PointType> > gatheredPoints(Pstream::nProcs());
55  gatheredPoints[Pstream::myProcNo()] = p.points();
56 
57  Pstream::gatherList(gatheredPoints);
58 
59  if (Pstream::master())
60  {
61  pointSizes = ListListOps::subSizes
62  (
63  gatheredPoints,
65  );
66 
67  mergedPoints = ListListOps::combine<Field<PointType> >
68  (
69  gatheredPoints,
71  );
72  }
73  }
74 
75  // Collect faces from all processors and renumber using sizes of
76  // gathered points
77  {
78  List<List<Face> > gatheredFaces(Pstream::nProcs());
79  gatheredFaces[Pstream::myProcNo()] = p;
80  Pstream::gatherList(gatheredFaces);
81 
82  if (Pstream::master())
83  {
84  mergedFaces = static_cast<const List<Face>&>
85  (
86  ListListOps::combineOffset<List<Face> >
87  (
88  gatheredFaces,
89  pointSizes,
92  )
93  );
94  }
95  }
96 
97  if (Pstream::master())
98  {
99  Field<PointType> newPoints;
100  labelList oldToNew;
101 
102  bool hasMerged = mergePoints
103  (
104  mergedPoints,
105  mergeDist,
106  false, // verbosity
107  oldToNew,
108  newPoints
109  );
110 
111  if (hasMerged)
112  {
113  // Store point mapping
114  pointMergeMap.transfer(oldToNew);
115 
116  // Copy points
117  mergedPoints.transfer(newPoints);
118 
119  // Relabel faces
120  List<Face>& faces = mergedFaces;
121 
122  forAll(faces, faceI)
123  {
124  inplaceRenumber(pointMergeMap, faces[faceI]);
125  }
126  }
127  }
128 }
129 
130 
131 // ************************************************************************* //
Foam::offsetOp
Definition: ListListOps.H:111
p
p
Definition: pEqn.H:62
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
ListListOps.H
face.H
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::accessOp
Definition: ListListOps.H:98
triFace.H
Foam::inplaceRenumber
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
Definition: ListOpsTemplates.C:57
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
PatchTools.H
Foam::List< Face >
Foam::ListListOps::subSizes
labelList subSizes(const List< T > &, AccessOp aop=accessOp< T >())
Gets sizes of sublists.
Definition: ListListOps.C:61
mergePoints.H
Merge points. See below.
Foam::PatchTools::gatherAndMerge
static void gatherAndMerge(const scalar mergeDist, const PrimitivePatch< Face, FaceList, PointField, PointType > &p, Field< PointType > &mergedPoints, List< Face > &mergedFaces, labelList &pointMergeMap)
Gather points and faces onto master and merge into single patch.
Definition: PatchToolsGatherAndMerge.C:43
Foam::mergePoints
label mergePoints(const UList< Type > &points, const scalar mergeTol, const bool verbose, labelList &pointMap, const Type &origin=Type::zero)
Sorts and merges points. All points closer than/equal mergeTol get merged.
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88