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

regionToCell.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 "regionToCell.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <meshTools/regionSplit.H>
00029 #include <OpenFOAM/globalMeshData.H>
00030 #include <meshTools/cellSet.H>
00031 #include <OpenFOAM/syncTools.H>
00032 
00033 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00034 
00035 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039 
00040 defineTypeNameAndDebug(regionToCell, 0);
00041 
00042 addToRunTimeSelectionTable(topoSetSource, regionToCell, word);
00043 
00044 addToRunTimeSelectionTable(topoSetSource, regionToCell, istream);
00045 
00046 }
00047 
00048 
00049 Foam::topoSetSource::addToUsageTable Foam::regionToCell::usage_
00050 (
00051     regionToCell::typeName,
00052     "\n    Usage: regionToCell subCellSet (x y z)\n\n"
00053     "    Select all cells in the connected region containing point.\n"
00054     "    If started inside the subCellSet keeps to it;\n"
00055     "    if started outside stays outside.\n"
00056 );
00057 
00058 
00059 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00060 
00061 void Foam::regionToCell::combine(topoSet& set, const bool add) const
00062 {
00063     label cellI = mesh_.findCell(insidePoint_);
00064 
00065     // Load the subset of cells
00066     boolList blockedFace(mesh_.nFaces(), false);
00067     {
00068         Info<< "Loading subset " << setName_ << " to delimit search region."
00069             << endl;
00070         cellSet subSet(mesh_, setName_);
00071 
00072         boolList inSubset(mesh_.nCells(), false);
00073         forAllConstIter(cellSet, subSet, iter)
00074         {
00075             inSubset[iter.key()] = true;
00076         }
00077 
00078         if (cellI != -1 && inSubset[cellI])
00079         {
00080             Pout<< "Point " << insidePoint_ << " is inside cellSet "
00081                 << setName_ << endl
00082                 << "Collecting all cells connected to " << cellI
00083                 << " and inside cellSet " << setName_ << endl;
00084         }
00085         else
00086         {
00087             Pout<< "Point " << insidePoint_ << " is outside cellSet "
00088                 << setName_ << endl
00089                 << "Collecting all cells connected to " << cellI
00090                 << " and outside cellSet " << setName_ << endl;
00091         }
00092 
00093         // Get coupled cell status
00094         label nInt = mesh_.nInternalFaces();
00095         boolList neiSet(mesh_.nFaces()-nInt, false);
00096         for (label faceI = nInt; faceI < mesh_.nFaces(); faceI++)
00097         {
00098              neiSet[faceI-nInt] = inSubset[mesh_.faceOwner()[faceI]];
00099         }
00100         syncTools::swapBoundaryFaceList(mesh_, neiSet, false);
00101 
00102         // Find faces inbetween subSet and non-subset.
00103         for (label faceI = 0; faceI < nInt; faceI++)
00104         {
00105             bool ownInSet = inSubset[mesh_.faceOwner()[faceI]];
00106             bool neiInSet = inSubset[mesh_.faceNeighbour()[faceI]];
00107             blockedFace[faceI] = (ownInSet != neiInSet);
00108         }
00109         for (label faceI = nInt; faceI < mesh_.nFaces(); faceI++)
00110         {
00111             bool ownInSet = inSubset[mesh_.faceOwner()[faceI]];
00112             bool neiInSet = neiSet[faceI-nInt];
00113             blockedFace[faceI] = (ownInSet != neiInSet);
00114         }
00115     }
00116 
00117     // Find connected regions without crossing boundary of the cellset.
00118     regionSplit regions(mesh_, blockedFace);
00119 
00120     // Get the region containing the insidePoint
00121     label regionI = -1;
00122 
00123     if (cellI != -1)
00124     {
00125         // On processor that has found cell.
00126         regionI = regions[cellI];
00127     }
00128 
00129     reduce(regionI, maxOp<label>());
00130 
00131     if (regionI == -1)
00132     {
00133         WarningIn
00134         (
00135             "regionToCell::combine(topoSet&, const bool) const"
00136         )   << "Point " << insidePoint_
00137             << " is not inside the mesh." << nl
00138             << "Bounding box of the mesh:" << mesh_.globalData().bb()
00139             << endl;
00140         return;
00141     }
00142 
00143 
00144     // Pick up the cells of the region
00145     const labelList regionCells(findIndices(regions, regionI));
00146 
00147     forAll(regionCells, i)
00148     {
00149         addOrDelete(set, regionCells[i], add);
00150     }
00151 }
00152 
00153 
00154 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00155 
00156 // Construct from components
00157 Foam::regionToCell::regionToCell
00158 (
00159     const polyMesh& mesh,
00160     const word& setName,
00161     const point& insidePoint
00162 )
00163 :
00164     topoSetSource(mesh),
00165     setName_(setName),
00166     insidePoint_(insidePoint)
00167 {}
00168 
00169 
00170 // Construct from dictionary
00171 Foam::regionToCell::regionToCell
00172 (
00173     const polyMesh& mesh,
00174     const dictionary& dict
00175 )
00176 :
00177     topoSetSource(mesh),
00178     setName_(dict.lookup("set")),
00179     insidePoint_(dict.lookup("insidePoint"))
00180 {}
00181 
00182 
00183 // Construct from Istream
00184 Foam::regionToCell::regionToCell
00185 (
00186     const polyMesh& mesh,
00187     Istream& is
00188 )
00189 :
00190     topoSetSource(mesh),
00191     setName_(checkIs(is)),
00192     insidePoint_(checkIs(is))
00193 {}
00194 
00195 
00196 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00197 
00198 Foam::regionToCell::~regionToCell()
00199 {}
00200 
00201 
00202 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00203 
00204 void Foam::regionToCell::applyToSet
00205 (
00206     const topoSetSource::setAction action,
00207     topoSet& set
00208 ) const
00209 {
00210     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00211     {
00212         Info<< "    Adding all cells of connected region containing point "
00213             << insidePoint_ << " ..." << endl;
00214 
00215         combine(set, true);
00216     }
00217     else if (action == topoSetSource::DELETE)
00218     {
00219         Info<< "    Removing all cells of connected region containing point "
00220             << insidePoint_ << " ..." << endl;
00221 
00222         combine(set, false);
00223     }
00224 }
00225 
00226 
00227 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines