CECCellToCellStencil.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 "CECCellToCellStencil.H"
27 #include "syncTools.H"
28 #include "dummyTransform.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 // Calculates per edge the neighbour data (= edgeCells)
34 (
35  const boolList& isValidBFace,
36  const labelList& boundaryEdges,
37  EdgeMap<labelList>& neiGlobal
38 ) const
39 {
40  neiGlobal.resize(2*boundaryEdges.size());
41 
42  labelHashSet edgeGlobals;
43 
44  forAll(boundaryEdges, i)
45  {
46  label edgeI = boundaryEdges[i];
47 
48  neiGlobal.insert
49  (
50  mesh().edges()[edgeI],
51  calcFaceCells
52  (
53  isValidBFace,
54  mesh().edgeFaces(edgeI),
55  edgeGlobals
56  )
57  );
58  }
59 
60  syncTools::syncEdgeMap(mesh(), neiGlobal, unionEqOp(), dummyTransform());
61 }
62 
63 
64 // Calculates per cell the neighbour data (= cell or boundary in global
65 // numbering). First element is always cell itself!
67 (
68  labelListList& globalCellCells
69 ) const
70 {
71  // Calculate edges on coupled patches
72  labelList boundaryEdges
73  (
74  allCoupledFacesPatch()().meshEdges
75  (
76  mesh().edges(),
77  mesh().pointEdges()
78  )
79  );
80 
81  //{
82  // OFstream str(mesh().time().path()/"boundaryEdges.obj");
83  // Pout<< "DUmping boundary edges to " << str.name() << endl;
84  //
85  // label vertI = 0;
86  // forAll(boundaryEdges, i)
87  // {
88  // label edgeI = boundaryEdges[i];
89  // const edge& e = mesh().edges()[edgeI];
90  // const point& p0 = mesh().points()[e[0]];
91  // const point& p1 = mesh().points()[e[1]];
92  //
93  // Pout<< "boundary edge " << edgeI << " between " << p0 << p1
94  // << endl;
95  //
96  // meshTools::writeOBJ(str, p0);
97  // vertI++;
98  // meshTools::writeOBJ(str, p1);
99  // vertI++;
100  // str << "l " << vertI-1 << ' ' << vertI << nl;
101  // }
102  //}
103 
104 
105  // Mark boundary faces to be included in stencil (i.e. not coupled or empty)
106  boolList isValidBFace;
107  validBoundaryFaces(isValidBFace);
108 
109 
110  // Swap edgeCells for coupled edges. Note: use EdgeMap for now since we've
111  // got syncTools::syncEdgeMap for those. Should be replaced with Map and
112  // syncTools functionality to handle those.
113  EdgeMap<labelList> neiGlobal;
114  calcEdgeBoundaryData
115  (
116  isValidBFace,
117  boundaryEdges,
118  neiGlobal
119  );
120 
121  globalCellCells.setSize(mesh().nCells());
122 
123  // Do coupled edges first
124 
125  forAll(boundaryEdges, i)
126  {
127  label edgeI = boundaryEdges[i];
128 
129  const labelList& eGlobals = neiGlobal[mesh().edges()[edgeI]];
130 
131  // Distribute to all edgeCells
132  const labelList& eCells = mesh().edgeCells(edgeI);
133 
134  forAll(eCells, j)
135  {
136  label cellI = eCells[j];
137 
138  // Insert pGlobals into globalCellCells
139  merge
140  (
141  globalNumbering().toGlobal(cellI),
142  eGlobals,
143  globalCellCells[cellI]
144  );
145  }
146  }
147  neiGlobal.clear();
148 
149  // Do remaining edges cells
150  labelHashSet edgeGlobals;
151 
152  for (label edgeI = 0; edgeI < mesh().nEdges(); edgeI++)
153  {
154  labelList eGlobals
155  (
156  calcFaceCells
157  (
158  isValidBFace,
159  mesh().edgeFaces(edgeI),
160  edgeGlobals
161  )
162  );
163 
164  const labelList& eCells = mesh().edgeCells(edgeI);
165 
166  forAll(eCells, j)
167  {
168  label cellI = eCells[j];
169 
170  merge
171  (
172  globalNumbering().toGlobal(cellI),
173  eGlobals,
174  globalCellCells[cellI]
175  );
176  }
177  }
178 }
179 
180 
181 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
182 
184 :
186 {
187  // Calculate per cell the (edge) connected cells (in global numbering)
188  calcCellStencil(*this);
189 }
190 
191 
192 // ************************************************************************* //
Foam::HashTable< T, edge, Hash< edge > >::resize
void resize(const label newSize)
Resize the hash table for efficiency.
Definition: HashTable.C:436
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::CECCellToCellStencil::CECCellToCellStencil
CECCellToCellStencil(const polyMesh &)
Construct from all cells and boundary faces.
Definition: CECCellToCellStencil.C:183
dummyTransform.H
Dummy transform to be used with syncTools.
Foam::HashTable< T, edge, Hash< edge > >::insert
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
Foam::dummyTransform
Definition: dummyTransform.H:44
Foam::HashSet< label, Hash< label > >
syncTools.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
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
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::EdgeMap
Map from edge (expressed as its endpoints) to value.
Definition: EdgeMap.H:47
Foam::CECCellToCellStencil::calcCellStencil
void calcCellStencil(labelListList &globalCellCells) const
Definition: CECCellToCellStencil.C:67
Foam::HashTable< T, edge, Hash< edge > >::clear
void clear()
Clear all entries from table.
Definition: HashTable.C:473
CECCellToCellStencil.H
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
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::CECCellToCellStencil::calcEdgeBoundaryData
void calcEdgeBoundaryData(const boolList &isValidBFace, const labelList &boundaryEdges, EdgeMap< labelList > &neiGlobal) const
Calculates per edge the neighbour data (= edgeCells)
Definition: CECCellToCellStencil.C:34
Foam::cellToCellStencil
baseclass for extended cell centred addressing. Contains per cell a list of neighbouring cells and/or...
Definition: cellToCellStencil.H:54
Foam::cellToCellStencil::unionEqOp
Combine operator for labelLists.
Definition: cellToCellStencil.H:87
merge
bool merge(dictionary &, const dictionary &, const bool, const HashTable< wordList, word > &)
Definition: changeDictionary.C:222