FreeFOAM The Cross-Platform CFD Toolkit
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) 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 "CECCellToCellStencil.H"
27 #include <OpenFOAM/syncTools.H>
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 // Calculates per edge the neighbour data (= edgeCells)
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 
60  (
61  mesh(),
62  neiGlobal,
63  unionEqOp(),
64  false // apply separation
65  );
66 }
67 
68 
69 // Calculates per cell the neighbour data (= cell or boundary in global
70 // numbering). First element is always cell itself!
71 void Foam::CECCellToCellStencil::calcCellStencil
72 (
73  labelListList& globalCellCells
74 ) const
75 {
76  // Calculate edges on coupled patches
77  labelList boundaryEdges
78  (
79  allCoupledFacesPatch()().meshEdges
80  (
81  mesh().edges(),
82  mesh().pointEdges()
83  )
84  );
85 
86  //{
87  // OFstream str(mesh().time().path()/"boundaryEdges.obj");
88  // Pout<< "DUmping boundary edges to " << str.name() << endl;
89  //
90  // label vertI = 0;
91  // forAll(boundaryEdges, i)
92  // {
93  // label edgeI = boundaryEdges[i];
94  // const edge& e = mesh().edges()[edgeI];
95  // const point& p0 = mesh().points()[e[0]];
96  // const point& p1 = mesh().points()[e[1]];
97  //
98  // Pout<< "boundary edge " << edgeI << " between " << p0 << p1
99  // << endl;
100  //
101  // meshTools::writeOBJ(str, p0);
102  // vertI++;
103  // meshTools::writeOBJ(str, p1);
104  // vertI++;
105  // str << "l " << vertI-1 << ' ' << vertI << nl;
106  // }
107  //}
108 
109 
110  // Mark boundary faces to be included in stencil (i.e. not coupled or empty)
111  boolList isValidBFace;
112  validBoundaryFaces(isValidBFace);
113 
114 
115  // Swap edgeCells for coupled edges. Note: use EdgeMap for now since we've
116  // got syncTools::syncEdgeMap for those. Should be replaced with Map and
117  // syncTools functionality to handle those.
118  EdgeMap<labelList> neiGlobal;
119  calcEdgeBoundaryData
120  (
121  isValidBFace,
122  boundaryEdges,
123  neiGlobal
124  );
125 
126  globalCellCells.setSize(mesh().nCells());
127 
128  // Do coupled edges first
129 
130  forAll(boundaryEdges, i)
131  {
132  label edgeI = boundaryEdges[i];
133 
134  const labelList& eGlobals = neiGlobal[mesh().edges()[edgeI]];
135 
136  // Distribute to all edgeCells
137  const labelList& eCells = mesh().edgeCells(edgeI);
138 
139  forAll(eCells, j)
140  {
141  label cellI = eCells[j];
142 
143  // Insert pGlobals into globalCellCells
144  merge
145  (
146  globalNumbering().toGlobal(cellI),
147  eGlobals,
148  globalCellCells[cellI]
149  );
150  }
151  }
152  neiGlobal.clear();
153 
154  // Do remaining edges cells
155  labelHashSet edgeGlobals;
156 
157  for (label edgeI = 0; edgeI < mesh().nEdges(); edgeI++)
158  {
159  labelList eGlobals
160  (
161  calcFaceCells
162  (
163  isValidBFace,
164  mesh().edgeFaces(edgeI),
165  edgeGlobals
166  )
167  );
168 
169  const labelList& eCells = mesh().edgeCells(edgeI);
170 
171  forAll(eCells, j)
172  {
173  label cellI = eCells[j];
174 
175  merge
176  (
177  globalNumbering().toGlobal(cellI),
178  eGlobals,
179  globalCellCells[cellI]
180  );
181  }
182  }
183 }
184 
185 
186 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
187 
188 Foam::CECCellToCellStencil::CECCellToCellStencil(const polyMesh& mesh)
189 :
190  cellToCellStencil(mesh)
191 {
192  // Calculate per cell the (edge) connected cells (in global numbering)
193  calcCellStencil(*this);
194 }
195 
196 
197 // ************************ vim: set sw=4 sts=4 et: ************************ //