CFCCellToCellStencil.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-2016 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 "CFCCellToCellStencil.H"
29 #include "syncTools.H"
30 #include "SortableList.H"
31 #include "emptyPolyPatch.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 void Foam::CFCCellToCellStencil::calcFaceBoundaryData
36 (
37  labelList& 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 cell on the other side
54  forAll(pp, i)
55  {
56  label bFacei = facei-mesh().nInternalFaces();
57  neiGlobal[bFacei] = globalNumbering().toGlobal(own[facei]);
58  facei++;
59  }
60  }
61  else if (isA<emptyPolyPatch>(pp))
62  {
63  forAll(pp, i)
64  {
65  label bFacei = facei-mesh().nInternalFaces();
66  neiGlobal[bFacei] = -1;
67  facei++;
68  }
69  }
70  else
71  {
72  // For noncoupled faces get the boundary face.
73  forAll(pp, i)
74  {
75  label bFacei = facei-mesh().nInternalFaces();
76  neiGlobal[bFacei] =
77  globalNumbering().toGlobal(mesh().nCells()+bFacei);
78  facei++;
79  }
80  }
81  }
83 }
84 
85 
86 void Foam::CFCCellToCellStencil::calcCellStencil
87 (
88  labelListList& globalCellCells
89 ) const
90 {
91  const label nBnd = mesh().nBoundaryFaces();
92  const labelList& own = mesh().faceOwner();
93  const labelList& nei = mesh().faceNeighbour();
94 
95 
96  // Calculate coupled neighbour (in global numbering)
97  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98 
99  labelList neiGlobal(nBnd);
100  calcFaceBoundaryData(neiGlobal);
101 
102 
103  // Determine cellCells in global numbering
104  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105 
106  globalCellCells.setSize(mesh().nCells());
107  forAll(globalCellCells, celli)
108  {
109  const cell& cFaces = mesh().cells()[celli];
110 
111  labelList& cCells = globalCellCells[celli];
112 
113  cCells.setSize(cFaces.size()+1);
114 
115  label nNbr = 0;
116 
117  // Myself
118  cCells[nNbr++] = globalNumbering().toGlobal(celli);
119 
120  // Collect neighbouring cells/faces
121  forAll(cFaces, i)
122  {
123  label facei = cFaces[i];
124 
125  if (mesh().isInternalFace(facei))
126  {
127  label nbrCelli = own[facei];
128  if (nbrCelli == celli)
129  {
130  nbrCelli = nei[facei];
131  }
132  cCells[nNbr++] = globalNumbering().toGlobal(nbrCelli);
133  }
134  else
135  {
136  label nbrCelli = neiGlobal[facei-mesh().nInternalFaces()];
137  if (nbrCelli != -1)
138  {
139  cCells[nNbr++] = nbrCelli;
140  }
141  }
142  }
143  cCells.setSize(nNbr);
144  }
145 }
146 
147 
148 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
149 
151 :
153 {
154  // Calculate per cell the (face) connected cells (in global numbering)
155  calcCellStencil(*this);
156 }
157 
158 
159 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::cellToCellStencil::mesh
const polyMesh & mesh() const
Definition: cellToCellStencil.H:123
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Number of internal faces.
Definition: primitiveMeshI.H:78
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:138
Foam::syncTools::swapBoundaryFaceList
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues)
Swap coupled boundary face values. Uses eqOp.
Definition: syncTools.H:439
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
syncTools.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::cellToCellStencil::globalNumbering
const globalIndex & globalNumbering() const
Global numbering for cells and boundary faces.
Definition: cellToCellStencil.H:129
SortableList.H
Foam::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1107
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
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::cellToCellStencil
baseclass for extended cell centred addressing. Contains per cell a list of neighbouring cells and/or...
Definition: cellToCellStencil.H:56
CFCCellToCellStencil.H
Foam::CFCCellToCellStencil::CFCCellToCellStencil
CFCCellToCellStencil(const polyMesh &mesh)
Construct from mesh.
Definition: CFCCellToCellStencil.C:150
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:164