twoPhaseEulerFoam:frictionalStressModel/Schaeffer: Correct mut on processor boundaries
[OpenFOAM-1.7.x.git] / src / meshTools / sets / cellSources / regionToCell / regionToCell.C
blobbaed0c8d93d17e0eea5cdf7d5d9801b84c0ae98b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2010 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
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
19     for more details.
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"
27 #include "polyMesh.H"
28 #include "regionSplit.H"
29 #include "globalMeshData.H"
30 #include "cellSet.H"
31 #include "syncTools.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 namespace Foam
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);
67     {
68         Info<< "Loading subset " << setName_ << " to delimit search region."
69             << endl;
70         cellSet subSet(mesh_, setName_);
72         boolList inSubset(mesh_.nCells(), false);
73         forAllConstIter(cellSet, subSet, iter)
74         {
75             inSubset[iter.key()] = true;
76         }
78         if (cellI != -1 && inSubset[cellI])
79         {
80             Pout<< "Point " << insidePoint_ << " is inside cellSet "
81                 << setName_ << endl
82                 << "Collecting all cells connected to " << cellI
83                 << " and inside cellSet " << setName_ << endl;
84         }
85         else
86         {
87             Pout<< "Point " << insidePoint_ << " is outside cellSet "
88                 << setName_ << endl
89                 << "Collecting all cells connected to " << cellI
90                 << " and outside cellSet " << setName_ << endl;
91         }
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++)
97         {
98              neiSet[faceI-nInt] = inSubset[mesh_.faceOwner()[faceI]];
99         }
100         syncTools::swapBoundaryFaceList(mesh_, neiSet, false);
102         // Find faces inbetween subSet and non-subset.
103         for (label faceI = 0; faceI < nInt; faceI++)
104         {
105             bool ownInSet = inSubset[mesh_.faceOwner()[faceI]];
106             bool neiInSet = inSubset[mesh_.faceNeighbour()[faceI]];
107             blockedFace[faceI] = (ownInSet != neiInSet);
108         }
109         for (label faceI = nInt; faceI < mesh_.nFaces(); faceI++)
110         {
111             bool ownInSet = inSubset[mesh_.faceOwner()[faceI]];
112             bool neiInSet = neiSet[faceI-nInt];
113             blockedFace[faceI] = (ownInSet != neiInSet);
114         }
115     }
117     // Find connected regions without crossing boundary of the cellset.
118     regionSplit regions(mesh_, blockedFace);
120     // Get the region containing the insidePoint
121     label regionI = -1;
123     if (cellI != -1)
124     {
125         // On processor that has found cell.
126         regionI = regions[cellI];
127     }
129     reduce(regionI, maxOp<label>());
131     if (regionI == -1)
132     {
133         WarningIn
134         (
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()
139             << endl;
140         return;
141     }
144     // Pick up the cells of the region
145     const labelList regionCells(findIndices(regions, regionI));
147     forAll(regionCells, i)
148     {
149         addOrDelete(set, regionCells[i], add);
150     }
154 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
156 // Construct from components
157 Foam::regionToCell::regionToCell
159     const polyMesh& mesh,
160     const word& setName,
161     const point& insidePoint
164     topoSetSource(mesh),
165     setName_(setName),
166     insidePoint_(insidePoint)
170 // Construct from dictionary
171 Foam::regionToCell::regionToCell
173     const polyMesh& mesh,
174     const dictionary& dict
177     topoSetSource(mesh),
178     setName_(dict.lookup("set")),
179     insidePoint_(dict.lookup("insidePoint"))
183 // Construct from Istream
184 Foam::regionToCell::regionToCell
186     const polyMesh& mesh,
187     Istream& is
190     topoSetSource(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,
207     topoSet& set
208 ) const
210     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
211     {
212         Info<< "    Adding all cells of connected region containing point "
213             << insidePoint_ << " ..." << endl;
215         combine(set, true);
216     }
217     else if (action == topoSetSource::DELETE)
218     {
219         Info<< "    Removing all cells of connected region containing point "
220             << insidePoint_ << " ..." << endl;
222         combine(set, false);
223     }
227 // ************************************************************************* //