wallLayerCells.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 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 "wallLayerCells.H"
27 #include "DynamicList.H"
28 #include "MeshWave.H"
29 #include "wallNormalInfo.H"
30 #include "OFstream.H"
31 
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 defineTypeNameAndDebug(wallLayerCells, 0);
39 
40 }
41 
42 
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 
45 bool Foam::wallLayerCells::usesCoupledPatch(const label cellI) const
46 {
47  const polyBoundaryMesh& patches = mesh().boundaryMesh();
48 
49  const cell& cFaces = mesh().cells()[cellI];
50 
51  forAll(cFaces, cFaceI)
52  {
53  label faceI = cFaces[cFaceI];
54 
55  label patchID = patches.whichPatch(faceI);
56 
57  if ((patchID >= 0) && (patches[patchID].coupled()))
58  {
59  return true;
60  }
61  }
62  return false;
63 }
64 
65 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
66 
67 // Construct from components
69 (
70  const polyMesh& mesh,
71  const List<word>& patchNames,
72  const label nLayers
73 )
74 :
75  edgeVertex(mesh),
77 {
78  // Find out cells connected to walls.
79 
80  const polyPatchList& patches = mesh.boundaryMesh();
81 
82  // Make map from name to local patch ID
83  HashTable<label> patchNameToIndex(patches.size());
84 
85  forAll(patches, patchI)
86  {
87  patchNameToIndex.insert(patches[patchI].name(), patchI);
88  }
89 
90 
91  // Count size of walls to set
92  label nWalls = 0;
93 
94  forAll(patchNames, patchNameI)
95  {
96  const word& name = patchNames[patchNameI];
97 
98  if (patchNameToIndex.found(name))
99  {
100  label patchI = patchNameToIndex[name];
101 
102  nWalls += patches[patchI].size();
103  }
104  }
105 
106  // Allocate storage for start of wave on faces
107  List<wallNormalInfo> changedFacesInfo(nWalls);
108  labelList changedFaces(nWalls);
109 
110  // Fill changedFaces info
111  label nChangedFaces = 0;
112 
113  forAll(patchNames, patchNameI)
114  {
115  const word& name = patchNames[patchNameI];
116 
117  if (patchNameToIndex.found(name))
118  {
119  label patchI = patchNameToIndex[name];
120 
121  const polyPatch& pp = patches[patchI];
122 
123  forAll(pp, patchFaceI)
124  {
125  label meshFaceI = pp.start() + patchFaceI;
126 
127  changedFaces[nChangedFaces] = meshFaceI;
128 
129  // Set transported information to the wall normal.
130  const vector& norm = pp.faceNormals()[patchFaceI];
131 
132  changedFacesInfo[nChangedFaces] = wallNormalInfo(norm);
133 
134  nChangedFaces++;
135  }
136  }
137  }
138 
139 
140  // Do a wave of nLayers, transporting the index in patchNames
141  // (cannot use local patchIDs since we might get info from neighbouring
142  // processor)
143 
144  MeshWave<wallNormalInfo> regionCalc
145  (
146  mesh,
147  changedFaces,
148  changedFacesInfo,
149  0
150  );
151 
152  regionCalc.iterate(nLayers);
153 
154 
155  // Now regionCalc should hold info on faces that are reachable from
156  // changedFaces within nLayers iterations. We use face info since that is
157  // guaranteed to be consistent across processor boundaries.
158 
159  const List<wallNormalInfo>& faceInfo = regionCalc.allFaceInfo();
160 
161  if (debug)
162  {
163  Info<< "wallLayerCells::getRefinement : dumping selected faces to "
164  << "selectedFaces.obj" << endl;
165 
166  OFstream fcStream("selectedFaces.obj");
167 
168  label vertI = 0;
169 
170  forAll(faceInfo, faceI)
171  {
172  const wallNormalInfo& info = faceInfo[faceI];
173 
174  if (info.valid(regionCalc.data()))
175  {
176  const face& f = mesh.faces()[faceI];
177 
178  point mid(0.0, 0.0, 0.0);
179 
180  forAll(f, fp)
181  {
182  mid += mesh.points()[f[fp]];
183  }
184  mid /= f.size();
185 
186  fcStream
187  << "v " << mid.x() << ' ' << mid.y() << ' ' << mid.z()
188  << endl;
189  vertI++;
190 
191  point end(mid + info.normal());
192 
193  fcStream
194  << "v " << end.x() << ' ' << end.y() << ' ' << end.z()
195  << endl;
196  vertI++;
197 
198  fcStream << "l " << vertI << ' ' <<vertI-1 << endl;
199  }
200  }
201  }
202 
203 
204  //
205  // Copy meshWave information to List<refineCell>
206  //
207 
208  // Estimate size
209 
210  DynamicList<refineCell> refineCells(3*nWalls);
211 
212  const List<wallNormalInfo>& cellInfo = regionCalc.allCellInfo();
213 
214  forAll(cellInfo, cellI)
215  {
216  const wallNormalInfo& info = cellInfo[cellI];
217 
218  if (info.valid(regionCalc.data()) && !usesCoupledPatch(cellI))
219  {
220  refineCells.append(refineCell(cellI, info.normal()));
221  }
222  }
223 
224  // Transfer refineCells storage to this.
225  transfer(refineCells);
226 }
227 
228 
229 // ************************************************************************* //
Output to file stream.
Definition: OFstream.H:81
const List< Type > & allCellInfo() const
Get allCellInfo.
Definition: MeshWave.H:125
Container with cells to refine. Refinement given as single direction.
Definition: refineCell.H:52
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
labelList f(nPoints)
A class for handling words, derived from string.
Definition: word.H:59
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:310
const cellList & cells() const
const vector & normal() const
messageStream Info
dynamicFvMesh & mesh
wallLayerCells(const polyMesh &mesh, const List< word > &patchNames, const label nLayers)
Construct from components.
const TrackingData & data() const
Additional data to be passed into container.
Definition: MeshWave.H:131
Namespace for OpenFOAM.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
const Cmpt & y() const
Definition: VectorI.H:71
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1035
#define forAll(list, i)
Definition: UList.H:421
const Cmpt & x() const
Definition: VectorI.H:65
const Cmpt & z() const
Definition: VectorI.H:77
const Field< PointType > & faceNormals() const
Return face normals for patch.
const List< Type > & allFaceInfo() const
Get allFaceInfo.
Definition: MeshWave.H:119
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:300
Holds information regarding nearest wall point. Used in wall refinement.
Holds information regarding type of cell. Used in inside/outside determination in cellClassification...
Definition: cellInfo.H:54
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
label iterate(const label maxIter)
Iterate until no changes or maxIter reached. Returns actual.
Definition: MeshWave.H:138
FaceCellWave plus data.
Definition: MeshWave.H:56
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1060
bool valid(TrackingData &td) const
Check whether origin has been changed at all or.
Combines edge or vertex in single label. Used to specify cuts across cell circumference.
Definition: edgeVertex.H:52
defineTypeNameAndDebug(combustionModel, 0)