1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "wallLayerCells.H"
28 #include <OpenFOAM/DynamicList.H>
29 #include <OpenFOAM/MeshWave.H>
30 #include <dynamicMesh/wallNormalInfo.H>
31 #include <OpenFOAM/OFstream.H>
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(wallLayerCells, 0);
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 bool Foam::wallLayerCells::usesCoupledPatch(const label cellI) const
48 const polyBoundaryMesh& patches = mesh().boundaryMesh();
50 const cell& cFaces = mesh().cells()[cellI];
52 forAll(cFaces, cFaceI)
54 label faceI = cFaces[cFaceI];
56 label patchID = patches.whichPatch(faceI);
58 if ((patchID >= 0) && (patches[patchID].coupled()))
66 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
68 // Construct from components
69 Foam::wallLayerCells::wallLayerCells
72 const List<word>& patchNames,
79 // Find out cells connected to walls.
81 const polyPatchList& patches = mesh.boundaryMesh();
83 // Make map from name to local patch ID
84 HashTable<label> patchNameToIndex(patches.size());
86 forAll(patches, patchI)
88 patchNameToIndex.insert(patches[patchI].name(), patchI);
92 // Count size of walls to set
95 forAll(patchNames, patchNameI)
97 const word& name = patchNames[patchNameI];
99 if (patchNameToIndex.found(name))
101 label patchI = patchNameToIndex[name];
103 nWalls += patches[patchI].size();
107 // Allocate storage for start of wave on faces
108 List<wallNormalInfo> changedFacesInfo(nWalls);
109 labelList changedFaces(nWalls);
111 // Fill changedFaces info
112 label nChangedFaces = 0;
114 forAll(patchNames, patchNameI)
116 const word& name = patchNames[patchNameI];
118 if (patchNameToIndex.found(name))
120 label patchI = patchNameToIndex[name];
122 const polyPatch& pp = patches[patchI];
124 forAll(pp, patchFaceI)
126 label meshFaceI = pp.start() + patchFaceI;
128 changedFaces[nChangedFaces] = meshFaceI;
130 // Set transported information to the wall normal.
131 const vector& norm = pp.faceNormals()[patchFaceI];
133 changedFacesInfo[nChangedFaces] = wallNormalInfo(norm);
141 // Do a wave of nLayers, transporting the index in patchNames
142 // (cannot use local patchIDs since we might get info from neighbouring
145 MeshWave<wallNormalInfo> regionCalc
153 regionCalc.iterate(nLayers);
156 // Now regionCalc should hold info on faces that are reachable from
157 // changedFaces within nLayers iterations. We use face info since that is
158 // guaranteed to be consistent across processor boundaries.
160 const List<wallNormalInfo>& faceInfo = regionCalc.allFaceInfo();
164 Info<< "wallLayerCells::getRefinement : dumping selected faces to "
165 << "selectedFaces.obj" << endl;
167 OFstream fcStream("selectedFaces.obj");
171 forAll(faceInfo, faceI)
173 const wallNormalInfo& info = faceInfo[faceI];
177 const face& f = mesh.faces()[faceI];
179 point mid(0.0, 0.0, 0.0);
183 mid += mesh.points()[f[fp]];
188 << "v " << mid.x() << ' ' << mid.y() << ' ' << mid.z()
192 point end(mid + info.normal());
195 << "v " << end.x() << ' ' << end.y() << ' ' << end.z()
199 fcStream << "l " << vertI << ' ' <<vertI-1 << endl;
206 // Copy meshWave information to List<refineCell>
211 DynamicList<refineCell> refineCells(3*nWalls);
213 const List<wallNormalInfo>& cellInfo = regionCalc.allCellInfo();
215 forAll(cellInfo, cellI)
217 const wallNormalInfo& info = cellInfo[cellI];
219 if (info.valid() && !usesCoupledPatch(cellI))
221 refineCells.append(refineCell(cellI, info.normal()));
225 // Transfer refineCells storage to this.
226 transfer(refineCells);
230 // ************************ vim: set sw=4 sts=4 et: ************************ //