FreeFOAM The Cross-Platform CFD Toolkit
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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/syncTools.H>
28 #include <OpenFOAM/SortableList.H>
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 // Calculates per face the neighbour data (= cell or boundary face)
34 void Foam::CFCCellToCellStencil::calcFaceBoundaryData
35 (
36  labelList& neiGlobal
37 ) const
38 {
39  const polyBoundaryMesh& patches = mesh().boundaryMesh();
40  const label nBnd = mesh().nFaces()-mesh().nInternalFaces();
41  const labelList& own = mesh().faceOwner();
42 
43  neiGlobal.setSize(nBnd);
44 
45  forAll(patches, patchI)
46  {
47  const polyPatch& pp = patches[patchI];
48  label faceI = pp.start();
49 
50  if (pp.coupled())
51  {
52  // For coupled faces get the cell on the other side
53  forAll(pp, i)
54  {
55  label bFaceI = faceI-mesh().nInternalFaces();
56  neiGlobal[bFaceI] = globalNumbering().toGlobal(own[faceI]);
57  faceI++;
58  }
59  }
60  else if (isA<emptyPolyPatch>(pp))
61  {
62  forAll(pp, i)
63  {
64  label bFaceI = faceI-mesh().nInternalFaces();
65  neiGlobal[bFaceI] = -1;
66  faceI++;
67  }
68  }
69  else
70  {
71  // For noncoupled faces get the boundary face.
72  forAll(pp, i)
73  {
74  label bFaceI = faceI-mesh().nInternalFaces();
75  neiGlobal[bFaceI] =
76  globalNumbering().toGlobal(mesh().nCells()+bFaceI);
77  faceI++;
78  }
79  }
80  }
81  syncTools::swapBoundaryFaceList(mesh(), neiGlobal, false);
82 }
83 
84 
85 // Calculates per cell the neighbour data (= cell or boundary in global
86 // numbering). First element is always cell itself!
87 void Foam::CFCCellToCellStencil::calcCellStencil(labelListList& globalCellCells)
88  const
89 {
90  const label nBnd = mesh().nFaces()-mesh().nInternalFaces();
91  const labelList& own = mesh().faceOwner();
92  const labelList& nei = mesh().faceNeighbour();
93 
94 
95  // Calculate coupled neighbour (in global numbering)
96  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97 
98  labelList neiGlobal(nBnd);
99  calcFaceBoundaryData(neiGlobal);
100 
101 
102  // Determine cellCells in global numbering
103  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104 
105  globalCellCells.setSize(mesh().nCells());
106  forAll(globalCellCells, cellI)
107  {
108  const cell& cFaces = mesh().cells()[cellI];
109 
110  labelList& cCells = globalCellCells[cellI];
111 
112  cCells.setSize(cFaces.size()+1);
113 
114  label nNbr = 0;
115 
116  // Myself
117  cCells[nNbr++] = globalNumbering().toGlobal(cellI);
118 
119  // Collect neighbouring cells/faces
120  forAll(cFaces, i)
121  {
122  label faceI = cFaces[i];
123 
124  if (mesh().isInternalFace(faceI))
125  {
126  label nbrCellI = own[faceI];
127  if (nbrCellI == cellI)
128  {
129  nbrCellI = nei[faceI];
130  }
131  cCells[nNbr++] = globalNumbering().toGlobal(nbrCellI);
132  }
133  else
134  {
135  label nbrCellI = neiGlobal[faceI-mesh().nInternalFaces()];
136  if (nbrCellI != -1)
137  {
138  cCells[nNbr++] = nbrCellI;
139  }
140  }
141  }
142  cCells.setSize(nNbr);
143  }
144 }
145 
146 
147 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
148 
149 Foam::CFCCellToCellStencil::CFCCellToCellStencil(const polyMesh& mesh)
150 :
151  cellToCellStencil(mesh)
152 {
153  // Calculate per cell the (face) connected cells (in global numbering)
154  calcCellStencil(*this);
155 }
156 
157 
158 // ************************ vim: set sw=4 sts=4 et: ************************ //