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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "CECCellToCellStencil.H"
30 #include "syncTools.H"
31 #include "dummyTransform.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 void Foam::CECCellToCellStencil::calcEdgeBoundaryData
36 (
37  const boolList& isValidBFace,
38  const labelList& boundaryEdges,
39  EdgeMap<labelList>& neiGlobal
40 ) const
41 {
42  neiGlobal.resize(2*boundaryEdges.size());
43 
44  labelHashSet edgeGlobals;
45 
46  forAll(boundaryEdges, i)
47  {
48  label edgeI = boundaryEdges[i];
49 
50  neiGlobal.insert
51  (
52  mesh().edges()[edgeI],
54  (
55  isValidBFace,
56  mesh().edgeFaces(edgeI),
57  edgeGlobals
58  )
59  );
60  }
61 
63  (
64  mesh(),
65  neiGlobal,
66  ListOps::unionEqOp(),
67  dummyTransform()
68  );
69 }
70 
71 
72 void Foam::CECCellToCellStencil::calcCellStencil
73 (
74  labelListList& globalCellCells
75 ) const
76 {
77  // Calculate edges on coupled patches
78  labelList boundaryEdges
79  (
80  allCoupledFacesPatch()().meshEdges
81  (
82  mesh().edges(),
83  mesh().pointEdges()
84  )
85  );
86 
87  //{
88  // OFstream str(mesh().time().path()/"boundaryEdges.obj");
89  // Pout<< "Dumping boundary edges to " << str.name() << endl;
90  //
91  // label vertI = 0;
92  // forAll(boundaryEdges, i)
93  // {
94  // label edgeI = boundaryEdges[i];
95  // const edge& e = mesh().edges()[edgeI];
96  // const point& p0 = mesh().points()[e[0]];
97  // const point& p1 = mesh().points()[e[1]];
98  //
99  // Pout<< "boundary edge " << edgeI << " between " << p0 << p1
100  // << endl;
101  //
102  // meshTools::writeOBJ(str, p0);
103  // vertI++;
104  // meshTools::writeOBJ(str, p1);
105  // vertI++;
106  // str << "l " << vertI-1 << ' ' << vertI << nl;
107  // }
108  //}
109 
110 
111  // Mark boundary faces to be included in stencil (i.e. not coupled or empty)
112  boolList isValidBFace;
113  validBoundaryFaces(isValidBFace);
114 
115 
116  // Swap edgeCells for coupled edges. Note: use EdgeMap for now since we've
117  // got syncTools::syncEdgeMap for those. Should be replaced with Map and
118  // syncTools functionality to handle those.
119  EdgeMap<labelList> neiGlobal;
120  calcEdgeBoundaryData
121  (
122  isValidBFace,
123  boundaryEdges,
124  neiGlobal
125  );
126 
127  globalCellCells.setSize(mesh().nCells());
128 
129  // Do coupled edges first
130 
131  forAll(boundaryEdges, i)
132  {
133  label edgeI = boundaryEdges[i];
134 
135  const labelList& eGlobals = neiGlobal[mesh().edges()[edgeI]];
136 
137  // Distribute to all edgeCells
138  const labelList& eCells = mesh().edgeCells(edgeI);
139 
140  forAll(eCells, j)
141  {
142  label celli = eCells[j];
143 
144  // Insert pGlobals into globalCellCells
145  merge
146  (
147  globalNumbering().toGlobal(celli),
148  eGlobals,
149  globalCellCells[celli]
150  );
151  }
152  }
153  neiGlobal.clear();
154 
155  // Do remaining edges cells
156  labelHashSet edgeGlobals;
157 
158  for (label edgeI = 0; edgeI < mesh().nEdges(); edgeI++)
159  {
160  labelList eGlobals
161  (
162  calcFaceCells
163  (
164  isValidBFace,
165  mesh().edgeFaces(edgeI),
166  edgeGlobals
167  )
168  );
169 
170  const labelList& eCells = mesh().edgeCells(edgeI);
171 
172  forAll(eCells, j)
173  {
174  label celli = eCells[j];
175 
176  merge
177  (
178  globalNumbering().toGlobal(celli),
179  eGlobals,
180  globalCellCells[celli]
181  );
182  }
183  }
184 }
185 
186 
187 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
188 
190 :
192 {
193  // Calculate per cell the (edge) connected cells (in global numbering)
194  calcCellStencil(*this);
195 }
196 
197 
198 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::cellToCellStencil::mesh
const polyMesh & mesh() const
Definition: cellToCellStencil.H:123
Foam::CECCellToCellStencil::CECCellToCellStencil
CECCellToCellStencil(const polyMesh &)
Construct from all cells and boundary faces.
Definition: CECCellToCellStencil.C:189
Foam::cellToCellStencil::calcFaceCells
labelList calcFaceCells(const boolList &nonEmptyFace, const labelList &faceLabels, labelHashSet &globals) const
Collect cell neighbours of faces in global numbering.
Definition: cellToCellStencil.C:285
Foam::primitiveMesh::nEdges
label nEdges() const
Number of mesh edges.
Definition: primitiveMeshI.H:67
dummyTransform.H
Dummy transform to be used with syncTools.
Foam::boolList
List< bool > boolList
A List of bools.
Definition: List.H:65
Foam::primitiveMesh::edges
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
Definition: primitiveMeshEdges.C:505
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::primitiveMesh::edgeCells
const labelListList & edgeCells() const
Definition: primitiveMeshEdgeCells.C:34
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
CECCellToCellStencil.H
Foam::syncTools::syncEdgeMap
static void syncEdgeMap(const polyMesh &mesh, EdgeMap< T > &edgeValues, const CombineOp &cop, const TransformOp &top)
Synchronize values on selected edges.
Definition: syncToolsTemplates.C:365
Foam::labelHashSet
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
Foam::cellToCellStencil
baseclass for extended cell centred addressing. Contains per cell a list of neighbouring cells and/or...
Definition: cellToCellStencil.H:56