OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

wallLayerCells.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "wallLayerCells.H"
00028 #include "DynamicList.H"
00029 #include "MeshWave.H"
00030 #include "wallNormalInfo.H"
00031 #include "OFstream.H"
00032 
00033 
00034 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038 
00039 defineTypeNameAndDebug(wallLayerCells, 0);
00040 
00041 }
00042 
00043 
00044 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00045 
00046 bool Foam::wallLayerCells::usesCoupledPatch(const label cellI) const
00047 {
00048     const polyBoundaryMesh& patches = mesh().boundaryMesh();
00049 
00050     const cell& cFaces = mesh().cells()[cellI];
00051 
00052     forAll(cFaces, cFaceI)
00053     {
00054         label faceI = cFaces[cFaceI];
00055 
00056         label patchID = patches.whichPatch(faceI);
00057 
00058         if ((patchID >= 0) && (patches[patchID].coupled()))
00059         {
00060             return true;
00061         }
00062     }
00063     return false;
00064 }
00065 
00066 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00067 
00068 // Construct from components
00069 Foam::wallLayerCells::wallLayerCells
00070 (
00071     const polyMesh& mesh,
00072     const List<word>& patchNames,
00073     const label nLayers
00074 )
00075 :
00076     edgeVertex(mesh),
00077     List<refineCell>()
00078 {
00079     // Find out cells connected to walls.
00080 
00081     const polyPatchList& patches = mesh.boundaryMesh();
00082 
00083     // Make map from name to local patch ID
00084     HashTable<label> patchNameToIndex(patches.size());
00085 
00086     forAll(patches, patchI)
00087     {
00088         patchNameToIndex.insert(patches[patchI].name(), patchI);
00089     }
00090 
00091 
00092     // Count size of walls to set
00093     label nWalls = 0;
00094 
00095     forAll(patchNames, patchNameI)
00096     {
00097         const word& name = patchNames[patchNameI];
00098 
00099         if (patchNameToIndex.found(name))
00100         {
00101             label patchI = patchNameToIndex[name];
00102 
00103             nWalls += patches[patchI].size();
00104         }
00105     }
00106 
00107     // Allocate storage for start of wave on faces
00108     List<wallNormalInfo> changedFacesInfo(nWalls);
00109     labelList changedFaces(nWalls);
00110 
00111     // Fill changedFaces info
00112     label nChangedFaces = 0;
00113 
00114     forAll(patchNames, patchNameI)
00115     {
00116         const word& name = patchNames[patchNameI];
00117 
00118         if (patchNameToIndex.found(name))
00119         {
00120             label patchI = patchNameToIndex[name];
00121 
00122             const polyPatch& pp = patches[patchI];
00123 
00124             forAll(pp, patchFaceI)
00125             {
00126                 label meshFaceI = pp.start() + patchFaceI;
00127 
00128                 changedFaces[nChangedFaces] = meshFaceI;
00129 
00130                 // Set transported information to the wall normal.
00131                 const vector& norm = pp.faceNormals()[patchFaceI];
00132 
00133                 changedFacesInfo[nChangedFaces] = wallNormalInfo(norm);
00134 
00135                 nChangedFaces++;
00136             }
00137         }
00138     }
00139 
00140 
00141     // Do a wave of nLayers, transporting the index in patchNames
00142     // (cannot use local patchIDs since we might get info from neighbouring
00143     //  processor)
00144 
00145     MeshWave<wallNormalInfo> regionCalc
00146     (
00147         mesh,
00148         changedFaces,
00149         changedFacesInfo,
00150         0
00151     );
00152 
00153     regionCalc.iterate(nLayers);
00154 
00155 
00156     // Now regionCalc should hold info on faces that are reachable from
00157     // changedFaces within nLayers iterations. We use face info since that is
00158     // guaranteed to be consistent across processor boundaries.
00159 
00160     const List<wallNormalInfo>& faceInfo = regionCalc.allFaceInfo();
00161 
00162     if (debug)
00163     {
00164         Info<< "wallLayerCells::getRefinement : dumping selected faces to "
00165             << "selectedFaces.obj" << endl;
00166 
00167         OFstream fcStream("selectedFaces.obj");
00168 
00169         label vertI = 0;
00170 
00171         forAll(faceInfo, faceI)
00172         {
00173             const wallNormalInfo& info = faceInfo[faceI];
00174 
00175             if (info.valid())
00176             {
00177                 const face& f = mesh.faces()[faceI];
00178 
00179                 point mid(0.0, 0.0, 0.0);
00180 
00181                 forAll(f, fp)
00182                 {
00183                     mid += mesh.points()[f[fp]];
00184                 }
00185                 mid /= f.size();
00186 
00187                 fcStream
00188                     << "v " << mid.x() << ' ' << mid.y() << ' ' << mid.z()
00189                     << endl;
00190                 vertI++;
00191 
00192                 point end(mid + info.normal());
00193 
00194                 fcStream
00195                     << "v " << end.x() << ' ' << end.y() << ' ' << end.z()
00196                     << endl;
00197                 vertI++;
00198 
00199                 fcStream << "l " << vertI << ' ' <<vertI-1 << endl;
00200             }
00201         }
00202     }
00203 
00204 
00205     //
00206     // Copy meshWave information to List<refineCell>
00207     //
00208 
00209     // Estimate size
00210 
00211     DynamicList<refineCell> refineCells(3*nWalls);
00212 
00213     const List<wallNormalInfo>& cellInfo = regionCalc.allCellInfo();
00214 
00215     forAll(cellInfo, cellI)
00216     {
00217         const wallNormalInfo& info = cellInfo[cellI];
00218 
00219         if (info.valid() && !usesCoupledPatch(cellI))
00220         {
00221             refineCells.append(refineCell(cellI, info.normal()));
00222         }
00223     }
00224 
00225     // Transfer refineCells storage to this.
00226     transfer(refineCells);
00227 }
00228 
00229 
00230 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd