All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CECCellToCellStencil.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 "CECCellToCellStencil.H"
27 #include "syncTools.H"
28 #include "dummyTransform.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 void Foam::CECCellToCellStencil::calcEdgeBoundaryData
33 (
34  const boolList& isValidBFace,
35  const labelList& boundaryEdges,
36  EdgeMap<labelList>& neiGlobal
37 ) const
38 {
39  neiGlobal.resize(2*boundaryEdges.size());
40 
41  labelHashSet edgeGlobals;
42 
43  forAll(boundaryEdges, i)
44  {
45  label edgeI = boundaryEdges[i];
46 
47  neiGlobal.insert
48  (
49  mesh().edges()[edgeI],
51  (
52  isValidBFace,
53  mesh().edgeFaces(edgeI),
54  edgeGlobals
55  )
56  );
57  }
58 
59  syncTools::syncEdgeMap(mesh(), neiGlobal, unionEqOp(), dummyTransform());
60 }
61 
62 
63 void Foam::CECCellToCellStencil::calcCellStencil
64 (
65  labelListList& globalCellCells
66 ) const
67 {
68  // Calculate edges on coupled patches
69  labelList boundaryEdges
70  (
71  allCoupledFacesPatch()().meshEdges
72  (
73  mesh().edges(),
74  mesh().pointEdges()
75  )
76  );
77 
78  //{
79  // OFstream str(mesh().time().path()/"boundaryEdges.obj");
80  // Pout<< "DUmping boundary edges to " << str.name() << endl;
81  //
82  // label vertI = 0;
83  // forAll(boundaryEdges, i)
84  // {
85  // label edgeI = boundaryEdges[i];
86  // const edge& e = mesh().edges()[edgeI];
87  // const point& p0 = mesh().points()[e[0]];
88  // const point& p1 = mesh().points()[e[1]];
89  //
90  // Pout<< "boundary edge " << edgeI << " between " << p0 << p1
91  // << endl;
92  //
93  // meshTools::writeOBJ(str, p0);
94  // vertI++;
95  // meshTools::writeOBJ(str, p1);
96  // vertI++;
97  // str << "l " << vertI-1 << ' ' << vertI << nl;
98  // }
99  //}
100 
101 
102  // Mark boundary faces to be included in stencil (i.e. not coupled or empty)
103  boolList isValidBFace;
104  validBoundaryFaces(isValidBFace);
105 
106 
107  // Swap edgeCells for coupled edges. Note: use EdgeMap for now since we've
108  // got syncTools::syncEdgeMap for those. Should be replaced with Map and
109  // syncTools functionality to handle those.
110  EdgeMap<labelList> neiGlobal;
111  calcEdgeBoundaryData
112  (
113  isValidBFace,
114  boundaryEdges,
115  neiGlobal
116  );
117 
118  globalCellCells.setSize(mesh().nCells());
119 
120  // Do coupled edges first
121 
122  forAll(boundaryEdges, i)
123  {
124  label edgeI = boundaryEdges[i];
125 
126  const labelList& eGlobals = neiGlobal[mesh().edges()[edgeI]];
127 
128  // Distribute to all edgeCells
129  const labelList& eCells = mesh().edgeCells(edgeI);
130 
131  forAll(eCells, j)
132  {
133  label celli = eCells[j];
134 
135  // Insert pGlobals into globalCellCells
136  merge
137  (
138  globalNumbering().toGlobal(celli),
139  eGlobals,
140  globalCellCells[celli]
141  );
142  }
143  }
144  neiGlobal.clear();
145 
146  // Do remaining edges cells
147  labelHashSet edgeGlobals;
148 
149  for (label edgeI = 0; edgeI < mesh().nEdges(); edgeI++)
150  {
151  labelList eGlobals
152  (
154  (
155  isValidBFace,
156  mesh().edgeFaces(edgeI),
157  edgeGlobals
158  )
159  );
160 
161  const labelList& eCells = mesh().edgeCells(edgeI);
162 
163  forAll(eCells, j)
164  {
165  label celli = eCells[j];
166 
167  merge
168  (
169  globalNumbering().toGlobal(celli),
170  eGlobals,
171  globalCellCells[celli]
172  );
173  }
174  }
175 }
176 
177 
178 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
179 
181 :
182  cellToCellStencil(mesh)
183 {
184  // Calculate per cell the (edge) connected cells (in global numbering)
185  calcCellStencil(*this);
186 }
187 
188 
189 // ************************************************************************* //
static void merge(const label global0, const label global1, const labelList &listA, labelList &listB)
Merge two lists.
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
CECCellToCellStencil(const polyMesh &)
Construct from all cells and boundary faces.
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
Dummy transform to be used with syncTools.
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:211
const labelListList & edgeCells() const
List< label > labelList
A List of labels.
Definition: labelList.H:56
void validBoundaryFaces(boolList &isValidBFace) const
Valid boundary faces (not empty and not coupled)
static void syncEdgeMap(const polyMesh &, EdgeMap< T > &edgeValues, const CombineOp &cop, const TransformOp &top)
Synchronise values on selected edges.
label nEdges() const
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
labelList calcFaceCells(const boolList &nonEmptyFace, const labelList &faceLabels, labelHashSet &globals) const
Collect cell neighbours of faces in global numbering.
const globalIndex & globalNumbering() const
Global numbering for cells and boundary faces.
const polyMesh & mesh() const
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
autoPtr< indirectPrimitivePatch > allCoupledFacesPatch() const
Return patch of all coupled faces.
baseclass for extended cell centred addressing. Contains per cell a list of neighbouring cells and/or...