1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "regionToCell.H"
29 #include "regionSplit.H"
30 #include "globalMeshData.H"
32 #include "syncTools.H"
34 #include "addToRunTimeSelectionTable.H"
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 defineTypeNameAndDebug(regionToCell, 0);
43 addToRunTimeSelectionTable(topoSetSource, regionToCell, word);
45 addToRunTimeSelectionTable(topoSetSource, regionToCell, istream);
50 Foam::topoSetSource::addToUsageTable Foam::regionToCell::usage_
52 regionToCell::typeName,
53 "\n Usage: regionToCell subCellSet (x y z)\n\n"
54 " Select all cells in the connected region containing point.\n"
55 " If started inside the subCellSet keeps to it;\n"
56 " if started outside stays outside.\n"
60 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
62 void Foam::regionToCell::combine(topoSet& set, const bool add) const
64 label cellI = mesh_.findCell(insidePoint_);
66 // Load the subset of cells
67 boolList blockedFace(mesh_.nFaces(), false);
69 Info<< "Loading subset " << setName_ << " to delimit search region."
71 cellSet subSet(mesh_, setName_);
73 boolList inSubset(mesh_.nCells(), false);
74 forAllConstIter(cellSet, subSet, iter)
76 inSubset[iter.key()] = true;
79 if (cellI != -1 && inSubset[cellI])
81 Pout<< "Point " << insidePoint_ << " is inside cellSet "
83 << "Collecting all cells connected to " << cellI
84 << " and inside cellSet " << setName_ << endl;
88 Pout<< "Point " << insidePoint_ << " is outside cellSet "
90 << "Collecting all cells connected to " << cellI
91 << " and outside cellSet " << setName_ << endl;
94 // Get coupled cell status
95 label nInt = mesh_.nInternalFaces();
96 boolList neiSet(mesh_.nFaces()-nInt, false);
97 for (label faceI = nInt; faceI < mesh_.nFaces(); faceI++)
99 neiSet[faceI-nInt] = inSubset[mesh_.faceOwner()[faceI]];
101 syncTools::swapBoundaryFaceList(mesh_, neiSet, false);
103 // Find faces inbetween subSet and non-subset.
104 for (label faceI = 0; faceI < nInt; faceI++)
106 bool ownInSet = inSubset[mesh_.faceOwner()[faceI]];
107 bool neiInSet = inSubset[mesh_.faceNeighbour()[faceI]];
108 blockedFace[faceI] = (ownInSet != neiInSet);
110 for (label faceI = nInt; faceI < mesh_.nFaces(); faceI++)
112 bool ownInSet = inSubset[mesh_.faceOwner()[faceI]];
113 bool neiInSet = neiSet[faceI-nInt];
114 blockedFace[faceI] = (ownInSet != neiInSet);
118 // Find connected regions without crossing boundary of the cellset.
119 regionSplit regions(mesh_, blockedFace);
121 // Get the region containing the insidePoint
126 // On processor that has found cell.
127 regionI = regions[cellI];
130 reduce(regionI, maxOp<label>());
136 "regionToCell::combine(topoSet&, const bool) const"
137 ) << "Point " << insidePoint_
138 << " is not inside the mesh." << nl
139 << "Bounding box of the mesh:" << mesh_.globalData().bb()
145 // Pick up the cells of the region
146 const labelList regionCells(findIndices(regions, regionI));
148 forAll(regionCells, i)
150 addOrDelete(set, regionCells[i], add);
155 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
157 // Construct from components
158 Foam::regionToCell::regionToCell
160 const polyMesh& mesh,
162 const point& insidePoint
167 insidePoint_(insidePoint)
171 // Construct from dictionary
172 Foam::regionToCell::regionToCell
174 const polyMesh& mesh,
175 const dictionary& dict
179 setName_(dict.lookup("set")),
180 insidePoint_(dict.lookup("insidePoint"))
184 // Construct from Istream
185 Foam::regionToCell::regionToCell
187 const polyMesh& mesh,
192 setName_(checkIs(is)),
193 insidePoint_(checkIs(is))
197 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
199 Foam::regionToCell::~regionToCell()
203 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
205 void Foam::regionToCell::applyToSet
207 const topoSetSource::setAction action,
211 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
213 Info<< " Adding all cells of connected region containing point "
214 << insidePoint_ << " ..." << endl;
218 else if (action == topoSetSource::DELETE)
220 Info<< " Removing all cells of connected region containing point "
221 << insidePoint_ << " ..." << endl;
228 // ************************************************************************* //