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 
46 {
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 :
77 {
78  // Find out cells connected to walls.
79 
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 // ************************************************************************* //
Foam::wallLayerCells::wallLayerCells
wallLayerCells(const polyMesh &mesh, const List< word > &patchNames, const label nLayers)
Construct from components.
Definition: wallLayerCells.C:69
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
Foam::MeshWave::allFaceInfo
const List< Type > & allFaceInfo() const
Get allFaceInfo.
Definition: MeshWave.H:119
Foam::wallNormalInfo::normal
const vector & normal() const
Definition: wallNormalInfoI.H:84
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:56
Foam::wallNormalInfo::valid
bool valid(TrackingData &td) const
Check whether origin has been changed at all or.
Definition: wallNormalInfoI.H:91
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:136
Foam::edgeVertex
Combines edge or vertex in single label. Used to specify cuts across cell circumference.
Definition: edgeVertex.H:52
Foam::HashTable::insert
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::MeshWave::iterate
label iterate(const label maxIter)
Iterate until no changes or maxIter reached. Returns actual.
Definition: MeshWave.H:138
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
OFstream.H
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:59
MeshWave.H
Foam::Info
messageStream Info
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::MeshWave
FaceCellWave plus data.
Definition: MeshWave.H:56
Foam::PtrList
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
patchNames
wordList patchNames(nPatches)
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
Foam::MeshWave::data
const TrackingData & data() const
Additional data to be passed into container.
Definition: MeshWave.H:131
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::HashTable::found
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Vector::z
const Cmpt & z() const
Definition: VectorI.H:77
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:312
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
wallNormalInfo.H
Foam::HashTable< label >
Foam::cellInfo
Holds information regarding type of cell. Used in inside/outside determination in cellClassification.
Definition: cellInfo.H:54
Foam::refineCell
Container with cells to refine. Refinement given as single direction.
Definition: refineCell.H:52
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
Foam::PrimitivePatch::faceNormals
const Field< PointType > & faceNormals() const
Return face normals for patch.
Definition: PrimitivePatchTemplate.C:520
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::List< word >
Foam::wallNormalInfo
Holds information regarding nearest wall point. Used in wall refinement.
Definition: wallNormalInfo.H:57
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::Vector::y
const Cmpt & y() const
Definition: VectorI.H:71
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
DynamicList.H
Foam::wallLayerCells::usesCoupledPatch
bool usesCoupledPatch(const label cellI) const
Check if any of the faces of cellI is on processorPatch.
Definition: wallLayerCells.C:45
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
wallLayerCells.H
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::MeshWave::allCellInfo
const List< Type > & allCellInfo() const
Get allCellInfo.
Definition: MeshWave.H:125
Foam::edgeVertex::mesh
const polyMesh & mesh() const
Definition: edgeVertex.H:98