All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CFCCellToCellStencil.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 "CFCCellToCellStencil.H"
27 #include "syncTools.H"
28 #include "SortableList.H"
29 #include "emptyPolyPatch.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 void Foam::CFCCellToCellStencil::calcFaceBoundaryData
34 (
35  labelList& neiGlobal
36 ) const
37 {
38  const polyBoundaryMesh& patches = mesh().boundaryMesh();
39  const label nBnd = mesh().nFaces()-mesh().nInternalFaces();
40  const labelList& own = mesh().faceOwner();
41 
42  neiGlobal.setSize(nBnd);
43 
45  {
46  const polyPatch& pp = patches[patchi];
47  label facei = pp.start();
48 
49  if (pp.coupled())
50  {
51  // For coupled faces get the cell on the other side
52  forAll(pp, i)
53  {
54  label bFacei = facei-mesh().nInternalFaces();
55  neiGlobal[bFacei] = globalNumbering().toGlobal(own[facei]);
56  facei++;
57  }
58  }
59  else if (isA<emptyPolyPatch>(pp))
60  {
61  forAll(pp, i)
62  {
63  label bFacei = facei-mesh().nInternalFaces();
64  neiGlobal[bFacei] = -1;
65  facei++;
66  }
67  }
68  else
69  {
70  // For noncoupled faces get the boundary face.
71  forAll(pp, i)
72  {
73  label bFacei = facei-mesh().nInternalFaces();
74  neiGlobal[bFacei] =
75  globalNumbering().toGlobal(mesh().nCells()+bFacei);
76  facei++;
77  }
78  }
79  }
81 }
82 
83 
84 void Foam::CFCCellToCellStencil::calcCellStencil
85 (
86  labelListList& globalCellCells
87 ) const
88 {
89  const label nBnd = mesh().nFaces()-mesh().nInternalFaces();
90  const labelList& own = mesh().faceOwner();
91  const labelList& nei = mesh().faceNeighbour();
92 
93 
94  // Calculate coupled neighbour (in global numbering)
95  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96 
97  labelList neiGlobal(nBnd);
98  calcFaceBoundaryData(neiGlobal);
99 
100 
101  // Determine cellCells in global numbering
102  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103 
104  globalCellCells.setSize(mesh().nCells());
105  forAll(globalCellCells, celli)
106  {
107  const cell& cFaces = mesh().cells()[celli];
108 
109  labelList& cCells = globalCellCells[celli];
110 
111  cCells.setSize(cFaces.size()+1);
112 
113  label nNbr = 0;
114 
115  // Myself
116  cCells[nNbr++] = globalNumbering().toGlobal(celli);
117 
118  // Collect neighbouring cells/faces
119  forAll(cFaces, i)
120  {
121  label facei = cFaces[i];
122 
123  if (mesh().isInternalFace(facei))
124  {
125  label nbrCelli = own[facei];
126  if (nbrCelli == celli)
127  {
128  nbrCelli = nei[facei];
129  }
130  cCells[nNbr++] = globalNumbering().toGlobal(nbrCelli);
131  }
132  else
133  {
134  label nbrCelli = neiGlobal[facei-mesh().nInternalFaces()];
135  if (nbrCelli != -1)
136  {
137  cCells[nNbr++] = nbrCelli;
138  }
139  }
140  }
141  cCells.setSize(nNbr);
142  }
143 }
144 
145 
146 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
147 
149 :
150  cellToCellStencil(mesh)
151 {
152  // Calculate per cell the (face) connected cells (in global numbering)
153  calcCellStencil(*this);
154 }
155 
156 
157 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
CFCCellToCellStencil(const polyMesh &mesh)
Construct from mesh.
void setSize(const label)
Reset size of List.
Definition: List.C:281
baseclass for extended cell centred addressing. Contains per cell a list of neighbouring cells and/or...
const globalIndex & globalNumbering() const
Global numbering for cells and boundary faces.
const polyMesh & mesh() const
label toGlobal(const label i) const
From local to global.
Definition: globalIndexI.H:82
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1339
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:404
label nInternalFaces() const
label nFaces() const
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled boundary face values.
Definition: syncTools.H:436
label patchi
const fvPatchList & patches
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57