cellToCellStencil.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 "cellToCellStencil.H"
27 #include "syncTools.H"
28 #include "SortableList.H"
29 #include "emptyPolyPatch.H"
30 
31 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32 
34 (
35  const label global0,
36  const label global1,
37  const labelList& listA,
38  labelList& listB
39 )
40 {
41  sort(listB);
42 
43  // See if global0, global1 already present in listB
44  label nGlobalInsert = 0;
45 
46  if (global0 != -1)
47  {
48  label index0 = findSortedIndex(listB, global0);
49  if (index0 == -1)
50  {
51  nGlobalInsert++;
52  }
53  }
54 
55  if (global1 != -1)
56  {
57  label index1 = findSortedIndex(listB, global1);
58  if (index1 == -1)
59  {
60  nGlobalInsert++;
61  }
62  }
63 
64 
65  // For all in listA see if they are present
66  label nInsert = 0;
67 
68  forAll(listA, i)
69  {
70  label elem = listA[i];
71 
72  if (elem != global0 && elem != global1)
73  {
74  if (findSortedIndex(listB, elem) == -1)
75  {
76  nInsert++;
77  }
78  }
79  }
80 
81  // Extend B with nInsert and whether global0,global1 need to be inserted.
82  labelList result(listB.size() + nGlobalInsert + nInsert);
83 
84  label resultI = 0;
85 
86  // Insert global0,1 first
87  if (global0 != -1)
88  {
89  result[resultI++] = global0;
90  }
91  if (global1 != -1)
92  {
93  result[resultI++] = global1;
94  }
95 
96 
97  // Insert listB
98  forAll(listB, i)
99  {
100  label elem = listB[i];
101 
102  if (elem != global0 && elem != global1)
103  {
104  result[resultI++] = elem;
105  }
106  }
107 
108 
109  // Insert listA
110  forAll(listA, i)
111  {
112  label elem = listA[i];
113 
114  if (elem != global0 && elem != global1)
115  {
116  if (findSortedIndex(listB, elem) == -1)
117  {
118  result[resultI++] = elem;
119  }
120  }
121  }
122 
123  if (resultI != result.size())
124  {
126  << "problem" << abort(FatalError);
127  }
128 
129  listB.transfer(result);
130 }
131 
132 
134 (
135  const label globalI,
136  const labelList& pGlobals,
137  labelList& cCells
138 )
139 {
140  labelHashSet set;
141  forAll(cCells, i)
142  {
143  if (cCells[i] != globalI)
144  {
145  set.insert(cCells[i]);
146  }
147  }
148 
149  forAll(pGlobals, i)
150  {
151  if (pGlobals[i] != globalI)
152  {
153  set.insert(pGlobals[i]);
154  }
155  }
156 
157  cCells.setSize(set.size()+1);
158  label n = 0;
159  cCells[n++] = globalI;
160 
161  forAllConstIter(labelHashSet, set, iter)
162  {
163  cCells[n++] = iter.key();
164  }
165 }
166 
167 
169 {
171 
172  isValidBFace.setSize(mesh().nFaces()-mesh().nInternalFaces(), true);
173 
174  forAll(patches, patchi)
175  {
176  const polyPatch& pp = patches[patchi];
177 
178  if (pp.coupled() || isA<emptyPolyPatch>(pp))
179  {
180  label bFacei = pp.start()-mesh().nInternalFaces();
181  forAll(pp, i)
182  {
183  isValidBFace[bFacei++] = false;
184  }
185  }
186  }
187 }
188 
189 
192 {
194 
195  label nCoupled = 0;
196 
197  forAll(patches, patchi)
198  {
199  const polyPatch& pp = patches[patchi];
200 
201  if (pp.coupled())
202  {
203  nCoupled += pp.size();
204  }
205  }
206  labelList coupledFaces(nCoupled);
207  nCoupled = 0;
208 
209  forAll(patches, patchi)
210  {
211  const polyPatch& pp = patches[patchi];
212 
213  if (pp.coupled())
214  {
215  label facei = pp.start();
216 
217  forAll(pp, i)
218  {
219  coupledFaces[nCoupled++] = facei++;
220  }
221  }
222  }
223 
225  (
227  (
229  (
230  mesh().faces(),
231  coupledFaces
232  ),
233  mesh().points()
234  )
235  );
236 }
237 
238 
239 void Foam::cellToCellStencil::unionEqOp::operator()
240 (
241  labelList& x,
242  const labelList& y
243 ) const
244 {
245  if (y.size())
246  {
247  if (x.empty())
248  {
249  x = y;
250  }
251  else
252  {
253  labelHashSet set(x);
254  forAll(y, i)
255  {
256  set.insert(y[i]);
257  }
258  x = set.toc();
259  }
260  }
261 }
262 
263 
265 (
266  const label exclude0,
267  const label exclude1,
268  const boolList& isValidBFace,
269  const labelList& faceLabels,
270  labelHashSet& globals
271 ) const
272 {
273  const labelList& own = mesh().faceOwner();
274  const labelList& nei = mesh().faceNeighbour();
275 
276  forAll(faceLabels, i)
277  {
278  label facei = faceLabels[i];
279 
280  label globalOwn = globalNumbering().toGlobal(own[facei]);
281  if (globalOwn != exclude0 && globalOwn != exclude1)
282  {
283  globals.insert(globalOwn);
284  }
285 
286  if (mesh().isInternalFace(facei))
287  {
288  label globalNei = globalNumbering().toGlobal(nei[facei]);
289  if (globalNei != exclude0 && globalNei != exclude1)
290  {
291  globals.insert(globalNei);
292  }
293  }
294  else
295  {
296  label bFacei = facei-mesh().nInternalFaces();
297 
298  if (isValidBFace[bFacei])
299  {
300  label globalI = globalNumbering().toGlobal
301  (
302  mesh().nCells()
303  + bFacei
304  );
305 
306  if (globalI != exclude0 && globalI != exclude1)
307  {
308  globals.insert(globalI);
309  }
310  }
311  }
312  }
313 }
314 
315 
317 (
318  const boolList& isValidBFace,
319  const labelList& faceLabels,
320  labelHashSet& globals
321 ) const
322 {
323  globals.clear();
324 
326  (
327  -1,
328  -1,
329  isValidBFace,
330  faceLabels,
331  globals
332  );
333 
334  return globals.toc();
335 }
336 
337 
338 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
339 
341 :
342  mesh_(mesh),
343  globalNumbering_(mesh_.nCells()+mesh_.nFaces()-mesh_.nInternalFaces())
344 {}
345 
346 
347 // ************************************************************************* //
static void merge(const label global0, const label global1, const labelList &listA, labelList &listB)
Merge two lists.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:434
label findSortedIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element in sorted list and return index,.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:325
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:323
label nInternalFaces() const
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1175
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
patches[0]
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
Foam::indirectPrimitivePatch.
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:111
scalar y
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:319
const pointField & points
void clear()
Clear all entries from table.
Definition: HashTable.C:468
void sort(UList< T > &)
Definition: UList.C:115
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1169
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::polyBoundaryMesh.
void validBoundaryFaces(boolList &isValidBFace) const
Valid boundary faces (not empty and not coupled)
void setSize(const label)
Reset size of List.
Definition: List.C:281
label toGlobal(const label i) const
From local to global.
Definition: globalIndexI.H:82
label patchi
labelList calcFaceCells(const boolList &nonEmptyFace, const labelList &faceLabels, labelHashSet &globals) const
Collect cell neighbours of faces in global numbering.
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:309
const globalIndex & globalNumbering() const
Global numbering for cells and boundary faces.
cellToCellStencil(const polyMesh &)
Construct from mesh.
const polyMesh & mesh() const
label n
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
void insertFaceCells(const label exclude0, const label exclude1, const boolList &nonEmptyFace, const labelList &faceLabels, labelHashSet &globals) const
Collect cell neighbours of faces in global numbering.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:202
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
A List with indirect addressing.
Definition: IndirectList.H:101
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
autoPtr< indirectPrimitivePatch > allCoupledFacesPatch() const
Return patch of all coupled faces.