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 | Copyright (C) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "CFCFaceToCellStencil.H"
27 #include "syncTools.H"
28 #include "emptyPolyPatch.H"
29 #include "dummyTransform.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 // Calculates per face the neighbour data (= faces of cell). Leaves out the
34 // face itself since this is already in stencil.
36 (
37  labelListList& neiGlobal
38 ) const
39 {
40  const polyBoundaryMesh& patches = mesh().boundaryMesh();
41  const label nBnd = mesh().nFaces()-mesh().nInternalFaces();
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  // Do nothing.
78  }
79  else
80  {
81  // Do nothing since face itself already in stencil
82  }
83  }
84  //syncTools::swapBoundaryFaceList(mesh(), neiGlobal);
85  syncTools::syncBoundaryFaceList
86  (
87  mesh(),
88  neiGlobal,
91  );
92 }
93 
94 
95 // Calculates per cell the neighbour data (= cell or boundary in global
96 // numbering). First element is always cell itself!
98  const
99 {
100  const label nBnd = mesh().nFaces()-mesh().nInternalFaces();
101  const labelList& own = mesh().faceOwner();
102  const labelList& nei = mesh().faceNeighbour();
103 
104 
105  // Calculate faces of coupled neighbour (in global numbering)
106  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107 
108  labelListList neiGlobal(nBnd);
109  calcFaceBoundaryData(neiGlobal);
110 
111 
112 
113  // Non-empty boundary faces
114  boolList validBFace(mesh().nFaces()-mesh().nInternalFaces(), true);
115 
117  forAll(patches, patchI)
118  {
119  const polyPatch& pp = patches[patchI];
120 
121  if (isA<emptyPolyPatch>(pp))
122  {
123  label bFaceI = pp.start()-mesh().nInternalFaces();
124  forAll(pp, i)
125  {
126  validBFace[bFaceI++] = false;
127  }
128  }
129  }
130 
131 
132  // Determine faces of cellCells in global numbering
133  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
134 
135  DynamicList<label> allGlobalFaces(100);
136 
137  globalCellFaces.setSize(mesh().nCells());
138  forAll(globalCellFaces, cellI)
139  {
140  const cell& cFaces = mesh().cells()[cellI];
141 
142  allGlobalFaces.clear();
143 
144  // My faces first
145  forAll(cFaces, i)
146  {
147  label faceI = cFaces[i];
148 
149  if
150  (
151  mesh().isInternalFace(faceI)
152  || validBFace[faceI-mesh().nInternalFaces()]
153  )
154  {
155  allGlobalFaces.append(globalNumbering().toGlobal(faceI));
156  }
157  }
158 
159  // faces of neighbouring cells second
160  forAll(cFaces, i)
161  {
162  label faceI = cFaces[i];
163 
164  if (mesh().isInternalFace(faceI))
165  {
166  label nbrCellI = own[faceI];
167  if (nbrCellI == cellI)
168  {
169  nbrCellI = nei[faceI];
170  }
171  const cell& nbrFaces = mesh().cells()[nbrCellI];
172 
173  forAll(nbrFaces, j)
174  {
175  label nbrFaceI = nbrFaces[j];
176 
177  if
178  (
179  mesh().isInternalFace(nbrFaceI)
180  || validBFace[nbrFaceI-mesh().nInternalFaces()]
181  )
182  {
183  label nbrGlobalI = globalNumbering().toGlobal(nbrFaceI);
184 
185  // Check if already there. Note:should use hashset?
186  if (findIndex(allGlobalFaces, nbrGlobalI) == -1)
187  {
188  allGlobalFaces.append(nbrGlobalI);
189  }
190  }
191  }
192  }
193  else
194  {
195  const labelList& nbrGlobalFaces =
196  neiGlobal[faceI-mesh().nInternalFaces()];
197 
198  forAll(nbrGlobalFaces, j)
199  {
200  label nbrGlobalI = nbrGlobalFaces[j];
201 
202  // Check if already there. Note:should use hashset?
203  if (findIndex(allGlobalFaces, nbrGlobalI) == -1)
204  {
205  allGlobalFaces.append(nbrGlobalI);
206  }
207  }
208  }
209  }
210 
211  globalCellFaces[cellI] = allGlobalFaces;
212  //Pout<< "** cell:" << cellI
213  // << " at:" << mesh().cellCentres()[cellI]
214  // << endl;
215  //const labelList& globalFaces = globalCellFaces[cellI];
216  //forAll(globalFaces, i)
217  //{
218  // label faceI = globalNumbering().toLocal(globalFaces[i]);
219  // Pout<< " face:" << faceI
220  // << " at:" << mesh().faceCentres()[faceI]
221  // << endl;
222  //}
223  }
224 }
225 
226 
227 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
228 
230 :
232 {
233  // Calculate per cell the (face) connected cells (in global numbering)
234  calcCellStencil(*this);
235 }
236 
237 
238 // ************************************************************************* //
Foam::faceToCellStencil::mesh
const polyMesh & mesh() const
Definition: faceToCellStencil.H:75
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::findIndex
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
Foam::DynamicList< label >
Foam::polyPatch::coupled
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:322
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:136
CFCFaceToCellStencil.H
dummyTransform.H
Dummy transform to be used with syncTools.
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::dummyTransform
Definition: dummyTransform.H:44
syncTools.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::faceToCellStencil::globalNumbering
const globalIndex & globalNumbering() const
Global numbering for faces.
Definition: faceToCellStencil.H:81
Foam::CFCFaceToCellStencil::calcFaceBoundaryData
void calcFaceBoundaryData(labelListList &neiGlobal) const
Definition: CFCFaceToCellStencil.C:36
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::CFCFaceToCellStencil::CFCFaceToCellStencil
CFCFaceToCellStencil(const polyMesh &)
Construct from mesh.
Definition: CFCFaceToCellStencil.C:229
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::DynamicList::clear
void clear()
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:242
Foam::CFCFaceToCellStencil::calcCellStencil
void calcCellStencil(labelListList &globalCellFaces) const
Definition: CFCFaceToCellStencil.C:97
Foam::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1017
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Definition: primitiveMeshI.H:52
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::eqOp
Definition: ops.H:70
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:312
emptyPolyPatch.H
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::primitiveMesh::nFaces
label nFaces() const
Definition: primitiveMeshI.H:58
Foam::faceToCellStencil
baseclass for extended cell centred addressing. Contains per cell a list of neighbouring faces in glo...
Definition: faceToCellStencil.H:54
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::polyMesh::faceNeighbour
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1023
Foam::globalIndex::toGlobal
label toGlobal(const label i) const
From local to global.
Definition: globalIndexI.H:82