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-------------------------------------------------------------------------------
10License
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
35namespace Foam
36{
38}
39
40
41// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42
44Foam::zoneCellStencils::nonEmptyFacesPatch() const
45{
46 const polyBoundaryMesh& patches = meshRef_.boundaryMesh();
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
73 return autoPtr<indirectPrimitivePatch>::New
74 (
75 IndirectList<face>
76 (
77 meshRef_.faces(),
78 nonEmptyFaces
79 ),
80 meshRef_.points()
81 );
82}
83
84
86Foam::zoneCellStencils::allCoupledFacesPatch() const
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
127void Foam::zoneCellStencils::validBoundaryFaces(boolList& isValidBFace) const
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
149void Foam::zoneCellStencils::merge
150(
151 const label globalI,
152 const labelList& pGlobals,
153 labelList& cCells
154)
155{
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
184void Foam::zoneCellStencils::insertFaceCells
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
234Foam::labelList Foam::zoneCellStencils::calcFaceCells
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 );
251
252 return globals.toc();
253}
254
255
256// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
257
258Foam::zoneCellStencils::zoneCellStencils(const fvMesh& mesh)
259:
260 labelListList(mesh.nCells()),
261 meshRef_(mesh),
262 needComm_(),
263 globalNumbering_(meshRef_.nCells() + meshRef_.nBoundaryFaces())
264{
265
266}
267
268
269// ************************************************************************* //
label n
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
void setSize(const label newLen)
Same as resize()
Definition: PtrList.H:151
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
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
base class for cell stencil in a narrow band
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
Dummy transform to be used with syncTools.
void set(List< bool > &bools, const labelUList &locations)
Set the listed locations (assign 'true').
Definition: BitOps.C:38
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
List< bool > boolList
A List of bools.
Definition: List.H:64
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333