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 {
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 
234 (
235  const label exclude0,
236  const label exclude1,
237  const boolList& isValidBFace,
238  const labelList& faceLabels,
239  labelHashSet& globals
240 ) const
241 {
242  const labelList& own = mesh().faceOwner();
243  const labelList& nei = mesh().faceNeighbour();
244 
245  forAll(faceLabels, i)
246  {
247  label facei = faceLabels[i];
248 
249  label globalOwn = globalNumbering().toGlobal(own[facei]);
250  if (globalOwn != exclude0 && globalOwn != exclude1)
251  {
252  globals.insert(globalOwn);
253  }
254 
255  if (mesh().isInternalFace(facei))
256  {
257  label globalNei = globalNumbering().toGlobal(nei[facei]);
258  if (globalNei != exclude0 && globalNei != exclude1)
259  {
260  globals.insert(globalNei);
261  }
262  }
263  else
264  {
265  label bFacei = facei-mesh().nInternalFaces();
266 
267  if (isValidBFace[bFacei])
268  {
269  label globalI = globalNumbering().toGlobal
270  (
271  mesh().nCells()
272  + bFacei
273  );
274 
275  if (globalI != exclude0 && globalI != exclude1)
276  {
277  globals.insert(globalI);
278  }
279  }
280  }
281  }
282 }
283 
284 
286 (
287  const boolList& isValidBFace,
288  const labelList& faceLabels,
289  labelHashSet& globals
290 ) const
291 {
292  globals.clear();
293 
294  insertFaceCells
295  (
296  -1,
297  -1,
298  isValidBFace,
299  faceLabels,
300  globals
301  );
302 
303  return globals.toc();
304 }
305 
306 
307 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
308 
310 :
311  mesh_(mesh),
312  globalNumbering_(mesh_.nCells()+mesh_.nBoundaryFaces())
313 {}
314 
315 
316 // ************************************************************************* //
Foam::autoPtr::New
static autoPtr< T > New(Args &&... args)
Construct autoPtr of T with forwarding arguments.
Foam::cellToCellStencil::mesh
const polyMesh & mesh() const
Definition: cellToCellStencil.H:123
cellToCellStencil.H
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
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:234
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:286
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
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:296
n
label n
Definition: TABSMDCalcMethod2.H:31
SortableList.H
Foam::cellToCellStencil::cellToCellStencil
cellToCellStencil(const polyMesh &)
Construct from mesh.
Definition: cellToCellStencil.C:309
Foam::cellToCellStencil::validBoundaryFaces
void validBoundaryFaces(boolList &isValidBFace) const
Valid boundary faces (not empty and not coupled)
Definition: cellToCellStencil.C:171
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1107
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:459
Foam::sort
void sort(UList< T > &a)
Definition: UList.C:254
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:144
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:381
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:181
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
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:1113
Foam::cellToCellStencil::merge
static void merge(const label global0, const label global1, const labelList &listA, labelList &listB)
Merge two lists.
Definition: cellToCellStencil.C:37