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-------------------------------------------------------------------------------
11License
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 "emptyPolyPatch.H"
32
33// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
34
36(
37 const label global0,
38 const label global1,
39 const labelList& listA,
40 labelList& listB
41)
42{
43 sort(listB);
44
45 // See if global0, global1 already present in listB
46 label nGlobalInsert = 0;
47
48 if (global0 != -1)
49 {
50 label index0 = findSortedIndex(listB, global0);
51 if (index0 == -1)
52 {
53 nGlobalInsert++;
54 }
55 }
56
57 if (global1 != -1)
58 {
59 label index1 = findSortedIndex(listB, global1);
60 if (index1 == -1)
61 {
62 nGlobalInsert++;
63 }
64 }
65
66
67 // For all in listA see if they are present
68 label nInsert = 0;
69
70 forAll(listA, i)
71 {
72 label elem = listA[i];
73
74 if (elem != global0 && elem != global1)
75 {
76 if (findSortedIndex(listB, elem) == -1)
77 {
78 nInsert++;
79 }
80 }
81 }
82
83 // Extend B with nInsert and whether global0,global1 need to be inserted.
84 labelList result(listB.size() + nGlobalInsert + nInsert);
85
86 label resultI = 0;
87
88 // Insert global0,1 first
89 if (global0 != -1)
90 {
91 result[resultI++] = global0;
92 }
93 if (global1 != -1)
94 {
95 result[resultI++] = global1;
96 }
97
98
99 // Insert listB
100 forAll(listB, i)
101 {
102 label elem = listB[i];
103
104 if (elem != global0 && elem != global1)
105 {
106 result[resultI++] = elem;
107 }
108 }
109
110
111 // Insert listA
112 forAll(listA, i)
113 {
114 label elem = listA[i];
115
116 if (elem != global0 && elem != global1)
117 {
118 if (findSortedIndex(listB, elem) == -1)
119 {
120 result[resultI++] = elem;
121 }
122 }
123 }
124
125 if (resultI != result.size())
126 {
128 << "problem" << abort(FatalError);
129 }
130
131 listB.transfer(result);
132}
133
134
136(
137 const label globalI,
138 const labelList& pGlobals,
139 labelList& cCells
140)
141{
142 labelHashSet set;
143 for (const label celli : cCells)
144 {
145 if (celli != globalI)
146 {
147 set.insert(celli);
148 }
149 }
150
151 for (const label celli : pGlobals)
152 {
153 if (celli != globalI)
154 {
155 set.insert(celli);
156 }
157 }
158
159 cCells.setSize(set.size()+1);
160 label n = 0;
161 cCells[n++] = globalI;
162
163 for (const label seti : set)
164 {
165 cCells[n++] = seti;
166 }
167}
168
169
171{
173
174 isValidBFace.setSize(mesh().nBoundaryFaces(), true);
175
176 for (const polyPatch& pp : patches)
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 for (const polyPatch& pp : patches)
198 {
199 if (pp.coupled())
200 {
201 nCoupled += pp.size();
202 }
203 }
204 labelList coupledFaces(nCoupled);
205 nCoupled = 0;
206
207 for (const polyPatch& pp : patches)
208 {
209 if (pp.coupled())
210 {
211 label facei = pp.start();
212
213 forAll(pp, i)
214 {
215 coupledFaces[nCoupled++] = facei++;
216 }
217 }
218 }
219
221 (
223 (
224 mesh().faces(),
225 coupledFaces
226 ),
227 mesh().points()
228 );
229}
230
231
233(
234 const label exclude0,
235 const label exclude1,
236 const boolList& isValidBFace,
237 const labelList& faceLabels,
238 labelHashSet& globals
239) const
240{
241 const labelList& own = mesh().faceOwner();
242 const labelList& nei = mesh().faceNeighbour();
243
244 forAll(faceLabels, i)
245 {
246 label facei = faceLabels[i];
247
248 label globalOwn = globalNumbering().toGlobal(own[facei]);
249 if (globalOwn != exclude0 && globalOwn != exclude1)
250 {
251 globals.insert(globalOwn);
252 }
253
254 if (mesh().isInternalFace(facei))
255 {
256 label globalNei = globalNumbering().toGlobal(nei[facei]);
257 if (globalNei != exclude0 && globalNei != exclude1)
258 {
259 globals.insert(globalNei);
260 }
261 }
262 else
263 {
264 label bFacei = facei-mesh().nInternalFaces();
265
266 if (isValidBFace[bFacei])
267 {
268 label globalI = globalNumbering().toGlobal
269 (
270 mesh().nCells()
271 + bFacei
272 );
273
274 if (globalI != exclude0 && globalI != exclude1)
275 {
276 globals.insert(globalI);
277 }
278 }
279 }
280 }
281}
282
283
285(
286 const boolList& isValidBFace,
287 const labelList& faceLabels,
288 labelHashSet& globals
289) const
290{
291 globals.clear();
292
293 insertFaceCells
294 (
295 -1,
296 -1,
297 isValidBFace,
298 faceLabels,
299 globals
300 );
301
302 return globals.toc();
303}
304
305
306// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
307
309:
310 mesh_(mesh),
311 globalNumbering_(mesh_.nCells()+mesh_.nBoundaryFaces())
312{}
313
314
315// ************************************************************************* //
label n
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:191
List< Key > toc() const
The table of contents (the keys) in unsorted order.
Definition: HashTable.C:122
void clear()
Clear all entries from table.
Definition: HashTable.C:678
A List with indirect addressing.
Definition: IndirectList.H:119
void transfer(List< T > &list)
Definition: List.C:447
void setSize(const label n)
Alias for resize()
Definition: List.H:218
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
baseclass for extended cell centred addressing. Contains per cell a list of neighbouring cells and/or...
autoPtr< indirectPrimitivePatch > allCoupledFacesPatch() const
Return patch of all coupled faces.
void validBoundaryFaces(boolList &isValidBFace) const
Valid boundary faces (not empty and not coupled)
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.
labelList calcFaceCells(const boolList &nonEmptyFace, const labelList &faceLabels, labelHashSet &globals) const
Collect cell neighbours of faces in global numbering.
virtual bool merge() const
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1121
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:456
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1127
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
label nInternalFaces() const noexcept
Number of internal faces.
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const pointField & points
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:342
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
label findSortedIndex(const ListType &input, typename ListType::const_reference val, const label start=0)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333