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 | 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 "wallLayerCells.H"
29 #include "DynamicList.H"
30 #include "MeshWave.H"
31 #include "wallNormalInfo.H"
32 #include "OFstream.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(wallLayerCells, 0);
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 bool Foam::wallLayerCells::usesCoupledPatch(const label celli) const
45 {
46  const polyBoundaryMesh& patches = mesh().boundaryMesh();
47 
48  const cell& cFaces = mesh().cells()[celli];
49 
50  forAll(cFaces, cFacei)
51  {
52  label facei = cFaces[cFacei];
53 
54  label patchID = patches.whichPatch(facei);
55 
56  if ((patchID >= 0) && (patches[patchID].coupled()))
57  {
58  return true;
59  }
60  }
61  return false;
62 }
63 
64 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
65 
67 (
68  const polyMesh& mesh,
69  const List<word>& patchNames,
70  const label nLayers
71 )
72 :
75 {
76  // Find out cells connected to walls.
77 
79 
80  // Make map from name to local patch ID
81  HashTable<label> patchNameToIndex(patches.size());
82 
83  forAll(patches, patchi)
84  {
85  patchNameToIndex.insert(patches[patchi].name(), patchi);
86  }
87 
88 
89  // Count size of walls to set
90  label nWalls = 0;
91 
92  forAll(patchNames, patchNameI)
93  {
94  const word& name = patchNames[patchNameI];
95 
96  if (patchNameToIndex.found(name))
97  {
98  label patchi = patchNameToIndex[name];
99 
100  nWalls += patches[patchi].size();
101  }
102  }
103 
104  // Allocate storage for start of wave on faces
105  List<wallNormalInfo> changedFacesInfo(nWalls);
106  labelList changedFaces(nWalls);
107 
108  // Fill changedFaces info
109  label nChangedFaces = 0;
110 
111  forAll(patchNames, patchNameI)
112  {
113  const word& name = patchNames[patchNameI];
114 
115  if (patchNameToIndex.found(name))
116  {
117  label patchi = patchNameToIndex[name];
118 
119  const polyPatch& pp = patches[patchi];
120 
121  forAll(pp, patchFacei)
122  {
123  label meshFacei = pp.start() + patchFacei;
124 
125  changedFaces[nChangedFaces] = meshFacei;
126 
127  // Set transported information to the wall normal.
128  const vector& norm = pp.faceNormals()[patchFacei];
129 
130  changedFacesInfo[nChangedFaces] = wallNormalInfo(norm);
131 
132  nChangedFaces++;
133  }
134  }
135  }
136 
137 
138  // Do a wave of nLayers, transporting the index in patchNames
139  // (cannot use local patchIDs since we might get info from neighbouring
140  // processor)
141 
142  MeshWave<wallNormalInfo> regionCalc
143  (
144  mesh,
145  changedFaces,
146  changedFacesInfo,
147  0
148  );
149 
150  regionCalc.iterate(nLayers);
151 
152 
153  // Now regionCalc should hold info on faces that are reachable from
154  // changedFaces within nLayers iterations. We use face info since that is
155  // guaranteed to be consistent across processor boundaries.
156 
157  const List<wallNormalInfo>& faceInfo = regionCalc.allFaceInfo();
158 
159  if (debug)
160  {
161  InfoInFunction << "Dumping selected faces to selectedFaces.obj" << endl;
162 
163  OFstream fcStream("selectedFaces.obj");
164 
165  label vertI = 0;
166 
167  forAll(faceInfo, facei)
168  {
169  const wallNormalInfo& info = faceInfo[facei];
170 
171  if (info.valid(regionCalc.data()))
172  {
173  const face& f = mesh.faces()[facei];
174 
175  point mid(Zero);
176 
177  forAll(f, fp)
178  {
179  mid += mesh.points()[f[fp]];
180  }
181  mid /= f.size();
182 
183  fcStream
184  << "v " << mid.x() << ' ' << mid.y() << ' ' << mid.z()
185  << endl;
186  vertI++;
187 
188  point end(mid + info.normal());
189 
190  fcStream
191  << "v " << end.x() << ' ' << end.y() << ' ' << end.z()
192  << endl;
193  vertI++;
194 
195  fcStream << "l " << vertI << ' ' <<vertI-1 << endl;
196  }
197  }
198  }
199 
200 
201  //
202  // Copy meshWave information to List<refineCell>
203  //
204 
205  // Estimate size
206 
207  DynamicList<refineCell> refineCells(3*nWalls);
208 
209  const List<wallNormalInfo>& cellInfo = regionCalc.allCellInfo();
210 
211  forAll(cellInfo, celli)
212  {
213  const wallNormalInfo& info = cellInfo[celli];
214 
215  if (info.valid(regionCalc.data()) && !usesCoupledPatch(celli))
216  {
217  refineCells.append(refineCell(celli, info.normal()));
218  }
219  }
220 
221  // Transfer refineCells storage to this.
222  transfer(refineCells);
223 }
224 
225 
226 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::wallLayerCells::wallLayerCells
wallLayerCells(const polyMesh &mesh, const List< word > &patchNames, const label nLayers)
Construct from components.
Definition: wallLayerCells.C:67
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1069
Foam::MeshWave::allFaceInfo
const List< Type > & allFaceInfo() const
Get allFaceInfo.
Definition: MeshWave.H:125
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:350
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::wallNormalInfo::valid
bool valid(TrackingData &td) const
Changed or contains original (invalid) value.
Definition: wallNormalInfoI.H:79
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:138
Foam::edgeVertex
Combines edge or vertex in single label. Used to specify cuts across cell circumference.
Definition: edgeVertex.H:55
Foam::wallNormalInfo::normal
const vector & normal() const
Definition: wallNormalInfo.H:95
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::MeshWave::iterate
label iterate(const label maxIter)
Iterate until no changes or maxIter reached.
Definition: MeshWave.H:144
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
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
OFstream.H
MeshWave.H
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::MeshWave
FaceCellWave plus data.
Definition: MeshWave.H:59
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:511
patchID
label patchID
Definition: boundaryProcessorFaPatchPoints.H:5
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
patchNames
wordList patchNames(nPatches)
Foam::MeshWave::data
const TrackingData & data() const
Additional data to be passed into container.
Definition: MeshWave.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:361
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:53
wallNormalInfo.H
Foam::HashTable< label >
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
Foam::cellInfo
Holds information regarding type of cell. Used in inside/outside determination in cellClassification.
Definition: cellInfo.H:64
Foam::refineCell
Container with cells to refine. Refinement given as single direction.
Definition: refineCell.H:56
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1094
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::List< word >
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::PrimitivePatch::faceNormals
const Field< point_type > & faceNormals() const
Return face unit normals for patch.
Definition: PrimitivePatch.C:445
Foam::wallNormalInfo
Holds information regarding nearest wall point. Used in wall refinement.
Definition: wallNormalInfo.H:64
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
DynamicList.H
coupled
bool coupled(solutionDict.getOrDefault("coupledEnergyField", false))
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
wallLayerCells.H
Foam::MeshWave::allCellInfo
const List< Type > & allCellInfo() const
Get allCellInfo.
Definition: MeshWave.H:131
Foam::edgeVertex::mesh
const polyMesh & mesh() const
Definition: edgeVertex.H:101