1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "regionToCell.H"
28 #include "regionSplit.H"
29 #include "globalMeshData.H"
31 #include "syncTools.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(regionToCell, 0);
42 addToRunTimeSelectionTable(topoSetSource, regionToCell, word);
44 addToRunTimeSelectionTable(topoSetSource, regionToCell, istream);
49 Foam::topoSetSource::addToUsageTable Foam::regionToCell::usage_
51 regionToCell::typeName,
52 "\n Usage: regionToCell subCellSet (x y z)\n\n"
53 " Select all cells in the connected region containing point.\n"
54 " If started inside the subCellSet keeps to it;\n"
55 " if started outside stays outside.\n"
59 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
61 void Foam::regionToCell::combine(topoSet& set, const bool add) const
63 label cellI = mesh_.findCell(insidePoint_);
65 // Load the subset of cells
66 boolList blockedFace(mesh_.nFaces(), false);
68 Info<< "Loading subset " << setName_ << " to delimit search region."
70 cellSet subSet(mesh_, setName_);
72 boolList inSubset(mesh_.nCells(), false);
73 forAllConstIter(cellSet, subSet, iter)
75 inSubset[iter.key()] = true;
78 if (cellI != -1 && inSubset[cellI])
80 Pout<< "Point " << insidePoint_ << " is inside cellSet "
82 << "Collecting all cells connected to " << cellI
83 << " and inside cellSet " << setName_ << endl;
87 Pout<< "Point " << insidePoint_ << " is outside cellSet "
89 << "Collecting all cells connected to " << cellI
90 << " and outside cellSet " << setName_ << endl;
93 // Get coupled cell status
94 label nInt = mesh_.nInternalFaces();
95 boolList neiSet(mesh_.nFaces()-nInt, false);
96 for (label faceI = nInt; faceI < mesh_.nFaces(); faceI++)
98 neiSet[faceI-nInt] = inSubset[mesh_.faceOwner()[faceI]];
100 syncTools::swapBoundaryFaceList(mesh_, neiSet, false);
102 // Find faces inbetween subSet and non-subset.
103 for (label faceI = 0; faceI < nInt; faceI++)
105 bool ownInSet = inSubset[mesh_.faceOwner()[faceI]];
106 bool neiInSet = inSubset[mesh_.faceNeighbour()[faceI]];
107 blockedFace[faceI] = (ownInSet != neiInSet);
109 for (label faceI = nInt; faceI < mesh_.nFaces(); faceI++)
111 bool ownInSet = inSubset[mesh_.faceOwner()[faceI]];
112 bool neiInSet = neiSet[faceI-nInt];
113 blockedFace[faceI] = (ownInSet != neiInSet);
117 // Find connected regions without crossing boundary of the cellset.
118 regionSplit regions(mesh_, blockedFace);
120 // Get the region containing the insidePoint
125 // On processor that has found cell.
126 regionI = regions[cellI];
129 reduce(regionI, maxOp<label>());
135 "regionToCell::combine(topoSet&, const bool) const"
136 ) << "Point " << insidePoint_
137 << " is not inside the mesh." << nl
138 << "Bounding box of the mesh:" << mesh_.globalData().bb()
144 // Pick up the cells of the region
145 const labelList regionCells(findIndices(regions, regionI));
147 forAll(regionCells, i)
149 addOrDelete(set, regionCells[i], add);
154 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
156 // Construct from components
157 Foam::regionToCell::regionToCell
159 const polyMesh& mesh,
161 const point& insidePoint
166 insidePoint_(insidePoint)
170 // Construct from dictionary
171 Foam::regionToCell::regionToCell
173 const polyMesh& mesh,
174 const dictionary& dict
178 setName_(dict.lookup("set")),
179 insidePoint_(dict.lookup("insidePoint"))
183 // Construct from Istream
184 Foam::regionToCell::regionToCell
186 const polyMesh& mesh,
191 setName_(checkIs(is)),
192 insidePoint_(checkIs(is))
196 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
198 Foam::regionToCell::~regionToCell()
202 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
204 void Foam::regionToCell::applyToSet
206 const topoSetSource::setAction action,
210 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
212 Info<< " Adding all cells of connected region containing point "
213 << insidePoint_ << " ..." << endl;
217 else if (action == topoSetSource::DELETE)
219 Info<< " Removing all cells of connected region containing point "
220 << insidePoint_ << " ..." << endl;
227 // ************************************************************************* //