FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "wallLayerCells.H"
00027 #include <OpenFOAM/DynamicList.H>
00028 #include <OpenFOAM/MeshWave.H>
00029 #include <dynamicMesh/wallNormalInfo.H>
00030 #include <OpenFOAM/OFstream.H>
00031 
00032 
00033 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 
00038 defineTypeNameAndDebug(wallLayerCells, 0);
00039 
00040 }
00041 
00042 
00043 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00044 
00045 bool Foam::wallLayerCells::usesCoupledPatch(const label cellI) const
00046 {
00047     const polyBoundaryMesh& patches = mesh().boundaryMesh();
00048 
00049     const cell& cFaces = mesh().cells()[cellI];
00050 
00051     forAll(cFaces, cFaceI)
00052     {
00053         label faceI = cFaces[cFaceI];
00054 
00055         label patchID = patches.whichPatch(faceI);
00056 
00057         if ((patchID >= 0) && (patches[patchID].coupled()))
00058         {
00059             return true;
00060         }
00061     }
00062     return false;
00063 }
00064 
00065 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00066 
00067 // Construct from components
00068 Foam::wallLayerCells::wallLayerCells
00069 (
00070     const polyMesh& mesh,
00071     const List<word>& patchNames,
00072     const label nLayers
00073 )
00074 :
00075     edgeVertex(mesh),
00076     List<refineCell>()
00077 {
00078     // Find out cells connected to walls.
00079 
00080     const polyPatchList& patches = mesh.boundaryMesh();
00081 
00082     // Make map from name to local patch ID
00083     HashTable<label> patchNameToIndex(patches.size());
00084 
00085     forAll(patches, patchI)
00086     {
00087         patchNameToIndex.insert(patches[patchI].name(), patchI);
00088     }
00089 
00090 
00091     // Count size of walls to set
00092     label nWalls = 0;
00093 
00094     forAll(patchNames, patchNameI)
00095     {
00096         const word& name = patchNames[patchNameI];
00097 
00098         if (patchNameToIndex.found(name))
00099         {
00100             label patchI = patchNameToIndex[name];
00101 
00102             nWalls += patches[patchI].size();
00103         }
00104     }
00105 
00106     // Allocate storage for start of wave on faces
00107     List<wallNormalInfo> changedFacesInfo(nWalls);
00108     labelList changedFaces(nWalls);
00109 
00110     // Fill changedFaces info
00111     label nChangedFaces = 0;
00112 
00113     forAll(patchNames, patchNameI)
00114     {
00115         const word& name = patchNames[patchNameI];
00116 
00117         if (patchNameToIndex.found(name))
00118         {
00119             label patchI = patchNameToIndex[name];
00120 
00121             const polyPatch& pp = patches[patchI];
00122 
00123             forAll(pp, patchFaceI)
00124             {
00125                 label meshFaceI = pp.start() + patchFaceI;
00126 
00127                 changedFaces[nChangedFaces] = meshFaceI;
00128 
00129                 // Set transported information to the wall normal.
00130                 const vector& norm = pp.faceNormals()[patchFaceI];
00131 
00132                 changedFacesInfo[nChangedFaces] = wallNormalInfo(norm);
00133 
00134                 nChangedFaces++;
00135             }
00136         }
00137     }
00138 
00139 
00140     // Do a wave of nLayers, transporting the index in patchNames
00141     // (cannot use local patchIDs since we might get info from neighbouring
00142     //  processor)
00143 
00144     MeshWave<wallNormalInfo> regionCalc
00145     (
00146         mesh,
00147         changedFaces,
00148         changedFacesInfo,
00149         0
00150     );
00151 
00152     regionCalc.iterate(nLayers);
00153 
00154 
00155     // Now regionCalc should hold info on faces that are reachable from
00156     // changedFaces within nLayers iterations. We use face info since that is
00157     // guaranteed to be consistent across processor boundaries.
00158 
00159     const List<wallNormalInfo>& faceInfo = regionCalc.allFaceInfo();
00160 
00161     if (debug)
00162     {
00163         Info<< "wallLayerCells::getRefinement : dumping selected faces to "
00164             << "selectedFaces.obj" << endl;
00165 
00166         OFstream fcStream("selectedFaces.obj");
00167 
00168         label vertI = 0;
00169 
00170         forAll(faceInfo, faceI)
00171         {
00172             const wallNormalInfo& info = faceInfo[faceI];
00173 
00174             if (info.valid())
00175             {
00176                 const face& f = mesh.faces()[faceI];
00177 
00178                 point mid(0.0, 0.0, 0.0);
00179 
00180                 forAll(f, fp)
00181                 {
00182                     mid += mesh.points()[f[fp]];
00183                 }
00184                 mid /= f.size();
00185 
00186                 fcStream
00187                     << "v " << mid.x() << ' ' << mid.y() << ' ' << mid.z()
00188                     << endl;
00189                 vertI++;
00190 
00191                 point end(mid + info.normal());
00192 
00193                 fcStream
00194                     << "v " << end.x() << ' ' << end.y() << ' ' << end.z()
00195                     << endl;
00196                 vertI++;
00197 
00198                 fcStream << "l " << vertI << ' ' <<vertI-1 << endl;
00199             }
00200         }
00201     }
00202 
00203 
00204     //
00205     // Copy meshWave information to List<refineCell>
00206     //
00207 
00208     // Estimate size
00209 
00210     DynamicList<refineCell> refineCells(3*nWalls);
00211 
00212     const List<wallNormalInfo>& cellInfo = regionCalc.allCellInfo();
00213 
00214     forAll(cellInfo, cellI)
00215     {
00216         const wallNormalInfo& info = cellInfo[cellI];
00217 
00218         if (info.valid() && !usesCoupledPatch(cellI))
00219         {
00220             refineCells.append(refineCell(cellI, info.normal()));
00221         }
00222     }
00223 
00224     // Transfer refineCells storage to this.
00225     transfer(refineCells);
00226 }
00227 
00228 
00229 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines