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 -------------------------------------------------------------------------------
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 "CFCFaceToCellStencil.H"
30 #include "syncTools.H"
31 #include "emptyPolyPatch.H"
32 #include "dummyTransform.H"
33 
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 
36 void 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 
94 void 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 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::faceToCellStencil::mesh
const polyMesh & mesh() const
Definition: faceToCellStencil.H:77
Foam::syncTools::syncBoundaryFaceList
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.
Definition: syncToolsTemplates.C:998
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:138
CFCFaceToCellStencil.H
dummyTransform.H
Dummy transform to be used with syncTools.
Foam::boolList
List< bool > boolList
A List of bools.
Definition: List.H:65
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
syncTools.H
Foam::polyBoundaryMesh::start
label start() const
The start label of the boundary faces in the polyMesh face list.
Definition: polyBoundaryMesh.C:611
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::faceToCellStencil::globalNumbering
const globalIndex & globalNumbering() const
Global numbering for faces.
Definition: faceToCellStencil.H:83
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::CFCFaceToCellStencil::CFCFaceToCellStencil
CFCFaceToCellStencil(const polyMesh &)
Construct from mesh.
Definition: CFCFaceToCellStencil.C:214
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1107
Foam::primitiveMesh::nBoundaryFaces
label nBoundaryFaces() const noexcept
Number of boundary faces (== nFaces - nInternalFaces)
Definition: primitiveMeshI.H:84
Foam::List::appendUniq
label appendUniq(const T &val)
Append an element if not already in the list.
Definition: ListI.H:232
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
emptyPolyPatch.H
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
Foam::faceToCellStencil
baseclass for extended cell centred addressing. Contains per cell a list of neighbouring faces in glo...
Definition: faceToCellStencil.H:56
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const noexcept
Number of internal faces.
Definition: primitiveMeshI.H:78
Foam::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::polyMesh::faceNeighbour
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1113
Foam::globalIndex::toGlobal
label toGlobal(const label i) const
From local to global index.
Definition: globalIndexI.H:240