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

channelIndex.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 "channelIndex.H"
00028 #include "boolList.H"
00029 #include "syncTools.H"
00030 #include "OFstream.H"
00031 #include "meshTools.H"
00032 #include "Time.H"
00033 #include "SortableList.H"
00034 
00035 // * * * * * * * * * * * * * Static Member Data  * * * * * * * * * * * * * * //
00036 
00037 template<>
00038 const char* Foam::NamedEnum<Foam::vector::components, 3>::names[] =
00039 {
00040     "x",
00041     "y",
00042     "z"
00043 };
00044 
00045 const Foam::NamedEnum<Foam::vector::components, 3>
00046     Foam::channelIndex::vectorComponentsNames_;
00047 
00048 
00049 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00050 
00051 // Determines face blocking
00052 void Foam::channelIndex::walkOppositeFaces
00053 (
00054     const polyMesh& mesh,
00055     const labelList& startFaces,
00056     boolList& blockedFace
00057 )
00058 {
00059     const cellList& cells = mesh.cells();
00060     const faceList& faces = mesh.faces();
00061     label nBnd = mesh.nFaces() - mesh.nInternalFaces();
00062 
00063     DynamicList<label> frontFaces(startFaces);
00064     forAll(frontFaces, i)
00065     {
00066         label faceI = frontFaces[i];
00067         blockedFace[faceI] = true;
00068     }
00069 
00070     while (returnReduce(frontFaces.size(), sumOp<label>()) > 0)
00071     {
00072         // Transfer across.
00073         boolList isFrontBndFace(nBnd, false);
00074         forAll(frontFaces, i)
00075         {
00076             label faceI = frontFaces[i];
00077 
00078             if (!mesh.isInternalFace(faceI))
00079             {
00080                 isFrontBndFace[faceI-mesh.nInternalFaces()] = true;
00081             }
00082         }
00083         syncTools::swapBoundaryFaceList(mesh, isFrontBndFace, false);
00084 
00085         // Add 
00086         forAll(isFrontBndFace, i)
00087         {
00088             label faceI = mesh.nInternalFaces()+i;
00089             if (isFrontBndFace[i] && !blockedFace[faceI])
00090             {
00091                 blockedFace[faceI] = true;
00092                 frontFaces.append(faceI);
00093             }
00094         }
00095 
00096         // Transfer across cells
00097         DynamicList<label> newFrontFaces(frontFaces.size());
00098 
00099         forAll(frontFaces, i)
00100         {
00101             label faceI = frontFaces[i];
00102 
00103             {
00104                 const cell& ownCell = cells[mesh.faceOwner()[faceI]];
00105 
00106                 label oppositeFaceI = ownCell.opposingFaceLabel(faceI, faces);
00107 
00108                 if (oppositeFaceI == -1)
00109                 {
00110                     FatalErrorIn("channelIndex::walkOppositeFaces(..)")
00111                         << "Face:" << faceI << " owner cell:" << ownCell
00112                         << " is not a hex?" << abort(FatalError);
00113                 }
00114                 else
00115                 {
00116                     if (!blockedFace[oppositeFaceI])
00117                     {
00118                         blockedFace[oppositeFaceI] = true;
00119                         newFrontFaces.append(oppositeFaceI);
00120                     }
00121                 }
00122             }
00123 
00124             if (mesh.isInternalFace(faceI))
00125             {
00126                 const cell& neiCell = mesh.cells()[mesh.faceNeighbour()[faceI]];
00127 
00128                 label oppositeFaceI = neiCell.opposingFaceLabel(faceI, faces);
00129 
00130                 if (oppositeFaceI == -1)
00131                 {
00132                     FatalErrorIn("channelIndex::walkOppositeFaces(..)")
00133                         << "Face:" << faceI << " neighbour cell:" << neiCell
00134                         << " is not a hex?" << abort(FatalError);
00135                 }
00136                 else
00137                 {
00138                     if (!blockedFace[oppositeFaceI])
00139                     {
00140                         blockedFace[oppositeFaceI] = true;
00141                         newFrontFaces.append(oppositeFaceI);
00142                     }
00143                 }
00144             }
00145         }
00146 
00147         frontFaces.transfer(newFrontFaces);
00148     }
00149 }
00150 
00151 
00152 // Calculate regions.
00153 void Foam::channelIndex::calcLayeredRegions
00154 (
00155     const polyMesh& mesh,
00156     const labelList& startFaces
00157 )
00158 {
00159     boolList blockedFace(mesh.nFaces(), false);
00160     walkOppositeFaces
00161     (
00162         mesh,
00163         startFaces,
00164         blockedFace
00165     );
00166 
00167 
00168     if (false)
00169     {
00170         OFstream str(mesh.time().path()/"blockedFaces.obj");
00171         label vertI = 0;
00172         forAll(blockedFace, faceI)
00173         {
00174             if (blockedFace[faceI])
00175             {
00176                 const face& f = mesh.faces()[faceI];
00177                 forAll(f, fp)
00178                 {
00179                     meshTools::writeOBJ(str, mesh.points()[f[fp]]);
00180                 }
00181                 str<< 'f';
00182                 forAll(f, fp)
00183                 {
00184                     str << ' ' << vertI+fp+1;
00185                 }
00186                 str << nl;
00187                 vertI += f.size();
00188             }
00189         }
00190     }
00191 
00192 
00193     // Do analysis for connected regions
00194     cellRegion_.reset(new regionSplit(mesh, blockedFace));
00195 
00196     Info<< "Detected " << cellRegion_().nRegions() << " layers." << nl << endl;
00197 
00198     // Sum number of entries per region
00199     regionCount_ = regionSum(scalarField(mesh.nCells(), 1.0));
00200 
00201     // Average cell centres to determine ordering.
00202     pointField regionCc
00203     (
00204         regionSum(mesh.cellCentres())
00205       / regionCount_
00206     );
00207 
00208     SortableList<scalar> sortComponent(regionCc.component(dir_));
00209 
00210     sortMap_ = sortComponent.indices();
00211 
00212     y_ = sortComponent;
00213 
00214     if (symmetric_)
00215     {
00216         y_.setSize(cellRegion_().nRegions()/2);
00217     }
00218 }
00219 
00220 
00221 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00222 
00223 Foam::channelIndex::channelIndex
00224 (
00225     const polyMesh& mesh,
00226     const dictionary& dict
00227 )
00228 :
00229     symmetric_(readBool(dict.lookup("symmetric"))),
00230     dir_(vectorComponentsNames_.read(dict.lookup("component")))
00231 {
00232     const polyBoundaryMesh& patches = mesh.boundaryMesh();
00233 
00234     const wordList patchNames(dict.lookup("patches"));
00235 
00236     label nFaces = 0;
00237 
00238     forAll(patchNames, i)
00239     {
00240         label patchI = patches.findPatchID(patchNames[i]);
00241 
00242         if (patchI == -1)
00243         {
00244             FatalErrorIn("channelIndex::channelIndex(const polyMesh&)")
00245                 << "Illegal patch " << patchNames[i]
00246                 << ". Valid patches are " << patches.name()
00247                 << exit(FatalError);
00248         }
00249 
00250         nFaces += patches[patchI].size();
00251     }
00252 
00253     labelList startFaces(nFaces);
00254     nFaces = 0;
00255 
00256     forAll(patchNames, i)
00257     {
00258         const polyPatch& pp = patches[patches.findPatchID(patchNames[i])];
00259 
00260         forAll(pp, j)
00261         {
00262             startFaces[nFaces++] = pp.start()+j;
00263         }
00264     }
00265 
00266     // Calculate regions.
00267     calcLayeredRegions(mesh, startFaces);
00268 }
00269 
00270 
00271 Foam::channelIndex::channelIndex
00272 (
00273     const polyMesh& mesh,
00274     const labelList& startFaces,
00275     const bool symmetric,
00276     const direction dir
00277 )
00278 :
00279     symmetric_(symmetric),
00280     dir_(dir)
00281 {
00282     // Calculate regions.
00283     calcLayeredRegions(mesh, startFaces);
00284 }
00285 
00286 
00287 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00288 
00289 
00290 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00291 
00292 
00293 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd