initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / sets / cellSources / regionToCell / regionToCell.C
blob51d3a74effddd176dae76b866867a7c8ecda3ef6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
28 #include "polyMesh.H"
29 #include "regionSplit.H"
30 #include "globalMeshData.H"
31 #include "cellSet.H"
32 #include "syncTools.H"
34 #include "addToRunTimeSelectionTable.H"
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 namespace Foam
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);
68     {
69         Info<< "Loading subset " << setName_ << " to delimit search region."
70             << endl;
71         cellSet subSet(mesh_, setName_);
73         boolList inSubset(mesh_.nCells(), false);
74         forAllConstIter(cellSet, subSet, iter)
75         {
76             inSubset[iter.key()] = true;
77         }
79         if (cellI != -1 && inSubset[cellI])
80         {
81             Pout<< "Point " << insidePoint_ << " is inside cellSet "
82                 << setName_ << endl
83                 << "Collecting all cells connected to " << cellI
84                 << " and inside cellSet " << setName_ << endl;
85         }
86         else
87         {
88             Pout<< "Point " << insidePoint_ << " is outside cellSet "
89                 << setName_ << endl
90                 << "Collecting all cells connected to " << cellI
91                 << " and outside cellSet " << setName_ << endl;
92         }
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++)
98         {
99              neiSet[faceI-nInt] = inSubset[mesh_.faceOwner()[faceI]];
100         }
101         syncTools::swapBoundaryFaceList(mesh_, neiSet, false);
103         // Find faces inbetween subSet and non-subset.
104         for (label faceI = 0; faceI < nInt; faceI++)
105         {
106             bool ownInSet = inSubset[mesh_.faceOwner()[faceI]];
107             bool neiInSet = inSubset[mesh_.faceNeighbour()[faceI]];
108             blockedFace[faceI] = (ownInSet != neiInSet);
109         }
110         for (label faceI = nInt; faceI < mesh_.nFaces(); faceI++)
111         {
112             bool ownInSet = inSubset[mesh_.faceOwner()[faceI]];
113             bool neiInSet = neiSet[faceI-nInt];
114             blockedFace[faceI] = (ownInSet != neiInSet);
115         }
116     }
118     // Find connected regions without crossing boundary of the cellset.
119     regionSplit regions(mesh_, blockedFace);
121     // Get the region containing the insidePoint
122     label regionI = -1;
124     if (cellI != -1)
125     {
126         // On processor that has found cell.
127         regionI = regions[cellI];
128     }
130     reduce(regionI, maxOp<label>());
132     if (regionI == -1)
133     {
134         WarningIn
135         (
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()
140             << endl;
141         return;
142     }
145     // Pick up the cells of the region
146     const labelList regionCells(findIndices(regions, regionI));
148     forAll(regionCells, i)
149     {
150         addOrDelete(set, regionCells[i], add);
151     }
155 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
157 // Construct from components
158 Foam::regionToCell::regionToCell
160     const polyMesh& mesh,
161     const word& setName,
162     const point& insidePoint
165     topoSetSource(mesh),
166     setName_(setName),
167     insidePoint_(insidePoint)
171 // Construct from dictionary
172 Foam::regionToCell::regionToCell
174     const polyMesh& mesh,
175     const dictionary& dict
178     topoSetSource(mesh),
179     setName_(dict.lookup("set")),
180     insidePoint_(dict.lookup("insidePoint"))
184 // Construct from Istream
185 Foam::regionToCell::regionToCell
187     const polyMesh& mesh,
188     Istream& is
191     topoSetSource(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,
208     topoSet& set
209 ) const
211     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
212     {
213         Info<< "    Adding all cells of connected region containing point "
214             << insidePoint_ << " ..." << endl;
216         combine(set, true);
217     }
218     else if (action == topoSetSource::DELETE)
219     {
220         Info<< "    Removing all cells of connected region containing point "
221             << insidePoint_ << " ..." << endl;
223         combine(set, false);
224     }
228 // ************************************************************************* //