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