CFCFaceToCellStencil.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-2017 OpenFOAM Foundation
9 Copyright (C) 2021 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
30#include "syncTools.H"
31#include "emptyPolyPatch.H"
32#include "dummyTransform.H"
33
34// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35
36void Foam::CFCFaceToCellStencil::calcFaceBoundaryData
37(
38 labelListList& neiGlobal
39) const
40{
41 const polyBoundaryMesh& patches = mesh().boundaryMesh();
42 const label nBnd = mesh().nBoundaryFaces();
43 const labelList& own = mesh().faceOwner();
44
45 neiGlobal.setSize(nBnd);
46
47 forAll(patches, patchi)
48 {
49 const polyPatch& pp = patches[patchi];
50 label facei = pp.start();
51
52 if (pp.coupled())
53 {
54 // For coupled faces get the faces of the cell on the other side
55 forAll(pp, i)
56 {
57 const labelList& cFaces = mesh().cells()[own[facei]];
58
59 labelList& globFaces = neiGlobal[facei-mesh().nInternalFaces()];
60 globFaces.setSize(cFaces.size()-1);
61 label globI = 0;
62
63 forAll(cFaces, j)
64 {
65 if (cFaces[j] != facei)
66 {
67 globFaces[globI++] = globalNumbering().toGlobal
68 (
69 cFaces[j]
70 );
71 }
72 }
73 facei++;
74 }
75 }
76 else if (isA<emptyPolyPatch>(pp))
77 {}
78 else
79 {
80 // Do nothing since face itself already in stencil
81 }
82 }
83
85 (
86 mesh(),
87 neiGlobal,
88 eqOp<labelList>(),
89 dummyTransform()
90 );
91}
92
93
94void Foam::CFCFaceToCellStencil::calcCellStencil
95(
96 labelListList& globalCellFaces
97) const
98{
99 const label nBnd = mesh().nBoundaryFaces();
100 const labelList& own = mesh().faceOwner();
101 const labelList& nei = mesh().faceNeighbour();
102
103
104 // Calculate faces of coupled neighbour (in global numbering)
105 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106
107 labelListList neiGlobal(nBnd);
108 calcFaceBoundaryData(neiGlobal);
109
110
111
112 // Non-empty boundary faces
113 boolList validBFace(mesh().nBoundaryFaces(), true);
114
115 const polyBoundaryMesh& patches = mesh().boundaryMesh();
116 forAll(patches, patchi)
117 {
118 const polyPatch& pp = patches[patchi];
119
120 if (isA<emptyPolyPatch>(pp))
121 {
122 label bFacei = pp.start()-mesh().nInternalFaces();
123 forAll(pp, i)
124 {
125 validBFace[bFacei++] = false;
126 }
127 }
128 }
129
130
131 // Determine faces of cellCells in global numbering
132 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
133
134 DynamicList<label> allGlobalFaces(100);
135
136 globalCellFaces.setSize(mesh().nCells());
137 forAll(globalCellFaces, celli)
138 {
139 const cell& cFaces = mesh().cells()[celli];
140
141 allGlobalFaces.clear();
142
143 // My faces first
144 for (const label facei : cFaces)
145 {
146 if
147 (
148 mesh().isInternalFace(facei)
149 || validBFace[facei-mesh().nInternalFaces()]
150 )
151 {
152 allGlobalFaces.append(globalNumbering().toGlobal(facei));
153 }
154 }
155
156 // faces of neighbouring cells second
157 for (const label facei : cFaces)
158 {
159 if (mesh().isInternalFace(facei))
160 {
161 label nbrCelli = own[facei];
162 if (nbrCelli == celli)
163 {
164 nbrCelli = nei[facei];
165 }
166 const cell& nbrFaces = mesh().cells()[nbrCelli];
167
168 for (const label nbrFacei : nbrFaces)
169 {
170 if
171 (
172 mesh().isInternalFace(nbrFacei)
173 || validBFace[nbrFacei-mesh().nInternalFaces()]
174 )
175 {
176 label nbrGlobali = globalNumbering().toGlobal(nbrFacei);
177
178 // Note:should use hashset?
179 allGlobalFaces.appendUniq(nbrGlobali);
180 }
181 }
182 }
183 else
184 {
185 const labelList& nbrGlobalFaces =
186 neiGlobal[facei-mesh().nInternalFaces()];
187
188 for (const label nbrGlobali : nbrGlobalFaces)
189 {
190 // Note:should use hashset?
191 allGlobalFaces.appendUniq(nbrGlobali);
192 }
193 }
194 }
195
196 globalCellFaces[celli] = allGlobalFaces;
197 //Pout<< "** cell:" << celli
198 // << " at:" << mesh().cellCentres()[celli]
199 // << endl;
200 //const labelList& globalFaces = globalCellFaces[celli];
201 //forAll(globalFaces, i)
202 //{
203 // label facei = globalNumbering().toLocal(globalFaces[i]);
204 // Pout<< " face:" << facei
205 // << " at:" << mesh().faceCentres()[facei]
206 // << endl;
207 //}
208 }
209}
210
211
212// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
213
215:
217{
218 // Calculate per cell the (face) connected cells (in global numbering)
219 calcCellStencil(*this);
220}
221
222
223// ************************************************************************* //
void setSize(const label n)
Alias for resize()
Definition: List.H:218
label appendUniq(const T &val)
Append an element if not already in the list.
Definition: ListI.H:232
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
baseclass for extended cell centred addressing. Contains per cell a list of neighbouring faces in glo...
const polyMesh & mesh() const
const globalIndex & globalNumbering() const
Global numbering for faces.
label toGlobal(const label i) const
From local to global index.
Definition: globalIndexI.H:260
label start() const noexcept
The start label of boundary faces in the polyMesh face list.
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
label nBoundaryFaces() const noexcept
Number of boundary faces (== nFaces - nInternalFaces)
label nInternalFaces() const noexcept
Number of internal faces.
const cellList & cells() const
static void syncBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop, const TransformOp &top, const bool parRun=Pstream::parRun())
Synchronize values on boundary faces only.
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
Dummy transform to be used with syncTools.
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
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333