zoneCellStencils.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) 2020 DLR
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "zoneCellStencils.H"
29 #include "syncTools.H"
30 #include "dummyTransform.H"
31 #include "emptyPolyPatch.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
38 }
39 
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
45 {
47 
48  label nNonEmpty = 0;
49 
50  for (const polyPatch& pp : patches)
51  {
52  if (!isA<emptyPolyPatch>(pp))
53  {
54  nNonEmpty += pp.size();
55  }
56  }
57  labelList nonEmptyFaces(nNonEmpty);
58  nNonEmpty = 0;
59 
60  for (const polyPatch& pp : patches)
61  {
62  if (!isA<emptyPolyPatch>(pp))
63  {
64  label facei = pp.start();
65 
66  forAll(pp, i)
67  {
68  nonEmptyFaces[nNonEmpty++] = facei++;
69  }
70  }
71  }
72 
74  (
75  IndirectList<face>
76  (
77  meshRef_.faces(),
78  nonEmptyFaces
79  ),
81  );
82 }
83 
84 
87 {
88  const polyBoundaryMesh& patches = meshRef_.boundaryMesh();
89 
90  label nCoupled = 0;
91 
92  for (const polyPatch& pp : patches)
93  {
94  if (pp.coupled())
95  {
96  nCoupled += pp.size();
97  }
98  }
99  labelList coupledFaces(nCoupled);
100  nCoupled = 0;
101 
102  for (const polyPatch& pp : patches)
103  {
104  if (pp.coupled())
105  {
106  label facei = pp.start();
107 
108  forAll(pp, i)
109  {
110  coupledFaces[nCoupled++] = facei++;
111  }
112  }
113  }
114 
116  (
117  IndirectList<face>
118  (
119  meshRef_.faces(),
120  coupledFaces
121  ),
122  meshRef_.points()
123  );
124 }
125 
126 
128 {
129  const polyBoundaryMesh& patches = meshRef_.boundaryMesh();
130 
131  isValidBFace.setSize(meshRef_.nBoundaryFaces());
132 
133  isValidBFace = true;
134 
135  for (const polyPatch& pp : patches)
136  {
137  if (pp.coupled() || isA<emptyPolyPatch>(pp))
138  {
139  label bFacei = pp.start() - meshRef_.nInternalFaces();
140  forAll(pp, i)
141  {
142  isValidBFace[bFacei++] = false;
143  }
144  }
145  }
146 }
147 
148 
150 (
151  const label globalI,
152  const labelList& pGlobals,
153  labelList& cCells
154 )
155 {
156  labelHashSet set;
157  for (const label celli : cCells)
158  {
159  if (celli != globalI)
160  {
161  set.insert(celli);
162  }
163  }
164 
165  for (const label celli : pGlobals)
166  {
167  if (celli != globalI)
168  {
169  set.insert(celli);
170  }
171  }
172 
173  cCells.setSize(set.size()+1);
174  label n = 0;
175  cCells[n++] = globalI;
176 
177  for (const label seti : set)
178  {
179  cCells[n++] = seti;
180  }
181 }
182 
183 
185 (
186  const label exclude0,
187  const label exclude1,
188  const boolList& isValidBFace,
189  const labelList& faceLabels,
190  labelHashSet& globals
191 ) const
192 {
193  const labelList& own = meshRef_.faceOwner();
194  const labelList& nei = meshRef_.faceNeighbour();
195 
196  for (const label facei : faceLabels)
197  {
198  const label globalOwn = globalNumbering().toGlobal(own[facei]);
199  if (globalOwn != exclude0 && globalOwn != exclude1)
200  {
201  globals.insert(globalOwn);
202  }
203 
204  if (meshRef_.isInternalFace(facei))
205  {
206  const label globalNei = globalNumbering().toGlobal(nei[facei]);
207  if (globalNei != exclude0 && globalNei != exclude1)
208  {
209  globals.insert(globalNei);
210  }
211  }
212  else
213  {
214  const label bFacei = facei - meshRef_.nInternalFaces();
215 
216  if (isValidBFace[bFacei])
217  {
218  label globalI = globalNumbering().toGlobal
219  (
220  meshRef_.nCells()
221  + bFacei
222  );
223 
224  if (globalI != exclude0 && globalI != exclude1)
225  {
226  globals.insert(globalI);
227  }
228  }
229  }
230  }
231 }
232 
233 
235 (
236  const boolList& isValidBFace,
237  const labelList& faceLabels,
238  labelHashSet& globals
239 ) const
240 {
241  globals.clear();
242 
243  insertFaceCells
244  (
245  -1,
246  -1,
247  isValidBFace,
248  faceLabels,
249  globals
250  );
252  return globals.toc();
253 }
254 
255 
256 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
257 
259 :
260  labelListList(mesh.nCells()),
261  meshRef_(mesh),
262  needComm_(),
263  globalNumbering_(meshRef_.nCells() + meshRef_.nBoundaryFaces())
264 {
265 
266 }
267 
268 
269 // ************************************************************************* //
void validBoundaryFaces(boolList &isValidBFace) const
Valid boundary faces (not empty and not coupled)
static void merge(const label globalI, const labelList &pGlobals, labelList &cCells)
Merge two lists and guarantee globalI is first.
zoneCellStencils(const zoneCellStencils &)=delete
No copy construct.
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.
autoPtr< indirectPrimitivePatch > nonEmptyFacesPatch() const
Return patch of all coupled faces.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:232
labelList faceLabels(nFaceLabels)
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1078
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
const fvMesh & meshRef_
const reference to fvMesh
Dummy transform to be used with syncTools.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
void setSize(const label n)
Alias for resize()
Definition: List.H:316
dynamicFvMesh & mesh
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:137
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:608
autoPtr< indirectPrimitivePatch > allCoupledFacesPatch() const
Return patch of all coupled faces.
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1103
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
defineTypeNameAndDebug(combustionModel, 0)
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
const polyBoundaryMesh & patches
base class for cell stencil in a narrow band
label n
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
List< label > labelList
A List of labels.
Definition: List.H:62
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition: autoPtr.H:178
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
List< bool > boolList
A List of bools.
Definition: List.H:60
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.