initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / dynamicMesh / meshCut / wallLayerCells / wallLayerCells.C
blobfaccc951617eeb4e6e49b3da2c1561d694d7cd79
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 "DynamicList.H"
29 #include "MeshWave.H"
30 #include "wallNormalInfo.H"
31 #include "OFstream.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 namespace Foam
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)
53     {
54         label faceI = cFaces[cFaceI];
56         label patchID = patches.whichPatch(faceI);
58         if ((patchID >= 0) && (patches[patchID].coupled()))
59         {
60             return true;
61         }
62     }
63     return false;
66 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
68 // Construct from components
69 Foam::wallLayerCells::wallLayerCells
71     const polyMesh& mesh,
72     const List<word>& patchNames,
73     const label nLayers
76     edgeVertex(mesh),
77     List<refineCell>()
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)
87     {
88         patchNameToIndex.insert(patches[patchI].name(), patchI);
89     }
92     // Count size of walls to set
93     label nWalls = 0;
95     forAll(patchNames, patchNameI)
96     {
97         const word& name = patchNames[patchNameI];
99         if (patchNameToIndex.found(name))
100         {
101             label patchI = patchNameToIndex[name];
103             nWalls += patches[patchI].size();
104         }
105     }
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)
115     {
116         const word& name = patchNames[patchNameI];
118         if (patchNameToIndex.found(name))
119         {
120             label patchI = patchNameToIndex[name];
122             const polyPatch& pp = patches[patchI];
124             forAll(pp, patchFaceI)
125             {
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);
135                 nChangedFaces++;
136             }
137         }
138     }
141     // Do a wave of nLayers, transporting the index in patchNames
142     // (cannot use local patchIDs since we might get info from neighbouring
143     //  processor)
145     MeshWave<wallNormalInfo> regionCalc
146     (
147         mesh,
148         changedFaces,
149         changedFacesInfo,
150         0
151     );
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();
162     if (debug)
163     {
164         Info<< "wallLayerCells::getRefinement : dumping selected faces to "
165             << "selectedFaces.obj" << endl;
167         OFstream fcStream("selectedFaces.obj");
169         label vertI = 0;
171         forAll(faceInfo, faceI)
172         {
173             const wallNormalInfo& info = faceInfo[faceI];
175             if (info.valid())
176             {
177                 const face& f = mesh.faces()[faceI];
179                 point mid(0.0, 0.0, 0.0);
181                 forAll(f, fp)
182                 {
183                     mid += mesh.points()[f[fp]];
184                 }
185                 mid /= f.size();
187                 fcStream
188                     << "v " << mid.x() << ' ' << mid.y() << ' ' << mid.z()
189                     << endl;
190                 vertI++;
192                 point end(mid + info.normal());
194                 fcStream
195                     << "v " << end.x() << ' ' << end.y() << ' ' << end.z()
196                     << endl;
197                 vertI++;
199                 fcStream << "l " << vertI << ' ' <<vertI-1 << endl;
200             }
201         }
202     }
205     //
206     // Copy meshWave information to List<refineCell>
207     //
209     // Estimate size
211     DynamicList<refineCell> refineCells(3*nWalls);
213     const List<wallNormalInfo>& cellInfo = regionCalc.allCellInfo();
215     forAll(cellInfo, cellI)
216     {
217         const wallNormalInfo& info = cellInfo[cellI];
219         if (info.valid() && !usesCoupledPatch(cellI))
220         {
221             refineCells.append(refineCell(cellI, info.normal()));
222         }
223     }
225     // Transfer refineCells storage to this.
226     transfer(refineCells);
230 // ************************************************************************* //