regionToCell.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
00061
00062 void Foam::regionToCell::combine(topoSet& set, const bool add) const
00063 {
00064 label cellI = mesh_.findCell(insidePoint_);
00065
00066
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
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
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
00119 regionSplit regions(mesh_, blockedFace);
00120
00121
00122 label regionI = -1;
00123
00124 if (cellI != -1)
00125 {
00126
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
00146 const labelList regionCells(findIndices(regions, regionI));
00147
00148 forAll(regionCells, i)
00149 {
00150 addOrDelete(set, regionCells[i], add);
00151 }
00152 }
00153
00154
00155
00156
00157
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
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
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
00198
00199 Foam::regionToCell::~regionToCell()
00200 {}
00201
00202
00203
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