cellToCellStencil.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) 2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 "cellToCellStencil.H"
30 #include "syncTools.H"
31 #include "SortableList.H"
32 #include "emptyPolyPatch.H"
33 
34 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
35 
37 (
38  const label global0,
39  const label global1,
40  const labelList& listA,
41  labelList& listB
42 )
43 {
44  sort(listB);
45 
46  // See if global0, global1 already present in listB
47  label nGlobalInsert = 0;
48 
49  if (global0 != -1)
50  {
51  label index0 = findSortedIndex(listB, global0);
52  if (index0 == -1)
53  {
54  nGlobalInsert++;
55  }
56  }
57 
58  if (global1 != -1)
59  {
60  label index1 = findSortedIndex(listB, global1);
61  if (index1 == -1)
62  {
63  nGlobalInsert++;
64  }
65  }
66 
67 
68  // For all in listA see if they are present
69  label nInsert = 0;
70 
71  forAll(listA, i)
72  {
73  label elem = listA[i];
74 
75  if (elem != global0 && elem != global1)
76  {
77  if (findSortedIndex(listB, elem) == -1)
78  {
79  nInsert++;
80  }
81  }
82  }
83 
84  // Extend B with nInsert and whether global0,global1 need to be inserted.
85  labelList result(listB.size() + nGlobalInsert + nInsert);
86 
87  label resultI = 0;
88 
89  // Insert global0,1 first
90  if (global0 != -1)
91  {
92  result[resultI++] = global0;
93  }
94  if (global1 != -1)
95  {
96  result[resultI++] = global1;
97  }
98 
99 
100  // Insert listB
101  forAll(listB, i)
102  {
103  label elem = listB[i];
104 
105  if (elem != global0 && elem != global1)
106  {
107  result[resultI++] = elem;
108  }
109  }
110 
111 
112  // Insert listA
113  forAll(listA, i)
114  {
115  label elem = listA[i];
116 
117  if (elem != global0 && elem != global1)
118  {
119  if (findSortedIndex(listB, elem) == -1)
120  {
121  result[resultI++] = elem;
122  }
123  }
124  }
125 
126  if (resultI != result.size())
127  {
129  << "problem" << abort(FatalError);
130  }
131 
132  listB.transfer(result);
133 }
134 
135 
137 (
138  const label globalI,
139  const labelList& pGlobals,
140  labelList& cCells
141 )
142 {
143  labelHashSet set;
144  for (const label celli : cCells)
145  {
146  if (celli != globalI)
147  {
148  set.insert(celli);
149  }
150  }
151 
152  for (const label celli : pGlobals)
153  {
154  if (celli != globalI)
155  {
156  set.insert(celli);
157  }
158  }
159 
160  cCells.setSize(set.size()+1);
161  label n = 0;
162  cCells[n++] = globalI;
163 
164  for (const label seti : set)
165  {
166  cCells[n++] = seti;
167  }
168 }
169 
170 
172 {
174 
175  isValidBFace.setSize(mesh().nBoundaryFaces(), true);
176 
177  for (const polyPatch& pp : patches)
178  {
179  if (pp.coupled() || isA<emptyPolyPatch>(pp))
180  {
181  label bFacei = pp.start()-mesh().nInternalFaces();
182  forAll(pp, i)
183  {
184  isValidBFace[bFacei++] = false;
185  }
186  }
187  }
188 }
189 
190 
193 {
195 
196  label nCoupled = 0;
197 
198  for (const polyPatch& pp : patches)
199  {
200  if (pp.coupled())
201  {
202  nCoupled += pp.size();
203  }
204  }
205  labelList coupledFaces(nCoupled);
206  nCoupled = 0;
207 
208  for (const polyPatch& pp : patches)
209  {
210  if (pp.coupled())
211  {
212  label facei = pp.start();
213 
214  forAll(pp, i)
215  {
216  coupledFaces[nCoupled++] = facei++;
217  }
218  }
219  }
220 
222  (
224  (
225  mesh().faces(),
226  coupledFaces
227  ),
228  mesh().points()
229  );
230 }
231 
232 
233 void Foam::cellToCellStencil::unionEqOp::operator()
234 (
235  labelList& x,
236  const labelList& y
237 ) const
238 {
239  if (y.size())
240  {
241  if (x.empty())
242  {
243  x = y;
244  }
245  else
246  {
247  labelHashSet set(x);
248  set.insert(y);
249  x = set.toc();
250  }
251  }
252 }
253 
254 
256 (
257  const label exclude0,
258  const label exclude1,
259  const boolList& isValidBFace,
260  const labelList& faceLabels,
261  labelHashSet& globals
262 ) const
263 {
264  const labelList& own = mesh().faceOwner();
265  const labelList& nei = mesh().faceNeighbour();
266 
267  forAll(faceLabels, i)
268  {
269  label facei = faceLabels[i];
270 
271  label globalOwn = globalNumbering().toGlobal(own[facei]);
272  if (globalOwn != exclude0 && globalOwn != exclude1)
273  {
274  globals.insert(globalOwn);
275  }
276 
277  if (mesh().isInternalFace(facei))
278  {
279  label globalNei = globalNumbering().toGlobal(nei[facei]);
280  if (globalNei != exclude0 && globalNei != exclude1)
281  {
282  globals.insert(globalNei);
283  }
284  }
285  else
286  {
287  label bFacei = facei-mesh().nInternalFaces();
288 
289  if (isValidBFace[bFacei])
290  {
291  label globalI = globalNumbering().toGlobal
292  (
293  mesh().nCells()
294  + bFacei
295  );
296 
297  if (globalI != exclude0 && globalI != exclude1)
298  {
299  globals.insert(globalI);
300  }
301  }
302  }
303  }
304 }
305 
306 
308 (
309  const boolList& isValidBFace,
310  const labelList& faceLabels,
311  labelHashSet& globals
312 ) const
313 {
314  globals.clear();
315 
316  insertFaceCells
317  (
318  -1,
319  -1,
320  isValidBFace,
321  faceLabels,
322  globals
323  );
324 
325  return globals.toc();
326 }
327 
328 
329 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
330 
332 :
333  mesh_(mesh),
334  globalNumbering_(mesh_.nCells()+mesh_.nBoundaryFaces())
335 {}
336 
337 
338 // ************************************************************************* //
Foam::autoPtr::New
static autoPtr< T > New(Args &&... args)
Construct autoPtr of T with forwarding arguments.
Foam::HashTable::size
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
Foam::cellToCellStencil::mesh
const polyMesh & mesh() const
Definition: cellToCellStencil.H:130
cellToCellStencil.H
Foam::cellToCellStencil::insertFaceCells
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.
Definition: cellToCellStencil.C:256
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::HashTable::toc
List< Key > toc() const
The table of contents (the keys) in unsorted order.
Definition: HashTable.C:121
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Number of internal faces.
Definition: primitiveMeshI.H:78
Foam::cellToCellStencil::calcFaceCells
labelList calcFaceCells(const boolList &nonEmptyFace, const labelList &faceLabels, labelHashSet &globals) const
Collect cell neighbours of faces in global numbering.
Definition: cellToCellStencil.C:308
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:435
Foam::HashSet< label, Hash< label > >
syncTools.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
n
label n
Definition: TABSMDCalcMethod2.H:31
SortableList.H
Foam::cellToCellStencil::cellToCellStencil
cellToCellStencil(const polyMesh &)
Construct from mesh.
Definition: cellToCellStencil.C:331
Foam::cellToCellStencil::validBoundaryFaces
void validBoundaryFaces(boolList &isValidBFace) const
Valid boundary faces (not empty and not coupled)
Definition: cellToCellStencil.C:171
Foam::label
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:62
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1076
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:436
Foam::sort
void sort(UList< T > &a)
Definition: UList.C:241
Foam::IndirectList
A List with indirect addressing.
Definition: IndirectList.H:56
Foam::findSortedIndex
label findSortedIndex(const ListType &input, typename ListType::const_reference val, const label start=0)
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
emptyPolyPatch.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::HashTable::clear
void clear()
Clear all entries from table.
Definition: HashTable.C:630
Foam::cellToCellStencil::allCoupledFacesPatch
autoPtr< indirectPrimitivePatch > allCoupledFacesPatch() const
Return patch of all coupled faces.
Definition: cellToCellStencil.C:192
Foam::List< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:182
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::polyMesh::faceNeighbour
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1082
Foam::cellToCellStencil::merge
static void merge(const label global0, const label global1, const labelList &listA, labelList &listB)
Merge two lists.
Definition: cellToCellStencil.C:37
y
scalar y
Definition: LISASMDCalcMethod1.H:14