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

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