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