FreeFOAM The Cross-Platform CFD Toolkit
faceSet.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 "faceSet.H"
27 #include <OpenFOAM/mapPolyMesh.H>
28 #include <OpenFOAM/polyMesh.H>
31 
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 
41 defineTypeNameAndDebug(faceSet, 0);
42 
43 addToRunTimeSelectionTable(topoSet, faceSet, word);
44 addToRunTimeSelectionTable(topoSet, faceSet, size);
45 addToRunTimeSelectionTable(topoSet, faceSet, set);
46 
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
51 :
52  topoSet(obj, typeName)
53 {}
54 
55 
57 (
58  const polyMesh& mesh,
59  const word& name,
60  readOption r,
61  writeOption w
62 )
63 :
64  topoSet(mesh, typeName, name, r, w)
65 {
66  check(mesh.nFaces());
67 }
68 
69 
71 (
72  const polyMesh& mesh,
73  const word& name,
74  const label size,
75  writeOption w
76 )
77 :
78  topoSet(mesh, name, size, w)
79 {}
80 
81 
83 (
84  const polyMesh& mesh,
85  const word& name,
86  const topoSet& set,
87  writeOption w
88 )
89 :
90  topoSet(mesh, name, set, w)
91 {}
92 
93 
95 (
96  const polyMesh& mesh,
97  const word& name,
98  const labelHashSet& set,
99  writeOption w
100 )
101 :
102  topoSet(mesh, name, set, w)
103 {}
104 
105 
106 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
107 
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113 
114 void faceSet::sync(const polyMesh& mesh)
115 {
116  const polyBoundaryMesh& patches = mesh.boundaryMesh();
117 
118  label nAdded = 0;
119 
120  if (Pstream::parRun())
121  {
122  // Send faces in set that are on a processorPatch. Send as patch face
123  // indices.
124  forAll(patches, patchI)
125  {
126  const polyPatch& pp = patches[patchI];
127 
128  if (isA<processorPolyPatch>(pp))
129  {
130  const processorPolyPatch& procPatch =
131  refCast<const processorPolyPatch>(pp);
132 
133  // Convert faceSet locally to labelList.
134  DynamicList<label> setFaces(pp.size());
135 
136  forAll(pp, i)
137  {
138  if (found(pp.start() + i))
139  {
140  setFaces.append(i);
141  }
142  }
143  setFaces.shrink();
144 
145  OPstream toNeighbour
146  (
148  procPatch.neighbProcNo()
149  );
150 
151  toNeighbour << setFaces;
152  }
153  }
154 
155  // Receive
156  forAll(patches, patchI)
157  {
158  const polyPatch& pp = patches[patchI];
159 
160  if (isA<processorPolyPatch>(pp))
161  {
162  const processorPolyPatch& procPatch =
163  refCast<const processorPolyPatch>(pp);
164 
165  IPstream fromNeighbour
166  (
168  procPatch.neighbProcNo()
169  );
170 
171  labelList setFaces(fromNeighbour);
172 
173  forAll(setFaces, i)
174  {
175  if (insert(pp.start() + setFaces[i]))
176  {
177  nAdded++;
178  }
179  }
180  }
181  }
182  }
183 
184  // Couple cyclic patches
185  forAll (patches, patchI)
186  {
187  const polyPatch& pp = patches[patchI];
188 
189  if (isA<cyclicPolyPatch>(pp))
190  {
191  const cyclicPolyPatch& cycPatch =
192  refCast<const cyclicPolyPatch>(pp);
193 
194  forAll (cycPatch, i)
195  {
196  label thisFaceI = cycPatch.start() + i;
197  label otherFaceI = cycPatch.transformGlobalFace(thisFaceI);
198 
199  if (found(thisFaceI))
200  {
201  if (insert(otherFaceI))
202  {
203  nAdded++;
204  }
205  }
206  else if (found(otherFaceI))
207  {
208  if (insert(thisFaceI))
209  {
210  nAdded++;
211  }
212  }
213  }
214  }
215  }
216 
217 
218  reduce(nAdded, sumOp<label>());
219 
220  //if (nAdded > 0)
221  //{
222  // Info<< "Added an additional " << nAdded
223  // << " faces on coupled patches. "
224  // << "(processorPolyPatch, cyclicPolyPatch)" << endl;
225  //}
226 }
227 
228 
229 label faceSet::maxSize(const polyMesh& mesh) const
230 {
231  return mesh.nFaces();
232 }
233 
234 
235 void faceSet::updateMesh(const mapPolyMesh& morphMap)
236 {
237  updateLabels(morphMap.reverseFaceMap());
238 }
239 
240 
242 (
243  Ostream& os,
244  const primitiveMesh& mesh,
245  const label maxLen
246 ) const
247 {
248  topoSet::writeDebug(os, mesh.faceCentres(), maxLen);
249 }
250 
251 
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
253 
254 } // End namespace Foam
255 
256 // ************************ vim: set sw=4 sts=4 et: ************************ //